Commit 2af3e36a authored by fangxinjiang's avatar fangxinjiang

权限批量导入

parent 213f97a6
package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Author fxj
* @Date 2023/10/17
* @Description
* @Version 1.0
*/
@Data
public class DataPermissionImportVo extends RowIndex implements Serializable {
@ExcelAttribute(name = "登录账号", maxLength = 30,isNotEmpty = true)
@Schema(description = "登录账号")
private String userLoginName;
@ExcelAttribute(name = "项目名称", maxLength = 32,isNotEmpty = false)
@Schema(description = "项目名称")
private String settleDomainName;
@Length(max = 32, message = "项目编码不能超过32个字符")
@ExcelAttribute(name = "项目编码", maxLength = 32,isNotEmpty = true)
@Schema(description = "项目编码")
private String settleDomainNo;
}
package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Author fxj
* @Date 2023/10/17
* @Description 社保公积金审核权限VO
* @Version 1.0
*/
@Data
public class SocialAuthHandleImportVo extends RowIndex implements Serializable {
@ExcelAttribute(name = "登录账号", maxLength = 30,isNotEmpty = true)
@Schema(description = "登录账号")
private String userLoginName;
@Length(max = 32, message = "户名称不能超过32个字符")
@ExcelAttribute(name = "户名称", maxLength = 32,isNotEmpty = true)
@Schema(description = "户名称")
private String houseHold;
}
package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.RowIndex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serializable;
/**
* @Author fxj
* @Date 2023/10/17
* @Description 社保公积金审核权限VO
* @Version 1.0
*/
@Data
public class SocialAuthImportVo extends RowIndex implements Serializable {
@ExcelAttribute(name = "登录账号", maxLength = 30,isNotEmpty = true)
@Schema(description = "登录账号")
private String userLoginName;
/**
* 户类型:0社保 1公积金
*/
@Schema(description ="户类型:0社保 1公积金")
@ExcelAttribute(name = "户类型:0社保 1公积金", maxLength = 32,isNotEmpty = true,isDataId = true,readConverterExp = "0=社保,1=公积金")
private String type;
@Length(max = 32, message = "户名称不能超过32个字符")
@ExcelAttribute(name = "户名称", maxLength = 32,isNotEmpty = false)
@Schema(description = "户名称")
private String houseHold;
}
...@@ -9,6 +9,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.service.TCutsomerDataPermissonServic ...@@ -9,6 +9,7 @@ import com.yifu.cloud.plus.v1.yifu.archives.service.TCutsomerDataPermissonServic
import com.yifu.cloud.plus.v1.yifu.archives.service.TSettleDomainService; import com.yifu.cloud.plus.v1.yifu.archives.service.TSettleDomainService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog; import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
...@@ -16,7 +17,10 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils; ...@@ -16,7 +17,10 @@ import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -39,6 +43,7 @@ public class TCutsomerDataPermissonController { ...@@ -39,6 +43,7 @@ public class TCutsomerDataPermissonController {
/** /**
* 简单分页查询 * 简单分页查询
*
* @param page 分页对象 * @param page 分页对象
* @param tCutsomerDataPermisson 客户数据权限表 * @param tCutsomerDataPermisson 客户数据权限表
* @return * @return
...@@ -46,11 +51,12 @@ public class TCutsomerDataPermissonController { ...@@ -46,11 +51,12 @@ public class TCutsomerDataPermissonController {
@Operation(description = "简单分页查询") @Operation(description = "简单分页查询")
@GetMapping("/page") @GetMapping("/page")
public R<IPage<TCutsomerDataPermisson>> getTCutsomerDataPermissonPage(Page<TCutsomerDataPermisson> page, TCutsomerDataPermisson tCutsomerDataPermisson) { public R<IPage<TCutsomerDataPermisson>> getTCutsomerDataPermissonPage(Page<TCutsomerDataPermisson> page, TCutsomerDataPermisson tCutsomerDataPermisson) {
return new R<>(tCutsomerDataPermissonService.getTCutsomerDataPermissonPage(page,tCutsomerDataPermisson)); return new R<>(tCutsomerDataPermissonService.getTCutsomerDataPermissonPage(page, tCutsomerDataPermisson));
} }
/** /**
* 导出list * 导出list
*
* @param tCutsomerDataPermisson 客户数据权限表 * @param tCutsomerDataPermisson 客户数据权限表
* @return * @return
*/ */
...@@ -61,11 +67,11 @@ public class TCutsomerDataPermissonController { ...@@ -61,11 +67,11 @@ public class TCutsomerDataPermissonController {
} }
/** /**
* @return
* @Author fxj * @Author fxj
* @Description 获取实体的权限: type-类型0:客户1:合同2:项目(不传默认2项目) * @Description 获取实体的权限: type-类型0:客户1:合同2:项目(不传默认2项目)
* @Date 15:20 2022/7/13 * @Date 15:20 2022/7/13
* @Param * @Param
* @return
**/ **/
@Operation(description = "获取实体的权限:默认项目") @Operation(description = "获取实体的权限:默认项目")
@GetMapping("/getPermissonByTypeAndId") @GetMapping("/getPermissonByTypeAndId")
...@@ -76,43 +82,45 @@ public class TCutsomerDataPermissonController { ...@@ -76,43 +82,45 @@ public class TCutsomerDataPermissonController {
} }
/** /**
* @return
* @Author fxj * @Author fxj
* @Description 获取实体的权限: type-类型0:客户1:合同2:项目(不传默认2项目) * @Description 获取实体的权限: type-类型0:客户1:合同2:项目(不传默认2项目)
* @Date 15:21 2022/7/13 * @Date 15:21 2022/7/13
* @Param * @Param
* @return
**/ **/
@Operation(description = "权限复制 权限同项目分配客服(wxhr:tsettledomain_assign_customerservice)") @Operation(description = "权限复制 权限同项目分配客服(wxhr:tsettledomain_assign_customerservice)")
@GetMapping("/copy") @GetMapping("/copy")
public R<String> insertForCopyCutsomerDataPermisson(String[] srcUser, String[] beUser) { public R<String> insertForCopyCutsomerDataPermisson(String[] srcUser, String[] beUser) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
R<String> result = tCutsomerDataPermissonService.insertForCopyCutsomerDataPermisson(srcUser, beUser, user); R<String> result = tCutsomerDataPermissonService.insertForCopyCutsomerDataPermisson(srcUser, beUser, user);
if(CommonConstants.SUCCESS.equals(result.getCode())){//权限刷新 if (CommonConstants.SUCCESS.equals(result.getCode())) {//权限刷新
settleDomainService.removeSettleCache(user, Arrays.asList(beUser)); settleDomainService.removeSettleCache(user, Arrays.asList(beUser));
} }
return result ; return result;
} }
/** /**
* 通过id查询单条记录 * 通过id查询单条记录
*
* @param id * @param id
* @return R * @return R
*/ */
@Operation(description = "id查询") @Operation(description = "id查询")
@GetMapping("/{id}") @GetMapping("/{id}")
public R<TCutsomerDataPermisson> getById(@PathVariable("id") String id){ public R<TCutsomerDataPermisson> getById(@PathVariable("id") String id) {
return new R<>(tCutsomerDataPermissonService.getById(id)); return new R<>(tCutsomerDataPermissonService.getById(id));
} }
/** /**
* 新增记录 * 新增记录
*
* @param tCutsomerDataPermisson * @param tCutsomerDataPermisson
* @return R * @return R
*/ */
@Operation(description = "新增") @Operation(description = "新增")
@SysLog("新增客户数据权限表") @SysLog("新增客户数据权限表")
@PostMapping @PostMapping
public R<String> save(@RequestBody TCutsomerDataPermisson tCutsomerDataPermisson){ public R<String> save(@RequestBody TCutsomerDataPermisson tCutsomerDataPermisson) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
settleDomainService.removeSettleCache(user, Arrays.asList(tCutsomerDataPermisson.getUserId())); settleDomainService.removeSettleCache(user, Arrays.asList(tCutsomerDataPermisson.getUserId()));
if (Common.isNotNull(tCutsomerDataPermisson.getUserId()) && Common.isNotNull(tCutsomerDataPermisson.getSettleDomainId())) { if (Common.isNotNull(tCutsomerDataPermisson.getUserId()) && Common.isNotNull(tCutsomerDataPermisson.getSettleDomainId())) {
...@@ -132,6 +140,7 @@ public class TCutsomerDataPermissonController { ...@@ -132,6 +140,7 @@ public class TCutsomerDataPermissonController {
/** /**
* 修改记录 * 修改记录
*
* @param tCutsomerDataPermisson * @param tCutsomerDataPermisson
* @return R * @return R
*/ */
...@@ -146,21 +155,35 @@ public class TCutsomerDataPermissonController { ...@@ -146,21 +155,35 @@ public class TCutsomerDataPermissonController {
/** /**
* 通过id删除一条记录 * 通过id删除一条记录
*
* @param id * @param id
* @return R * @return R
*/ */
@Operation(description = "删除(tcutsomerdatapermisson_del)") @Operation(description = "删除(tcutsomerdatapermisson_del)")
@SysLog("删除客户数据权限表") @SysLog("删除客户数据权限表")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public R<Boolean> removeById(@PathVariable String id){ public R<Boolean> removeById(@PathVariable String id) {
YifuUser user = SecurityUtils.getUser(); YifuUser user = SecurityUtils.getUser();
TCutsomerDataPermisson tdp = tCutsomerDataPermissonService.getById(id); TCutsomerDataPermisson tdp = tCutsomerDataPermissonService.getById(id);
if(null == tdp){ if (null == tdp) {
return new R<>(true); return new R<>(true);
} }
//刷新缓存 //刷新缓存
settleDomainService.removeSettleCache(user, Arrays.asList(tdp.getUserId())); settleDomainService.removeSettleCache(user, Arrays.asList(tdp.getUserId()));
return new R<>(tCutsomerDataPermissonService.removeById(id)); return new R<>(tCutsomerDataPermissonService.removeById(id));
} }
/**
* @Author fxj
* @Description 批量导入项目权限
* @Date 16:59 2023/10/17
* @Param
* @return
**/
@SneakyThrows
@Operation(description = "批量新增项目权限")
@SysLog("批量新增项目权限")
@PostMapping("/importListAdd")
public R<List<ErrorMessage>> importListAdd(@RequestBody MultipartFile file) {
return tCutsomerDataPermissonService.importDiy(file.getInputStream());
}
} }
...@@ -24,9 +24,11 @@ import com.yifu.cloud.plus.v1.yifu.archives.entity.TCustomerInfo; ...@@ -24,9 +24,11 @@ import com.yifu.cloud.plus.v1.yifu.archives.entity.TCustomerInfo;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TSettleDomain; import com.yifu.cloud.plus.v1.yifu.archives.entity.TSettleDomain;
import com.yifu.cloud.plus.v1.yifu.archives.vo.*; import com.yifu.cloud.plus.v1.yifu.archives.vo.*;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
...@@ -111,4 +113,6 @@ public interface TSettleDomainMapper extends BaseMapper<TSettleDomain> { ...@@ -111,4 +113,6 @@ public interface TSettleDomainMapper extends BaseMapper<TSettleDomain> {
void changeIssueStatus(@Param("changeIssueStatusVo")ChangeIssueStatusVo changeIssueStatusVo); void changeIssueStatus(@Param("changeIssueStatusVo")ChangeIssueStatusVo changeIssueStatusVo);
List<TSettleDomain> getAllInfoMap();
} }
...@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TCutsomerDataPermisson; import com.yifu.cloud.plus.v1.yifu.archives.entity.TCutsomerDataPermisson;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
...@@ -43,4 +45,6 @@ public interface TCutsomerDataPermissonService extends IService<TCutsomerDataPer ...@@ -43,4 +45,6 @@ public interface TCutsomerDataPermissonService extends IService<TCutsomerDataPer
* @return * @return
**/ **/
R<String> insertForCopyCutsomerDataPermisson(String[] srcUserList, String[] beUser, YifuUser user); R<String> insertForCopyCutsomerDataPermisson(String[] srcUserList, String[] beUser, YifuUser user);
R<List<ErrorMessage>> importDiy(InputStream inputStream);
} }
package com.yifu.cloud.plus.v1.yifu.archives.service.impl; package com.yifu.cloud.plus.v1.yifu.archives.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.util.ListUtils;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.AllUserNaVo;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TCompanyInfo;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TCutsomerDataPermisson; import com.yifu.cloud.plus.v1.yifu.archives.entity.TCutsomerDataPermisson;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TSettleDomain;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TCutsomerDataPermissonMapper; import com.yifu.cloud.plus.v1.yifu.archives.mapper.TCutsomerDataPermissonMapper;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TSettleDomainMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.TCutsomerDataPermissonService; import com.yifu.cloud.plus.v1.yifu.archives.service.TCutsomerDataPermissonService;
import com.yifu.cloud.plus.v1.yifu.archives.service.TSettleDomainService;
import com.yifu.cloud.plus.v1.yifu.archives.vo.DataPermissionImportVo;
import com.yifu.cloud.plus.v1.yifu.archives.vo.TCompanyInfoVo;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants; import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common; import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ExcelUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R; import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprUpmsProperties; import com.yifu.cloud.plus.v1.yifu.common.dapr.config.DaprUpmsProperties;
import com.yifu.cloud.plus.v1.yifu.common.dapr.util.UpmsDaprUtils;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.InputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
...@@ -32,9 +55,13 @@ import java.util.*; ...@@ -32,9 +55,13 @@ import java.util.*;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@EnableConfigurationProperties(DaprUpmsProperties.class) @EnableConfigurationProperties(DaprUpmsProperties.class)
@AllArgsConstructor
@Slf4j @Slf4j
public class TCutsomerDataPermissonServiceImpl extends ServiceImpl<TCutsomerDataPermissonMapper, TCutsomerDataPermisson> implements TCutsomerDataPermissonService { public class TCutsomerDataPermissonServiceImpl extends ServiceImpl<TCutsomerDataPermissonMapper, TCutsomerDataPermisson> implements TCutsomerDataPermissonService {
@Autowired
private UpmsDaprUtils upmsDaprUtils;
@Autowired
private TSettleDomainMapper domainMapper;
/** /**
* 客户数据权限表简单分页查询 * 客户数据权限表简单分页查询
* *
...@@ -118,4 +145,172 @@ public class TCutsomerDataPermissonServiceImpl extends ServiceImpl<TCutsomerData ...@@ -118,4 +145,172 @@ public class TCutsomerDataPermissonServiceImpl extends ServiceImpl<TCutsomerData
public boolean save(TCutsomerDataPermisson cutsomerDataPermisson){ public boolean save(TCutsomerDataPermisson cutsomerDataPermisson){
return super.save(cutsomerDataPermisson); return super.save(cutsomerDataPermisson);
} }
/**
* @Author fxj
* @Description 批量导入项目权限
* @Date 16:59 2023/10/17
* @Param
* @return
**/
@Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
@Override
public R<List<ErrorMessage>> importDiy(InputStream inputStream) {
List<ErrorMessage> errorMessageList = new ArrayList<>();
ExcelUtil<DataPermissionImportVo> util1 = new ExcelUtil<>(DataPermissionImportVo.class);
List<TSettleDomain> settleDomains = domainMapper.getAllInfoMap();
Map<String, TSettleDomain> domainMap = null;
if (Common.isNotNull(settleDomains)){
domainMap = settleDomains.stream().collect(Collectors.toMap(k->k.getDepartNo(),k->k));
}
if (Common.isEmpty(domainMap)){
domainMap = new HashMap<>();
}
Map<String,SysUser> userMap = new HashMap<>();
Map<String,String> existMap = new HashMap<>();
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try {
Map<String, TSettleDomain> finalDomainMap = domainMap;
EasyExcel.read(inputStream, DataPermissionImportVo.class, new ReadListener<DataPermissionImportVo>() {
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
/**
*临时存储
*/
private List<DataPermissionImportVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(DataPermissionImportVo data, AnalysisContext context) {
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex+1);
ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
if (Common.isNotNull(errorMessage)){
errorMessageList.add(errorMessage);
}else {
cachedDataList.add(data);
}
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
saveData();
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
importEntity(cachedDataList,errorMessageList, finalDomainMap,userMap,existMap);
log.info("存储数据库成功!");
}
}).sheet().doRead();
}catch (Exception e){
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR,e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
}finally {
// 清理
domainMap.clear();
}
return judgeAllMessage(errorMessageList);
}
/**
* @Author fxj
* @Description 判断所有返回数据,是否全部为正确的
* @Date 18:01 2023/10/18
* @Param
* @return
**/
private R<List<ErrorMessage>> judgeAllMessage(List<ErrorMessage> errorMessageList) {
if (!errorMessageList.isEmpty() && errorMessageList.stream().noneMatch(e-> e.getColor().equals(CommonConstants.RED))) {
return R.ok();
}
return R.ok(errorMessageList);
}
private void importEntity(List<DataPermissionImportVo> excelVOList,
List<ErrorMessage> errorMessageList,
Map<String,TSettleDomain> domainMap,
Map<String,SysUser> userMap,
Map<String,String> existMap) {
// 执行数据插入操作 组装
TCutsomerDataPermisson permission = null;
SysUser user;
R<SysUser> res;
TSettleDomain domain;
TCutsomerDataPermisson exist;
String temp;
DataPermissionImportVo excel;
for (int i = 0; i < excelVOList.size(); i++) {
excel = excelVOList.get(i);
// 数据合法情况
user = userMap.get(excel.getUserLoginName());
// 用户信息验证
if (Common.isEmpty(user)){
res = upmsDaprUtils.getSimpleUserByLoginName(excel.getUserLoginName());
if (Common.isNotNull(res) && Common.isNotNull(res.getData())){
user = res.getData();
userMap.put(user.getUsername(),user);
}else {
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),CommonConstants.USER_FAIL));
continue;
}
}
if (Common.isEmpty(user.getDeptName())){
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),"对应登录账号无部门信息,请完善后导入"));
continue;
}
// 项目信息验证
domain = domainMap.get(excel.getSettleDomainNo());
if (Common.isEmpty(domain)){
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),CommonConstants.SETTLE_DOMAIN_NOT_EXIST));
continue;
}
// 重复校验
temp = existMap.get(excel.getUserLoginName()+CommonConstants.DOWN_LINE_STRING+excel.getSettleDomainNo());
if (Common.isNotNull(temp)){
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),"对应账号的权限已存在,请勿重复导入"));
continue;
}else {
exist = baseMapper.selectOne(Wrappers.<TCutsomerDataPermisson>query().lambda()
.eq(TCutsomerDataPermisson::getSettleDomainNo,excel.getSettleDomainNo())
.eq(TCutsomerDataPermisson::getUserLoginName,excel.getUserLoginName())
.last(CommonConstants.LAST_ONE_SQL));
if (Common.isNotNull(exist)){
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),"对应账号的权限已存在,请勿重复导入"));
continue;
}
}
// 初始化及新增数据
permission = new TCutsomerDataPermisson();
permission.setType(CommonConstants.ONE_STRING);
permission.setSettleDomainId(domain.getId());
permission.setRemark("批量授权");
permission.setSettleDomainName(domain.getDepartName());
permission.setSettleDomainNo(domain.getDepartNo());
permission.setStatus(CommonConstants.ZERO_STRING);
permission.setUserId(user.getUserId());
permission.setUserDeptName(user.getDeptName());
permission.setUserLoginName(user.getUsername());
permission.setUserNickName(user.getNickname());
insertExcel(permission);
// 加入map 验证当前表单数据是否重复
existMap.put(excel.getUserLoginName()+CommonConstants.DOWN_LINE_STRING+excel.getSettleDomainNo(),excel.getSettleDomainNo());
errorMessageList.add(new ErrorMessage(excel.getRowIndex(),CommonConstants.SAVE_SUCCESS,CommonConstants.GREEN));
}
}
/**
* 插入excel bad record
*/
private void insertExcel(TCutsomerDataPermisson entity) {
this.save(entity);
}
} }
...@@ -510,4 +510,11 @@ ...@@ -510,4 +510,11 @@
set a.ISSUE_STATUS=#{changeIssueStatusVo.issueStatus} set a.ISSUE_STATUS=#{changeIssueStatusVo.issueStatus}
WHERE a.ID=#{changeIssueStatusVo.id} WHERE a.ID=#{changeIssueStatusVo.id}
</update> </update>
<select id="getAllInfoMap" resultMap="tSettleDomainMap">
SELECT
<include refid="Base_Column_List"/>
FROM
t_settle_domain a
where a.DELETE_FLAG = '0'
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment