Jelajahi Sumber

archiveManageController已完成修改,文件/图片/音频上传的公共接口

weclouds 1 tahun lalu
induk
melakukan
3250c780f3

+ 7 - 0
src/main/java/com/welampiot/common/InterfaceResultEnum.java

@@ -250,6 +250,13 @@ public enum InterfaceResultEnum {
     PERSON_BIND_ERROR("0900","推送人员已经绑定了","The pusher is already bound","толкатель уже связал"),
     PERSON_OVER_ERROR("0901","推送人员不能超过10个","No more than 10 people can be pushed","Численность персонала не должна превышать 10 человек"),
 
+    //档案管理 1000-1999
+    LACK_FILE_NAME_ERROR("0901","请输入名称","Please enter a name","Введите имя"),
+    LACK_FILE_NUMBER_ERROR("0902","请输入编号","Please enter the number","Пожалуйста, войдите в номер."),
+    REPEAT_FILE_NAME_ERROR("0903","文件名称已存在","File name already exists","Имя файла уже существует"),
+    LACK_FILE_ERROR("0904","缺少文件","Missing file","Отсутствие документов"),
+    FILE_TYPE_ERROR("0905","文件不支持","File type not supported","Тип файла не поддерживается "),
+    UNKNOW_FILE_ERROR("0906","文件未知错误","Unknown file error","Файл Неизвестная ошибка"),
 
     ;
     private String code;

+ 0 - 2
src/main/java/com/welampiot/controller/AcDeviceController.java

@@ -10,8 +10,6 @@ import com.welampiot.service.AcDevInfoService;
 import com.welampiot.utils.ExcelUtil;
 import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.AcDevInfoVO;
-import jdk.nashorn.internal.runtime.Version;
-import org.apache.commons.collections4.Put;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.DigestUtils;
 import org.springframework.web.bind.annotation.CrossOrigin;

+ 32 - 32
src/main/java/com/welampiot/controller/AlarmController.java

@@ -291,20 +291,19 @@ public class AlarmController {
     public BaseResult<?> data(HttpServletRequest request) {
         int version = (int) toolUtils.getRequestContent(request,"version",1);
         AllAlarmInfoLogVO allAlarmInfoLogVO = new AllAlarmInfoLogVO();
-        AllAlarmInfoLogVO allAlarmInfoLogVO1 = new AllAlarmInfoLogVO();
-        UserDTO user = toolUtils.getUser(request);
-        Integer role = user.getRole();
-        if (role != ToolUtils.SYSTEM_ADMIN){
-            //不是超级用户
-            allAlarmInfoLogVO.setSectionList(toolUtils.getSectionList(request));
-        }
+        AllAlarmInfoLogVO vo = new AllAlarmInfoLogVO();
+
+        List<String> sectionList = toolUtils.getSectionList(request);
+        allAlarmInfoLogVO.setSectionList(sectionList);
+        if (sectionList == null || sectionList.size() == 0) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version);
+
 //        allAlarmInfoLogVO1.setUnTreatedCount(allAlarmInfoLogService.getUnTreatedCountByStatus(allAlarmInfoLogVO));
 //        allAlarmInfoLogVO1.setProcessingCount(allAlarmInfoLogService.getProcessingCountByStatus(allAlarmInfoLogVO));
-        allAlarmInfoLogVO1.setHandling(allAlarmInfoLogService.getProcessingCountByStatus(allAlarmInfoLogVO));
-        allAlarmInfoLogVO1.setUnAssigned(allAlarmInfoLogService.getUnTreatedCountByStatus(allAlarmInfoLogVO));
-        allAlarmInfoLogVO1.setHandleCount(allAlarmInfoLogService.getHandleCountByStatus(allAlarmInfoLogVO));
-        allAlarmInfoLogVO1.setTotal(allAlarmInfoLogService.getAlarmTotalByStatus(allAlarmInfoLogVO));
-        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,allAlarmInfoLogVO1);
+        vo.setHandling(allAlarmInfoLogService.getProcessingCountByStatus(allAlarmInfoLogVO));
+        vo.setUnAssigned(allAlarmInfoLogService.getUnTreatedCountByStatus(allAlarmInfoLogVO));
+        vo.setHandleCount(allAlarmInfoLogService.getHandleCountByStatus(allAlarmInfoLogVO));
+        vo.setTotal(allAlarmInfoLogService.getAlarmTotalByStatus(allAlarmInfoLogVO));
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,vo);
     }
 
     /**
@@ -510,19 +509,23 @@ public class AlarmController {
     @RequestMapping(value = "/alarmNav", method = RequestMethod.POST)
     public BaseResult<?> alarmNav(HttpServletRequest request) {
         Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
-        UserDTO user = toolUtils.getUser(request);
-        List<SectionDTO> allList = null;
+//        UserDTO user = toolUtils.getUser(request);
+//        List<SectionDTO> allList = null;
+//        SectionDTO sectionDTO = new SectionDTO();
+//        if (user.getRole() == ToolUtils.SYSTEM_ADMIN){
+//            //超级用户(id,pid)
+//             allList = sectionService.getAllList(sectionDTO);
+//        }else {
+//            List sectionList = toolUtils.getSectionList(request);
+//            sectionDTO.setSectionList(sectionList);
+//            allList = sectionService.getAllList(sectionDTO);
+//        }
         SectionDTO sectionDTO = new SectionDTO();
-        if (user.getRole() == ToolUtils.SYSTEM_ADMIN){
-            //超级用户(id,pid)
-             allList = sectionService.getAllList(sectionDTO);
-        }else {
-            List sectionList = toolUtils.getSectionList(request);
-            sectionDTO.setSectionList(sectionList);
-            allList = sectionService.getAllList(sectionDTO);
-        }
+        List sList = toolUtils.getSectionList(request);
+        sectionDTO.setSectionList(sList);
+        List<SectionDTO> allList = sectionService.getAllList(sectionDTO);
         List<GlobalLocationDTO> globalList = new ArrayList<>();
-        if (allList == null) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,globalList);
+        if (allList == null || allList.size() == 0) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,globalList);
 
         //获取pid,并去重
         Set<Integer> pidList = new HashSet<>();
@@ -748,18 +751,15 @@ public class AlarmController {
     @RequestMapping(value = "/emAlarmHistory", method = RequestMethod.POST)
     public BaseResult<?> emAlarmHistory(HttpServletRequest request) {
         Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
-        UserDTO user = toolUtils.getUser(request);
-        List<String> sectionList = null;
+//
         EmergencyVO emergencyVO = new EmergencyVO();
+        List<EmergencyDTO> list = new ArrayList<>();
+        emergencyVO.setList(list);
+        List<String> sectionList = toolUtils.getSectionList(request);
+        if (sectionList == null || sectionList.size() == 0) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS, version, emergencyVO);
 
-        if (user.getRole() != ToolUtils.SYSTEM_ADMIN){
-            List<EmergencyDTO>list = new ArrayList<>();
-            emergencyVO.setList(list);
-            sectionList = toolUtils.getSectionList(request);
-            if (sectionList == null) return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,emergencyVO);
-        }
         emergencyVO.setSectionList(sectionList);
-       List<EmergencyDTO> joinList = emergencyService.getEmergencyJoinList(emergencyVO);
+        List<EmergencyDTO> joinList = emergencyService.getEmergencyJoinList(emergencyVO);
         for (EmergencyDTO dto:joinList) {
             dto.setName(dto.getSection()+" "+dto.getModel());
         }

+ 368 - 0
src/main/java/com/welampiot/controller/ArchiveManageController.java

@@ -0,0 +1,368 @@
+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);
+
+    }
+
+}

+ 0 - 2
src/main/java/com/welampiot/controller/DataController.java

@@ -16,8 +16,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;

+ 0 - 2
src/main/java/com/welampiot/controller/SmartLockController.java

@@ -3,9 +3,7 @@ package com.welampiot.controller;
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.dto.SmartLockDevInfoDTO;
-import com.welampiot.dto.WifiDTO;
 import com.welampiot.service.SmartLockDevInfoService;
-import com.welampiot.service.WifiInfoLogService;
 import com.welampiot.service.WifiService;
 import com.welampiot.utils.ExcelUtil;
 import com.welampiot.utils.ToolUtils;

+ 11 - 0
src/main/java/com/welampiot/dao/ArchiveInfoAttachmentDao.java

@@ -0,0 +1,11 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.ArchiveInfoAttachmentDTO;
+
+import java.util.List;
+
+public interface ArchiveInfoAttachmentDao {
+    void addData(ArchiveInfoAttachmentDTO dto);
+    void deleteData(ArchiveInfoAttachmentDTO dto);
+    List<ArchiveInfoAttachmentDTO> getOneData(ArchiveInfoAttachmentDTO dto);
+}

+ 14 - 0
src/main/java/com/welampiot/dao/ArchiveManageDao.java

@@ -0,0 +1,14 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.ArchiveManageDTO;
+import com.welampiot.vo.ArchiveManageVO;
+
+import java.util.List;
+
+public interface ArchiveManageDao {
+    void addData(ArchiveManageDTO dto);
+    void updateData(ArchiveManageDTO dto);
+    Integer chectCount(ArchiveManageDTO dto);
+    List<ArchiveManageDTO> getJoinList(ArchiveManageVO vo);
+    Integer getCount(ArchiveManageVO vo);
+}

+ 12 - 0
src/main/java/com/welampiot/dto/ArchiveInfoAttachmentDTO.java

@@ -0,0 +1,12 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+@Data
+public class ArchiveInfoAttachmentDTO {
+    private Integer id;
+    private String name;
+    private String path;
+    private Integer archiveInfoId;
+    private Integer type;
+}

+ 38 - 0
src/main/java/com/welampiot/dto/ArchiveManageDTO.java

@@ -0,0 +1,38 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class ArchiveManageDTO {
+    private Integer id;
+    private Integer type;
+    private String name;
+    private String number;
+    private Integer status;
+    private Integer areaId;
+    private Integer sectionId;
+    private String time;
+    private String planEndTime;
+    private String updateTime;
+    private String createTime;
+    private String department;
+    private String area;
+    private String section;
+    private List<ArchiveInfoAttachmentDTO> fileList;
+    private Integer count0;
+    private Integer count1;
+    private Integer count2;
+    private Integer count3;
+    private Integer count4;
+    private List<ArchiveInfoAttachmentDTO> fileList0;
+    private List<ArchiveInfoAttachmentDTO> fileList1;
+    private List<ArchiveInfoAttachmentDTO> fileList2;
+    private List<ArchiveInfoAttachmentDTO> fileList3;
+    private List<ArchiveInfoAttachmentDTO> fileList4;
+    private List<ArchiveManageDTO> list;
+    private Integer total;
+    private String path;
+
+}

+ 11 - 0
src/main/java/com/welampiot/service/ArchiveInfoAttachmentService.java

@@ -0,0 +1,11 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.ArchiveInfoAttachmentDTO;
+
+import java.util.List;
+
+public interface ArchiveInfoAttachmentService {
+    void addData(ArchiveInfoAttachmentDTO dto);
+    void deleteData(ArchiveInfoAttachmentDTO dto);
+    List<ArchiveInfoAttachmentDTO> getOneData(ArchiveInfoAttachmentDTO dto);
+}

+ 16 - 0
src/main/java/com/welampiot/service/ArchiveManageService.java

@@ -0,0 +1,16 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.ArchiveManageDTO;
+import com.welampiot.vo.ArchiveManageVO;
+
+import java.util.List;
+
+public interface ArchiveManageService {
+    void addData(ArchiveManageDTO dto);
+    void updateData(ArchiveManageDTO dto);
+
+    Integer chectCount(ArchiveManageDTO dto);
+    List<ArchiveManageDTO> getJoinList(ArchiveManageVO vo);
+    Integer getCount(ArchiveManageVO vo);
+
+}

+ 29 - 0
src/main/java/com/welampiot/service/impl/ArchiveInfoAttachmentServiceImpl.java

@@ -0,0 +1,29 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.ArchiveInfoAttachmentDao;
+import com.welampiot.dto.ArchiveInfoAttachmentDTO;
+import com.welampiot.service.ArchiveInfoAttachmentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ArchiveInfoAttachmentServiceImpl implements ArchiveInfoAttachmentService {
+    @Autowired
+    private ArchiveInfoAttachmentDao archiveInfoAttachmentDao;
+
+
+    @Override
+    public void addData(ArchiveInfoAttachmentDTO dto){
+        archiveInfoAttachmentDao.addData(dto);
+    }
+    @Override
+    public void deleteData(ArchiveInfoAttachmentDTO dto){
+        archiveInfoAttachmentDao.deleteData(dto);
+    }
+    @Override
+    public List<ArchiveInfoAttachmentDTO> getOneData(ArchiveInfoAttachmentDTO dto){
+        return archiveInfoAttachmentDao.getOneData(dto);
+    }
+}

+ 37 - 0
src/main/java/com/welampiot/service/impl/ArchiveManageServiceImpl.java

@@ -0,0 +1,37 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.ArchiveManageDao;
+import com.welampiot.dto.ArchiveManageDTO;
+import com.welampiot.service.ArchiveManageService;
+import com.welampiot.vo.ArchiveManageVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ArchiveManageServiceImpl implements ArchiveManageService {
+    @Autowired
+    private ArchiveManageDao archiveManageDao;
+
+    @Override
+    public void addData(ArchiveManageDTO dto) {
+        archiveManageDao.addData(dto);
+    }
+    @Override
+    public void updateData(ArchiveManageDTO dto){
+        archiveManageDao.updateData(dto);
+    }
+    @Override
+    public Integer chectCount(ArchiveManageDTO dto){
+        return archiveManageDao.chectCount(dto);
+    }
+    @Override
+    public List<ArchiveManageDTO> getJoinList(ArchiveManageVO vo){
+        return archiveManageDao.getJoinList(vo);
+    }
+    @Override
+    public Integer getCount(ArchiveManageVO vo){
+        return archiveManageDao.getCount(vo);
+    }
+}

+ 3 - 3
src/main/java/com/welampiot/utils/ExcelUtil.java

@@ -15,7 +15,6 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -24,11 +23,12 @@ import java.util.Map;
 public class ExcelUtil {
     /**
      * 文件导出到excel
-     * @param titleList  标题列表 一维列表
+     *
+     * @param titleList   标题列表 一维列表
      * @param contentList 数据列表 二维列表
      * @return
      */
