From ddaee239feb428cc426396a742c9d992d5983548 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Fri, 18 Feb 2022 10:42:38 +0800
Subject: [PATCH] screen-api 更改优良天变化率正负号
---
screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java | 102 ++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 80 insertions(+), 22 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 8237bfa..e6df36e 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,8 +2,10 @@
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.mapper.SupervisionMapper;
+import com.moral.api.service.OrganizationService;
import com.moral.api.service.SupervisionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -11,13 +13,15 @@
import com.moral.constant.ResponseCodeEnum;
import com.moral.util.FileUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
-import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
-import java.io.FileNotFoundException;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -36,26 +40,35 @@
* @since 2022-01-12
*/
@Service
+@Slf4j
public class SupervisionServiceImpl extends ServiceImpl<SupervisionMapper, Supervision> implements SupervisionService {
@Autowired
private SupervisionMapper supervisionMapper;
+ @Autowired
+ private OrganizationService organizationService;
+
@Override
+ @Transactional
public Map<String, Object> add(MultipartFile[] files, Supervision supervision) {
-
- String path = null;
- try {
- path = ResourceUtils.getURL("classpath:").getPath() + "static/img/";
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
-
+ //������jar���������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ //���jar������������������������������upload������������������������������������
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
Map<String, Object> result = new HashMap<>();
- List<String> images = new ArrayList<>();
+ //���������������������
+ 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();
@@ -83,6 +96,8 @@
.collect(Collectors.joining(","));
supervision.setImages(image);
}
+
+
supervisionMapper.insert(supervision);
return result;
}
@@ -90,30 +105,44 @@
@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();
-
Map<String, Object> result = new LinkedHashMap<>();
result.put("total", supervisionPage.getTotal());
@@ -126,10 +155,13 @@
}
@Override
+ @Transactional
public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) {
- String path = this.getClass().getClassLoader()
- .getResource("").getFile() + "static/img/";
+ //������jar���������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ //���jar������������������������������upload������������������������������������
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
Map<String, Object> result = new HashMap<>();
@@ -165,4 +197,30 @@
supervisionMapper.updateById(supervision);
return result;
}
+
+ @Override
+ @Transactional
+ public void deleteSupervision(Integer supervisionId) {
+ QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("id", "images").eq("id", supervisionId);
+ Supervision supervision = supervisionMapper.selectOne(queryWrapper);
+ String[] images = supervision.getImages().split(",");
+
+ //������������
+ supervision.setIsDelete(Constants.DELETE);
+ supervision.setImages(null);
+ supervisionMapper.updateById(supervision);
+
+
+ //���������������������������������������
+ ApplicationHome applicationHome = new ApplicationHome(getClass());
+ String path = applicationHome.getSource().getParentFile().toString() + "/static/img";
+ for (String image : images) {
+ String realPath = path + File.separator + image;
+ File file = new File(realPath);
+ if (file.exists() && file.isFile()) {
+ file.delete();
+ }
+ }
+ }
}
--
Gitblit v1.8.0