package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.base;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IProjectTourConfirmService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProjectTourDetail;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesPcnBaseController;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@Api(tags = "工程巡回确认")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/project-tour-data")
public class ProjectTourController extends MesPcnBaseController {
    public static final Logger LOGGER = LoggerFactory.getLogger(ProjectTourController.class);

    @Autowired
    private IProjectTourConfirmService projectTourConfirmService;


    /**
     * 查询工程巡回确认明细
     *
     * @param projectTourDetail
     * @return
     */
    @GetMapping(value = "/query")
    @ApiOperation(value = "查询工程巡回确认明细")
    public ResultBean queryProjectTourConfirm(MesProjectTourDetail projectTourDetail) {
        try {
            return ResultBean.success("查询成功").setResultList(projectTourConfirmService.queryProjectTourConfirm(projectTourDetail))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 工程巡回确认作业
     *
     * @param projectTourDetail
     * @return
     */
    @PutMapping(value = "/update")
    @ApiOperation(value = "工程巡回确认作业")
    public ResultBean updateProjectTourConfirm(MesProjectTourDetail projectTourDetail) {
        try {
            projectTourConfirmService.updateProjectTourConfirm(projectTourDetail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
