ArchiveManageController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package com.welampiot.controller;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.ArchiveInfoAttachmentDTO;
  5. import com.welampiot.dto.ArchiveManageDTO;
  6. import com.welampiot.service.ArchiveInfoAttachmentService;
  7. import com.welampiot.service.ArchiveManageService;
  8. import com.welampiot.utils.ExcelUtil;
  9. import com.welampiot.utils.ToolUtils;
  10. import com.welampiot.vo.ArchiveManageVO;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.CrossOrigin;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestMethod;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import org.springframework.web.multipart.MultipartFile;
  17. import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
  18. import javax.servlet.http.HttpServletRequest;
  19. import java.text.ParseException;
  20. import java.text.SimpleDateFormat;
  21. import java.util.*;
  22. @RestController
  23. @CrossOrigin
  24. @RequestMapping("/archiveManage")
  25. public class ArchiveManageController {
  26. @Autowired
  27. private ToolUtils toolUtils;
  28. @Autowired
  29. private ArchiveManageService archiveManageService;
  30. @Autowired
  31. private ArchiveInfoAttachmentService archiveInfoAttachmentService;
  32. @RequestMapping(value = "/save",method = RequestMethod.POST)
  33. public BaseResult<?> save(HttpServletRequest request) {
  34. Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
  35. Integer version = request.getParameter("versoin") == null ? 0 : Integer.parseInt(request.getParameter("versoin"));
  36. Integer areaId = request.getParameter("areaId") == null ? 0 : Integer.parseInt(request.getParameter("areaId"));
  37. Integer sectionId = request.getParameter("sectionId") == null ? 0 : Integer.parseInt(request.getParameter("sectionId"));
  38. String name = request.getParameter("name");
  39. Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
  40. String department = request.getParameter("department");
  41. String number = request.getParameter("number");
  42. if(areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR, version);
  43. if(sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR, version);
  44. if (name == null || (name != null && name.isEmpty())) return toolUtils.response(InterfaceResultEnum.LACK_FILE_NAME_ERROR,version);
  45. if (number == null || (number != null && number.isEmpty())) return toolUtils.response(InterfaceResultEnum.LACK_FILE_NUMBER_ERROR,version);
  46. ArrayList<ArchiveInfoAttachmentDTO> list = new ArrayList<>();
  47. ArchiveInfoAttachmentDTO dto = null;
  48. Map<String, String[]> fileList = request.getParameterMap();
  49. int i = 0; //每三个值都设置一次就会重设置
  50. //set排序,从下标0开始
  51. Set<String> setCollection = fileList.keySet();
  52. Set<String> sortSet = new TreeSet<String>((o1, o2) -> o1.compareTo(o2));
  53. sortSet.addAll(setCollection);
  54. //查找相应的值 - 这里是二维数组
  55. for (String key : sortSet) {//返回set类型,无序的
  56. if (key.contains("fileList")) {
  57. String[] values = fileList.get(key);
  58. if (i == 0) {
  59. dto = new ArchiveInfoAttachmentDTO();
  60. }
  61. i++;
  62. if (key.contains("name")) {
  63. dto.setName(values[0]);
  64. }
  65. if (key.contains("type")) {
  66. dto.setType(Integer.parseInt(values[0]));
  67. }
  68. if (key.contains("url")) {
  69. dto.setPath(values[0]);
  70. }
  71. if (i == 3) {
  72. if (dto.getName() != null && dto.getType() != null && dto.getPath() != null) {
  73. //三个必须都有值
  74. list.add(dto);
  75. i = 0;
  76. } else {
  77. //有一个没有值,返回
  78. return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
  79. }
  80. }
  81. }
  82. }
  83. if (i > 0 && i < 3) {
  84. //有一个没有值,返回
  85. return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
  86. }
  87. //fileList
  88. ArchiveManageDTO archiveManageDTO = new ArchiveManageDTO();
  89. archiveManageDTO.setAreaId(areaId);
  90. archiveManageDTO.setSectionId(sectionId);
  91. archiveManageDTO.setName(name);
  92. archiveManageDTO.setType(type);
  93. archiveManageDTO.setDepartment(department);
  94. archiveManageDTO.setNumber(number);
  95. Date date = new Date();
  96. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  97. String currentTime = dateFormat.format(date);
  98. if (id == 0) {
  99. //新建
  100. Integer total = archiveManageService.chectCount(archiveManageDTO);
  101. if (total > 0 ) toolUtils.response(InterfaceResultEnum.REPEAT_FILE_NAME_ERROR, 0);
  102. archiveManageDTO.setCreateTime(currentTime);
  103. archiveManageService.addData(archiveManageDTO);
  104. } else {
  105. //编辑
  106. archiveManageDTO.setId(id);
  107. Integer total = archiveManageService.chectCount(archiveManageDTO);
  108. if (total > 0 ) toolUtils.response(InterfaceResultEnum.REPEAT_FILE_NAME_ERROR, 0);
  109. archiveManageDTO.setUpdateTime(currentTime);
  110. archiveManageService.updateData(archiveManageDTO);
  111. }
  112. if (list.size() != 0) {
  113. ArchiveInfoAttachmentDTO archiveInfoAttachmentDTO = new ArchiveInfoAttachmentDTO();
  114. archiveInfoAttachmentDTO.setArchiveInfoId(id);
  115. archiveInfoAttachmentService.deleteData(archiveInfoAttachmentDTO);
  116. for (ArchiveInfoAttachmentDTO item : list) {
  117. item.setArchiveInfoId(archiveManageDTO.getId());
  118. archiveInfoAttachmentService.addData(item);
  119. }
  120. }
  121. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, 0);
  122. }
  123. @RequestMapping(value = "/getList",method = RequestMethod.POST)
  124. public BaseResult<?> getList(HttpServletRequest request) {
  125. Integer version = request.getParameter("versoin") == null ? 0 : Integer.parseInt(request.getParameter("versoin"));
  126. Integer areaId = request.getParameter("areaId") == null ? 0 : Integer.parseInt(request.getParameter("areaId"));
  127. Integer sectionId = request.getParameter("sectionId") == null ? 0 : Integer.parseInt(request.getParameter("sectionId"));
  128. Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
  129. Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
  130. Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
  131. String keyword = request.getParameter("keyword");
  132. String date = request.getParameter("date");
  133. Integer download = request.getParameter("download") == null ? 0 : Integer.parseInt(request.getParameter("download"));
  134. ArchiveManageVO vo = new ArchiveManageVO();
  135. ArrayList<ArchiveManageDTO> list = new ArrayList<>();
  136. vo.setList(list);
  137. if (sectionId == 0){
  138. List sectionList = toolUtils.getSectionList(request);
  139. if (sectionList == null || sectionList.size() == 0) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
  140. vo.setSectionList(sectionList);
  141. }
  142. vo.setPage((page-1) * count);
  143. vo.setCount(count);
  144. vo.setType(type);
  145. vo.setKeyword(keyword);
  146. vo.setDate(date);
  147. vo.setVersion(version);
  148. vo.setAreaId(areaId);
  149. vo.setSectionId(sectionId);
  150. if (date != null){
  151. String[] splits = date.split("/");
  152. vo.setBeginTime(splits[0] + " 00:00:00");
  153. if (splits.length == 1){
  154. vo.setEndTime(splits[0] + " 23:59:59");
  155. }else {
  156. vo.setEndTime(splits[1] + " 23:59:59");
  157. }
  158. }
  159. List<ArchiveManageDTO> joinList = archiveManageService.getJoinList(vo);
  160. ArchiveInfoAttachmentDTO attachmentDTO = new ArchiveInfoAttachmentDTO();
  161. ArchiveManageDTO archiveManageDTO = new ArchiveManageDTO();
  162. if (download == 0){
  163. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  164. for (ArchiveManageDTO item:joinList) {
  165. ArrayList<ArchiveInfoAttachmentDTO> fileList0 = new ArrayList<>();
  166. ArrayList<ArchiveInfoAttachmentDTO> fileList1 = new ArrayList<>();
  167. ArrayList<ArchiveInfoAttachmentDTO> fileList2 = new ArrayList<>();
  168. ArrayList<ArchiveInfoAttachmentDTO> fileList3 = new ArrayList<>();
  169. ArrayList<ArchiveInfoAttachmentDTO> fileList4 = new ArrayList<>();
  170. attachmentDTO.setArchiveInfoId(item.getId());
  171. List<ArchiveInfoAttachmentDTO> dtos = archiveInfoAttachmentService.getOneData(attachmentDTO);
  172. item.setCount0(0);
  173. item.setCount1(0);
  174. item.setCount2(0);
  175. item.setCount3(0);
  176. item.setCount4(0);
  177. for (ArchiveInfoAttachmentDTO dto:dtos) {
  178. dto.setId(null);
  179. if(dto.getType() == 0){
  180. item.setCount0(item.getCount0() + 1);
  181. dto.setType(null);
  182. fileList0.add(dto);
  183. } else if (dto.getType() == 1) {
  184. item.setCount1(item.getCount1() + 1);
  185. dto.setType(null);
  186. fileList1.add(dto);
  187. }else if (dto.getType() == 2) {
  188. item.setCount2(item.getCount2() + 1);
  189. dto.setType(null);
  190. fileList2.add(dto);
  191. }else if (dto.getType() == 3) {
  192. item.setCount3(item.getCount3() + 1);
  193. dto.setType(null);
  194. fileList3.add(dto);
  195. }else if (dto.getType() == 4) {
  196. item.setCount4(item.getCount4() + 1);
  197. dto.setType(null);
  198. fileList4.add(dto);
  199. }
  200. }
  201. item.setFileList0(fileList0);
  202. item.setFileList1(fileList1);
  203. item.setFileList2(fileList2);
  204. item.setFileList3(fileList3);
  205. item.setFileList4(fileList4);
  206. try {
  207. Date parse = dateFormat.parse(item.getCreateTime());
  208. item.setCreateTime(dateFormat.format(parse));
  209. } catch (ParseException e) {
  210. throw new RuntimeException(e);
  211. }
  212. }
  213. Integer total = archiveManageService.getCount(vo);
  214. archiveManageDTO.setList(joinList);
  215. archiveManageDTO.setTotal(total);
  216. // return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,archiveManageDTO);
  217. }else {
  218. String title;
  219. if (version == 0) {
  220. if (type == 0){
  221. title = "序号,项目名称,项目编号,立项档案,设计档案,验收档案,建档时间,归档情况";
  222. } else if (type == 1) {
  223. title = "序号,设备名称,设备编号,档案,建档时间,归档情况";
  224. }else {
  225. title = "序号,工单名称,工单号,档案,建档时间,归档情况";
  226. }
  227. } else if (version == 1) {
  228. if (type == 0){
  229. title = "SN,Project Name,Project No.,Project Initiation File,Design File,Acceptance File,Filing Time,Filing Status";
  230. }else if (type == 1) {
  231. title = "SN,Equipment Name,Equipment No.,File,File Creation Time,Archive Status";
  232. }else{
  233. title = "SN,work order name,work order number,file,filing time,filing status";
  234. }
  235. } else {
  236. if (type == 0){
  237. title = "Серийный номер,Название проекта,Номер проекта,Архив проекта,Архив проекта,Архив проекта,Архив приемки,Время архивирования,Архивное положение";
  238. }else if (type == 1){
  239. title = "Серийный номер,название устройства,номер устройства,архив,время архивирования,архив ситуации";
  240. }else{
  241. title = "Серийный номер,название рабочего листа,номер рабочего листа,архив,время архивирования,архивная ситуация";
  242. }
  243. }
  244. List<String> titleList = Arrays.asList(title.split(","));
  245. List<List<String>> contentList = new ArrayList<>();
  246. int number = 1;//序号
  247. for (ArchiveManageDTO item:joinList){
  248. int index = 0; //下标
  249. List<String> newString = new ArrayList<>();
  250. newString.add(index++, String.valueOf(number));
  251. newString.add(index++,item.getName());
  252. newString.add(index++,item.getNumber());
  253. attachmentDTO.setArchiveInfoId(item.getId());
  254. List<ArchiveInfoAttachmentDTO> dtos = archiveInfoAttachmentService.getOneData(attachmentDTO);
  255. if (dtos == null || dtos.size() == 0){
  256. newString.add(index++,"");
  257. if (type == 0){
  258. newString.add(index++,"");
  259. newString.add(index++,"");
  260. }
  261. }else {
  262. int typeIndex = 0;
  263. for (ArchiveInfoAttachmentDTO dto:dtos) {
  264. if (dto.getType() == 2){
  265. //立项
  266. newString.add(index++,dto.getPath());
  267. typeIndex ++;
  268. } else if (dto.getType() == 1) {
  269. //设计
  270. newString.add(index++,dto.getPath());
  271. typeIndex ++;
  272. } else if (dto.getType() == 4) {
  273. //验收
  274. newString.add(index++,dto.getPath());
  275. typeIndex ++;
  276. }else {
  277. //其它
  278. newString.add(index++,dto.getPath());
  279. }
  280. }
  281. if (type == 0 && typeIndex < 3){
  282. for (int i = 3 - typeIndex; i >0; i -- ){
  283. newString.add(index++,"");
  284. }
  285. }
  286. }
  287. newString.add(index++,item.getCreateTime());
  288. if (version == 0){
  289. if (item.getStatus() == 0){
  290. newString.add(index++,"未归档");
  291. } else if (item.getStatus() == 1) {
  292. newString.add(index++,"归档中");
  293. }else {
  294. newString.add(index++,"已归档");
  295. }
  296. } else if (version == 1) {
  297. if (item.getStatus() == 0){
  298. newString.add(index++,"not archived");
  299. } else if (item.getStatus() == 1) {
  300. newString.add(index++,"being archived");
  301. }else {
  302. newString.add(index++,"archived");
  303. }
  304. }else {
  305. if (item.getStatus() == 0){
  306. newString.add(index++,"Не архивировано");
  307. } else if (item.getStatus() == 1) {
  308. newString.add(index++,"Архивировано");
  309. }else {
  310. newString.add(index++,"Архивировано");
  311. }
  312. }
  313. contentList.add(joinList.indexOf(item),newString);
  314. number ++;
  315. }
  316. String path = ExcelUtil.outExcel(titleList, contentList);
  317. archiveManageDTO.setPath(path);
  318. }
  319. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,archiveManageDTO);
  320. }
  321. @RequestMapping(value = "/updateFile",method = RequestMethod.POST)
  322. public BaseResult<?> updateFile(HttpServletRequest request) throws Exception {
  323. MultipartFile file = ((StandardMultipartHttpServletRequest) request).getFile("file");
  324. String result = toolUtils.uploadFile(file,null, null,null);
  325. if (result.equals("0001")){
  326. //缺少文件
  327. return toolUtils.response(InterfaceResultEnum.LACK_FILE_ERROR,0);
  328. } else if (result.equals("0002")) {
  329. //类型不对
  330. return toolUtils.response(InterfaceResultEnum.FILE_TYPE_ERROR,0);
  331. } else if (result.equals("0003")) {
  332. //未知错误
  333. return toolUtils.response(InterfaceResultEnum.UNKNOW_FILE_ERROR,0);
  334. }
  335. HashMap<String, String> hashMap = new HashMap<>();
  336. hashMap.put("path",result);
  337. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,0,hashMap);
  338. }
  339. }