123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- package com.welampiot.controller;
- import com.welampiot.common.BaseResult;
- import com.welampiot.common.InterfaceResultEnum;
- import com.welampiot.dto.ArchiveInfoAttachmentDTO;
- import com.welampiot.dto.ArchiveManageDTO;
- import com.welampiot.service.ArchiveInfoAttachmentService;
- import com.welampiot.service.ArchiveManageService;
- import com.welampiot.utils.ExcelUtil;
- import com.welampiot.utils.ToolUtils;
- import com.welampiot.vo.ArchiveManageVO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.CrossOrigin;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
- import javax.servlet.http.HttpServletRequest;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @RestController
- @CrossOrigin
- @RequestMapping("/archiveManage")
- public class ArchiveManageController {
- @Autowired
- private ToolUtils toolUtils;
- @Autowired
- private ArchiveManageService archiveManageService;
- @Autowired
- private ArchiveInfoAttachmentService archiveInfoAttachmentService;
- @RequestMapping(value = "/save",method = RequestMethod.POST)
- public BaseResult<?> save(HttpServletRequest request) {
- Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
- Integer version = request.getParameter("versoin") == null ? 0 : Integer.parseInt(request.getParameter("versoin"));
- Integer areaId = request.getParameter("areaId") == null ? 0 : Integer.parseInt(request.getParameter("areaId"));
- Integer sectionId = request.getParameter("sectionId") == null ? 0 : Integer.parseInt(request.getParameter("sectionId"));
- String name = request.getParameter("name");
- Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
- String department = request.getParameter("department");
- String number = request.getParameter("number");
- if(areaId == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR, version);
- if(sectionId == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR, version);
- if (name == null || (name != null && name.isEmpty())) return toolUtils.response(InterfaceResultEnum.LACK_FILE_NAME_ERROR,version);
- if (number == null || (number != null && number.isEmpty())) return toolUtils.response(InterfaceResultEnum.LACK_FILE_NUMBER_ERROR,version);
- ArrayList<ArchiveInfoAttachmentDTO> list = new ArrayList<>();
- ArchiveInfoAttachmentDTO dto = null;
- Map<String, String[]> fileList = request.getParameterMap();
- int i = 0; //每三个值都设置一次就会重设置
- //set排序,从下标0开始
- Set<String> setCollection = fileList.keySet();
- Set<String> sortSet = new TreeSet<String>((o1, o2) -> o1.compareTo(o2));
- sortSet.addAll(setCollection);
- //查找相应的值 - 这里是二维数组
- for (String key : sortSet) {//返回set类型,无序的
- if (key.contains("fileList")) {
- String[] values = fileList.get(key);
- if (i == 0) {
- dto = new ArchiveInfoAttachmentDTO();
- }
- i++;
- if (key.contains("name")) {
- dto.setName(values[0]);
- }
- if (key.contains("type")) {
- dto.setType(Integer.parseInt(values[0]));
- }
- if (key.contains("url")) {
- dto.setPath(values[0]);
- }
- if (i == 3) {
- if (dto.getName() != null && dto.getType() != null && dto.getPath() != null) {
- //三个必须都有值
- list.add(dto);
- i = 0;
- } else {
- //有一个没有值,返回
- return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
- }
- }
- }
- }
- if (i > 0 && i < 3) {
- //有一个没有值,返回
- return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR, version);
- }
- //fileList
- ArchiveManageDTO archiveManageDTO = new ArchiveManageDTO();
- archiveManageDTO.setAreaId(areaId);
- archiveManageDTO.setSectionId(sectionId);
- archiveManageDTO.setName(name);
- archiveManageDTO.setType(type);
- archiveManageDTO.setDepartment(department);
- archiveManageDTO.setNumber(number);
- Date date = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String currentTime = dateFormat.format(date);
- if (id == 0) {
- //新建
- Integer total = archiveManageService.chectCount(archiveManageDTO);
- if (total > 0 ) toolUtils.response(InterfaceResultEnum.REPEAT_FILE_NAME_ERROR, 0);
- archiveManageDTO.setCreateTime(currentTime);
- archiveManageService.addData(archiveManageDTO);
- } else {
- //编辑
- archiveManageDTO.setId(id);
- Integer total = archiveManageService.chectCount(archiveManageDTO);
- if (total > 0 ) toolUtils.response(InterfaceResultEnum.REPEAT_FILE_NAME_ERROR, 0);
- archiveManageDTO.setUpdateTime(currentTime);
- archiveManageService.updateData(archiveManageDTO);
- }
- if (list.size() != 0) {
- ArchiveInfoAttachmentDTO archiveInfoAttachmentDTO = new ArchiveInfoAttachmentDTO();
- archiveInfoAttachmentDTO.setArchiveInfoId(id);
- archiveInfoAttachmentService.deleteData(archiveInfoAttachmentDTO);
- for (ArchiveInfoAttachmentDTO item : list) {
- item.setArchiveInfoId(archiveManageDTO.getId());
- archiveInfoAttachmentService.addData(item);
- }
- }
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, 0);
- }
- @RequestMapping(value = "/getList",method = RequestMethod.POST)
- public BaseResult<?> getList(HttpServletRequest request) {
- Integer version = request.getParameter("versoin") == null ? 0 : Integer.parseInt(request.getParameter("versoin"));
- Integer areaId = request.getParameter("areaId") == null ? 0 : Integer.parseInt(request.getParameter("areaId"));
- Integer sectionId = request.getParameter("sectionId") == null ? 0 : Integer.parseInt(request.getParameter("sectionId"));
- Integer page = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
- Integer count = request.getParameter("count") == null ? 16 : Integer.parseInt(request.getParameter("count"));
- Integer type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type"));
- String keyword = request.getParameter("keyword");
- String date = request.getParameter("date");
- Integer download = request.getParameter("download") == null ? 0 : Integer.parseInt(request.getParameter("download"));
- ArchiveManageVO vo = new ArchiveManageVO();
- ArrayList<ArchiveManageDTO> list = new ArrayList<>();
- vo.setList(list);
- if (sectionId == 0){
- List sectionList = toolUtils.getSectionList(request);
- if (sectionList == null || sectionList.size() == 0) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
- vo.setSectionList(sectionList);
- }
- vo.setPage((page-1) * count);
- vo.setCount(count);
- vo.setType(type);
- vo.setKeyword(keyword);
- vo.setDate(date);
- vo.setVersion(version);
- vo.setAreaId(areaId);
- vo.setSectionId(sectionId);
- if (date != null){
- String[] splits = date.split("/");
- vo.setBeginTime(splits[0] + " 00:00:00");
- if (splits.length == 1){
- vo.setEndTime(splits[0] + " 23:59:59");
- }else {
- vo.setEndTime(splits[1] + " 23:59:59");
- }
- }
- List<ArchiveManageDTO> joinList = archiveManageService.getJoinList(vo);
- ArchiveInfoAttachmentDTO attachmentDTO = new ArchiveInfoAttachmentDTO();
- ArchiveManageDTO archiveManageDTO = new ArchiveManageDTO();
- if (download == 0){
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- for (ArchiveManageDTO item:joinList) {
- ArrayList<ArchiveInfoAttachmentDTO> fileList0 = new ArrayList<>();
- ArrayList<ArchiveInfoAttachmentDTO> fileList1 = new ArrayList<>();
- ArrayList<ArchiveInfoAttachmentDTO> fileList2 = new ArrayList<>();
- ArrayList<ArchiveInfoAttachmentDTO> fileList3 = new ArrayList<>();
- ArrayList<ArchiveInfoAttachmentDTO> fileList4 = new ArrayList<>();
- attachmentDTO.setArchiveInfoId(item.getId());
- List<ArchiveInfoAttachmentDTO> dtos = archiveInfoAttachmentService.getOneData(attachmentDTO);
- item.setCount0(0);
- item.setCount1(0);
- item.setCount2(0);
- item.setCount3(0);
- item.setCount4(0);
- for (ArchiveInfoAttachmentDTO dto:dtos) {
- dto.setId(null);
- if(dto.getType() == 0){
- item.setCount0(item.getCount0() + 1);
- dto.setType(null);
- fileList0.add(dto);
- } else if (dto.getType() == 1) {
- item.setCount1(item.getCount1() + 1);
- dto.setType(null);
- fileList1.add(dto);
- }else if (dto.getType() == 2) {
- item.setCount2(item.getCount2() + 1);
- dto.setType(null);
- fileList2.add(dto);
- }else if (dto.getType() == 3) {
- item.setCount3(item.getCount3() + 1);
- dto.setType(null);
- fileList3.add(dto);
- }else if (dto.getType() == 4) {
- item.setCount4(item.getCount4() + 1);
- dto.setType(null);
- fileList4.add(dto);
- }
- }
- item.setFileList0(fileList0);
- item.setFileList1(fileList1);
- item.setFileList2(fileList2);
- item.setFileList3(fileList3);
- item.setFileList4(fileList4);
- try {
- Date parse = dateFormat.parse(item.getCreateTime());
- item.setCreateTime(dateFormat.format(parse));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }
- Integer total = archiveManageService.getCount(vo);
- archiveManageDTO.setList(joinList);
- archiveManageDTO.setTotal(total);
- // return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,archiveManageDTO);
- }else {
- String title;
- if (version == 0) {
- if (type == 0){
- title = "序号,项目名称,项目编号,立项档案,设计档案,验收档案,建档时间,归档情况";
- } else if (type == 1) {
- title = "序号,设备名称,设备编号,档案,建档时间,归档情况";
- }else {
- title = "序号,工单名称,工单号,档案,建档时间,归档情况";
- }
- } else if (version == 1) {
- if (type == 0){
- title = "SN,Project Name,Project No.,Project Initiation File,Design File,Acceptance File,Filing Time,Filing Status";
- }else if (type == 1) {
- title = "SN,Equipment Name,Equipment No.,File,File Creation Time,Archive Status";
- }else{
- title = "SN,work order name,work order number,file,filing time,filing status";
- }
- } else {
- if (type == 0){
- title = "Серийный номер,Название проекта,Номер проекта,Архив проекта,Архив проекта,Архив проекта,Архив приемки,Время архивирования,Архивное положение";
- }else if (type == 1){
- title = "Серийный номер,название устройства,номер устройства,архив,время архивирования,архив ситуации";
- }else{
- title = "Серийный номер,название рабочего листа,номер рабочего листа,архив,время архивирования,архивная ситуация";
- }
- }
- List<String> titleList = Arrays.asList(title.split(","));
- List<List<String>> contentList = new ArrayList<>();
- int number = 1;//序号
- for (ArchiveManageDTO item:joinList){
- int index = 0; //下标
- List<String> newString = new ArrayList<>();
- newString.add(index++, String.valueOf(number));
- newString.add(index++,item.getName());
- newString.add(index++,item.getNumber());
- attachmentDTO.setArchiveInfoId(item.getId());
- List<ArchiveInfoAttachmentDTO> dtos = archiveInfoAttachmentService.getOneData(attachmentDTO);
- if (dtos == null || dtos.size() == 0){
- newString.add(index++,"");
- if (type == 0){
- newString.add(index++,"");
- newString.add(index++,"");
- }
- }else {
- int typeIndex = 0;
- for (ArchiveInfoAttachmentDTO dto:dtos) {
- if (dto.getType() == 2){
- //立项
- newString.add(index++,dto.getPath());
- typeIndex ++;
- } else if (dto.getType() == 1) {
- //设计
- newString.add(index++,dto.getPath());
- typeIndex ++;
- } else if (dto.getType() == 4) {
- //验收
- newString.add(index++,dto.getPath());
- typeIndex ++;
- }else {
- //其它
- newString.add(index++,dto.getPath());
- }
- }
- if (type == 0 && typeIndex < 3){
- for (int i = 3 - typeIndex; i >0; i -- ){
- newString.add(index++,"");
- }
- }
- }
- newString.add(index++,item.getCreateTime());
- if (version == 0){
- if (item.getStatus() == 0){
- newString.add(index++,"未归档");
- } else if (item.getStatus() == 1) {
- newString.add(index++,"归档中");
- }else {
- newString.add(index++,"已归档");
- }
- } else if (version == 1) {
- if (item.getStatus() == 0){
- newString.add(index++,"not archived");
- } else if (item.getStatus() == 1) {
- newString.add(index++,"being archived");
- }else {
- newString.add(index++,"archived");
- }
- }else {
- if (item.getStatus() == 0){
- newString.add(index++,"Не архивировано");
- } else if (item.getStatus() == 1) {
- newString.add(index++,"Архивировано");
- }else {
- newString.add(index++,"Архивировано");
- }
- }
- contentList.add(joinList.indexOf(item),newString);
- number ++;
- }
- String path = ExcelUtil.outExcel(titleList, contentList);
- archiveManageDTO.setPath(path);
- }
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,archiveManageDTO);
- }
- @RequestMapping(value = "/updateFile",method = RequestMethod.POST)
- public BaseResult<?> updateFile(HttpServletRequest request) throws Exception {
- MultipartFile file = ((StandardMultipartHttpServletRequest) request).getFile("file");
- String result = toolUtils.uploadFile(file,null, null,null);
- if (result.equals("0001")){
- //缺少文件
- return toolUtils.response(InterfaceResultEnum.LACK_FILE_ERROR,0);
- } else if (result.equals("0002")) {
- //类型不对
- return toolUtils.response(InterfaceResultEnum.FILE_TYPE_ERROR,0);
- } else if (result.equals("0003")) {
- //未知错误
- return toolUtils.response(InterfaceResultEnum.UNKNOW_FILE_ERROR,0);
- }
- HashMap<String, String> hashMap = new HashMap<>();
- hashMap.put("path",result);
- return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,0,hashMap);
- }
- }
|