7caf29f53b63a52f7e09271be4d394874556b518.svn-base 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package cn.com.goldenwater.dcproj.controller.ducha;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers;
  5. import cn.com.goldenwater.dcproj.model.BisInspMtprggd;
  6. import cn.com.goldenwater.dcproj.model.BisInspPlanDp;
  7. import cn.com.goldenwater.dcproj.model.BisInspPlanYear;
  8. import cn.com.goldenwater.dcproj.model.BisInspPlanYearPrg;
  9. import cn.com.goldenwater.dcproj.param.BisInspPlanDpParam;
  10. import cn.com.goldenwater.dcproj.param.BisInspPlanYearParam;
  11. import cn.com.goldenwater.dcproj.param.BisInspPlanYearPrgParam;
  12. import cn.com.goldenwater.dcproj.param.BisInspPlandpRlParam;
  13. import cn.com.goldenwater.dcproj.service.*;
  14. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  15. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  16. import cn.com.goldenwater.dcproj.utils.Constant;
  17. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  18. import cn.com.goldenwater.id.util.UuidUtil;
  19. import com.github.pagehelper.PageInfo;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import io.swagger.annotations.ApiParam;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  25. import org.slf4j.Logger;
  26. import org.slf4j.LoggerFactory;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.beans.factory.annotation.Value;
  29. import org.springframework.util.Assert;
  30. import org.springframework.web.bind.annotation.*;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.File;
  34. import java.io.IOException;
  35. import java.nio.file.Paths;
  36. import java.text.SimpleDateFormat;
  37. import java.util.*;
  38. import java.util.stream.Collectors;
  39. /**
  40. * @author lhc
  41. * @date 2022-3-3
  42. */
  43. @Api(value = "山东年度计划管理", tags = "山东年度计划管理")
  44. @RestController
  45. @RequestMapping("/bis/insp/plan/year")
  46. public class BisInspPlanYearController extends BaseController {
  47. private Logger logger = LoggerFactory.getLogger(getClass());
  48. @Autowired
  49. private BisInspPlanYearService bisInspPlanYearService;
  50. @Autowired
  51. private BisInspPlanYearPrgService bisInspPlanYearPrgService;
  52. @Autowired
  53. private BisInspMtprggdService mtprggdService;
  54. @Autowired
  55. private BisInspMtprggdService bisInspMtprggdService;
  56. @Autowired
  57. private OlBisInspOrgService olBisInspOrgService;
  58. @Autowired
  59. private BisInspPlandpRlService bisInspPlandpRlService;
  60. @Autowired
  61. private BisInspAllRlationPersService bisInspAllRlationPersService;
  62. @Autowired
  63. private BisInspPlanDpService bisInspPlanDpService;
  64. private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  65. @Value("${export.templatePath}")
  66. private String templatePath;
  67. @ApiOperation(value = "添加山东年度计划")
  68. @RequestMapping(value = "/", method = RequestMethod.POST)
  69. public BaseResponse<BisInspPlanYear> insert(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) {
  70. bisInspPlanYear.setOrgId(getCurrentOrgId());
  71. String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()));
  72. if (StringUtils.isBlank(bisInspPlanYear.getId())) {
  73. bisInspPlanYear.setAdCode(olBisInspOrgService.getRlProvince(getCurrentOrgId()));
  74. bisInspPlanYear.setPersId(getCurrentPersId());
  75. bisInspPlanYearService.insert(bisInspPlanYear);
  76. } else {
  77. bisInspPlanYearService.update(bisInspPlanYear);
  78. }
  79. //山东
  80. if (StringUtils.equalsAny(addvcd, "37")) {
  81. bisInspPlanYearService.updatePostProcessing(bisInspPlanYear);
  82. }
  83. return buildSuccessResponse(bisInspPlanYear);
  84. }
  85. @ApiOperation(value = "根据ID删除山东年度计划")
  86. @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
  87. public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  88. int ret = bisInspPlanYearService.delete(id);
  89. return buildSuccessResponse();
  90. }
  91. @ApiOperation(value = "更新山东年度计划信息")
  92. @RequestMapping(value = "/update", method = RequestMethod.POST)
  93. public BaseResponse<BisInspPlanYear> update(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) {
  94. Assert.notNull(bisInspPlanYear.getId(), "主键id为必填参数");
  95. int ret = bisInspPlanYearService.update(bisInspPlanYear);
  96. return buildSuccessResponse(bisInspPlanYear);
  97. }
  98. @ApiOperation(value = "更新山东年度计划信息")
  99. @RequestMapping(value = "/bingObjType", method = RequestMethod.POST)
  100. public BaseResponse<BisInspPlanYear> bingObjType(@ApiParam(name = "bisInspPlanYear", value = "BisInspPlanYear", required = true) @RequestBody BisInspPlanYear bisInspPlanYear) {
  101. Assert.notNull(bisInspPlanYear.getId(), "主键id为必填参数");
  102. String curentOrgId = getCurrentOrgId();
  103. bisInspPlanYear.setOrgId(curentOrgId);
  104. int ret = bisInspPlanYearService.bingObjType(bisInspPlanYear);
  105. return buildSuccessResponse(bisInspPlanYear);
  106. }
  107. @ApiOperation(value = "根据ID获取山东年度计划(单表)")
  108. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  109. public BaseResponse<BisInspPlanYear> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  110. BisInspPlanYear bisInspPlanYear = bisInspPlanYearService.get(id);
  111. if (Objects.nonNull(bisInspPlanYear)) {
  112. String addvcd = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()));
  113. //山东
  114. if (StringUtils.equalsAny(addvcd,"37")){
  115. //参加处室单位 ids
  116. List<String> planDpIdList = bisInspPlandpRlService.findByPlanDpIdList(new BisInspPlandpRlParam(id, Constant.STRING_ZERO));
  117. bisInspPlanYear.setPlanDpRlIds(planDpIdList);
  118. //参加处室单位 names
  119. List<BisInspPlanDp> dpList = bisInspPlanDpService.findList(new BisInspPlanDpParam(addvcd));
  120. bisInspPlanYear.setJoinDep(dpList.stream().filter(dp -> planDpIdList.contains(dp.getId())).map(BisInspPlanDp::getDpName).collect(Collectors.joining(",")));
  121. }
  122. }
  123. return buildSuccessResponse(bisInspPlanYear);
  124. }
  125. @ApiOperation(value = "获取列 表(分页)")
  126. @RequestMapping(value = "findPageList", method = RequestMethod.POST)
  127. public BaseResponse<PageInfo<BisInspPlanYear>> findPageList(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearParam bisInspPlanYearParam, HttpServletResponse response) {
  128. bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  129. BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
  130. //山东
  131. if (StringUtils.equalsAny(bisInspPlanYearParam.getAdCode(),"37")){
  132. bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getRlProvince(getCurrentOrgId())));
  133. String planDpId = byId.getPlanDpId();
  134. if (StringUtils.isBlank(planDpId)){
  135. return buildSuccessResponse(new PageInfo<>());
  136. }
  137. Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{
  138. if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){
  139. bisInspPlanYearParam.setPlanDpId(dp.getId());
  140. }
  141. });
  142. }
  143. PageInfo<BisInspPlanYear> bisInspPlanYearPageInfo = bisInspPlanYearService.findPageList(bisInspPlanYearParam);
  144. return buildSuccessResponse(bisInspPlanYearPageInfo);
  145. }
  146. @ApiOperation(value = "获取列表")
  147. @RequestMapping(value = "findList", method = RequestMethod.POST)
  148. public BaseResponse<List<BisInspPlanYear>> findList(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearParam bisInspPlanYearParam, HttpServletResponse response) {
  149. bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  150. BisInspAllRlationPers byId = bisInspAllRlationPersService.getById(getCurrentPersId());
  151. //山东
  152. if (StringUtils.equalsAny(bisInspPlanYearParam.getAdCode(),"37")){
  153. String planDpId = byId.getPlanDpId();
  154. if (StringUtils.isBlank(planDpId)){
  155. return buildSuccessResponse(new ArrayList<>());
  156. }
  157. Optional.ofNullable(bisInspPlanDpService.get(planDpId)).ifPresent(dp ->{
  158. if (!StringUtils.equals(Constant.STRING_TWO,dp.getDpType())){
  159. bisInspPlanYearParam.setPlanDpId(dp.getId());
  160. }
  161. });
  162. }
  163. List<BisInspPlanYear> bisInspPlanYearPageInfo = bisInspPlanYearService.findList(bisInspPlanYearParam);
  164. return buildSuccessResponse(bisInspPlanYearPageInfo);
  165. }
  166. @ApiOperation(value = "获取列表")
  167. @RequestMapping(value = "findListByMonth", method = RequestMethod.POST)
  168. public BaseResponse<Object> findListByMonth(@ApiParam(name = "BisInspPlanYearPrgParam", value = "BisInspPlanYearPrgParam", required = true) @RequestBody BisInspPlanYearPrgParam bisInspPlanYearPrgParam, HttpServletResponse response) {
  169. bisInspPlanYearPrgParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  170. if ("37".equals(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())))) {
  171. List<BisInspPlanYearPrg> list = bisInspPlanYearPrgService.findListByMonth(bisInspPlanYearPrgParam);
  172. return buildSuccessResponse(list);
  173. } else {
  174. List<BisInspMtprggd> list = bisInspMtprggdService.findListByMonth(bisInspPlanYearPrgParam);
  175. return buildSuccessResponse(list);
  176. }
  177. }
  178. @ApiOperation(value = "导出检查表")
  179. @RequestMapping(value = "/exportMonth", method = RequestMethod.POST)
  180. public void export(HttpServletResponse response, @RequestBody BisInspPlanYearPrgParam bisInspPlanYearPrgParam) {
  181. bisInspPlanYearPrgParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  182. if ("37".equals(bisInspPlanYearPrgParam.getAdCode())) {
  183. bisInspPlanYearPrgParam.setOrgId(getCurrentOrgId());
  184. bisInspPlanYearPrgService.export(response, bisInspPlanYearPrgParam, "1");
  185. } else {
  186. mtprggdService.exportMonth(response, null, bisInspPlanYearPrgParam, "1");
  187. }
  188. }
  189. @ApiOperation("获取导入模板")
  190. @GetMapping(value = "/getExl")
  191. public BaseResponse getExl(HttpServletResponse response) {
  192. String path = templatePath + File.separator + "planCheckSd.xls";
  193. try {
  194. ExpAndImpUtil.downloadFile(response, path, "年度检查表");
  195. } catch (Exception e) {
  196. logger.error(e.getMessage(), e);
  197. }
  198. return buildSuccessResponse();
  199. }
  200. @ApiOperation(value = "导出检查表")
  201. @RequestMapping(value = "/export", method = RequestMethod.POST)
  202. public void export(HttpServletResponse response, @RequestBody BisInspPlanYearParam bisInspPlanYearParam) {
  203. bisInspPlanYearParam.setAdCode(AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId())));
  204. bisInspPlanYearService.export(response, bisInspPlanYearParam);
  205. }
  206. @ApiOperation("上传 xls 导入数据")
  207. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  208. public BaseResponse<Map<String, Object>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  209. // 获取文件名
  210. String fileName = multfile.getOriginalFilename();
  211. // 获取文件后缀
  212. String prefix = fileName.substring(fileName.lastIndexOf("."));
  213. // 用uuid作为文件名,防止生成的临时文件重复
  214. String uuid = UuidUtil.uuid();
  215. File file = File.createTempFile(uuid, prefix);
  216. // MultipartFile to File
  217. multfile.transferTo(Paths.get(file.getPath()));
  218. Map<String, Object> map = new HashMap<>(2);
  219. int shu = 0;
  220. int success = 0;
  221. String[][] data = ReadExcelUtil.getData(file, 3);
  222. try {
  223. if (data != null && data.length > 0) {
  224. for (int i = 0; i < data.length; i++) {
  225. BisInspPlanYear bisInspPlanYear = new BisInspPlanYear();
  226. bisInspPlanYear.setChkName(data[i][1]);
  227. bisInspPlanYear.setChkType(data[i][2]);
  228. bisInspPlanYear.setPlanSttm(simpleDateFormat.parse(data[i][3]));
  229. bisInspPlanYear.setPlanEntm(simpleDateFormat.parse(data[i][4]));
  230. bisInspPlanYear.setLeadDep(data[i][5]);
  231. bisInspPlanYear.setJoinDep(data[i][6]);
  232. bisInspPlanYear.setChkForm(data[i][7]);
  233. bisInspPlanYear.setChkScope(data[i][8]);
  234. bisInspPlanYear.setChkRly(data[i][9]);
  235. bisInspPlanYear.setNote(data[i][10]);
  236. insert(bisInspPlanYear);
  237. success++;
  238. }
  239. }
  240. } catch (Exception e) {
  241. shu++;
  242. logger.error(e.getMessage(), e);
  243. }
  244. map.put("false", shu);
  245. map.put("success", success);
  246. return buildSuccessResponse(map);
  247. }
  248. }