From 0e4aa8d08a3bf8e8683d05081baefdbf96ce080f Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Wed, 08 Nov 2023 11:45:08 +0800
Subject: [PATCH] fix:小程序添加流程状态变更

---
 screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java |  137 ++++++++++++++++++++++++---------------------
 1 files changed, 72 insertions(+), 65 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
index 92d2d94..947456e 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
@@ -2,11 +2,9 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.moral.api.entity.MonitorPoint;
 import com.moral.api.entity.Organization;
 import com.moral.api.entity.Supervision;
 import com.moral.api.mapper.SupervisionMapper;
-import com.moral.api.service.MonitorPointService;
 import com.moral.api.service.OrganizationService;
 import com.moral.api.service.SupervisionService;
 
@@ -51,12 +49,9 @@
     @Autowired
     private OrganizationService organizationService;
 
-    @Autowired
-    private MonitorPointService monitorPointService;
-
     @Override
     @Transactional
-    public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
+    public Map<String, Object> add(List<MultipartFile> files, Supervision supervision) {
         //������jar���������������
         ApplicationHome applicationHome = new ApplicationHome(getClass());
         //���jar������������������������������upload������������������������������������
@@ -64,26 +59,37 @@
 
         Map<String, Object> result = new HashMap<>();
 
+        //���������������������
+        QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("number", supervision.getNumber()).eq("is_delete", Constants.NOT_DELETE);
+        if (supervisionMapper.selectOne(queryWrapper) != null) {
+            result.put("code", ResponseCodeEnum.SUPERVISION_NUMBER_EXIT.getCode());
+            result.put("msg", ResponseCodeEnum.SUPERVISION_NUMBER_EXIT.getMsg());
+            return result;
+        }
+
         List<String> images = new ArrayList<>();
 
-        for (MultipartFile file : files) {
-            //������������������������
-            String fileType = file.getContentType();
-            if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
-                //���������������
-                String fileName = file.getOriginalFilename();
-                //���������������������
-                String suffixName = fileName.substring(fileName.lastIndexOf("."));
-                //���������������������
-                fileName = UUID.randomUUID() + suffixName;
-                //������������
-                if (FileUtils.upload(file, path, fileName)) {
-                    images.add(fileName);
+        if (files.size() > 0) {
+            for (MultipartFile file : files) {
+                //������������������������
+                String fileType = file.getContentType();
+                if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
+                    //���������������
+                    String fileName = file.getOriginalFilename();
+                    //���������������������
+                    String suffixName = fileName.substring(fileName.lastIndexOf("."));
+                    //���������������������
+                    fileName = UUID.randomUUID() + suffixName;
+                    //������������
+                    if (FileUtils.upload(file, path, fileName)) {
+                        images.add(fileName);
+                    }
+                } else {
+                    result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
+                    result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
+                    return result;
                 }
-            } else {
-                result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
-                result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
-                return result;
             }
         }
 
@@ -104,30 +110,17 @@
         int size = Integer.parseInt(params.get("size").toString());
         Object start = params.get("start");
         Object end = params.get("end");
+        Integer orgId = Integer.parseInt(params.get("organizationId").toString());
 
+        //������������������������������
+        List<Organization> organizations = organizationService.getChildrenOrganizationsById(orgId);
+        List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
+        orgIds.add(orgId);
 
         QueryWrapper<Supervision> supervisionQueryWrapper = new QueryWrapper<>();
-        supervisionQueryWrapper.eq("is_delete", Constants.NOT_DELETE);
-        if (params.get("organizationId") != null) {
-            Integer orgId = Integer.parseInt(params.get("organizationId").toString());
-            //������������������������������
-            List<Organization> organizations = organizationService.getChildrenOrganizationsById(orgId);
-            List<Integer> orgIds = organizations.stream().map(Organization::getId).collect(Collectors.toList());
-            orgIds.add(orgId);
-            QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>();
-            queryWrapper.select("city_code")
-                    .eq("is_delete", Constants.NOT_DELETE)
-                    .in("organization_id", orgIds);
-
-            //������������id������������������������code
-            List<Object> cityCodes = monitorPointService.listObjs(queryWrapper);
-
-            cityCodes = cityCodes.stream()
-                    .distinct()
-                    .collect(Collectors.toList());
-
-            supervisionQueryWrapper.in("CONCAT(LEFT(city_code,4),'00')", cityCodes);
-        } else {
+        supervisionQueryWrapper.eq("is_delete", Constants.NOT_DELETE).in("organization_id", orgIds);
+        //���������������������������������������������������������������������������������������������������������������������������
+        if (params.get("cityCode") != null) {
             String cityCode = params.get("cityCode").toString();
             //���������������������������������������������������������������������������������������
             if (cityCode.endsWith("00")) {
@@ -136,7 +129,6 @@
                 supervisionQueryWrapper.eq("city_code", cityCode);
             }
         }
-
 
         if (start != null) {
             supervisionQueryWrapper.ge("time", start);
@@ -165,8 +157,7 @@
 
     @Override
     @Transactional
-    public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) {
-
+    public Map<String, Object> updateSupervision(List<MultipartFile> files, Supervision supervision) {
         //������jar���������������
         ApplicationHome applicationHome = new ApplicationHome(getClass());
         //���jar������������������������������upload������������������������������������
@@ -176,28 +167,44 @@
 
         List<String> images = new ArrayList<>();
 
-
-        for (MultipartFile file : files) {
-            //������������������������
-            String fileType = file.getContentType();
-            if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
-                //���������������
-                String fileName = file.getOriginalFilename();
-                //���������������������
-                String suffixName = fileName.substring(fileName.lastIndexOf("."));
-                //���������������������
-                fileName = UUID.randomUUID() + suffixName;
-                //������������
-                if (FileUtils.upload(file, path, fileName)) {
-                    images.add(fileName);
+        //������������������������������������������������������������������������
+        if (files.size() > 0) {
+            //���������������������������������������������
+            String[] oldImages = supervisionMapper.selectById(supervision.getId()).getImages().split(",");
+            for (String image : oldImages) {
+                String realPath = path + File.separator + image;
+                File file = new File(realPath);
+                if (file.exists() && file.isFile()) {
+                    file.delete();
                 }
-            } else {
-                result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
-                result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
-                return result;
+            }
+
+
+            for (MultipartFile file : files) {
+                //������������������������
+                String fileType = file.getContentType();
+                if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) {
+                    //���������������
+                    String fileName = file.getOriginalFilename();
+                    //���������������������
+                    String suffixName = fileName.substring(fileName.lastIndexOf("."));
+                    //���������������������
+                    fileName = UUID.randomUUID() + suffixName;
+                    //������������
+                    if (FileUtils.upload(file, path, fileName)) {
+                        images.add(fileName);
+                    }
+                } else {
+                    result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode());
+                    result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg());
+                    return result;
+                }
             }
         }
+
+
         if (!ObjectUtils.isEmpty(images)) {
+
             String image = images.stream()
                     .map(String::valueOf)
                     .collect(Collectors.joining(","));

--
Gitblit v1.8.0