|
|
@ -1,6 +1,8 @@ |
|
|
|
package com.epmet.modules.partymember.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.enums.GenderEnum; |
|
|
|
import com.epmet.commons.tools.enums.PartyOrgTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
@ -9,19 +11,25 @@ import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
|
import com.epmet.commons.tools.utils.PidUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.modules.partyOrg.dao.IcPartyActDao; |
|
|
|
import com.epmet.modules.partyOrg.dao.IcPartyActTypeDictDao; |
|
|
|
import com.epmet.modules.partyOrg.dao.IcPartyOrgDao; |
|
|
|
import com.epmet.modules.partyOrg.entity.IcPartyActTypeDictEntity; |
|
|
|
import com.epmet.modules.partyOrg.entity.IcPartyOrgEntity; |
|
|
|
import com.epmet.modules.partymember.dao.IcPartyMemberDao; |
|
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberEntity; |
|
|
|
import com.epmet.modules.partymember.service.LingShanScreenService; |
|
|
|
import com.epmet.resi.group.feign.ResiGroupOpenFeignClient; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.result.LingShanScreenPartyActQtyStatsResultDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.result.LingShanScreenPartyActTypeAndQtyResultDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.result.LingShanScreenPartyOrgCategoryResultDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.result.LingShanScreenPartyOrgTreeResultDTO; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
@ -34,6 +42,12 @@ public class LingShanScreenServiceImpl implements LingShanScreenService, ResultD |
|
|
|
@Autowired |
|
|
|
private IcPartyActDao partyActDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcPartyMemberDao icPartyMemberDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcPartyActTypeDictDao partyActTypeDictDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ResiGroupOpenFeignClient groupOpenFeignClient; |
|
|
|
|
|
|
@ -101,8 +115,9 @@ public class LingShanScreenServiceImpl implements LingShanScreenService, ResultD |
|
|
|
// 2.组装树了开始
|
|
|
|
Map<String, LingShanScreenPartyOrgTreeResultDTO.PartyOrg> lMap = l.stream().collect(Collectors.toMap(e -> e.getId(), Function.identity())); |
|
|
|
|
|
|
|
// 树根组织的id
|
|
|
|
String parentPartyOrgId = null; |
|
|
|
|
|
|
|
// 最高的组织级别,用于找到树根。初始值给个100,大一点,不影响
|
|
|
|
Integer maxLevel = 100; |
|
|
|
// 将组织放入到父组织的children列表中
|
|
|
|
for (Iterator<LingShanScreenPartyOrgTreeResultDTO.PartyOrg> it = l.iterator(); it.hasNext();) { |
|
|
@ -116,6 +131,7 @@ public class LingShanScreenServiceImpl implements LingShanScreenService, ResultD |
|
|
|
|
|
|
|
if (pOrg != null) { |
|
|
|
pOrg.getChildren().add(e); |
|
|
|
// 修剪枝叶
|
|
|
|
it.remove(); |
|
|
|
} |
|
|
|
} |
|
|
@ -127,4 +143,146 @@ public class LingShanScreenServiceImpl implements LingShanScreenService, ResultD |
|
|
|
r.setList(parentOrg.getChildren()); |
|
|
|
return r; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<LingShanScreenPartyOrgTreeResultDTO.Partymember> partymemberListByPartyOrgId(String partyOrgId) { |
|
|
|
IcPartyOrgEntity partyOrg = icPartyOrgDao.selectById(partyOrgId); |
|
|
|
LambdaQueryWrapper<IcPartyMemberEntity> query = null; |
|
|
|
if (partyOrg == null) { |
|
|
|
String baseErrorMsg = "【灵山大屏】党组织下的党员列表-未找到党组织信息。"; |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), String.format(baseErrorMsg + "partyOrgId:" + partyOrg), baseErrorMsg); |
|
|
|
} else if (Integer.valueOf(partyOrg.getPartyOrgType()) >= 4) { |
|
|
|
// 0省委,1市委,2区委,3党工委,4党委,5支部。党委以上,除了支部
|
|
|
|
query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(IcPartyMemberEntity::getOrgPids, PidUtils.convertPid2OrgIdPath(partyOrgId, partyOrg.getOrgPids())); |
|
|
|
query.eq(IcPartyMemberEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); |
|
|
|
} else { |
|
|
|
// 5支部
|
|
|
|
query = new LambdaQueryWrapper<>(); |
|
|
|
query.eq(IcPartyMemberEntity::getOrgPids, partyOrg.getOrgPids()); |
|
|
|
query.eq(IcPartyMemberEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); |
|
|
|
} |
|
|
|
|
|
|
|
List<IcPartyMemberEntity> l = icPartyMemberDao.selectList(query); |
|
|
|
|
|
|
|
// 党员列表转化为需要的dto返回
|
|
|
|
return l.stream().map(e -> { |
|
|
|
// 查询支部
|
|
|
|
IcPartyOrgEntity branch = icPartyOrgDao.selectById(e.getSszb()); |
|
|
|
|
|
|
|
LingShanScreenPartyOrgTreeResultDTO.Partymember t = new LingShanScreenPartyOrgTreeResultDTO.Partymember(); |
|
|
|
t.setName(e.getName()); |
|
|
|
t.setAge(e.getAgencyId()); |
|
|
|
Integer gender = e.getGender(); |
|
|
|
t.setGender(gender != null ? GenderEnum.getName(gender.toString()) : "未知"); |
|
|
|
t.setOrgname(branch != null ? branch.getPartyOrgName() : null); |
|
|
|
t.setPhone(e.getMobile()); |
|
|
|
t.setRemarks(e.getRemark()); |
|
|
|
t.setPhoto(e.getHeadPhoto()); |
|
|
|
// t.setIsDby();
|
|
|
|
// t.setIsLhdy();
|
|
|
|
// t.setWorkStatus();
|
|
|
|
// t.setWorknumber();
|
|
|
|
// t.setWorkEvent();
|
|
|
|
return t; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description: 这个方法其实有更容易实现,更容易阅读和理解的方式。循环活动类型,每个活动类型都查询一次统计数据即可。 |
|
|
|
* 但是前期追求更少次数的数据库调用以提升效率,越写越复杂,既然已经这样了也懒得改了,就这样吧。 |
|
|
|
* 如果后面有人感觉维护不了了,直接按照上述方式重写就行了,不要犹豫,不要徘徊,很容易改,没有暗雷!!! |
|
|
|
* @param agencyId: 行政组织id |
|
|
|
* @return |
|
|
|
* @author: WangXianZhang |
|
|
|
* @date: 2023/4/14 11:33 PM |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<LingShanScreenPartyActQtyStatsResultDTO> actQtyOfPartyOrgStats(String agencyId, Date holdTimeStart, Date holdTimeEnd) { |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(agencyId); |
|
|
|
if (agencyInfo == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "查询当前组织信息失败,agencyId:" + agencyId, "查询当前组织信息失败"); |
|
|
|
} |
|
|
|
|
|
|
|
// String orgIdpath = PidUtils.convertPid2OrgIdPath(agencyId, agencyInfo.getPids());
|
|
|
|
|
|
|
|
// 先查当前党组织信息
|
|
|
|
LambdaQueryWrapper<IcPartyOrgEntity> currentPartyOrgQuery = new LambdaQueryWrapper<>(); |
|
|
|
currentPartyOrgQuery.eq(IcPartyOrgEntity::getAgencyId, agencyId); |
|
|
|
currentPartyOrgQuery.orderByAsc(IcPartyOrgEntity::getPartyOrgType); |
|
|
|
currentPartyOrgQuery.last(" limit 1 "); |
|
|
|
|
|
|
|
IcPartyOrgEntity currentPartyOrg = icPartyOrgDao.selectOne(currentPartyOrgQuery); |
|
|
|
|
|
|
|
if (currentPartyOrg == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), null, "未找到党组织信息"); |
|
|
|
} |
|
|
|
|
|
|
|
// ----------------------------要重写的话,上面建议保留噢,只重写下面就可以了,淦---------------------------------
|
|
|
|
|
|
|
|
// 找出当前党组织的下级党组织(全部),及其对应的活动数量
|
|
|
|
List<LingShanScreenPartyActQtyStatsResultDTO.StatsData> l = partyActDao.actQtyOfPartyOrgStats(currentPartyOrg.getId(), holdTimeStart, holdTimeEnd); |
|
|
|
|
|
|
|
// 将结果遍历,分成2个纬度,分别建立地址引用
|
|
|
|
// Map<actType, Map<orgId, LingShanScreenPartyActQtyStatsResultDTO.StatsData>>
|
|
|
|
Map<String, Map<String, LingShanScreenPartyActQtyStatsResultDTO.StatsData>> orgDimMap = new HashMap<>(); |
|
|
|
HashMap<String, String> orgIdAndName = new HashMap<>(); |
|
|
|
|
|
|
|
l.forEach(e -> { |
|
|
|
orgIdAndName.put(e.getOrgId(), e.getName()); |
|
|
|
String actType = e.getActType(); |
|
|
|
if (StringUtils.isNotBlank(actType)) { |
|
|
|
// 不为空,说明该类型有活动数据
|
|
|
|
Map<String, LingShanScreenPartyActQtyStatsResultDTO.StatsData> m = orgDimMap.get(actType); |
|
|
|
if (m == null) { |
|
|
|
m = new HashMap<>(); |
|
|
|
orgDimMap.put(actType, m); |
|
|
|
} |
|
|
|
m.put(e.getOrgId(), e); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 所有的活动类型,并且建立字典,供后续使用
|
|
|
|
LambdaQueryWrapper<IcPartyActTypeDictEntity> actTypeQuery = new LambdaQueryWrapper<>(); |
|
|
|
actTypeQuery.eq(IcPartyActTypeDictEntity::getCustomerId, EpmetRequestHolder.getLoginUserCustomerId()); |
|
|
|
List<IcPartyActTypeDictEntity> actTypes = partyActTypeDictDao.selectList(actTypeQuery); |
|
|
|
|
|
|
|
Map<String, String> actTypeKeyAndName = actTypes.stream().collect(Collectors.toMap(IcPartyActTypeDictEntity::getTypeKey, IcPartyActTypeDictEntity::getTypeName)); |
|
|
|
|
|
|
|
// 二维遍历,外层活动类型,内层组织id。确保两个维度的坐标都是全的(哪怕value=0)
|
|
|
|
for (IcPartyActTypeDictEntity actType : actTypes) { |
|
|
|
// 补全外层活动类型
|
|
|
|
Map<String, LingShanScreenPartyActQtyStatsResultDTO.StatsData> orgIdAndStats = orgDimMap.get(actType.getTypeKey()); |
|
|
|
if (orgIdAndStats == null) { |
|
|
|
orgIdAndStats = new HashMap<>(); |
|
|
|
orgDimMap.put(actType.getTypeKey(), orgIdAndStats); |
|
|
|
} |
|
|
|
|
|
|
|
// 为活动类型补全组织列表(没有活动的组织赋值0)
|
|
|
|
for (Map.Entry<String, String> entry : orgIdAndName.entrySet()) { |
|
|
|
String orgId = entry.getKey(); |
|
|
|
LingShanScreenPartyActQtyStatsResultDTO.StatsData statsData = orgIdAndStats.get(orgId); |
|
|
|
if (statsData == null) { |
|
|
|
LingShanScreenPartyActQtyStatsResultDTO.StatsData e = new LingShanScreenPartyActQtyStatsResultDTO.StatsData(); |
|
|
|
e.setOrgId(orgId); |
|
|
|
e.setName(entry.getValue()); |
|
|
|
e.setValue(0); |
|
|
|
e.setActType(actType.getTypeKey()); |
|
|
|
orgIdAndStats.put(orgId, e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 将结果map转化为list,返回
|
|
|
|
ArrayList<LingShanScreenPartyActQtyStatsResultDTO> rl = new ArrayList<>(); |
|
|
|
|
|
|
|
orgDimMap.forEach((actType, orgStatsMap) -> { |
|
|
|
LingShanScreenPartyActQtyStatsResultDTO re = new LingShanScreenPartyActQtyStatsResultDTO(); |
|
|
|
re.setType(actTypeKeyAndName.get(actType)); |
|
|
|
re.setData(orgStatsMap.values()); |
|
|
|
rl.add(re); |
|
|
|
}); |
|
|
|
|
|
|
|
return rl; |
|
|
|
} |
|
|
|
} |
|
|
|