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.BisInspPresSafe; import cn.com.goldenwater.dcproj.param.BisInspPresSafeParam; import cn.com.goldenwater.dcproj.service.BisInspPresSafeService; import cn.com.goldenwater.dcproj.service.BisInspRsvrRgstrService; 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.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; import java.util.List; /** * @author lhc * @date 2021-3-13 */ @Api(value = "xxx管理", tags = "xxx管理") @RestController @RequestMapping("/bis/insp/presSafe") public class BisInspPresSafeController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private BisInspPresSafeService bisInspPresSafeService; @Autowired private BisInspRsvrRgstrService bisInspRsvrRgstrService; @ApiOperation(value = "修改xxx") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "bisInspPresSafe", value = "BisInspPresSafe", required = true) @RequestBody BisInspPresSafe bisInspPresSafe) { if (StringUtils.isBlank(bisInspPresSafe.getRgstrId())) { throw new CheckException("缺少登记表编码!"); } BisInspPresSafeParam benefitsParam = new BisInspPresSafeParam(); benefitsParam.setRgstrId(bisInspPresSafe.getRgstrId()); List list = bisInspPresSafeService.findList(benefitsParam); bisInspPresSafe.setUpTm(new Date()); if (list != null && list.size() > 0) { bisInspPresSafe.setId(list.get(0).getId()); bisInspPresSafeService.update(bisInspPresSafe); } else { bisInspPresSafe.setId(UuidUtil.uuid()); bisInspPresSafe.setInTm(new Date()); bisInspPresSafeService.insert(bisInspPresSafe); } bisInspRsvrRgstrService.updateRsvr(bisInspPresSafe.getRgstrId(), bisInspPresSafe.getStatus(), "persSafe"); return buildSuccessResponse(bisInspPresSafe); } @ApiOperation(value = "根据ID删除xxx") @RequestMapping(value = "delete/{id}", method = RequestMethod.POST) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = bisInspPresSafeService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "根据ID获取xxx(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { BisInspPresSafe bisInspPresSafe = bisInspPresSafeService.get(id); // bisInspPresSafe = Optional.ofNullable(bisInspPresSafe).orElseGet(() -> { // BisInspPresSafe presSafe = Builder.of(BisInspPresSafe::new).with(BisInspPresSafe::setRgstrId, id).build(); // bisInspPresSafeService.insert(presSafe); // return presSafe; // }); return buildSuccessResponse(bisInspPresSafe); } }