|
|
@ -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,8 +44,13 @@ 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; |
|
|
|
|
|
|
|
import static com.epmet.commons.tools.utils.DateUtils.DATE_PATTERN; |
|
|
|
|
|
|
@ -119,6 +127,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
* @author zxc |
|
|
|
* @date 2021/11/19 8:33 上午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void addCommunitySelfOrganization(TokenDto tokenDto, AddCommunitySelfOrganizationFormDTO formDTO) { |
|
|
|
String customerId = tokenDto.getCustomerId(); |
|
|
@ -138,6 +147,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
orgEntity.setCustomerId(customerId); |
|
|
|
orgEntity.setOrgId(staffInfo.getAgencyId()); |
|
|
|
orgEntity.setOrgType(IcCommunitySelfOrganizationConstant.ORG_TYPE_AGENCY); |
|
|
|
orgEntity.setOrganizationCreatedTime(DateUtils.parse(formDTO.getOrganizationCreatedTime(), DATE_PATTERN)); |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId()); |
|
|
|
if (null == agencyInfo){ |
|
|
|
throw new RenException(String.format("查询组织信息失败%s",staffInfo.getAgencyId())); |
|
|
@ -154,6 +164,22 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
baseDao.insert(orgEntity); |
|
|
|
if(CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ |
|
|
|
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); |
|
|
|
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); |
|
|
|
List<String> phones = new ArrayList<>(); |
|
|
|
groupPhone.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(orgEntity.getId()); |
|
|
@ -170,6 +196,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
* @author zxc |
|
|
|
* @date 2021/11/19 10:12 上午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void editCommunitySelfOrganization(TokenDto tokenDto, EditCommunitySelfOrganizationFormDTO formDTO) { |
|
|
|
LambdaQueryWrapper<IcCommunitySelfOrganizationEntity> l = new LambdaQueryWrapper<>(); |
|
|
@ -188,6 +215,22 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
personnelService.deleteByOrgId(formDTO.getOrgId()); |
|
|
|
if (CollectionUtils.isNotEmpty(formDTO.getOrganizationPersonnel())){ |
|
|
|
List<IcCommunitySelfOrganizationPersonnelEntity> persons = ConvertUtils.sourceToTarget(formDTO.getOrganizationPersonnel(), IcCommunitySelfOrganizationPersonnelEntity.class); |
|
|
|
Map<String, List<IcCommunitySelfOrganizationPersonnelEntity>> groupPhone = persons.stream().collect(Collectors.groupingBy(IcCommunitySelfOrganizationPersonnelEntity::getPersonPhone)); |
|
|
|
List<String> phones = new ArrayList<>(); |
|
|
|
groupPhone.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.setOrgId(formDTO.getOrgId()); |
|
|
|
p.setCustomerId(tokenDto.getCustomerId()); |
|
|
@ -213,14 +256,26 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
final int[] i = {(formDTO.getPageNo() - NumConstant.ONE) * formDTO.getPageSize() + NumConstant.ONE}; |
|
|
|
CommunitySelfOrganizationListResultDTO result = new CommunitySelfOrganizationListResultDTO(); |
|
|
|
PageInfo<CommunitySelfOrganizationListDTO> objectPageInfo = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()).doSelectPageInfo(() -> baseDao.selectCommunitySelfOrganizationList(formDTO)); |
|
|
|
result.setTotal(Integer.valueOf(String.valueOf(objectPageInfo.getTotal()))); |
|
|
|
if (CollectionUtils.isNotEmpty(objectPageInfo.getList())){ |
|
|
|
objectPageInfo.getList().forEach(l -> { |
|
|
|
l.setSort(i[NumConstant.ZERO]); |
|
|
|
i[NumConstant.ZERO]++; |
|
|
|
if (formDTO.getIsPage()){ |
|
|
|
PageInfo<CommunitySelfOrganizationListDTO> objectPageInfo = PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize()).doSelectPageInfo(() -> baseDao.selectCommunitySelfOrganizationList(formDTO)); |
|
|
|
result.setTotal(Integer.valueOf(String.valueOf(objectPageInfo.getTotal()))); |
|
|
|
if (CollectionUtils.isNotEmpty(objectPageInfo.getList())){ |
|
|
|
objectPageInfo.getList().forEach(l -> { |
|
|
|
l.setSort(i[NumConstant.ZERO]); |
|
|
|
i[NumConstant.ZERO]++; |
|
|
|
}); |
|
|
|
result.setList(objectPageInfo.getList()); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
List<CommunitySelfOrganizationListDTO> resultDTOs = baseDao.selectCommunitySelfOrganizationList(formDTO); |
|
|
|
if (CollectionUtils.isNotEmpty(resultDTOs)){ |
|
|
|
result.setTotal(resultDTOs.size()); |
|
|
|
AtomicReference<Integer> sort = new AtomicReference<>(NumConstant.ONE); |
|
|
|
resultDTOs.forEach(r -> { |
|
|
|
r.setSort(sort.getAndSet(sort.get() + NumConstant.ONE)); |
|
|
|
}); |
|
|
|
result.setList(objectPageInfo.getList()); |
|
|
|
result.setList(resultDTOs); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
@ -232,6 +287,7 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
* @author zxc |
|
|
|
* @date 2021/11/19 4:22 下午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void delCommunitySelfOrganization(DelCommunitySelfOrganizationFormDTO formDTO) { |
|
|
|
baseDao.deleteById(formDTO.getOrgId()); |
|
|
@ -256,6 +312,9 @@ public class IcCommunitySelfOrganizationServiceImpl extends BaseServiceImpl<IcCo |
|
|
|
if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { |
|
|
|
if(staffInfoCacheResult.getAgencyPIds().contains(StrConstant.COLON)){ |
|
|
|
agencyIds.addAll(Arrays.asList(staffInfoCacheResult.getAgencyPIds().split(StrConstant.COLON))); |
|
|
|
}else{ |
|
|
|
//当前用户属于第二级组织的人,不会有:
|
|
|
|
agencyIds.add(staffInfoCacheResult.getAgencyPIds()); |
|
|
|
} |
|
|
|
} |
|
|
|
agencyIds.add(staffInfoCacheResult.getAgencyId()); |
|
|
@ -263,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); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |