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.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.AttRsBaseCrrctDao; import cn.com.goldenwater.dcproj.dto.RsCountDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.dcproj.utils.Builder; import cn.com.goldenwater.dcproj.utils.DateUtils; 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.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; import java.util.Optional; import java.util.regex.Pattern; /** * @author lune * @date 2019-2-25 */ @Api(value = "水库基础表管理", tags = "水库基础表管理") @RestController @RequestMapping("/dc/att/rsBase") public class AttRsBaseController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private AttRsBaseService attRsBaseService; @Autowired private BisInspRsvrRgstrService bisInspRsvrRgstrService; @Autowired private BisInspRsvrynRgstrService bisInspRsvrynRgstrService; @Autowired private BisInspStndRgstrService bisInspStndRgstrService; @Autowired private BisInspRsfcoRgstrService bisInspRsfcoRgstrService; static Pattern pattern = Pattern.compile("[0-9]*"); @Autowired private GwComFileService gwComFileService; @Autowired private AttRsBaseCrrctDao attRsBaseCrrctDao; @Autowired private BisInspRsmlRgstrService rsmlRgstrService; @Autowired private BisInspRsvrRgstrChkInfoService bisInspRsvrRgstrChkInfoService; public static boolean isNumeric(String str) { return pattern.matcher(str).matches(); } @ApiOperation(value = "添加水库基础表管理") @RequestMapping(value = "", method = RequestMethod.POST) public Object insert(@ApiParam(name = "attRsBase", value = "AttRsBase", required = true) @RequestBody AttRsBase attRsBase) { //创建水库编码 AttRsBaseParam attRsBaseParam = new AttRsBaseParam(); attRsBaseParam.setRsName(attRsBase.getRsName()); String location = attRsBase.getLocation(); String maxResCode = ""; if (isNumeric(location)) { attRsBaseParam.setLocation(attRsBase.getLocation()); List rsBases = attRsBaseService.findList(attRsBaseParam); if (rsBases != null && !rsBases.isEmpty()) { return buildFailResponse("该水库信息已经存在!!"); } attRsBase.setUptm(new Date()); location = location.replace("00", ""); maxResCode = attRsBaseService.findMax(location); attRsBase.setAdmDiv(attRsBase.getLocation()); attRsBase.setLocation(attRsBase.getRsLoc()); } else { attRsBaseParam.setAdmDiv(attRsBase.getAdmDiv()); List rsBases = attRsBaseService.findList(attRsBaseParam); if (rsBases != null && !rsBases.isEmpty()) { return buildFailResponse("该水库信息已经存在!!"); } attRsBase.setUptm(new Date()); String admDiv = attRsBase.getAdmDiv(); if (StringUtils.isBlank(admDiv)) { return buildFailResponse("地区编码不能为空!!"); } admDiv = admDiv.replace("00", ""); maxResCode = attRsBaseService.findMax(admDiv); attRsBase.setRsLoc(attRsBase.getRsLoc()); attRsBase.setLocation(attRsBase.getLocation()); } long regCode = 0; if (maxResCode == null) { regCode = Long.valueOf(attRsBase.getAdmDiv()) + 2; } else { regCode = Long.valueOf(maxResCode) + 2; } attRsBase.setRsCode(regCode + ""); Date compDate = new Date(attRsBase.getCompDateDesc()); attRsBase.setCompDate(compDate); if (StringUtils.isNotBlank(attRsBase.getCenterX()) && StringUtils.isNotBlank(attRsBase.getCenterY())) { attRsBase.setCenterXGd(attRsBase.getCenterX()); attRsBase.setCenterYGd(attRsBase.getCenterY()); attRsBase.setCenterY(""); attRsBase.setCenterX(""); } try { //新增水库默认未督查 attRsBase.setHstInsp("0"); attRsBaseService.insert(attRsBase); return buildSuccessResponse(attRsBase); } catch (Exception e) { return buildFailResponse("该水库代码已经被占用"); } } @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 = attRsBaseService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "纠错水库基础表管理信息") @RequestMapping(value = "/update", method = RequestMethod.POST) public BaseResponse update(@ApiParam(name = "attRsBase", value = "AttRsBase", required = true) @RequestBody AttRsBaseCrrct attRsBase) { //更新小水库基本信息 if (StringUtils.isBlank(attRsBase.getRsCode())) { throw new CheckException("rsCode.no"); } if (StringUtils.isNotBlank(attRsBase.getCompDateStr())) { attRsBase.setCompDate(DateUtils.Str2Date(attRsBase.getCompDateStr(), SplitValue.TIME_SPLIT)); } attRsBase.setCenterX(attRsBase.getCenterXGd()); attRsBase.setCenterY(attRsBase.getCenterYGd()); AttRsBase attRsBaseTemp = new AttRsBase(); BeanUtils.copyProperties(attRsBase, attRsBaseTemp); // 更新 水库登记号 if(StringUtils.isNotBlank(attRsBase.getDamRegCode())){ attRsBase.setRegCode(attRsBase.getDamRegCode()); } // 水库位置 if(StringUtils.isNotBlank(attRsBase.getHystSite())){ attRsBase.setRsLoc(attRsBase.getHystSite()); } // 水库行政区划 if(StringUtils.isNotBlank(attRsBase.getAdCode())){ attRsBase.setAdmDiv(attRsBase.getAdCode()); } // 水库建成时间 if(null !=attRsBase.getResCreateTime() ){ attRsBase.setCompDate(attRsBase.getResCreateTime()); } // 水库经纬度 if (attRsBase.getRsvrLat() != null) { attRsBase.setCenterYGd(attRsBase.getRsvrLat().toString()); } if (attRsBase.getRsvrLong() != null) { attRsBase.setCenterXGd(attRsBase.getRsvrLong().toString()); } attRsBaseTemp.setRegCode(attRsBase.getDamRegCode()); attRsBaseService.update(attRsBaseTemp); AttRsBaseCrrct baseCrrct = attRsBaseCrrctDao.get(attRsBase.getRsCode(), attRsBase.getPersId()); if (baseCrrct == null) { attRsBaseCrrctDao.insert(attRsBase); } else { attRsBaseCrrctDao.update(attRsBase); } // 更新小水库标准化登记表 BisInspStndRgstrParam bisInspStndRgstrParam = new BisInspStndRgstrParam(); bisInspStndRgstrParam.setObjId(attRsBase.getObjId()); bisInspStndRgstrParam.setRsCode(attRsBase.getRsCode()); BisInspStndRgstr bisInspStndRgstr = bisInspStndRgstrService.getBy(bisInspStndRgstrParam); if (bisInspStndRgstr != null) { bisInspStndRgstr.setDamType(attRsBase.getDamType()); bisInspStndRgstr.setDamRegCode(attRsBase.getRegCode()); bisInspStndRgstr.setEngScal(attRsBase.getEngScal()); bisInspStndRgstr.setAdCode(attRsBase.getAdmDiv()); bisInspStndRgstr.setAdNm(attRsBase.getLocation()); bisInspStndRgstr.setObjId(attRsBase.getObjId()); //详细地址 bisInspStndRgstr.setHystSite(attRsBase.getRsLoc()); bisInspStndRgstr.setRsCode(attRsBase.getRsCode()); bisInspStndRgstr.setTotCap(attRsBase.getTotCap()); bisInspStndRgstr.setResCreateTime(attRsBase.getCompDate()); Date date = new Date(); bisInspStndRgstr.setUptm(date); bisInspStndRgstr.setHasDamRegCode("1"); bisInspStndRgstr.setRsvrNm(attRsBase.getRsName()); bisInspStndRgstr.setJxRsvrType(attRsBase.getJxRsvrType()); bisInspStndRgstr.setJxRsvrStndLev(attRsBase.getJxRsvrStndLev()); bisInspStndRgstr.setJxDuty(attRsBase.getJxDuty()); bisInspStndRgstr.setJxDutyPhone(attRsBase.getJxDutyPhone()); bisInspStndRgstrService.update(bisInspStndRgstr); } //小水库防洪纠错 BisInspRsfcoRgstrParam rsfcoRgstrParam = new BisInspRsfcoRgstrParam(); rsfcoRgstrParam.setObjId(attRsBase.getObjId()); rsfcoRgstrParam.setRsCode(attRsBase.getRsCode()); BisInspRsfcoRgstr rgstr = bisInspRsfcoRgstrService.getBy(rsfcoRgstrParam); if (rgstr != null) { rgstr.setHasDamRegCode("1"); rgstr.setDamRegCode(attRsBase.getRegCode()); rgstr.setAdCode(attRsBase.getAdmDiv()); rgstr.setLocation(attRsBase.getLocation()); rgstr.setHystSite(attRsBase.getRsLoc()); rgstr.setCompDateStr(attRsBase.getCompDateStr()); if (attRsBase.getCenterYGd() != null) { rgstr.setGdX(Double.parseDouble(attRsBase.getCenterYGd())); } if (attRsBase.getCenterXGd() != null) { rgstr.setGdY(Double.parseDouble(attRsBase.getCenterXGd())); } if (attRsBase.getCenterX() != null) { rgstr.setCenterX(Double.parseDouble(attRsBase.getCenterX())); } if (attRsBase.getCenterY() != null) { rgstr.setCenterY(Double.parseDouble(attRsBase.getCenterY())); } rgstr.setRsAdmCode(attRsBase.getRsAdmCode()); rgstr.setRsAdmName(attRsBase.getRsAdmName()); rgstr.setEngScal(attRsBase.getEngScal()); rgstr.setDamType(attRsBase.getDamType()); rgstr.setTotCap(attRsBase.getTotCap()); rgstr.setDamSizeHig(attRsBase.getDamSizeHig()); rgstr.setResCreateTime(attRsBase.getCompDate()); bisInspRsfcoRgstrService.update(rgstr); } //更新小水库登记表 BisInspRsvrRgstrParam bisInspRsvrRgstrParam = new BisInspRsvrRgstrParam(); bisInspRsvrRgstrParam.setObjId(attRsBase.getObjId()); bisInspRsvrRgstrParam.setRsCode(attRsBase.getRsCode()); BisInspRsvrRgstr bisInspRsvrRgstr = bisInspRsvrRgstrService.getBy(bisInspRsvrRgstrParam); if (bisInspRsvrRgstr != null) { bisInspRsvrRgstr.setBuildStat(attRsBase.getBuildStat()); bisInspRsvrRgstr.setDamType(attRsBase.getDamType()); bisInspRsvrRgstr.setDamRegCode(attRsBase.getRegCode()); bisInspRsvrRgstr.setEngScal(attRsBase.getEngScal()); bisInspRsvrRgstr.setAdCode(attRsBaseTemp.getAdmDiv()); bisInspRsvrRgstr.setObjId(attRsBase.getObjId()); //详细地址 bisInspRsvrRgstr.setHystSite(attRsBase.getRsLoc()); if (StringUtils.isNotBlank(attRsBase.getLocation()) && !isNumeric(attRsBase.getLocation())) { bisInspRsvrRgstr.setLocation(attRsBase.getLocation()); } bisInspRsvrRgstr.setRsvrAdmName(attRsBase.getRsAdmName()); bisInspRsvrRgstr.setRsvrAdmName(attRsBase.getRsvrAdmName()); if (attRsBase.getDamSizeHig() == null) { bisInspRsvrRgstr.setDamMaxHigh(null); } else { bisInspRsvrRgstr.setDamMaxHigh(Double.toString(attRsBase.getDamSizeHig())); } bisInspRsvrRgstr.setRsCode(attRsBase.getRsCode()); bisInspRsvrRgstr.setTotCap(attRsBase.getTotCap()); if (attRsBase.getCenterYGd() != null) { bisInspRsvrRgstr.setRsvrLat(Double.parseDouble(attRsBase.getCenterYGd())); } if (attRsBase.getCenterXGd() != null) { bisInspRsvrRgstr.setRsvrLong(Double.parseDouble(attRsBase.getCenterXGd())); } bisInspRsvrRgstr.setResCreateTime(attRsBase.getCompDate()); bisInspRsvrRgstr.setCompDateStr(attRsBase.getCompDateStr()); bisInspRsvrRgstr.setUptm(new Date()); bisInspRsvrRgstr.setHasDamRegCode("1"); bisInspRsvrRgstr.setRsvrNm(attRsBase.getRsName()); bisInspRsvrRgstr.setRsClass(attRsBase.getRsClass()); bisInspRsvrRgstr.setImpdDt(attRsBase.getImpdDt()); bisInspRsvrRgstr.setRnfcImpdDt(attRsBase.getRnfcImpdDt()); bisInspRsvrRgstr.setDesFlStag(attRsBase.getDesFlStag()); bisInspRsvrRgstr.setFlConTopStag(attRsBase.getFlConTopStag()); bisInspRsvrRgstr.setFsltdz(attRsBase.getFsltdz()); bisInspRsvrRgstr.setNormz(attRsBase.getNormz()); bisInspRsvrRgstr.setInspType(attRsBase.getInspType()); bisInspRsvrRgstr.setIsAction(attRsBase.getIsAction()); bisInspRsvrRgstr.setIsSaf(attRsBase.getIsSaf()); bisInspRsvrRgstr.setIsSite(attRsBase.getIsSite()); bisInspRsvrRgstr.setDutyDep(attRsBase.getDutyDep()); bisInspRsvrRgstrService.update(bisInspRsvrRgstr); //更新小水库管理单位信息表 BisInspRsvrRgstrChkInfoParam bisInspRsvrRgstrChkInfoParam = new BisInspRsvrRgstrChkInfoParam(); bisInspRsvrRgstrChkInfoParam.setRgstrId(bisInspRsvrRgstr.getRgstrId()); BisInspRsvrRgstrChkInfo bisInspRsvrRgstrChkInfo=bisInspRsvrRgstrChkInfoService.getBy(bisInspRsvrRgstrChkInfoParam); if(null != bisInspRsvrRgstrChkInfo){ bisInspRsvrRgstrChkInfo.setDutyUnit(attRsBase.getRsvrAdmName()); bisInspRsvrRgstrChkInfoService.update(bisInspRsvrRgstrChkInfo); } } //更新小水库复查登记表 BisInspRsvrynRgstr bisInspRsvrynRgstr = bisInspRsvrynRgstrService.getBy(Builder.of(BisInspRsvrynRgstrParam::new) .with(BisInspRsvrynRgstrParam::setObjId, attRsBase.getObjId()) .with(BisInspRsvrynRgstrParam::setRsCode, attRsBase.getRsCode()) .build()); Optional.ofNullable(bisInspRsvrynRgstr).ifPresent(rsvr -> { rsvr.setBuildStat(attRsBase.getBuildStat()); rsvr.setDamType(attRsBase.getDamType()); rsvr.setDamRegCode(attRsBase.getRegCode()); rsvr.setEngScal(attRsBase.getEngScal()); rsvr.setAdCode(attRsBase.getAdmDiv()); rsvr.setObjId(attRsBase.getObjId()); //详细地址 rsvr.setHystSite(attRsBase.getRsLoc()); if (StringUtils.isNotBlank(attRsBase.getLocation()) && !isNumeric(attRsBase.getLocation())) { rsvr.setLocation(attRsBase.getLocation()); } rsvr.setRsvrAdmName(attRsBase.getRsAdmName()); rsvr.setRsvrAdmName(attRsBase.getRsvrAdmName()); if (attRsBase.getDamSizeHig() == null) { rsvr.setDamMaxHigh(null); } else { rsvr.setDamMaxHigh(Double.toString(attRsBase.getDamSizeHig())); } rsvr.setRsCode(attRsBase.getRsCode()); rsvr.setTotCap(attRsBase.getTotCap()); if (attRsBase.getCenterYGd() != null) { rsvr.setRsvrLat(Double.parseDouble(attRsBase.getCenterYGd())); } if (attRsBase.getCenterXGd() != null) { rsvr.setRsvrLong(Double.parseDouble(attRsBase.getCenterXGd())); } rsvr.setResCreateTime(attRsBase.getCompDate()); rsvr.setCompDateStr(attRsBase.getCompDateStr()); rsvr.setUptm(new Date()); rsvr.setHasDamRegCode("1"); rsvr.setRsvrNm(attRsBase.getRsName()); rsvr.setRsClass(attRsBase.getRsClass()); rsvr.setImpdDt(attRsBase.getImpdDt()); rsvr.setRnfcImpdDt(attRsBase.getRnfcImpdDt()); rsvr.setDesFlStag(attRsBase.getDesFlStag()); rsvr.setFlConTopStag(attRsBase.getFlConTopStag()); rsvr.setFsltdz(attRsBase.getFsltdz()); rsvr.setNormz(attRsBase.getNormz()); rsvr.setInspType(attRsBase.getInspType()); rsvr.setIsAction(attRsBase.getIsAction()); rsvr.setIsSaf(attRsBase.getIsSaf()); rsvr.setIsSite(attRsBase.getIsSite()); rsvr.setDutyDep(attRsBase.getDutyDep()); bisInspRsvrynRgstrService.update(rsvr); }); // 更新大中型水库 BisInspRsmlRgstrParam rsmlRgstrParam = new BisInspRsmlRgstrParam(); rsmlRgstrParam.setObjId(attRsBase.getObjId()); rsmlRgstrParam.setRsCode(attRsBase.getRsCode()); BisInspRsmlRgstr inspRsmlRgstr = rsmlRgstrService.getBy(rsmlRgstrParam); if (inspRsmlRgstr != null) { // inspRsmlRgstr.setBuildStat(attRsBase.getBuildStat()); inspRsmlRgstr.setDamType(attRsBase.getDamType()); inspRsmlRgstr.setRsAdmName(attRsBase.getRsAdmName()); inspRsmlRgstr.setRsAdmCode(attRsBase.getRsAdmCode()); inspRsmlRgstr.setDamRegCode(attRsBase.getRegCode()); inspRsmlRgstr.setEngScal(attRsBase.getEngScal()); inspRsmlRgstr.setAdCode(attRsBase.getAdmDiv()); inspRsmlRgstr.setObjId(attRsBase.getObjId()); //详细地址 inspRsmlRgstr.setHystSite(attRsBase.getRsLoc()); if (StringUtils.isNotBlank(attRsBase.getLocation()) && !isNumeric(attRsBase.getLocation())) { inspRsmlRgstr.setLocation(attRsBase.getLocation()); } if (attRsBase.getCenterYGd() != null) { inspRsmlRgstr.setCenterY(Double.parseDouble(attRsBase.getCenterYGd())); } if (attRsBase.getCenterXGd() != null) { inspRsmlRgstr.setCenterX(Double.parseDouble(attRsBase.getCenterXGd())); } if (attRsBase.getDamSizeHig() == null) { inspRsmlRgstr.setDamSizeHig(null); } else { inspRsmlRgstr.setDamSizeHig(attRsBase.getDamSizeHig()); } inspRsmlRgstr.setRsCode(attRsBase.getRsCode()); inspRsmlRgstr.setTotCap(attRsBase.getTotCap()); inspRsmlRgstr.setResCreateTime(attRsBase.getCompDate()); Date date = new Date(); inspRsmlRgstr.setUptm(date); inspRsmlRgstr.setHasDamRegCode("1"); inspRsmlRgstr.setRsClass(attRsBase.getRsClass()); inspRsmlRgstr.setImpdDt(attRsBase.getImpdDt()); inspRsmlRgstr.setRnfcImpdDt(attRsBase.getRnfcImpdDt()); inspRsmlRgstr.setDesFlStag(attRsBase.getDesFlStag()); inspRsmlRgstr.setFlConTopStag(attRsBase.getFlConTopStag()); inspRsmlRgstr.setFsltdz(attRsBase.getFsltdz()); inspRsmlRgstr.setNormz(attRsBase.getNormz()); inspRsmlRgstr.setInspType(attRsBase.getInspType()); inspRsmlRgstr.setIsAction(attRsBase.getIsAction()); inspRsmlRgstr.setIsSaf(attRsBase.getIsSaf()); inspRsmlRgstr.setIsSite(attRsBase.getIsSite()); rsmlRgstrService.update(inspRsmlRgstr); } return buildSuccessResponse(attRsBase); } @ApiOperation(value = "根据ID获取水库基础表管理(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { AttRsBase attRsBase = attRsBaseService.get(id); List comFiles = gwComFileService.findFileByBiz(attRsBase.getRsCode()); attRsBase.setGwComFiles(comFiles); return buildSuccessResponse(attRsBase); } @ApiOperation(value = "获取纠错信息") @RequestMapping(value = "/crrct/{rsCode}/{persId}", method = RequestMethod.GET) public Object getCrrct(@ApiParam(name = "rsCode", value = "rsCode", required = true) @PathVariable String rsCode, @PathVariable String persId) { AttRsBase attRsBase = attRsBaseService.get(rsCode); List comFiles = gwComFileService.findFileByBiz(rsCode); attRsBase.setGwComFiles(comFiles); return buildSuccessResponse(attRsBase); } @ApiOperation(value = "根据rsName,location查询水库是否存在") @RequestMapping(value = "/findByNameAndLoc", method = RequestMethod.POST) public BaseResponse> findByNameAndLoc(@RequestParam String rsName, @RequestParam String location) { AttRsBaseParam attRsBase = new AttRsBaseParam(); attRsBase.setRsName(rsName); attRsBase.setLocation(location); List rsBases = attRsBaseService.findList(attRsBase); return buildSuccessResponse(rsBases); } @ApiOperation(value = "根据行政区划编码获取水库统计") @RequestMapping(value = "/getRsCountByAdCode", method = RequestMethod.GET) public BaseResponse> getRsCountByAdCode(@RequestParam(required = false, defaultValue = "000000000000") String adCode, @RequestParam String adGrad, @RequestParam String objType) { if (StringUtils.isBlank(objType)) { objType = "1"; } List rsCountDtoList = this.attRsBaseService.getRsCountByAdCode(adCode, adGrad, objType); return buildSuccessResponse(rsCountDtoList); } @ApiOperation(value = "根据节点id及地区code查询水库") @RequestMapping(value = "/getRsListByNodeIdsAndAdCodes", method = RequestMethod.GET) public BaseResponse> getRsListByNodeIdsAndAdCodes(@RequestParam(required = false) String nodeIds, @RequestParam(required = false) String adCodes, @RequestParam String persGuid, @RequestParam String pType) { if (StringUtils.isBlank(pType)) { pType = "1"; } List rsList = this.attRsBaseService.getRsListByNodeIdsAndAdCodes(nodeIds, adCodes, persGuid, pType); return buildSuccessResponse(rsList); } @ApiOperation(value = "更新信息为空的经纬到高德") @RequestMapping(value = "/updateCenteXToGd", method = RequestMethod.POST) public BaseResponse updateCenteXToGd() { try { attRsBaseService.updateCenteXToGd(); } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return buildFailResponse(e.getMessage()); } return buildSuccessResponse(); } }