|
@@ -1,12 +1,15 @@
|
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
-import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.ruoyi.common.datascope.annotation.DataScope;
|
|
|
import com.ruoyi.common.datascope.context.DataScopeContextHolder;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.common.core.util.BeanMapperUtils;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.fire.domain.*;
|
|
@@ -19,17 +22,18 @@ import com.usky.fire.service.util.OnlineMethod;
|
|
|
import com.usky.fire.service.vo.DataCountVo;
|
|
|
import com.usky.fire.service.vo.PatrolInspectionAreaVo;
|
|
|
import com.usky.fire.service.vo.PatrolInspectionSiteExportVo;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionSiteImportVo;
|
|
|
import com.usky.system.model.LoginUser;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -194,16 +198,24 @@ public class PatrolInspectionSiteServiceImpl extends AbstractCrudService<PatrolI
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void addSiteContent(List<PatrolInspectionSiteContent> siteContentList) {
|
|
|
- LambdaQueryWrapper<PatrolInspectionSiteContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(PatrolInspectionSiteContent::getSiteId, siteContentList.get(0).getSiteId());
|
|
|
- List<PatrolInspectionSiteContent> siteContenListOne = siteContentService.list(queryWrapper);
|
|
|
- if (siteContenListOne.size() > 0) {
|
|
|
- for (int i = 0; i < siteContenListOne.size(); i++) {
|
|
|
- siteContentService.removeById(siteContenListOne.get(i).getId());
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ List<Integer> list2 = new ArrayList<>();
|
|
|
+ if (siteContentList.size()>0){
|
|
|
+ for (int i = 0; i < siteContentList.size(); i++) {
|
|
|
+ list.add(siteContentList.get(i).getSiteId());
|
|
|
+ }
|
|
|
+ list2 = removeDuplicatesUsingHashSet(list);
|
|
|
+ LambdaQueryWrapper<PatrolInspectionSiteContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.in(PatrolInspectionSiteContent::getSiteId, list2);
|
|
|
+ List<PatrolInspectionSiteContent> siteContenListOne = siteContentService.list(queryWrapper);
|
|
|
+ if (siteContenListOne.size() > 0) {
|
|
|
+ for (int i = 0; i < siteContenListOne.size(); i++) {
|
|
|
+ siteContentService.removeById(siteContenListOne.get(i).getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < siteContentList.size(); i++) {
|
|
|
+ siteContentService.save(siteContentList.get(i));
|
|
|
}
|
|
|
- }
|
|
|
- for (int i = 0; i < siteContentList.size(); i++) {
|
|
|
- siteContentService.save(siteContentList.get(i));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -285,4 +297,45 @@ public class PatrolInspectionSiteServiceImpl extends AbstractCrudService<PatrolI
|
|
|
}
|
|
|
return siteIdList;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void patrolInspectionSiteImport(MultipartFile multipartFile) {
|
|
|
+ ImportParams params = new ImportParams();
|
|
|
+ params.setHeadRows(1);
|
|
|
+ String err="文件导入失败";
|
|
|
+ try {
|
|
|
+ List<PatrolInspectionSiteImportVo> patrolInspectionSiteImportVos =
|
|
|
+ ExcelImportUtil.importExcel(multipartFile.getInputStream(),
|
|
|
+ PatrolInspectionSiteImportVo.class, params);
|
|
|
+ if (CollectionUtils.isNotEmpty(patrolInspectionSiteImportVos)){
|
|
|
+ int rot=0;
|
|
|
+ for (PatrolInspectionSiteImportVo patrolInspectionSiteImportVo:patrolInspectionSiteImportVos) {
|
|
|
+ PatrolInspectionSite patrolInspectionSite = BeanMapperUtils.map(patrolInspectionSiteImportVo, PatrolInspectionSite.class);
|
|
|
+ patrolInspectionSite.setEnable(1);
|
|
|
+ patrolInspectionSite.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionSite.setCollector(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
|
|
+ patrolInspectionSite.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionSite.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionSite.setSiteType(2);
|
|
|
+ try{
|
|
|
+ this.save(patrolInspectionSite);
|
|
|
+ }catch (Exception e){
|
|
|
+ int h=rot+2;
|
|
|
+ err="文件导入失败,第"+h+"行数据导入失败";
|
|
|
+ throw new BusinessException(err);
|
|
|
+ }
|
|
|
+ rot++;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ err="文件不能为空";
|
|
|
+ throw new BusinessException(err);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static <T> List<T> removeDuplicatesUsingHashSet(List<T> list) {
|
|
|
+ Set<T> set = new HashSet<>(list);
|
|
|
+ return new ArrayList<>(set);
|
|
|
+ }
|
|
|
}
|