package cn.com.goldenwater.dcproj.controller.rsvryn; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.model.AttRsBase; import cn.com.goldenwater.dcproj.model.BisInspRsvrynRgstr; import cn.com.goldenwater.dcproj.model.BisInspRsvrynRgstrChkInfo; import cn.com.goldenwater.dcproj.param.BisInspRsvrynRgstrChkInfoParam; import cn.com.goldenwater.dcproj.service.AttRsBaseService; import cn.com.goldenwater.dcproj.service.BisInspRsvrynRgstrChkInfoService; import cn.com.goldenwater.dcproj.service.BisInspRsvrynRgstrService; import cn.com.goldenwater.dcproj.utils.Constant; import cn.com.goldenwater.id.util.UuidUtil; import cn.com.goldenwater.target.CheckException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.Optional; import static cn.com.goldenwater.dcproj.util.CheckUtil.notEmpty; /** * @author lune * @date 2021年4月14日 */ @Api(value = "督查水库登记表-水库检查情况", tags = "督查水库登记表-水库检查情况") @RestController @RequestMapping("/bis/insp/rsvryn/chk/info") public class BisInspRsvrynRgstrChkInfoController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspRsvrynRgstrChkInfoService bisInspRsvrynRgstrChkInfoService; @Autowired private BisInspRsvrynRgstrService bisInspRsvrynRgstrService; @Autowired private AttRsBaseService attRsBaseService; @ApiOperation(value = "添加/修改督查水库登记表-水库检查情况-新") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspRsvrynRgstrChkInfo", value = "BisInspRsvrynRgstrChkInfo", required = true) @RequestBody BisInspRsvrynRgstrChkInfo bisInspRsvrynRgstrChkInfo) { String rgstrId = bisInspRsvrynRgstrChkInfo.getRgstrId(); notEmpty(rgstrId, "rgstrId.no"); // 更新登记表 BisInspRsvrynRgstr rgstr = bisInspRsvrynRgstrService.get(rgstrId); Optional.ofNullable(rgstr).orElseThrow(() -> new CheckException("登记表ID错误,未获取到对应登记表信息")); if (!Constant.STRING_TWO.equals(rgstr.getState())) { BisInspRsvrynRgstr bisInspRsvrynRgstr = new BisInspRsvrynRgstr(); bisInspRsvrynRgstr.setRgstrId(rgstrId); bisInspRsvrynRgstr.setChkInfoStat(bisInspRsvrynRgstrChkInfo.getStatus()); bisInspRsvrynRgstr.setState(Constant.STRING_ONE); bisInspRsvrynRgstrService.update(bisInspRsvrynRgstr); } /* * if isSite(是否到现场) 1:是 2:否 * 是: * 督查形式不是必查时,则修改水库基本信息表及登记表的“督查形式”为 抽查 * * inspType(督查形式) 1:必查 2:抽查 */ if ("1".equals(bisInspRsvrynRgstrChkInfo.getIsSite())) { AttRsBase attRsBase = attRsBaseService.get(rgstr.getRsCode()); Optional.ofNullable(attRsBase).ifPresent(base -> { if (!"1".equals(base.getInspType())) { base.setInspType("2"); attRsBaseService.update(base); } }); } BisInspRsvrynRgstrChkInfo oldChkInfo = bisInspRsvrynRgstrChkInfoService.get(rgstrId); if (oldChkInfo == null) { bisInspRsvrynRgstrChkInfo.setId(UuidUtil.uuid()); bisInspRsvrynRgstrChkInfo.setIntm(new Date()); bisInspRsvrynRgstrChkInfo.setUptm(new Date()); bisInspRsvrynRgstrChkInfoService.insert(bisInspRsvrynRgstrChkInfo); } else { bisInspRsvrynRgstrChkInfo.setId(oldChkInfo.getId()); bisInspRsvrynRgstrChkInfo.setUptm(new Date()); bisInspRsvrynRgstrChkInfoService.update(bisInspRsvrynRgstrChkInfo); } return buildSuccessResponse(bisInspRsvrynRgstrChkInfo); } @ApiOperation(value = "根据ID删除督查水库登记表-水库检查情况-新") @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspRsvrynRgstrChkInfoService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "根据ID获取督查水库登记表-水库检查情况-新(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspRsvrynRgstrChkInfo bisInspRsvrynRgstrChkInfo = bisInspRsvrynRgstrChkInfoService.get(id); return buildSuccessResponse(bisInspRsvrynRgstrChkInfo); } @ApiOperation(value = "根据ID获取督查水库登记表-水库检查情况-新(单表)") @RequestMapping(value = "getBy/{rgstrId}", method = RequestMethod.GET) public BaseResponse getBy(@ApiParam(name = "rgstrId", value = "rgstrId", required = true) @PathVariable String rgstrId) { BisInspRsvrynRgstrChkInfoParam param = new BisInspRsvrynRgstrChkInfoParam(); param.setRgstrId(rgstrId); BisInspRsvrynRgstrChkInfo bisInspRsvrynRgstrChkInfo = bisInspRsvrynRgstrChkInfoService.getBy(param); if (bisInspRsvrynRgstrChkInfo == null) { bisInspRsvrynRgstrChkInfo = new BisInspRsvrynRgstrChkInfo(); bisInspRsvrynRgstrChkInfo.setRgstrId(rgstrId); BisInspRsvrynRgstr rgstr = bisInspRsvrynRgstrService.get(rgstrId); Optional.ofNullable(rgstr).orElseThrow(() -> new CheckException("登记表ID错误,未获取到对应登记表信息")); AttRsBase base = attRsBaseService.get(rgstr.getRsCode()); if (base != null) { bisInspRsvrynRgstrChkInfo.setInspYear(base.getInspYear()); bisInspRsvrynRgstrChkInfo.setWcEvltOld(base.getWcEvltOld()); } insert(bisInspRsvrynRgstrChkInfo); } return buildSuccessResponse(bisInspRsvrynRgstrChkInfo); } }