Browse Source

导入修改end

master
yinzuomei 3 years ago
parent
commit
bc73167867
  1. 1
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcSocietyOrgController.java
  2. 4
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcSocietyOrgDao.java
  3. 13
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcSocietyOrgImportExcelDTO.java
  4. 157
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcSocietyOrgExcelImportListener.java
  5. 50
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcSocietyOrgServiceImpl.java
  6. 9
      epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcSocietyOrgDao.xml
  7. 34
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java

1
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcSocietyOrgController.java

@ -268,7 +268,6 @@ public class IcSocietyOrgController implements ResultDataResolver {
@PostMapping("importV2")
public Result importExcelV2(@LoginUser TokenDto tokenDto, @RequestPart("file") MultipartFile file) {
String userId = EpmetRequestHolder.getHeader(AppClientConstant.USER_ID);
// 1.暂存文件
String originalFilename = file.getOriginalFilename();
String extName = originalFilename.substring(originalFilename.lastIndexOf("."));

4
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcSocietyOrgDao.java

@ -59,4 +59,8 @@ public interface IcSocietyOrgDao extends BaseDao<IcSocietyOrgEntity> {
* @Description 查询当前组织下的社会组织数据
**/
List<IcSocietyOrgDTO> getByAgencyId(@Param("agencyId") String agencyId);
List<IcSocietyOrgEntity> selectListForUniqueName(@Param("agencyId") String agencyId,
@Param("societyName") String societyName,
@Param("id") String id);
}

13
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/IcSocietyOrgImportExcelDTO.java

@ -16,22 +16,21 @@ import javax.validation.constraints.NotBlank;
public class IcSocietyOrgImportExcelDTO {
@ExcelProperty(value = "组织名称")
@NotBlank(message = "不能为空")
@Length(max=50,message = "不能超过50个字")
@NotBlank(message = "组织名称不能为空")
@Length(max=50,message = "组织名称不能超过50个字")
private String societyName;
@ExcelProperty(value = "服务内容")
@NotBlank(message = "不能为空")
@Length(max=1000,message = "不能超过1000个字")
@NotBlank(message = "服务内容不能为空")
@Length(max=1000,message = "服务内容不能超过1000个字")
private String serviceMatters;
@ExcelProperty(value = "服务电话")
@NotBlank(message = "不能为空")
@Length(max=11,message = "不能超过11个字")
@NotBlank(message = "服务电话不能为空")
private String mobile;
@ExcelProperty(value = "服务时间")
@NotBlank(message = "不能为空")
@NotBlank(message = "服务时间不能为空")
private String serviceTimeStr;
@ExcelProperty(value = "管理员姓名")

157
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/handler/IcSocietyOrgExcelImportListener.java

@ -0,0 +1,157 @@
package com.epmet.excel.handler;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.ValidateException;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.ObjectUtil;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.entity.IcSocietyOrgEntity;
import com.epmet.excel.IcSocietyOrgImportExcelDTO;
import com.epmet.service.impl.IcSocietyOrgServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Description
* @Author yzm
* @Date 2022/8/24 11:42
*/
@Slf4j
public class IcSocietyOrgExcelImportListener implements ReadListener<IcSocietyOrgImportExcelDTO> {
// 最大条数阈值
public static final int MAX_THRESHOLD = 2;
private String currentCustomerId;
/**
* 当前操作用户
*/
private CustomerStaffInfoCacheResult staffInfo;
private IcSocietyOrgServiceImpl icSocietyOrgService;
private List<IcSocietyOrgImportExcelDTO.ErrorRow> errorRows = new ArrayList<>();
/**
* 要插入的数据
*/
private List<IcSocietyOrgEntity> insertDatas = new ArrayList<>();
/**
* 根据组织名称更新的数据
*/
private List<IcSocietyOrgEntity> updateDatas = new ArrayList<>();
private Map<String,String> staffMap=new HashMap<>();
public IcSocietyOrgExcelImportListener(String customerId, CustomerStaffInfoCacheResult staffInfo, IcSocietyOrgServiceImpl icSocietyOrgService, Map<String,String> staffMap) {
this.currentCustomerId = customerId;
this.staffInfo = staffInfo;
this.icSocietyOrgService = icSocietyOrgService;
this.staffMap=staffMap;
}
@Override
public void invoke(IcSocietyOrgImportExcelDTO data, AnalysisContext analysisContext) {
try {
// log.warn("有数据吗?"+JSON.toJSONString(data));
// 不能为空先校验数据
ValidatorUtils.validateEntity(data);
// 去除空格
ObjectUtil.objectToTrim(data);
IcSocietyOrgEntity icSocietyOrgEntity = ConvertUtils.sourceToTarget(data, IcSocietyOrgEntity.class);
icSocietyOrgEntity.setCustomerId(currentCustomerId);
icSocietyOrgEntity.setAgencyId(staffInfo.getAgencyId());
icSocietyOrgEntity.setPids(staffInfo.getAgencyPIds());
if(StringUtils.isNotBlank(data.getAdminStaffName())){
String adminStaffId = null;
for(String key:staffMap.keySet()){
if (data.getAdminStaffName().equals(staffMap.get(key))) {
adminStaffId=key;
break;
}
}
if (StringUtils.isBlank(adminStaffId)) {
String msg = String.format("当前组织下没有【%s】", data.getAdminStaffName());
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), msg, msg);
}
icSocietyOrgEntity.setAdminStaffId(adminStaffId);
}
//网格id+场所名称
List<IcSocietyOrgEntity> originList = icSocietyOrgService.selectForUniqueName(icSocietyOrgEntity.getAgencyId(), icSocietyOrgEntity.getSocietyName(), null);
if(CollectionUtils.isEmpty(originList)){
insertDatas.add(icSocietyOrgEntity);
}else{
IcSocietyOrgEntity origin=originList.get(NumConstant.ZERO);
icSocietyOrgEntity.setId(origin.getId());
updateDatas.add(icSocietyOrgEntity);
}
if (insertDatas.size() == MAX_THRESHOLD) {
execPersist();
}
if (updateDatas.size() == MAX_THRESHOLD) {
execPersist();
}
} catch (Exception e) {
String errorMsg = null;
if (e instanceof ValidateException) {
errorMsg = ((ValidateException) e).getMsg();
}else if(e instanceof EpmetException){
errorMsg = ((EpmetException) e).getMsg();
}else {
errorMsg = "未知错误";
log.error("【社会组织导入】出错:{}", ExceptionUtils.getErrorStackTrace(e));
}
IcSocietyOrgImportExcelDTO.ErrorRow errorRow = new IcSocietyOrgImportExcelDTO.ErrorRow();
errorRow.setSocietyName(data.getSocietyName());
errorRow.setServiceMatters(data.getServiceMatters());
errorRow.setMobile(data.getMobile());
errorRow.setServiceTimeStr(data.getServiceTimeStr());
errorRow.setAdminStaffName(data.getAdminStaffName());
errorRow.setAddress(data.getAddress());
errorRow.setErrorInfo(errorMsg);
errorRows.add(errorRow);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
log.info("☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆");
// 最后几条达不到阈值,这里必须再调用一次
execPersist();
}
/**
* 执行持久化
*/
private void execPersist() {
try {
if (CollectionUtils.isNotEmpty(insertDatas)) {
icSocietyOrgService.insertBatch(insertDatas);
}
if (CollectionUtils.isNotEmpty(updateDatas)) {
icSocietyOrgService.updateBatchById(updateDatas);
}
} finally {
insertDatas.clear();
updateDatas.clear();
}
}
/**
* 获取错误行
*
* @return
*/
public List<IcSocietyOrgImportExcelDTO.ErrorRow> getErrorRows() {
return errorRows;
}
}

50
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcSocietyOrgServiceImpl.java

@ -41,6 +41,7 @@ import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcSocietyOrgEntity;
import com.epmet.excel.IcSocietyOrgExcel;
import com.epmet.excel.IcSocietyOrgImportExcelDTO;
import com.epmet.excel.handler.IcSocietyOrgExcelImportListener;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
@ -164,14 +165,23 @@ public class IcSocietyOrgServiceImpl extends BaseServiceImpl<IcSocietyOrgDao, Ic
Map<String, Integer> pointMap = icUserDemandRecService.getServicePoint(formDTO.getCustomerId(), UserDemandConstant.SOCIAL_ORG);
//2.查询被绑定管理员信息
UserIdsFormDTO dto = new UserIdsFormDTO();
List<String> staffIdList = result.getList().stream().map(SocietyOrgListResultDTO::getAdminStaffId).collect(Collectors.toList());
staffIdList = staffIdList.stream().distinct().collect(Collectors.toList());
dto.setUserIds(staffIdList);
Result<List<StaffSinGridResultDTO>> listResult = epmetUserOpenFeignClient.getStaffInfoList(dto);
if (!listResult.success()) {
throw new RenException("获取工作人员基本信息失败......");
List<String> staffIdList = result.getList().stream().filter(u->StringUtils.isNotBlank(u.getAdminStaffId())).map(SocietyOrgListResultDTO::getAdminStaffId).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(staffIdList)){
staffIdList = staffIdList.stream().distinct().collect(Collectors.toList());
dto.setUserIds(staffIdList);
Result<List<StaffSinGridResultDTO>> listResult = epmetUserOpenFeignClient.getStaffInfoList(dto);
if (!listResult.success()) {
throw new RenException("获取工作人员基本信息失败......");
}
result.getList().stream().filter(f->StringUtils.isNotBlank(f.getAdminStaffId())).forEach(r -> listResult.getData().stream().filter(u -> r.getAdminStaffId().equals(u.getStaffId())).forEach(u -> r.setAdminStaffName(u.getStaffName())));
/* result.getList().forEach(dto1->{
listResult.getData().forEach(staff->{
if(dto1.getAdminStaffId().equals(staff.getStaffId())){
dto1.setAdminStaffName(staff.getStaffName());
}
});
});*/
}
result.getList().forEach(r -> listResult.getData().stream().filter(u -> r.getAdminStaffId().equals(u.getStaffId())).forEach(u -> r.setAdminStaffName(u.getStaffName())));
//3.查询被绑定管理员信息
OrgInfoFormDTO org = new OrgInfoFormDTO();
@ -340,14 +350,28 @@ public class IcSocietyOrgServiceImpl extends BaseServiceImpl<IcSocietyOrgDao, Ic
try {
//获取当前登录用户所属组织id
CustomerStaffInfoCacheResult staffInfo= queryCurrentStaff(customerId,userId);
//当前组织下的人
AgencyIdFormDTO agencyIdFormDTO=new AgencyIdFormDTO();
agencyIdFormDTO.setAgencyId(staffInfo.getAgencyId());
Result<List<String>> staffIdsRes=govOrgOpenFeignClient.getAgencyStaffs(agencyIdFormDTO);
if (!staffIdsRes.success() || CollectionUtils.isEmpty(staffIdsRes.getData())) {
String msg = "查询当前组织下工作人员列表异常";
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), msg, msg);
}
Result<CustomerStaffListResultDTO> currentAgencyStaffs=epmetUserOpenFeignClient.getCustomerStaffList(staffIdsRes.getData());
if (!currentAgencyStaffs.success() || null == currentAgencyStaffs.getData() || CollectionUtils.isEmpty(currentAgencyStaffs.getData().getStaffList())) {
String msg = "查询当前组织下工作人员信息异常";
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), msg, msg);
}
List<StaffListResultDTO> staffList=currentAgencyStaffs.getData().getStaffList();
Map<String,String> staffMap=staffList.stream().collect(Collectors.toMap(StaffListResultDTO::getStaffId, StaffListResultDTO::getStaffName));
// todo
/*IcEnterpriseExcelImportListener listener = new IcEnterpriseExcelImportListener(customerId,staffInfo, this);
EasyExcel.read(filePath.toFile(), IcSocietyOrgImportExcelDTO.class, listener).headRowNumber(1).sheet(0).doRead();*/
IcSocietyOrgExcelImportListener listener = new IcSocietyOrgExcelImportListener(customerId,staffInfo, this,staffMap);
EasyExcel.read(filePath.toFile(), IcSocietyOrgImportExcelDTO.class, listener).headRowNumber(1).sheet(0).doRead();
Path errorDescFile = null;
String errorDesFileUrl = null;
List<IcSocietyOrgImportExcelDTO.ErrorRow> errorRows = null;// todo listener.getErrorRows();
List<IcSocietyOrgImportExcelDTO.ErrorRow> errorRows = listener.getErrorRows();
boolean failed = errorRows.size() > 0;
if (failed) {
@ -420,4 +444,8 @@ public class IcSocietyOrgServiceImpl extends BaseServiceImpl<IcSocietyOrgDao, Ic
}
return staffInfo;
}
public List<IcSocietyOrgEntity> selectForUniqueName(String agencyId, String societyName, String id) {
return baseDao.selectListForUniqueName(agencyId,societyName,id);
}
}

9
epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcSocietyOrgDao.xml

@ -92,4 +92,13 @@
AND agency_id = #{agencyId}
</select>
<select id="selectListForUniqueName" parameterType="map" resultType="com.epmet.entity.IcSocietyOrgEntity">
select o.* from ic_society_org o
where o.del_flag='0'
and o.agency_id = #{agencyId}
and o.society_name =#{societyName}
<if test="null != id and id != '' ">
and o.id != #{id}
</if>
</select>
</mapper>

34
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java

@ -617,25 +617,23 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl<CustomerStaffDao,
List<StaffSinGridResultDTO> staffInfoList = new ArrayList<>();
userIds.forEach(staffId -> {
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), staffId);
if (staffInfo == null) {
log.error("getStaffInfoList fail customerId:{}, staffId:{} not exist in db", formDTO.getCustomerId(), staffId);
return;
if (null != staffInfo) {
StaffSinGridResultDTO resultDTO = new StaffSinGridResultDTO();
resultDTO.setStaffId(staffId);
resultDTO.setStaffName(staffInfo.getRealName());
resultDTO.setHeadPhoto(staffInfo.getHeadPhoto());
resultDTO.setGender(staffInfo.getGender());
List<RoleResultDTO> roleInfoList = new ArrayList<>();
staffInfo.getRoleMap().forEach((key, value) -> {
RoleResultDTO dto = new RoleResultDTO();
dto.setRoleKey(key);
dto.setRoleName(value);
roleInfoList.add(dto);
});
resultDTO.setRoleList(roleInfoList);
staffInfoList.add(resultDTO);
}
StaffSinGridResultDTO resultDTO = new StaffSinGridResultDTO();
resultDTO.setStaffId(staffId);
resultDTO.setStaffName(staffInfo.getRealName());
resultDTO.setHeadPhoto(staffInfo.getHeadPhoto());
resultDTO.setGender(staffInfo.getGender());
List<RoleResultDTO> roleInfoList = new ArrayList<>();
staffInfo.getRoleMap().forEach((key, value) -> {
RoleResultDTO dto = new RoleResultDTO();
dto.setRoleKey(key);
dto.setRoleName(value);
roleInfoList.add(dto);
});
resultDTO.setRoleList(roleInfoList);
staffInfoList.add(resultDTO);
});
/*List<StaffSinGridResultDTO> staffInfoList = customerStaffDao.getStaffInfoList(userIds);

Loading…
Cancel
Save