BusJcebController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. package com.railway.business.catenary.controller;
  2. import com.railway.business.baseinfo.service.IBaseStationService;
  3. import com.railway.business.catenary.domain.vo.JcebCountVo;
  4. import com.railway.business.catenary.domain.vo.JcebQueryVo;
  5. import com.railway.business.catenary.domain.vo.JcebRecordVo;
  6. import com.railway.business.catenary.domain.vo.JcebStationVo;
  7. import com.railway.business.catenary.enums.JcebStatusEnum;
  8. import com.railway.business.catenary.enums.JcebTypeEnum;
  9. import com.railway.business.catenary.enums.SortTypeEnum;
  10. import com.railway.business.catenary.service.IBusJcbBlqService;
  11. import com.railway.business.catenary.service.IBusJcbDmcgyqService;
  12. import com.railway.business.catenary.service.IBusJcbFdfxjyqService;
  13. import com.railway.business.catenary.service.IBusJcbGlkgService;
  14. import com.railway.business.catenary.service.IBusJcbJcxcService;
  15. import com.railway.business.catenary.service.IBusJcbWjcxcService;
  16. import com.railway.business.catenary.service.IBusJcebFzswjfxcService;
  17. import com.railway.business.catenary.service.IBusJcebGjsfxService;
  18. import com.railway.business.catenary.service.IBusJcebJddzService;
  19. import com.railway.business.catenary.service.IBusJcebJyzqsjlService;
  20. import com.railway.business.catenary.service.IBusJcebLbjghjlService;
  21. import com.railway.business.catenary.service.IBusJcebQmjcjlService;
  22. import com.railway.business.catenary.service.IBusJcebXsjcjlService;
  23. import com.railway.business.catenary.util.JcebQueryUtil;
  24. import com.railway.common.core.controller.BaseController;
  25. import com.railway.common.core.domain.AjaxResult;
  26. import com.railway.common.core.page.TableDataInfo;
  27. import com.railway.common.utils.StringUtils;
  28. import com.railway.system.service.ISysFileService;
  29. import io.swagger.annotations.Api;
  30. import io.swagger.annotations.ApiOperation;
  31. import java.util.ArrayList;
  32. import java.util.Comparator;
  33. import java.util.List;
  34. import lombok.extern.slf4j.Slf4j;
  35. import org.springframework.validation.annotation.Validated;
  36. import org.springframework.web.bind.annotation.GetMapping;
  37. import org.springframework.web.bind.annotation.RequestMapping;
  38. import org.springframework.web.bind.annotation.RestController;
  39. /**
  40. * @author ZhaoMn
  41. */
  42. @Slf4j
  43. @Api(value = "rest/catenary/bus/jceb/view", tags = "检测表 - 汇总接口")
  44. @RestController
  45. @Validated
  46. @RequestMapping(value = "business/catenary/bus/jceb/view")
  47. public class BusJcebController extends BaseController {
  48. private final IBusJcebXsjcjlService xsjcjlService;
  49. private final IBusJcebQmjcjlService qmjcjlService;
  50. private final IBusJcebLbjghjlService lbjghjlService;
  51. private final IBusJcebJyzqsjlService jyzqsjlService;
  52. private final IBusJcebJddzService jddzService;
  53. private final IBusJcebGjsfxService gjsfxService;
  54. private final IBusJcebFzswjfxcService fzswjfxcService;
  55. private final IBusJcbBlqService blqService;
  56. private final IBusJcbDmcgyqService dmcgyqService;
  57. private final IBusJcbFdfxjyqService fdfxjyqService;
  58. private final IBusJcbGlkgService glkgService;
  59. private final IBusJcbJcxcService jcxcService;
  60. private final IBusJcbWjcxcService wjcxcService;
  61. private final IBaseStationService stationService;
  62. private final ISysFileService fileService;
  63. public BusJcebController(
  64. IBusJcebXsjcjlService xsjcjlService,
  65. IBusJcebQmjcjlService qmjcjlService,
  66. IBusJcebLbjghjlService lbjghjlService,
  67. IBusJcebJyzqsjlService jyzqsjlService,
  68. IBusJcebJddzService jddzService,
  69. IBusJcebGjsfxService gjsfxService,
  70. IBusJcebFzswjfxcService fzswjfxcService,
  71. IBusJcbBlqService blqService,
  72. IBusJcbDmcgyqService dmcgyqService,
  73. IBusJcbFdfxjyqService fdfxjyqService,
  74. IBusJcbGlkgService glkgService,
  75. IBusJcbJcxcService jcxcService,
  76. IBusJcbWjcxcService wjcxcService,
  77. IBaseStationService stationService,
  78. ISysFileService fileService) {
  79. this.xsjcjlService = xsjcjlService;
  80. this.qmjcjlService = qmjcjlService;
  81. this.lbjghjlService = lbjghjlService;
  82. this.jyzqsjlService = jyzqsjlService;
  83. this.jddzService = jddzService;
  84. this.gjsfxService = gjsfxService;
  85. this.fzswjfxcService = fzswjfxcService;
  86. this.blqService = blqService;
  87. this.dmcgyqService = dmcgyqService;
  88. this.fdfxjyqService = fdfxjyqService;
  89. this.glkgService = glkgService;
  90. this.jcxcService = jcxcService;
  91. this.wjcxcService = wjcxcService;
  92. this.stationService = stationService;
  93. this.fileService = fileService;
  94. }
  95. @ApiOperation(value = "筛选车间列表")
  96. @GetMapping(value = "listStation")
  97. public TableDataInfo listStation(JcebQueryVo query) {
  98. JcebQueryUtil.setBusJcebQuery(query);
  99. JcebTypeEnum jcebTypeEnum = JcebTypeEnum.ofValue(query.getJcebType());
  100. List<JcebStationVo> list;
  101. switch (jcebTypeEnum) {
  102. case Blq:
  103. list = blqService.listStation(query);
  104. break;
  105. case Dmcgyq:
  106. list = dmcgyqService.listStation(query);
  107. break;
  108. case Fdfxjyq:
  109. list = fdfxjyqService.listStation(query);
  110. break;
  111. case Glkg:
  112. list = glkgService.listStation(query);
  113. break;
  114. case Jcxc:
  115. list = jcxcService.listStation(query);
  116. break;
  117. case Wjcxc:
  118. list = wjcxcService.listStation(query);
  119. break;
  120. default:
  121. list = stationService.listStation(query);
  122. break;
  123. }
  124. return getDataTable(list);
  125. }
  126. @ApiOperation(value = "列表")
  127. @GetMapping(value = "listByType")
  128. public TableDataInfo listByType(JcebQueryVo query) {
  129. log.debug("#$#$#$#$ ---- JcebQueryVo = {}", query.toString());
  130. startPage();
  131. JcebTypeEnum jcebTypeEnum = JcebTypeEnum.ofValue(query.getJcebType());
  132. // 设置查询权限
  133. JcebQueryUtil.setBusJcebQuery(query);
  134. if (jcebTypeEnum.isJcabType()) {
  135. query.setSubmitState(JcebStatusEnum.COMPLETED.getCode());
  136. }
  137. query.setJcebTypeText(jcebTypeEnum.getDescribe());
  138. List<JcebRecordVo> list = null;
  139. switch (jcebTypeEnum) {
  140. case Jddz:
  141. list = jddzService.getListByType(query);
  142. break;
  143. case Gjsfx:
  144. list = gjsfxService.getListByType(query);
  145. break;
  146. case Qmjcjl:
  147. list = qmjcjlService.getListByType(query);
  148. break;
  149. case Xsjcjl:
  150. list = xsjcjlService.getListByType(query);
  151. break;
  152. case Jyzqsjl:
  153. list = jyzqsjlService.getListByType(query);
  154. break;
  155. case Lbjghjl:
  156. list = lbjghjlService.getListByType(query);
  157. break;
  158. case Fzswjfxc:
  159. list = fzswjfxcService.getListByType(query);
  160. break;
  161. case Blq:
  162. list = blqService.getListByType(query);
  163. break;
  164. case Dmcgyq:
  165. list = dmcgyqService.getListByType(query);
  166. break;
  167. case Fdfxjyq:
  168. list = fdfxjyqService.getListByType(query);
  169. break;
  170. case Glkg:
  171. list = glkgService.getListByType(query);
  172. break;
  173. case Jcxc:
  174. list = jcxcService.getListByType(query);
  175. break;
  176. case Wjcxc:
  177. list = wjcxcService.getListByType(query);
  178. break;
  179. default:
  180. break;
  181. }
  182. return getDataTable(list);
  183. }
  184. @ApiOperation(value = "导出Excel")
  185. @GetMapping(value = "exportExcel")
  186. public AjaxResult exportExcel(JcebQueryVo query) {
  187. JcebTypeEnum jcebTypeEnum = JcebTypeEnum.ofValue(query.getJcebType());
  188. // 设置查询权限
  189. JcebQueryUtil.setBusJcebQuery(query);
  190. if (jcebTypeEnum.isJcabType()) {
  191. query.setSubmitState(JcebStatusEnum.COMPLETED.getCode());
  192. }
  193. String localFilePath = null;
  194. switch (jcebTypeEnum) {
  195. case Jddz:
  196. localFilePath = jddzService.exportExcel(query);
  197. break;
  198. case Gjsfx:
  199. localFilePath = gjsfxService.exportExcel(query);
  200. break;
  201. case Qmjcjl:
  202. localFilePath = qmjcjlService.exportExcel(query);
  203. break;
  204. case Xsjcjl:
  205. localFilePath = xsjcjlService.exportExcel(query);
  206. break;
  207. case Jyzqsjl:
  208. localFilePath = jyzqsjlService.exportExcel(query);
  209. break;
  210. case Lbjghjl:
  211. localFilePath = lbjghjlService.exportExcel(query);
  212. break;
  213. case Fzswjfxc:
  214. localFilePath = fzswjfxcService.exportExcel(query);
  215. break;
  216. case Blq:
  217. localFilePath = blqService.exportExcel(query);
  218. break;
  219. case Dmcgyq:
  220. localFilePath = dmcgyqService.exportExcel(query);
  221. break;
  222. case Fdfxjyq:
  223. localFilePath = fdfxjyqService.exportExcel(query);
  224. break;
  225. case Glkg:
  226. localFilePath = glkgService.exportExcel(query);
  227. break;
  228. case Jcxc:
  229. localFilePath = jcxcService.exportExcel(query);
  230. break;
  231. case Wjcxc:
  232. localFilePath = wjcxcService.exportExcel(query);
  233. break;
  234. default:
  235. break;
  236. }
  237. if (StringUtils.isEmpty(localFilePath)) {
  238. return AjaxResult.error("下载失败");
  239. }
  240. return fileService.uploadFile(localFilePath);
  241. }
  242. @ApiOperation(value = "汇总列表")
  243. @GetMapping(value = "listAll")
  244. public TableDataInfo listAll(JcebQueryVo query) {
  245. // 设置查询权限
  246. JcebQueryUtil.setBusJcebQuery(query);
  247. String submitState = query.getSubmitState();
  248. List<JcebCountVo> list = new ArrayList<>();
  249. for (JcebTypeEnum jcebTypeEnum : JcebTypeEnum.values()) {
  250. if (jcebTypeEnum.isJcabType()) {
  251. query.setSubmitState(JcebStatusEnum.COMPLETED.getCode());
  252. } else {
  253. query.setSubmitState(submitState);
  254. }
  255. JcebCountVo jcebRecordVo = null;
  256. switch (jcebTypeEnum) {
  257. case Jddz:
  258. jcebRecordVo = jddzService.getCountByType(query);
  259. break;
  260. case Gjsfx:
  261. jcebRecordVo = gjsfxService.getCountByType(query);
  262. break;
  263. case Qmjcjl:
  264. jcebRecordVo = qmjcjlService.getCountByType(query);
  265. break;
  266. case Xsjcjl:
  267. jcebRecordVo = xsjcjlService.getCountByType(query);
  268. break;
  269. case Jyzqsjl:
  270. jcebRecordVo = jyzqsjlService.getCountByType(query);
  271. break;
  272. case Lbjghjl:
  273. jcebRecordVo = lbjghjlService.getCountByType(query);
  274. break;
  275. case Fzswjfxc:
  276. jcebRecordVo = fzswjfxcService.getCountByType(query);
  277. break;
  278. case Blq:
  279. jcebRecordVo = blqService.getCountByType(query);
  280. break;
  281. case Dmcgyq:
  282. jcebRecordVo = dmcgyqService.getCountByType(query);
  283. break;
  284. case Fdfxjyq:
  285. jcebRecordVo = fdfxjyqService.getCountByType(query);
  286. break;
  287. case Glkg:
  288. jcebRecordVo = glkgService.getCountByType(query);
  289. break;
  290. case Jcxc:
  291. jcebRecordVo = jcxcService.getCountByType(query);
  292. break;
  293. case Wjcxc:
  294. jcebRecordVo = wjcxcService.getCountByType(query);
  295. break;
  296. default:
  297. break;
  298. }
  299. if (null != jcebRecordVo) {
  300. jcebRecordVo.setJcebType(jcebTypeEnum.getTypeCode());
  301. list.add(jcebRecordVo);
  302. }
  303. }
  304. // 汇总结果按日期(最新的操作日期)排序
  305. SortTypeEnum sortType = SortTypeEnum.ofValue(query.getIsAsc());
  306. JcebCountComparator comparator = new JcebCountComparator();
  307. if (null == sortType || sortType == SortTypeEnum.DESC) {
  308. comparator.setIsAsc(SortTypeEnum.DESC);
  309. list.sort(comparator);
  310. } else {
  311. log.info("排序类型 - {}", sortType.getNotes());
  312. comparator.setIsAsc(SortTypeEnum.ASC);
  313. list.sort(comparator);
  314. }
  315. return getDataTable(list);
  316. }
  317. /**
  318. * 按最后操作时间排序策略
  319. */
  320. static class JcebCountComparator implements Comparator<JcebCountVo> {
  321. private SortTypeEnum isAsc;
  322. public void setIsAsc(SortTypeEnum isAsc) {
  323. this.isAsc = isAsc;
  324. }
  325. @Override
  326. public int compare(JcebCountVo jceb1, JcebCountVo jceb2) {
  327. if (jceb1.getOperationDate() != null && jceb2.getOperationDate() != null) {
  328. long t1 = jceb1.getOperationDate().getTime();
  329. long t2 = jceb2.getOperationDate().getTime();
  330. int ret = Long.compare(t1, t2);
  331. if (isAsc == SortTypeEnum.DESC) {
  332. ret *= -1;
  333. }
  334. return ret;
  335. } else {
  336. return jceb1.getOperationDate() == null ? 1 : -1;
  337. }
  338. }
  339. }
  340. }