|
|
@ -8,20 +8,46 @@ import com.epmet.dao.IcPolicyDao; |
|
|
|
import com.epmet.dao.IcPolicyRuleDetailDao; |
|
|
|
import com.epmet.dataaggre.dto.epmetuser.form.ResisByPolicyRulesFormDTO; |
|
|
|
import com.epmet.dataaggre.feign.DataAggregatorOpenFeignClient; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.FileCommonDTO; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.*; |
|
|
|
import com.epmet.dto.IcPolicyCategoryDTO; |
|
|
|
import com.epmet.dto.IcPolicyDTO; |
|
|
|
import com.epmet.dto.IcPolicyItemResultDTO; |
|
|
|
import com.epmet.entity.IcPolicyEntity; |
|
|
|
import com.epmet.entity.IcPolicyRuleDetailEntity; |
|
|
|
import com.epmet.dto.IcPolicyRuleDTO; |
|
|
|
import com.epmet.dto.form.policy.IcPolicyFormDTO; |
|
|
|
import com.epmet.dto.form.policy.IcPolicyPageFormDTO; |
|
|
|
import com.epmet.dto.form.policy.IcPolicyRuleDetailDTO; |
|
|
|
import com.epmet.dto.form.policy.IcPolicyRuleFormDTO; |
|
|
|
import com.epmet.entity.*; |
|
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
|
import com.epmet.service.IcPolicyService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
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 java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* 政策表 |
|
|
@ -37,6 +63,16 @@ public class IcPolicyServiceImpl extends BaseServiceImpl<IcPolicyDao, IcPolicyEn |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DataAggregatorOpenFeignClient dataAggregatorOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcPolicyCategoryDao icPolicyCategoryDao; |
|
|
|
@Autowired |
|
|
|
private IcPolicyRuleDao icPolicyRuleDao; |
|
|
|
@Autowired |
|
|
|
private HeartAttachmentDao heartAttachmentDao; |
|
|
|
@Autowired |
|
|
|
private IcPolicyRuleDetailDao icPolicyRuleDetailDao; |
|
|
|
@Autowired |
|
|
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* 房屋信息、统计信息查询有哪些可选项 |
|
|
@ -47,16 +83,232 @@ public class IcPolicyServiceImpl extends BaseServiceImpl<IcPolicyDao, IcPolicyEn |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<IcPolicyItemResultDTO> itemList(String customerId, String groupType) { |
|
|
|
if(StringUtils.isBlank(groupType)){ |
|
|
|
if (StringUtils.isBlank(groupType)) { |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<IcPolicyItemResultDTO> resultList=baseDao.selectItemList(customerId,groupType); |
|
|
|
if(CollectionUtils.isEmpty(resultList)){ |
|
|
|
return baseDao.selectItemList(Constant.DEFAULT_CUSTOMER,groupType); |
|
|
|
List<IcPolicyItemResultDTO> resultList = baseDao.selectItemList(customerId, groupType); |
|
|
|
if (CollectionUtils.isEmpty(resultList)) { |
|
|
|
return baseDao.selectItemList(Constant.DEFAULT_CUSTOMER, groupType); |
|
|
|
} |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 政策管理-新增/修改 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void addOrUpdatePolicy(IcPolicyFormDTO formDTO) { |
|
|
|
// 校验参数
|
|
|
|
checkAddFormDTO(formDTO); |
|
|
|
// 设置所属组织
|
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId()); |
|
|
|
if (null == staffInfo || StringUtils.isBlank(staffInfo.getAgencyId())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "工作人员缓存信息异常", "工作人员信息异常"); |
|
|
|
} |
|
|
|
IcPolicyEntity icPolicyEntity = ConvertUtils.sourceToTarget(formDTO, IcPolicyEntity.class); |
|
|
|
icPolicyEntity.setOrgId(staffInfo.getAgencyId()); |
|
|
|
icPolicyEntity.setOrgIdPath(StringUtils.isNotBlank(staffInfo.getAgencyPIds()) ? staffInfo.getAgencyPIds().concat(StrConstant.COLON).concat(staffInfo.getAgencyId()) : staffInfo.getAgencyId()); |
|
|
|
if(StringUtils.isNotBlank(formDTO.getPolicyId())){ |
|
|
|
icPolicyEntity.setId(formDTO.getPolicyId()); |
|
|
|
baseDao.updateById(icPolicyEntity); |
|
|
|
}else{ |
|
|
|
// 插入政策主表
|
|
|
|
baseDao.insert(icPolicyEntity); |
|
|
|
//删除规则、规则明细、分类、附件
|
|
|
|
icPolicyRuleDao.deleteByIcPolicyId(icPolicyEntity.getId()); |
|
|
|
icPolicyCategoryDao.deleteByIcPolicyId(icPolicyEntity.getId()); |
|
|
|
heartAttachmentDao.deleteByBusinessId(icPolicyEntity.getId()); |
|
|
|
} |
|
|
|
// 插入细则
|
|
|
|
int ruleSort = 1; |
|
|
|
for (IcPolicyRuleFormDTO rule : formDTO.getRuleList()) { |
|
|
|
IcPolicyRuleEntity ruleEntity = new IcPolicyRuleEntity(); |
|
|
|
ruleEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
ruleEntity.setIcPolicyId(icPolicyEntity.getId()); |
|
|
|
ruleEntity.setRuleName(rule.getRuleName()); |
|
|
|
ruleEntity.setSort(ruleSort); |
|
|
|
icPolicyRuleDao.insert(ruleEntity); |
|
|
|
//删除规则明细
|
|
|
|
icPolicyRuleDetailDao.deleteByRuleId(ruleEntity.getId()); |
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(rule.getResiRuleList())) { |
|
|
|
int resiRuleSort = 1; |
|
|
|
for (IcPolicyRuleDetailDTO ruleDetailDTO : rule.getResiRuleList()) { |
|
|
|
IcPolicyRuleDetailEntity icPolicyRuleDetailEntity = ConvertUtils.sourceToTarget(ruleDetailDTO, IcPolicyRuleDetailEntity.class); |
|
|
|
icPolicyRuleDetailEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
icPolicyRuleDetailEntity.setIcPolicyId(icPolicyEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setRuleId(ruleEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setSort(resiRuleSort); |
|
|
|
icPolicyRuleDetailEntity.setGroupType("resi"); |
|
|
|
icPolicyRuleDetailDao.insert(icPolicyRuleDetailEntity); |
|
|
|
resiRuleSort++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(rule.getHouseRuleList())) { |
|
|
|
int houseRuleSort = 1; |
|
|
|
for (IcPolicyRuleDetailDTO ruleDetailDTO : rule.getHouseRuleList()) { |
|
|
|
IcPolicyRuleDetailEntity icPolicyRuleDetailEntity = ConvertUtils.sourceToTarget(ruleDetailDTO, IcPolicyRuleDetailEntity.class); |
|
|
|
icPolicyRuleDetailEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
icPolicyRuleDetailEntity.setIcPolicyId(icPolicyEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setRuleId(ruleEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setSort(houseRuleSort); |
|
|
|
icPolicyRuleDetailEntity.setGroupType("house"); |
|
|
|
icPolicyRuleDetailDao.insert(icPolicyRuleDetailEntity); |
|
|
|
houseRuleSort++; |
|
|
|
} |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(rule.getStatRuleList())) { |
|
|
|
int statRuleSort = 1; |
|
|
|
for (IcPolicyRuleDetailDTO ruleDetailDTO : rule.getStatRuleList()) { |
|
|
|
IcPolicyRuleDetailEntity icPolicyRuleDetailEntity = ConvertUtils.sourceToTarget(ruleDetailDTO, IcPolicyRuleDetailEntity.class); |
|
|
|
icPolicyRuleDetailEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
icPolicyRuleDetailEntity.setIcPolicyId(icPolicyEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setRuleId(ruleEntity.getId()); |
|
|
|
icPolicyRuleDetailEntity.setSort(statRuleSort); |
|
|
|
icPolicyRuleDetailEntity.setGroupType("stat"); |
|
|
|
icPolicyRuleDetailDao.insert(icPolicyRuleDetailEntity); |
|
|
|
statRuleSort++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 插入分类
|
|
|
|
if (CollectionUtils.isNotEmpty(formDTO.getCategoryList())) { |
|
|
|
for (IcPolicyCategoryDTO categoryDTO : formDTO.getCategoryList()) { |
|
|
|
IcPolicyCategoryEntity icPolicyCategoryEntity = new IcPolicyCategoryEntity(); |
|
|
|
icPolicyCategoryEntity.setCustomerId(formDTO.getCustomerId()); |
|
|
|
icPolicyCategoryEntity.setIcPolicyId(icPolicyEntity.getId()); |
|
|
|
icPolicyCategoryEntity.setCategoryCode(categoryDTO.getCategoryCode()); |
|
|
|
icPolicyCategoryEntity.setCodePath(categoryDTO.getCodePath()); |
|
|
|
icPolicyCategoryDao.insert(icPolicyCategoryEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
// 插入附件
|
|
|
|
if (CollectionUtils.isNotEmpty(formDTO.getAttachmentList())) { |
|
|
|
int sort = 1; |
|
|
|
for (FileCommonDTO fileCommonDTO : formDTO.getAttachmentList()) { |
|
|
|
HeartAttachmentEntity heartAttachment = ConvertUtils.sourceToTarget(fileCommonDTO,HeartAttachmentEntity.class); |
|
|
|
heartAttachment.setCustomerId(formDTO.getCustomerId()); |
|
|
|
heartAttachment.setBusinessId(icPolicyEntity.getId()); |
|
|
|
heartAttachment.setAttachTo("ic_policy"); |
|
|
|
// heartAttachment.setName(fileCommonDTO.getName());
|
|
|
|
// heartAttachment.setFormat(fileCommonDTO.getFormat());
|
|
|
|
// heartAttachment.setType(fileCommonDTO.getType());
|
|
|
|
// heartAttachment.setUrl(fileCommonDTO.getUrl());
|
|
|
|
heartAttachment.setSort(sort); |
|
|
|
heartAttachment.setStatus(Constant.AUTO_PASSED); |
|
|
|
// heartAttachment.setDuration(fileCommonDTO.getDuration());
|
|
|
|
heartAttachmentDao.insert(heartAttachment); |
|
|
|
sort++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void checkAddFormDTO(IcPolicyFormDTO formDTO) { |
|
|
|
List<IcPolicyRuleFormDTO> ruleList = formDTO.getRuleList(); |
|
|
|
for (IcPolicyRuleFormDTO rule : ruleList) { |
|
|
|
if (CollectionUtils.isEmpty(rule.getResiRuleList()) |
|
|
|
&& CollectionUtils.isEmpty(rule.getHouseRuleList()) |
|
|
|
&& CollectionUtils.isEmpty(rule.getStatRuleList())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "人员信息、房屋信息、统计信息任意选择一项填写", "请填写细则明细"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 政策文件最多3个先不限制了吧,前端控制下
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 列表查询 |
|
|
|
* |
|
|
|
* @param formDTO |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public PageData<IcPolicyDTO> policyList(IcPolicyPageFormDTO formDTO) { |
|
|
|
// 设置所属组织
|
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId()); |
|
|
|
if (null == staffInfo || StringUtils.isBlank(staffInfo.getAgencyId())) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "工作人员缓存信息异常", "工作人员信息异常"); |
|
|
|
} |
|
|
|
formDTO.setAgencyId(staffInfo.getAgencyId()); |
|
|
|
PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()); |
|
|
|
List<IcPolicyDTO> list = baseDao.policyList(formDTO); |
|
|
|
if (CollectionUtils.isNotEmpty(list)) { |
|
|
|
for (IcPolicyDTO icPolicyDTO : list) { |
|
|
|
// 查询字典表
|
|
|
|
Result<Map<String, String>> levelRes = adminOpenFeignClient.dictMap(DictTypeEnum.POLICY_LEVEL.getCode()); |
|
|
|
Map<String, String> levelMap = levelRes.success() && MapUtils.isNotEmpty(levelRes.getData()) ? levelRes.getData() : new HashMap<>(); |
|
|
|
icPolicyDTO.setPolicyLevelName(MapUtils.isNotEmpty(levelMap) && levelMap.containsKey(icPolicyDTO.getPolicyLevel()) ? levelMap.get(icPolicyDTO.getPolicyLevel()) : StrConstant.EPMETY_STR); |
|
|
|
} |
|
|
|
} |
|
|
|
PageInfo<IcPolicyDTO> pageInfo = new PageInfo<>(list); |
|
|
|
return new PageData<>(list, pageInfo.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<IcPolicyRuleDTO> ruleList(String customerId, String policyId) { |
|
|
|
LambdaQueryWrapper<IcPolicyRuleEntity> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
wrapper.eq(IcPolicyRuleEntity::getCustomerId, customerId) |
|
|
|
.eq(IcPolicyRuleEntity::getIcPolicyId, policyId) |
|
|
|
.orderByAsc(IcPolicyRuleEntity::getSort); |
|
|
|
List<IcPolicyRuleEntity> list = icPolicyRuleDao.selectList(wrapper); |
|
|
|
return ConvertUtils.sourceToTarget(list, IcPolicyRuleDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public IcPolicyDTO policyDetail(String customerId, String policyId) { |
|
|
|
IcPolicyEntity policyEntity = baseDao.selectById(policyId); |
|
|
|
IcPolicyDTO icPolicyDTO = ConvertUtils.sourceToTarget(policyEntity, IcPolicyDTO.class); |
|
|
|
if (null != icPolicyDTO) { |
|
|
|
icPolicyDTO.setPolicyId(policyId); |
|
|
|
|
|
|
|
LambdaQueryWrapper<HeartAttachmentEntity> attWrapper = new LambdaQueryWrapper<>(); |
|
|
|
attWrapper.eq(HeartAttachmentEntity::getBusinessId, policyId) |
|
|
|
.orderByAsc(HeartAttachmentEntity::getSort); |
|
|
|
List<HeartAttachmentEntity> attList = heartAttachmentDao.selectList(attWrapper); |
|
|
|
icPolicyDTO.setAttachmentList(CollectionUtils.isNotEmpty(attList) ? ConvertUtils.sourceToTarget(attList, FileCommonDTO.class) : new ArrayList<>()); |
|
|
|
|
|
|
|
LambdaQueryWrapper<IcPolicyCategoryEntity> cateWrapper = new LambdaQueryWrapper<>(); |
|
|
|
cateWrapper.eq(IcPolicyCategoryEntity::getIcPolicyId, policyId); |
|
|
|
List<IcPolicyCategoryEntity> cateList = icPolicyCategoryDao.selectList(cateWrapper); |
|
|
|
icPolicyDTO.setCategoryList(CollectionUtils.isNotEmpty(cateList) ? ConvertUtils.sourceToTarget(cateList, IcPolicyCategoryDTO.class) : new ArrayList<>()); |
|
|
|
|
|
|
|
List<IcPolicyRuleDTO> ruleDTOList = ruleList(customerId, policyId); |
|
|
|
List<IcPolicyRuleFormDTO> ruleList = new ArrayList<>(); |
|
|
|
if (CollectionUtils.isNotEmpty(ruleDTOList)) { |
|
|
|
ruleList = ConvertUtils.sourceToTarget(ruleDTOList, IcPolicyRuleFormDTO.class); |
|
|
|
for (IcPolicyRuleFormDTO rule : ruleList) { |
|
|
|
LambdaQueryWrapper<IcPolicyRuleDetailEntity> ruleDetailWrapper = new LambdaQueryWrapper<>(); |
|
|
|
ruleDetailWrapper.eq(IcPolicyRuleDetailEntity::getRuleId, rule.getId()) |
|
|
|
.eq(IcPolicyRuleDetailEntity::getGroupType, "resi") |
|
|
|
.orderByAsc(IcPolicyRuleDetailEntity::getSort); |
|
|
|
List<IcPolicyRuleDetailEntity> resiList = icPolicyRuleDetailDao.selectList(ruleDetailWrapper); |
|
|
|
List<IcPolicyRuleDetailDTO> resiRuleList = CollectionUtils.isNotEmpty(resiList) ? ConvertUtils.sourceToTarget(resiList, IcPolicyRuleDetailDTO.class) : new ArrayList<>(); |
|
|
|
rule.setResiRuleList(resiRuleList); |
|
|
|
|
|
|
|
ruleDetailWrapper.eq(IcPolicyRuleDetailEntity::getRuleId, rule.getId()) |
|
|
|
.eq(IcPolicyRuleDetailEntity::getGroupType, "house") |
|
|
|
.orderByAsc(IcPolicyRuleDetailEntity::getSort); |
|
|
|
List<IcPolicyRuleDetailEntity> houseList = icPolicyRuleDetailDao.selectList(ruleDetailWrapper); |
|
|
|
List<IcPolicyRuleDetailDTO> houseRuleList = CollectionUtils.isNotEmpty(houseList) ? ConvertUtils.sourceToTarget(houseList, IcPolicyRuleDetailDTO.class) : new ArrayList<>(); |
|
|
|
rule.setHouseRuleList(houseRuleList); |
|
|
|
|
|
|
|
ruleDetailWrapper.eq(IcPolicyRuleDetailEntity::getRuleId, rule.getId()) |
|
|
|
.eq(IcPolicyRuleDetailEntity::getGroupType, "stat") |
|
|
|
.orderByAsc(IcPolicyRuleDetailEntity::getSort); |
|
|
|
List<IcPolicyRuleDetailEntity> statList = icPolicyRuleDetailDao.selectList(ruleDetailWrapper); |
|
|
|
List<IcPolicyRuleDetailDTO> statRuleList = CollectionUtils.isNotEmpty(statList) ? ConvertUtils.sourceToTarget(statList, IcPolicyRuleDetailDTO.class) : new ArrayList<>(); |
|
|
|
; |
|
|
|
rule.setStatRuleList(statRuleList); |
|
|
|
} |
|
|
|
} |
|
|
|
icPolicyDTO.setRuleList(ruleList); |
|
|
|
} |
|
|
|
return icPolicyDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void listResiUserByPolicyRules(String customerId, String ruleId, Integer pageNo, Integer pageSize) { |
|
|
|
LambdaQueryWrapper<IcPolicyRuleDetailEntity> query = new LambdaQueryWrapper(); |
|
|
|