package cn.com.goldenwater.dcproj.controller.rsvr; import cn.com.goldenwater.dcproj.model.BisInspRsvrProject; import cn.com.goldenwater.dcproj.param.BisInspRsvrProjectParam; import cn.com.goldenwater.dcproj.service.BisInspRsvrProjectService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.service.BisInspRsvrRgstrService; import cn.com.goldenwater.id.util.UuidUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.Date; import java.util.List; /** * @author lune * @date 2019-5-9 */ @Api(value = "APP 水库工程实体管理", tags = "APP 水库工程实体管理") @RestController @RequestMapping("/dc/rever/project") public class BisInspRsvrProjectController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspRsvrProjectService bisInspRsvrProjectService; @Autowired private BisInspRsvrRgstrService bisInspRsvrRgstrService; @ApiOperation(value = "水库工程实体管理") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspRsvrProject", value = "BisInspRsvrProject", required = true) @RequestBody BisInspRsvrProject bisInspRsvrProject) { //登记表不能为空判断 if(StringUtils.isBlank(bisInspRsvrProject.getRgstrId())){ return buildFailResponse(30001,"登记表ID不能为空"); } bisInspRsvrProject.setCreateTime(new Date()); if (StringUtils.isNotBlank(bisInspRsvrProject.getId())) { bisInspRsvrProject.setUpdateTime(new Date()); bisInspRsvrProjectService.update(bisInspRsvrProject); } else { BisInspRsvrProjectParam benefitsParam = new BisInspRsvrProjectParam(); benefitsParam.setRgstrId(bisInspRsvrProject.getRgstrId()); List list = bisInspRsvrProjectService.findList(benefitsParam); if (list.size()>0) { bisInspRsvrProject.setId(list.get(0).getId()); bisInspRsvrProject.setUpdateTime(new Date()); bisInspRsvrProjectService.update(bisInspRsvrProject); } else { String uuid = UuidUtil.uuid(); bisInspRsvrProject.setId(uuid); bisInspRsvrProjectService.insert(bisInspRsvrProject); } } bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), bisInspRsvrProject.getStatus(), "project"); return buildSuccessResponse(bisInspRsvrProject); } @ApiOperation(value = "水库安全鉴定及除险加固情况") @RequestMapping(value = "/insert", method = RequestMethod.POST) public BaseResponse insertRein(@ApiParam(name = "bisInspRsvrProject", value = "BisInspRsvrProject", required = true) @RequestBody BisInspRsvrProject bisInspRsvrProject) { if (StringUtils.isNotBlank(bisInspRsvrProject.getId())) { bisInspRsvrProject.setUpdateTime(new Date()); if ("2".equals(bisInspRsvrProject.getIfDamSafe())) { bisInspRsvrProject.setIfDamSafeReq(""); bisInspRsvrProject.setIfDamSafeRul(""); bisInspRsvrProject.setIfDamSafeDepRul(""); bisInspRsvrProject.setIfDamSafeThr(""); int a = bisInspRsvrProjectService.updateProject(bisInspRsvrProject); } if ("2".equals(bisInspRsvrProject.getIfDamSafeReq() )) { bisInspRsvrProject.setIfDamSafeRul(""); bisInspRsvrProject.setIfDamSafeDepRul(""); bisInspRsvrProject.setIfDamSafeThr(""); int a = bisInspRsvrProjectService.updateProject(bisInspRsvrProject); } else { bisInspRsvrProjectService.update(bisInspRsvrProject); } } else { if(StringUtils.isNotBlank(bisInspRsvrProject.getRgstrId())){ BisInspRsvrProjectParam rsvrProjectParam=new BisInspRsvrProjectParam(); rsvrProjectParam.setRgstrId(bisInspRsvrProject.getRgstrId()); BisInspRsvrProject inspRsvrProject=bisInspRsvrProjectService.getBy(rsvrProjectParam); if(inspRsvrProject!=null){ bisInspRsvrProjectService.update(bisInspRsvrProject); }else{ bisInspRsvrProject.setId(UuidUtil.uuid()); bisInspRsvrProjectService.insert(bisInspRsvrProject); } }else { bisInspRsvrProject.setCreateTime(new Date()); String uuid = UuidUtil.uuid(); bisInspRsvrProject.setId(uuid); bisInspRsvrProjectService.insert(bisInspRsvrProject); } } bisInspRsvrRgstrService.updateRsvr(bisInspRsvrProject.getRgstrId(), bisInspRsvrProject.getStatus(), "rein"); return buildSuccessResponse(bisInspRsvrProject); } @ApiOperation(value = "更新水库工程实体管理信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspRsvrProject", value = "BisInspRsvrProject", required = true) @RequestBody BisInspRsvrProject bisInspRsvrProject) { Assert.notNull(bisInspRsvrProject.getId(), "主键id为必填参数"); int ret = bisInspRsvrProjectService.update(bisInspRsvrProject); return buildSuccessResponse(); } @ApiOperation(value = "根据工程实体主键ID获取水库工程实体(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspRsvrProject bisInspRsvrProject = bisInspRsvrProjectService.get(id); return buildSuccessResponse(bisInspRsvrProject); } @ApiOperation(value = "根据督查表主键主键ID获取水库工程实体(单表)") @RequestMapping(value = "/getBy/{rgstrId}", method = RequestMethod.GET) public BaseResponse getBy(@ApiParam(name = "rgstrId", value = "rgstrId", required = true) @PathVariable String rgstrId) { BisInspRsvrProjectParam rsvrProjectParam = new BisInspRsvrProjectParam(); rsvrProjectParam.setRgstrId(rgstrId); BisInspRsvrProject bisInspRsvrProject = bisInspRsvrProjectService.getBy(rsvrProjectParam); return buildSuccessResponse(bisInspRsvrProject); } }