package cn.com.goldenwater.dcproj.controller.rsvr; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.model.BisInspSafeExtApp; import cn.com.goldenwater.dcproj.model.BisInspSafeExtManage; import cn.com.goldenwater.dcproj.param.BisInspSafeExtManageParam; import cn.com.goldenwater.dcproj.service.BisInspRsvrRgstrService; import cn.com.goldenwater.dcproj.service.BisInspSafeExtManageService; import cn.com.goldenwater.dcproj.utils.Builder; 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.web.bind.annotation.*; import java.util.Date; /** * @author lune * @date 2019-2-18 */ @Api(value = "APP 水库安全运行管理情况", tags = "APP 水库安全运行管理情况") @RestController @RequestMapping("/dc/insp/safeExtManage") public class BisInspSafeExtManageController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspSafeExtManageService bisInspSafeExtManageService; @Autowired private BisInspRsvrRgstrService bisInspRsvrRgstrService; @ApiOperation(value = "添加安全运行管理") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspSafeExtManage", value = "BisInspSafeExtManage", required = true) @RequestBody BisInspSafeExtManage bisInspSafeExtManage) { BisInspSafeExtManage safeExtManage = bisInspSafeExtManageService.getBy(Builder .of(BisInspSafeExtManageParam::new) .with(BisInspSafeExtManageParam::setRgstrId, bisInspSafeExtManage.getRgstrId()) .build() ); if (safeExtManage == null) { bisInspSafeExtManageService.insert(bisInspSafeExtManage); } else { bisInspSafeExtManageService.update(bisInspSafeExtManage); } bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), bisInspSafeExtManage.getStatus(), "safe"); return buildSuccessResponse(bisInspSafeExtManage); } @ApiOperation(value = "添加安全运行管理") @RequestMapping(value = "/insert", method = RequestMethod.POST) public BaseResponse insertDam(@ApiParam(name = "bisInspSafeExtManage", value = "BisInspSafeExtManage", required = true) @RequestBody BisInspSafeExtManage bisInspSafeExtManage) { bisInspSafeExtManage.setUpdateTime(new Date()); BisInspSafeExtManageParam safeExtManageParam = new BisInspSafeExtManageParam(); safeExtManageParam.setRgstrId(bisInspSafeExtManage.getRgstrId()); BisInspSafeExtManage safeExtManage = bisInspSafeExtManageService.getBy(safeExtManageParam); if (safeExtManage == null) { String uuid = UuidUtil.uuid(); bisInspSafeExtManage.setMngrnId(uuid); bisInspSafeExtManage.setCreateTime(new Date()); bisInspSafeExtManageService.insert(bisInspSafeExtManage); } else { bisInspSafeExtManage.setMngrnId(safeExtManage.getMngrnId()); bisInspSafeExtManageService.update(bisInspSafeExtManage); } bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), bisInspSafeExtManage.getStatus(), "dam"); return buildSuccessResponse(bisInspSafeExtManage); } @ApiOperation(value = "根据ID删除安全运行管理") @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspSafeExtManageService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "根据督查登记表获取安全运行管理信息") @RequestMapping(value = "/get/{rgstrId}", method = RequestMethod.GET) public BaseResponse getByRgstrId(@ApiParam(name = "rgstrId", value = "rgstrId", required = true) @PathVariable String rgstrId) { BisInspSafeExtManageParam safeExtManageParam = new BisInspSafeExtManageParam(); safeExtManageParam.setRgstrId(rgstrId); BisInspSafeExtManage bisInspSafeExtManage = bisInspSafeExtManageService.getBy(safeExtManageParam); return buildSuccessResponse(bisInspSafeExtManage); } @ApiOperation(value = "根据安全运行管理id获取精简版数据,手机专用接口") @RequestMapping(value = "/getApp/{id}", method = RequestMethod.GET) public BaseResponse getApp(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspSafeExtApp bisInspSafeExtManage = bisInspSafeExtManageService.getApp(id); return buildSuccessResponse(bisInspSafeExtManage); } @ApiOperation(value = "更新安全运行管理信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "bisInspSafeExtManage", value = "BisInspSafeExtManage", required = true) @RequestBody BisInspSafeExtManage bisInspSafeExtManage) { bisInspSafeExtManage.setUpdateTime(new Date()); if (StringUtils.isBlank(bisInspSafeExtManage.getMngrnId())) { if (StringUtils.isNotBlank(bisInspSafeExtManage.getRgstrId())) { BisInspSafeExtManageParam safeExtManageParam = new BisInspSafeExtManageParam(); safeExtManageParam.setRgstrId(bisInspSafeExtManage.getRgstrId()); BisInspSafeExtManage bisInspSafeExtManageReg = bisInspSafeExtManageService.getBy(safeExtManageParam); if (bisInspSafeExtManageReg != null) { bisInspSafeExtManageReg.setMngrnId(bisInspSafeExtManageReg.getMngrnId()); } } } int ret = bisInspSafeExtManageService.update(bisInspSafeExtManage); bisInspRsvrRgstrService.updateRsvr(bisInspSafeExtManage.getRgstrId(), bisInspSafeExtManage.getStatus(), "safe"); return buildSuccessResponse(bisInspSafeExtManage); } @ApiOperation(value = "根据ID获取安全运行管理(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspSafeExtManage bisInspSafeExtManage = bisInspSafeExtManageService.get(id); return buildSuccessResponse(bisInspSafeExtManage); } }