From dbb8355061b6f60976d410fe475157c6e82f5593 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 15 Jun 2023 16:12:21 +0800
Subject: [PATCH] 添加多站多参接口

---
 screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java |  157 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 91 insertions(+), 66 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 7057c08..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
@@ -1,15 +1,14 @@
 package com.moral.api.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.moral.api.entity.Organization;
 import com.moral.api.entity.Supervision;
-import com.moral.api.entity.SysArea;
 import com.moral.api.mapper.SupervisionMapper;
+import com.moral.api.service.OrganizationService;
 import com.moral.api.service.SupervisionService;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.moral.api.service.SysAreaService;
 import com.moral.constant.Constants;
 import com.moral.constant.ResponseCodeEnum;
 import com.moral.util.FileUtils;
@@ -48,11 +47,11 @@
     private SupervisionMapper supervisionMapper;
 
     @Autowired
-    private SysAreaService sysAreaService;
+    private OrganizationService organizationService;
 
     @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������������������������������������
@@ -60,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;
             }
         }
 
@@ -96,59 +106,58 @@
     @Override
     public Map<String, Object> selectSupervisions(Map<String, Object> params) {
         //������������������
-        int cityCode = Integer.parseInt(params.get("cityCode").toString());
         int page = Integer.parseInt(params.get("page").toString());
         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());
 
-        QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("city_code", cityCode)
-                .eq("is_delete", Constants.NOT_DELETE);
+        //������������������������������
+        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).in("organization_id", orgIds);
+        //���������������������������������������������������������������������������������������������������������������������������
+        if (params.get("cityCode") != null) {
+            String cityCode = params.get("cityCode").toString();
+            //���������������������������������������������������������������������������������������
+            if (cityCode.endsWith("00")) {
+                supervisionQueryWrapper.eq("CONCAT(LEFT(city_code,4),'00')", cityCode);
+            } else {
+                supervisionQueryWrapper.eq("city_code", cityCode);
+            }
+        }
+
         if (start != null) {
-            queryWrapper.ge("time", start);
+            supervisionQueryWrapper.ge("time", start);
         }
         if (start != null) {
-            queryWrapper.le("time", end);
+            supervisionQueryWrapper.le("time", end);
         }
 
         //���time������
-        queryWrapper.orderByDesc("time");
+        supervisionQueryWrapper.orderByDesc("time");
 
         //������
         Page<Supervision> supervisionPage = new Page<>(page, size);
-        supervisionMapper.selectPage(supervisionPage, queryWrapper);
+        supervisionMapper.selectPage(supervisionPage, supervisionQueryWrapper);
         List<Supervision> supervisions = supervisionPage.getRecords();
-
-        //������������������
-        List<Map<String, Object>> item = new ArrayList<>();
-        QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
-        sysAreaQueryWrapper.eq("area_code", cityCode);
-        SysArea one = sysAreaService.getOne(sysAreaQueryWrapper);
-        String cityName = one.getAreaName();
-        for (Supervision supervision : supervisions) {
-            Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(supervision), Map.class);
-            map.remove("isDelete");
-            map.remove("createTime");
-            map.remove("updateTime");
-            map.put("cityName", cityName);
-            item.add(map);
-        }
 
         Map<String, Object> result = new LinkedHashMap<>();
         result.put("total", supervisionPage.getTotal());
         result.put("totalPage", supervisionPage.getPages());
         result.put("current", supervisionPage.getCurrent());
         result.put("pageSize", supervisionPage.getSize());
-        result.put("item", item);
+        result.put("item", supervisions);
 
         return result;
     }
 
     @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������������������������������������
@@ -158,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