package cn.estsh.i3plus.ext.mes.apiservice.controller.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataPushNotifyService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxPushDataNotifyParamAssistModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.model.platform.PushDataNotifyModel;
import cn.estsh.impp.framework.base.controller.MesBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES)
@Api(tags = "生产数据推送通知数据处理控制层")
public class SxProdDataPushNotifyController extends MesBaseController {

    @Autowired
    private ISxProdDataPushNotifyService prodDataPushNotifyService;

    @PostMapping(value = "/sx/ext/prod-data-push-notify/exec")
    @ApiOperation(value = "生产数据推送通知数据处理")
    public ResultBean execProdDataPushNotify(@RequestBody PushDataNotifyModel data) {
        try {
            ValidatorBean.beginValid(data)
                    .notNull(MesExtConstWords.PUSH_NAME, data.getPushName())
                    .notNull(MesExtConstWords.PUSH_PARAM, data.getPushParam())
                    .notNull(MesExtConstWords.PUSH_TYPE, data.getPushType());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(prodDataPushNotifyService.execProdDataPushNotify(data));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    public static void main(String[] args) {
        SxPushDataNotifyParamAssistModel param = new SxPushDataNotifyParamAssistModel();
        param.setOrganizeCode("CKF1");
        param.setStrategyClass("sxProdDataPushNotifyStrategyAssistService");
        param.setFlag("1");
        param.setOwnerDepartment("10");
        param.setOwnerDepartmentName("营业");
        PushDataNotifyModel model = new PushDataNotifyModel();
        model.setPushName("111");
        model.setPushType(10);
        model.setPushParam(JSONObject.toJSONString(param));
        System.out.println(JSONObject.toJSONString(model));
    }

}
