6c26b56acef0a043be090066493416a96cc04247.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package cn.com.goldenwater.dcproj.controller.plansd;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dto.BisInspPlanDtlDto;
  5. import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers;
  6. import cn.com.goldenwater.dcproj.model.BisInspPlanDtl;
  7. import cn.com.goldenwater.dcproj.model.BisInspPlanDtlAddvcd;
  8. import cn.com.goldenwater.dcproj.model.BisInspPlanDtlPtyp;
  9. import cn.com.goldenwater.dcproj.param.BisInspPlanDtlAddvcdParam;
  10. import cn.com.goldenwater.dcproj.param.BisInspPlanDtlParam;
  11. import cn.com.goldenwater.dcproj.param.BisInspPlanDtlPtypParam;
  12. import cn.com.goldenwater.dcproj.param.BisInspPlandpRlParam;
  13. import cn.com.goldenwater.dcproj.service.*;
  14. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  15. import cn.com.goldenwater.dcproj.utils.Constant;
  16. import cn.com.goldenwater.dcproj.utils.StringUtils;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import io.swagger.annotations.ApiParam;
  20. import org.apache.commons.collections.CollectionUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.beans.BeanUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.util.Assert;
  26. import org.springframework.web.bind.annotation.*;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.Objects;
  32. import java.util.Optional;
  33. import java.util.stream.Collectors;
  34. /**
  35. * @author hjp
  36. * @date 2022-8-9
  37. */
  38. @Api(value = "检查年度计划分解管理", tags = "检查年度计划分解管理")
  39. @RestController
  40. @RequestMapping("/bis/insp/plan/dtl")
  41. public class BisInspPlanDtlController extends BaseController {
  42. private Logger logger = LoggerFactory.getLogger(getClass());
  43. @Autowired
  44. private BisInspPlanDtlService bisInspPlanDtlService;
  45. @Autowired
  46. private BisInspPlanDtlAddvcdService bisInspPlanDtlAddvcdService;
  47. @Autowired
  48. private BisInspPlanDtlPtypService bisInspPlanDtlPtypService;
  49. @Autowired
  50. private BisInspPlandpRlService bisInspPlandpRlService;
  51. @Autowired
  52. private BisInspAllRlationPersService bisInspAllRlationPersService;
  53. @Autowired
  54. private BisInspPlanDpService bisInspPlanDpService;
  55. @Autowired
  56. private AttAdBaseService attAdBaseService;
  57. @Autowired
  58. private OlBisInspOrgService olBisInspOrgService;
  59. @ApiOperation(value = "添加检查年度计划分解")
  60. @RequestMapping(value = "/", method = RequestMethod.POST)
  61. public BaseResponse<BisInspPlanDtlDto> insert(@ApiParam(name = "BisInspPlanDtlDto", value = "BisInspPlanDtlDto", required = true) @RequestBody BisInspPlanDtlDto bisInspPlanDtlDto) {
  62. Assert.notNull(bisInspPlanDtlDto.getPlanId(), "年度计划ID为必填参数");
  63. List<String> adCodes = bisInspPlanDtlDto.getdAdCodes();
  64. Assert.notNull(adCodes, "检查区域为必填参数");
  65. bisInspPlanDtlDto.setPersId(getCurrentPersId());
  66. bisInspPlanDtlDto.setOrgId(getCurrentOrgId());
  67. // 把不在列表中的 开展检查实施处室(单位) 保存到详细计划表中
  68. bisInspPlanDtlDto.setChkImplDept(bisInspPlanDtlDto.getPlanDpRlNames());
  69. //判断是否重复创建
  70. if (null != bisInspPlanDtlDto.getDetermine() && !bisInspPlanDtlDto.getDetermine()) {
  71. // true 表示 有重复计划 false 表示没有
  72. List<Map<String, String>> byAdCodeAndTm = bisInspPlanDtlAddvcdService.getByAdCodeAndTm(bisInspPlanDtlDto);
  73. BaseResponse response = buildFailResponse(String.valueOf(CollectionUtils.isNotEmpty(byAdCodeAndTm)));
  74. if(CollectionUtils.isNotEmpty(byAdCodeAndTm)){
  75. String hasAdCodes = byAdCodeAndTm.stream().map(m->m.get("AD_CODE").substring(0,4)).collect(Collectors.joining("','","'","'"));
  76. List<BisInspPlanDtlDto> byAdCodeAndTmList = bisInspPlanDtlAddvcdService.getByAdCodeAndTmList(hasAdCodes, bisInspPlanDtlDto);
  77. if (StringUtils.isNotBlank(bisInspPlanDtlDto.getId())){
  78. // 编辑
  79. if(null !=byAdCodeAndTmList && byAdCodeAndTmList.size()>0){
  80. // 把自身去掉
  81. byAdCodeAndTmList = byAdCodeAndTmList.stream().filter(f-> !bisInspPlanDtlDto.getId().equals(f.getId())).collect(Collectors.toList());
  82. }
  83. response = buildFailResponse(String.valueOf(CollectionUtils.isNotEmpty(byAdCodeAndTmList)));
  84. }
  85. response.setData(byAdCodeAndTmList);
  86. }
  87. List<Map<String, String>> byAdCodeAndTmAndPlan = bisInspPlanDtlAddvcdService.getByAdCodeAndTmAndPlan(bisInspPlanDtlDto);
  88. if(CollectionUtils.isNotEmpty(byAdCodeAndTmAndPlan)){
  89. response.setSuccess(false);
  90. response.setCode(500);
  91. response.setMessage("报错");
  92. }
  93. return response;
  94. }
  95. if (StringUtils.isBlank(bisInspPlanDtlDto.getId())) {
  96. bisInspPlanDtlService.insert(bisInspPlanDtlDto);
  97. } else {
  98. bisInspPlanDtlService.update(bisInspPlanDtlDto);
  99. }
  100. bisInspPlanDtlService.updatePostProcessing(bisInspPlanDtlDto);
  101. return buildSuccessResponse(bisInspPlanDtlDto);
  102. }
  103. /* @ApiOperation(value = "添加检查年度计划分解")
  104. @RequestMapping(value = "/", method = RequestMethod.POST)
  105. public BaseResponse<BisInspPlanDtlDto> insert(@ApiParam(name = "BisInspPlanDtlDto", value = "BisInspPlanDtlDto", required = true) @RequestBody BisInspPlanDtlDto bisInspPlanDtlDto) {
  106. Assert.notNull(bisInspPlanDtlDto.getPlanId(), "年度计划ID为必填参数");
  107. List<String> adCodes = bisInspPlanDtlDto.getdAdCodes();
  108. Assert.notNull(adCodes, "检查区域为必填参数");
  109. bisInspPlanDtlDto.setPersId(getCurrentPersId());
  110. bisInspPlanDtlDto.setOrgId(getCurrentOrgId());
  111. // 把不在列表中的 开展检查实施处室(单位) 保存到详细计划表中
  112. bisInspPlanDtlDto.setChkImplDept(bisInspPlanDtlDto.getPlanDpRlNames());
  113. // true 表示 有重复计划 false 表示没有
  114. List<Map<String, String>> byAdCodeAndTmAndPlan = bisInspPlanDtlAddvcdService.getByAdCodeAndTmAndPlan(bisInspPlanDtlDto);
  115. if(CollectionUtils.isNotEmpty(byAdCodeAndTmAndPlan)){
  116. BaseResponse resp = new BaseResponse();
  117. resp.setSuccess(false);
  118. resp.setCode(500);
  119. resp.setMessage("报错");
  120. return resp;
  121. }
  122. return null;
  123. }*/
  124. @ApiOperation(value = "根据ID删除检查年度计划分解")
  125. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  126. public BaseResponse<?> delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  127. Assert.notNull(id, "主键ID为必填参数");
  128. int ret = bisInspPlanDtlService.delete(id);
  129. return buildSuccessResponse();
  130. }
  131. @ApiOperation(value = "根据ID获取检查年度计划分解(单表)")
  132. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  133. public BaseResponse<BisInspPlanDtlDto> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  134. BisInspPlanDtl dtl = bisInspPlanDtlService.get(id);
  135. if (Objects.isNull(dtl)) {
  136. return buildSuccessResponse(null);
  137. }
  138. BisInspPlanDtlDto dto = new BisInspPlanDtlDto();
  139. BeanUtils.copyProperties(dtl, dto);
  140. //检查行政区
  141. Optional.ofNullable(bisInspPlanDtlAddvcdService.findList(new BisInspPlanDtlAddvcdParam(dto.getId()))).ifPresent(a -> {
  142. dto.setdAdCodes(a.stream().map(BisInspPlanDtlAddvcd::getAdCode).collect(Collectors.toList()));
  143. dto.setdAdName(a.stream().map(BisInspPlanDtlAddvcd::getAdName).collect(Collectors.joining(",")));
  144. });
  145. //督查类型
  146. Optional.ofNullable(bisInspPlanDtlPtypService.findList(new BisInspPlanDtlPtypParam(dto.getId()))).ifPresent(b -> {
  147. dto.setPtypIds(b.stream().map(BisInspPlanDtlPtyp::getPtype).collect(Collectors.toList()));
  148. });
  149. //参加处室单位
  150. dto.setPlanDpRlIds(bisInspPlandpRlService.findByPlanDpIdList(new BisInspPlandpRlParam(dto.getPlanId(), Constant.STRING_ONE)));
  151. return buildSuccessResponse(dto);
  152. }
  153. @ApiOperation(value = "获取列表")
  154. @RequestMapping(value = "/list", method = RequestMethod.POST)
  155. public BaseResponse<List<BisInspPlanDtlDto>> findPageList(@ApiParam(name = "bisInspPlanDtlParam", value = "bisInspPlanDtlParam", required = true) @RequestBody BisInspPlanDtlParam bisInspPlanDtlParam) {
  156. BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
  157. String planDpId = byId.getPlanDpId();
  158. if (StringUtils.isBlank(planDpId)){
  159. return buildSuccessResponse(new ArrayList<>());
  160. }
  161. Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{
  162. if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){
  163. bisInspPlanDtlParam.setPlanDpId(dp.getId());
  164. bisInspPlanDtlParam.setDdAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  165. }
  166. });
  167. return buildSuccessResponse(bisInspPlanDtlService.findDtlList(bisInspPlanDtlParam));
  168. }
  169. @ApiOperation(value = "导出详细计划")
  170. @RequestMapping(value = "/export", method = RequestMethod.POST)
  171. public void exportExcel(HttpServletResponse response, @ApiParam(name = "bisInspPlanDtlParam", value = "bisInspPlanDtlParam", required = true) @RequestBody BisInspPlanDtlParam bisInspPlanDtlParam){
  172. BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
  173. String planDpId = byId.getPlanDpId();
  174. if (StringUtils.isBlank(planDpId)){
  175. return ;
  176. }
  177. Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{
  178. if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){
  179. bisInspPlanDtlParam.setPlanDpId(dp.getId());
  180. bisInspPlanDtlParam.setDdAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  181. }
  182. });
  183. bisInspPlanDtlService.export(response, bisInspPlanDtlParam);
  184. }
  185. }