package cn.com.goldenwater.dcproj.controller.swhs; import cn.com.goldenwater.dcproj.model.BisInspSwhsRgstr; import cn.com.goldenwater.dcproj.model.BisInspSwhsRgstrSafety; import cn.com.goldenwater.dcproj.param.BisInspSwhsRgstrSafetyParam; import cn.com.goldenwater.dcproj.service.BisInspSwhsRgstrSafetyService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.service.BisInspSwhsRgstrService; 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 com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; /** * @author lune * @date 2019-8-7 */ @Api(value = "BIS 安全保障达标落实情况管理",tags="BIS 安全保障达标落实情况管理") @RestController @RequestMapping("/bis/insp/swhs/rgstr/safety") public class BisInspSwhsRgstrSafetyController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspSwhsRgstrSafetyService bisInspSwhsRgstrSafetyService; @Autowired private BisInspSwhsRgstrService swhsRgstrService; @ApiOperation(value = "添加/修改安全保障达标落实情况") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspSwhsRgstrSafety", value = "BisInspSwhsRgstrSafety", required = true) @RequestBody BisInspSwhsRgstrSafety bisInspSwhsRgstrSafety) { if(StringUtils.isBlank(bisInspSwhsRgstrSafety.getId())) { BisInspSwhsRgstrSafetyParam param = new BisInspSwhsRgstrSafetyParam(); param.setRgstrId(bisInspSwhsRgstrSafety.getRgstrId()); List list = bisInspSwhsRgstrSafetyService.findList(param); if (list.size() > 0 ){ return buildFailResponse(); } bisInspSwhsRgstrSafety.setInTm(new Date()); bisInspSwhsRgstrSafety.setUpTm(new Date()); String uuid = UuidUtil.uuid(); // 生成uuid bisInspSwhsRgstrSafety.setId(uuid); bisInspSwhsRgstrSafetyService.insert(bisInspSwhsRgstrSafety); }else{ bisInspSwhsRgstrSafety.setUpTm(new Date()); bisInspSwhsRgstrSafetyService.update(bisInspSwhsRgstrSafety); } if (StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getRgstrId())) { BisInspSwhsRgstr rgstr = swhsRgstrService.get(bisInspSwhsRgstrSafety.getRgstrId()); if (rgstr != null) { rgstr.setSafetyStat(bisInspSwhsRgstrSafety.getDataStat()); if (!"2".equals(rgstr.getState())) { rgstr.setState("1"); } swhsRgstrService.update(rgstr); } } return buildSuccessResponse(bisInspSwhsRgstrSafety); } @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 = bisInspSwhsRgstrSafetyService.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) { BisInspSwhsRgstrSafety bisInspSwhsRgstrSafety = bisInspSwhsRgstrSafetyService.get(id); return buildSuccessResponse(bisInspSwhsRgstrSafety); } @ApiOperation(value = "获取安全保障达标落实情况(列表所有)") @RequestMapping(value = "/list", method = RequestMethod.POST) public BaseResponse> list(@ApiParam(name = "bisInspSwhsRgstrSafetyParam", value = "bisInspSwhsRgstrSafetyParam", required = true) @RequestBody BisInspSwhsRgstrSafetyParam bisInspSwhsRgstrSafetyParam) { List bisInspSwhsRgstrSafetyList = bisInspSwhsRgstrSafetyService.findList(bisInspSwhsRgstrSafetyParam); return buildSuccessResponse(bisInspSwhsRgstrSafetyList); } @ApiOperation(value = "获取安全保障达标落实情况(列表--分页)") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse> page(@ApiParam(name = "bisInspSwhsRgstrSafetyParam", value = "bisInspSwhsRgstrSafetyParam", required = true) @RequestBody BisInspSwhsRgstrSafetyParam bisInspSwhsRgstrSafetyParam) { PageInfo bisInspSwhsRgstrSafetyList = bisInspSwhsRgstrSafetyService.findPageInfo(bisInspSwhsRgstrSafetyParam); return buildSuccessResponse(bisInspSwhsRgstrSafetyList); } @ApiOperation(value = "根据注册表id获取安全保证信息") @RequestMapping(value = "/getBy/{rgstrId}", method = RequestMethod.GET) public BaseResponse getBy(@ApiParam(name = "rgstrId", value = "rgstrId", required = true) @PathVariable String rgstrId,HttpServletRequest request) { if (StringUtils.isBlank(rgstrId)) { return buildFailResponse(); } BisInspSwhsRgstrSafetyParam param = new BisInspSwhsRgstrSafetyParam(); param.setRgstrId(rgstrId); BisInspSwhsRgstrSafety swhsRgstrSafety = this.bisInspSwhsRgstrSafetyService.getBy(param); return buildSuccessResponse(swhsRgstrSafety); } }