-    public static String outExcel(List<String> titleList,List<List<String>> contentList){
+    public static String outExcel(List<String> titleList, List<List<String>> contentList){
         XSSFWorkbook sheets = new XSSFWorkbook();
         XSSFSheet sheet = sheets.createSheet();
 

+ 110 - 11
src/main/java/com/welampiot/utils/ToolUtils.java

@@ -1,6 +1,5 @@
 package com.welampiot.utils;
 
-import com.alibaba.druid.support.json.JSONUtils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -14,10 +13,8 @@ import com.welampiot.dto.*;
 import com.welampiot.handle.MqttHandler;
 import com.welampiot.service.*;
 import com.welampiot.vo.DevEnumVO;
-import com.welampiot.vo.LampPoleVO;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.poi.ss.formula.functions.T;
 import org.eclipse.paho.client.mqttv3.MqttClient;
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
 import org.eclipse.paho.client.mqttv3.MqttMessage;
@@ -30,12 +27,15 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.io.*;
 import java.lang.reflect.Field;
-import java.net.*;
-import java.nio.charset.StandardCharsets;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URLConnection;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -102,13 +102,13 @@ public class ToolUtils {
             return sectionList;
         }
 
-        String provinceid = request.getParameter("provinceid");
+        String provinceid = request.getParameter("provinceId");
         provinceid = provinceid == null || provinceid.equals("0") ? request.getParameter("provinceId") : provinceid;
-        String cityid = request.getParameter("cityid");
+        String cityid = request.getParameter("cityId");
         cityid = cityid == null || cityid.equals("0") ? request.getParameter("cityId") : cityid;
-        String areaid = request.getParameter("areaid");
+        String areaid = request.getParameter("areaId");
         areaid = areaid == null || areaid.equals("0") ? request.getParameter("areaId") : areaid;
-        String sectionid = request.getParameter("sectionid");
+        String sectionid = request.getParameter("sectionId");
         sectionid = sectionid == null || sectionid.equals("0") ? request.getParameter("sectionId") : sectionid;
         if (sectionid != null && sectionid.length() != 0 && !sectionid.equals("0")){
             sectionList.add(sectionid);
@@ -1083,7 +1083,7 @@ System.out.println(res);
         return protocolTypeStr;
     }
 
-    /* 向第三方请求post
+    /** 向第三方请求post
      *@param  requestMethod:请求方式
      * @param  url:路径
      * @param param:参数
@@ -1145,7 +1145,7 @@ System.out.println(res);
         return result;
     }
 
-    /* 向第三方请求post
+    /** 向第三方请求post
      *@param  request:请求方式
      * @param  url:路径
      * @param param:参数
@@ -1406,4 +1406,103 @@ System.out.println(res);
         //字符串拼接
         return String.join(".", stringList);
     }
+
+    /**
+     * 上传文件/图片/音频
+     * @param file 文件
+     * @param image 图片
+     * @param video 音频
+     * @param title 名称
+     * @return
+     * @throws Exception
+     */
+    public String uploadFile(MultipartFile file, MultipartFile image,MultipartFile video, String title) throws Exception {
+
+        String rootPath = System.getProperty("user.dir");
+        int lastedIndex = rootPath.lastIndexOf("/");
+        rootPath = rootPath.substring(0,lastedIndex); //工程根目录
+        File imagePath; //图⽚存放地址
+        File fileRealPath; //⽂件存放地址
+        File videoPath; //音视频存在地址
+        if (file == null && image == null && video == null) return "0001"; //文件\图片\音频不能都不传
+
+        //获取⽂件名称
+        if (file != null){
+            //判断文件的类型
+            boolean b = this.fileType(file,2);
+            if (b == false) return "0002"; //类型不对
+            String pathName = "/upload/files";
+            fileRealPath = new File(rootPath+pathName);
+            //判断⽂件夹是否存在
+            if(!fileRealPath.exists()){
+                //不存在,创建
+                fileRealPath.mkdirs();
+            }
+            String fileName = file.getOriginalFilename();
+            //创建⽂件存放地址
+            File resultPath = new File(fileRealPath+"/"+fileName);
+            file.transferTo(resultPath);
+            System.out.println("resultPath:"+resultPath.getCanonicalPath());
+            return pathName+"/"+fileName;
+        }
+        if (image != null){ //图片
+            //判断文件的类型
+            boolean b = this.fileType(image,1);
+            if (b == false) return "0002"; //类型不对
+            String pathName = "/upload/images";
+            imagePath = new File(rootPath+pathName);
+            if(!imagePath.exists()){
+                //不存在,创建
+                imagePath.mkdirs();
+            }
+            String imageName = image.getOriginalFilename();
+            //创建图⽚存放地址
+            File imageResultPath = new File(imagePath+"/"+imageName);
+            image.transferTo(imageResultPath);
+            System.out.println("imageResultPath:"+imageResultPath.getCanonicalPath());
+            return pathName+"/"+imageName;
+        }
+        if (video != null){ //音频
+            //判断文件的类型
+            boolean b = this.fileType(video,3);
+            if (b == false) return "0002"; //类型不对
+            String pathName = "/upload/videos";
+            videoPath = new File(rootPath+pathName);
+            if(!videoPath.exists()){
+                //不存在,创建
+                videoPath.mkdirs();
+            }
+            String videoName = video.getOriginalFilename();
+            //创建图⽚存放地址
+            File videoResultPath = new File(videoPath+"/"+videoName);
+            video.transferTo(videoResultPath);
+            return pathName+"/"+videoName;
+        }
+        return "0003"; //未知问题
+    }
+    private boolean fileType(MultipartFile tempFile,int type) throws IOException {
+        InputStream inputStream = tempFile.getInputStream();
+        byte[] buffer = new byte[8];
+        inputStream.read(buffer);
+        String magicNumber = bytes2HexString(buffer);
+        if (magicNumber.substring(0,4).equals("FFD8") && type == 1) {
+            // ⽂件是JPEG/jpg类型
+        } else if (magicNumber.substring(0,8).equals("89504E47") && type == 1) {
+            // ⽂件是PNG类型
+        } else if (magicNumber.substring(0,8).equals("47494638") && type == 1) {
+            // ⽂件是GIF类型
+        }else  if (magicNumber.substring(0,8).equals("25504446") && type == 2) {
+            // ⽂件是PDF类型
+        } else if (magicNumber.substring(0,8).equals("504B0304") && type == 2) {
+            // ⽂件是DOCX类型
+        } else if (magicNumber.substring(0,8).equals("32303230") && type == 2){
+            //⽂件是txt类型
+        }else if (magicNumber.substring(0,6).equals("494433") && type == 3){//4944330400000000
+            // ⽂件是mp3类型
+        }else {
+            // ⽂件类型未知
+            return false; //文件类型不对
+        }
+        return true;
+    }
 }

+ 23 - 0
src/main/java/com/welampiot/vo/ArchiveManageVO.java

@@ -0,0 +1,23 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.ArchiveManageDTO;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class ArchiveManageVO {
+    private List<ArchiveManageDTO> list;
+    private Integer areaId;
+    private Integer sectionId;
+    private Integer page;
+    private Integer count;
+    private Integer type;
+    private String keyword;
+    private String date;
+    private Integer version;
+    private Integer download;
+    private List<String>sectionList;
+    private String beginTime;
+    private String endTime;
+}

+ 27 - 0
src/main/resources/mapper/ArchiveInfoAttachmentMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.ArchiveInfoAttachmentDao">
+    <insert id="addData" parameterType="ArchiveInfoAttachmentDTO">
+        insert into archive_info_attachment( name, path, archive_info_id, type)
+        VALUES (#{name},#{path},#{archiveInfoId},#{type})
+    </insert>
+
+    <delete id="deleteData" parameterType="ArchiveInfoAttachmentDTO">
+        delete from archive_info_attachment
+        where id = 0
+            <if test="archiveInfoId">
+              or  archive_info_id = #{archiveInfoId}
+            </if>
+    </delete>
+
+    <select id="getOneData" resultType="ArchiveInfoAttachmentDTO">
+        select id,name,path,type from archive_info_attachment
+        <trim prefix="where" suffixOverrides="and|or">
+            <if test="archiveInfoId != null and archiveInfoId != 0">
+                archive_info_id = #{archiveInfoId} and
+            </if>
+        </trim>
+    </select>
+</mapper>

+ 113 - 0
src/main/resources/mapper/ArchiveManageMapper.xml

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.welampiot.dao.ArchiveManageDao">
+    <insert id="addData" parameterType="ArchiveManageDTO" useGeneratedKeys="true" keyProperty="id">
+        insert into archive_info(
+        type, name, number, areaid, sectionid, create_time
+        <if test="department != null">
+            ,department
+        </if>
+        )
+        VALUES(
+        #{type},#{name},#{number},#{areaId},#{sectionId},#{createTime}
+        <if test="department != null">
+            ,#{department}
+        </if>
+        )
+    </insert>
+
+    <update id="updateData" parameterType="ArchiveManageDTO">
+        update archive_info
+        set type = #{type},name = #{name},number = #{number},areaid = #{areaId},sectionid = #{sectionId},update_time = #{updateTime}
+        <if test="department != null">
+            ,department = #{department}
+        </if>
+        where id = #{id}
+    </update>
+
+    <select id="chectCount" parameterType="ArchiveManageDTO">
+        select count(*) from archive_info
+        where sectionid = #{sectionId} and name = #{name}
+        <if test="id != null">
+            and id != #{id}
+        </if>
+    </select>
+
+    <select id="getJoinList" parameterType="ArchiveManageVO" resultType="ArchiveManageDTO">
+        select A.id,A.type,A.name,A.number,A.status,A.update_time as updateTime,A.create_time as createTime,A.department,
+        <choose>
+            <when test="version == 0">
+                G.chinese_name as area,S.name as section
+            </when>
+            <when test="version == 1">
+                G.english_name as area,S.name as section
+            </when>
+            <otherwise>
+                G.ru_name as area,S.name as section
+            </otherwise>
+        </choose>
+        from archive_info A
+        left join section as S on S.id = A.sectionid
+        left join global_location as G on G.id = S.pid
+        <trim prefix="where" suffixOverrides="and|or">
+            <if test="areaId != null and areaId != 0">
+                A.areaid = #{areaId} and
+            </if>
+            <if test="sectionId != null and sectionId != 0">
+                A.sectionid = #{sectionId} and
+            </if>
+            <if test="sectionList != null and sectionList.size > 0">
+                A.sectionid in
+                <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                    #{vo}
+                </foreach>
+                 and
+            </if>
+             <if test="type != null and type != 0">
+                 A.type = #{type} and
+             </if>
+            <if test="keyword != null ">
+                 (A.number like '%#{keyword}%' or A.name like '#{keyword%') and
+            </if>
+            <if test="date != null">
+                (A.create_time between #{beginTime} and #{endTime}) and
+            </if>
+        </trim>
+        <if test="page >= 0 and count > 0">
+            limit #{page},#{count}
+        </if>
+    </select>
+
+    <select id="getCount" resultType="integer" parameterType="ArchiveManageVO">
+        select count(*) as total
+        from archive_info A
+        left join section as S on S.id = A.sectionid
+        left join global_location as G on G.id = S.pid
+        <trim prefix="where" suffixOverrides="and|or">
+            <if test="areaId != null and areaId != 0">
+                A.areaid = #{areaId} and
+            </if>
+            <if test="sectionId != null and sectionId != 0">
+                A.sectionid = #{sectionId} and
+            </if>
+            <if test="sectionList != null and sectionList.size > 0">
+                A.sectionid in
+                <foreach item="vo" collection="sectionList" open="(" separator="," close=")">
+                    #{vo}
+                </foreach>
+                and
+            </if>
+            <if test="type != null and type != 0">
+                A.type = #{type} and
+            </if>
+            <if test="keyword != null ">
+                (A.number like '%#{keyword}%' or A.name like '#{keyword%') and
+            </if>
+            <if test="date != null">
+                (A.create_time between #{beginTime} and #{endTime}) and
+            </if>
+        </trim>
+    </select>
+</mapper>

+ 7 - 0
src/main/resources/prod/application.yml

@@ -29,6 +29,13 @@ spring:
 #      write-null-map-values: true
 #  gson:
 #    serialize-nulls: true
+  servlet:
+    multipart:
+      #上传最大文件大小
+      max-file-size: 100MB
+      #最大请求大小
+      max-request-size: 100MB
+
 
 welampiot:
   mqtt:

+ 6 - 0
src/main/resources/test/application.yml

@@ -29,6 +29,12 @@ spring:
 #      write-null-map-values: true
 #  gson:
 #    serialize-nulls: true
+  servlet:
+    multipart:
+      #上传最大文件大小
+      max-file-size: 100MB
+      #最大请求大小
+      max-request-size: 100MB
 
 welampiot:
   mqtt: