Browse Source

导入

dev_shibei_match
zxc 4 years ago
parent
commit
e62829c4b6
  1. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  2. 2
      epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/AddCommunitySelfOrganizationFormDTO.java
  3. 2
      epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/EditCommunitySelfOrganizationFormDTO.java
  4. 31
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java
  5. 9
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java
  6. 40
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganization.java
  7. 20
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganizationSon.java
  8. 13
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java
  9. 83
      epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java
  10. 13
      epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml

2
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java

@ -157,6 +157,8 @@ public enum EpmetErrorCode {
EXISTS_SAME_PHONE_ERROR(8529, "%s存在重复"),
COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR(8530, "%s社区自组织名称已存在"),
// 该错误不会提示给前端,只是后端传输错误信息用。
ACCESS_SQL_FILTER_MISSION_ARGS(8701, "缺少生成权限过滤SQL所需参数"),
OPER_ADD_CUSTOMER_ROOT_AGENCY_ERROR(8702, "添加客户根级组织失败"),

2
epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/AddCommunitySelfOrganizationFormDTO.java

@ -59,13 +59,11 @@ public class AddCommunitySelfOrganizationFormDTO implements Serializable {
/**
* 经度
*/
@NotBlank(message = "longitude不能为空",groups = AddCommunitySelfOrganizationForm.class)
private String longitude;
/**
* 纬度
*/
@NotBlank(message = "latitude不能为空",groups = AddCommunitySelfOrganizationForm.class)
private String latitude;
/**

2
epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/EditCommunitySelfOrganizationFormDTO.java

@ -61,13 +61,11 @@ public class EditCommunitySelfOrganizationFormDTO implements Serializable {
/**
* 经度
*/
@NotBlank(message = "longitude不能为空",groups = EditCommunitySelfOrganizationForm.class)
private String longitude;
/**
* 纬度
*/
@NotBlank(message = "latitude不能为空",groups = EditCommunitySelfOrganizationForm.class)
private String latitude;
/**

31
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/IcCommunitySelfOrganizationController.java

@ -18,6 +18,7 @@
package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ExcelUtils;
@ -28,18 +29,17 @@ import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.IcCommunitySelfOrganizationDTO;
import com.epmet.dto.form.AddCommunitySelfOrganizationFormDTO;
import com.epmet.dto.form.CommunitySelfOrganizationListFormDTO;
import com.epmet.dto.form.DelCommunitySelfOrganizationFormDTO;
import com.epmet.dto.form.EditCommunitySelfOrganizationFormDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.excel.ExportCommunitySelfOrganizationExcel;
import com.epmet.excel.IcCommunitySelfOrganizationExcel;
import com.epmet.service.IcCommunitySelfOrganizationService;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@ -115,7 +115,28 @@ public class IcCommunitySelfOrganizationController {
ExcelUtils.exportExcelToTarget(response, null, resultDTO.getList(), ExportCommunitySelfOrganizationExcel.class);
}
//@PostMapping("importcommunityselforganization")
/**
* @Description 导入
* @param tokenDto
* @param response
* @param file
* @author zxc
* @date 2021/11/25 9:03 上午
*/
@PostMapping("importcommunityselforganization")
public Result importCommunitySelfOrganization(@LoginUser TokenDto tokenDto, HttpServletResponse response, @RequestPart("file") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw new RenException("请上传文件");
}
// 校验文件类型
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
if (!"xls".equals(extension) && !"xlsx".equals(extension)) {
throw new RenException("文件类型不匹配");
}
icCommunitySelfOrganizationService.importCommunitySelfOrganization(tokenDto, response, file);
return new Result();
}
/**
* @Description 添加社区自组织

9
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/dao/IcCommunitySelfOrganizationDao.java

@ -55,4 +55,13 @@ public interface IcCommunitySelfOrganizationDao extends BaseDao<IcCommunitySelfO
List<OptionDTO> selectListByAgencyId(@Param("customerId") String customerId,
@Param("agencyIds") List<String> agencyIds,
@Param("orgName") String orgName);
/**
* @Description 根据名字查询存在的自组织
* @param names
* @author zxc
* @date 2021/11/25 9:07 上午
*/
List<String> selectOrgByOrgName(@Param("names")List<String> names, @Param("customerId") String customerId);
}

40
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganization.java

@ -0,0 +1,40 @@
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.epmet.commons.tools.utils.ExcelVerifyInfo;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @Author zxc
* @DateTime 2021/11/24 4:34 下午
* @DESC
*/
@Data
public class ImportCommunitySelfOrganization extends ExcelVerifyInfo {
@Excel(name = "组织名称", needMerge = true)
private String organizationName;
@Excel(name = "组织人数", needMerge = true)
private Integer organizationPersonCount;
@Excel(name = "服务事项", needMerge = true)
private String serviceItem;
@Excel(name = "负责人", needMerge = true)
private String principalName;
@Excel(name = "联系电话", needMerge = true)
private String principalPhone;
@Excel(name = "创建时间", needMerge = true)
private Date organizationCreatedTime;
@ExcelCollection(name = "组织成员")
private List<ImportCommunitySelfOrganizationSon> persons;
}

20
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/excel/ImportCommunitySelfOrganizationSon.java

@ -0,0 +1,20 @@
package com.epmet.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
/**
* @Author zxc
* @DateTime 2021/11/24 4:46 下午
* @DESC
*/
@Data
public class ImportCommunitySelfOrganizationSon {
@Excel(name = "姓名")
private String personName;
@Excel(name = "电话")
private String personPhone;
}

13
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/IcCommunitySelfOrganizationService.java

@ -29,7 +29,10 @@ import com.epmet.dto.form.demand.ServiceQueryFormDTO;
import com.epmet.dto.result.CommunitySelfOrganizationListResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcCommunitySelfOrganizationEntity;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -145,4 +148,14 @@ public interface IcCommunitySelfOrganizationService extends BaseService<IcCommun
* @return
*/
List<OptionDTO> queryServiceList(ServiceQueryFormDTO formDTO);
/**
* @Description 导入
* @param tokenDto
* @param response
* @param file
* @author zxc
* @date 2021/11/25 9:03 上午
*/
void importCommunitySelfOrganization(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException;
}

83
epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/IcCommunitySelfOrganizationServiceImpl.java

@ -1,5 +1,6 @@
package com.epmet.service.impl;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -18,6 +19,7 @@ import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.ExcelPoiUtils;
import com.epmet.constant.IcCommunitySelfOrganizationConstant;
import com.epmet.dao.IcCommunitySelfOrganizationDao;
import com.epmet.dto.IcCommunitySelfOrganizationDTO;
@ -31,6 +33,7 @@ import com.epmet.dto.result.CommunitySelfOrganizationListResultDTO;
import com.epmet.dto.result.demand.OptionDTO;
import com.epmet.entity.IcCommunitySelfOrganizationEntity;
import com.epmet.entity.IcCommunitySelfOrganizationPersonnelEntity;
import com.epmet.excel.ImportCommunitySelfOrganization;
import com.epmet.service.IcCommunitySelfOrganizationPersonnelService;
import com.epmet.service.IcCommunitySelfOrganizationService;
import com.epmet.service.IcUserDemandRecService;
@ -41,7 +44,10 @@ 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.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@ -316,4 +322,81 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo
return resultList;
}
/**
* @Description 导入
* @param tokenDto
* @param response
* @param file
* @author zxc
* @date 2021/11/25 9:03 上午
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void importCommunitySelfOrganization(TokenDto tokenDto, HttpServletResponse response, MultipartFile file) throws IOException {
ExcelImportResult<ImportCommunitySelfOrganization> testExcelImportResult = ExcelPoiUtils.importExcelMore(file, 0, 2, ImportCommunitySelfOrganization.class);
List<ImportCommunitySelfOrganization> list = testExcelImportResult.getList();
if (CollectionUtils.isNotEmpty(list)){
String customerId = tokenDto.getCustomerId();
List<String> existsNames = baseDao.selectOrgByOrgName(list.stream().map(m -> m.getOrganizationName()).collect(Collectors.toList()), customerId);
Map<String, List<ImportCommunitySelfOrganization>> groupByName = list.stream().collect(Collectors.groupingBy(ImportCommunitySelfOrganization::getOrganizationName));
groupByName.forEach((k,v) -> {
if (v.size() > NumConstant.ONE){
existsNames.add(k);
}
});
List<String> repeatName = existsNames.stream().distinct().collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(repeatName)){
StringBuffer sb = new StringBuffer();
repeatName.forEach(p -> {
sb.append(p).append(",");
});
String copywriter = sb.toString().substring(NumConstant.ZERO, sb.length() - NumConstant.ONE);
EpmetErrorCode.COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR.setMsg(String.format(EpmetErrorCode.COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR.getMsg(),copywriter));
throw new RenException(EpmetErrorCode.COMMUNITY_SELF_ORGANIZATION_LIST_REPART_ERROR.getCode());
}
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, tokenDto.getUserId());
if (null == staffInfo){
throw new RenException(String.format("查询人员{%s}信息失败",tokenDto.getUserId()));
}
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId());
if (null == agencyInfo){
throw new RenException(String.format("查询组织信息失败%s",staffInfo.getAgencyId()));
}
list.forEach(l -> {
IcCommunitySelfOrganizationEntity e = ConvertUtils.sourceToTarget(l, IcCommunitySelfOrganizationEntity.class);
e.setCustomerId(customerId);
e.setOrgId(staffInfo.getAgencyId());
e.setOrgType(IcCommunitySelfOrganizationConstant.ORG_TYPE_AGENCY);
e.setPid(agencyInfo.getPid());
e.setPids(agencyInfo.getPids());
e.setOrganizationCreatedTime(l.getOrganizationCreatedTime());
baseDao.insert(e);
if (CollectionUtils.isNotEmpty(l.getPersons())){
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(l.getPersons(), IcCommunitySelfOrganizationPersonnelEntity.class);
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupByPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone));
List<String> phones = new ArrayList<>();
groupByPhone.forEach((k,v) -> {
if (v.size() > NumConstant.ONE){
phones.add(k);
}
});
if (CollectionUtils.isNotEmpty(phones)){
StringBuffer sb = new StringBuffer();
phones.forEach(p -> {
sb.append(p).append(",");
});
String copywriter = sb.toString().substring(NumConstant.ZERO, sb.length() - NumConstant.ONE);
EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.setMsg(String.format(EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.getMsg(),copywriter));
throw new RenException(EpmetErrorCode.EXISTS_SAME_PHONE_ERROR.getCode());
}
persons.forEach(p -> {
p.setCustomerId(customerId);
p.setOrgId(e.getId());
});
personnelService.insertBatch(persons);
}
});
}
}
}

13
epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/IcCommunitySelfOrganizationDao.xml

@ -84,4 +84,17 @@
</if>
</foreach>
</select>
<!-- 根据名字查询存在的自组织 -->
<select id="selectOrgByOrgName" resultType="java.lang.String">
SELECT
ORGANIZATION_NAME
FROM ic_community_self_organization
WHERE DEL_FLAG = 0
AND CUSTOMER_ID = #{customerId}
AND ORGANIZATION_NAME IN
<foreach collection="names" item="n" open="(" close=")" separator=",">
#{n}
</foreach>
</select>
</mapper>
Loading…
Cancel
Save