|
@@ -5,19 +5,23 @@ import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.aspose.words.*;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.rongwei.bscommon.sys.dao.ZhcxPersistentManageDao;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxDeptPeopleCountService;
|
|
|
import com.rongwei.bscommon.sys.service.ZhcxPersistentManageService;
|
|
|
-import com.rongwei.bsentity.domain.ZhcxItpProjectNodesDo;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxDeptPeopleCountDo;
|
|
|
import com.rongwei.bsentity.domain.ZhcxPersistentManageDo;
|
|
|
import com.rongwei.bsentity.dto.ZhcxPersistentManageDto;
|
|
|
+import com.rongwei.bsentity.dto.ZhcxPersistentReportDto;
|
|
|
import com.rongwei.bsentity.vo.FormDataVO;
|
|
|
+import com.rongwei.bsentity.vo.OrganizationVo;
|
|
|
+import com.rongwei.bsentity.vo.PersistentVo;
|
|
|
import com.rongwei.bsentity.vo.ZhcxPersistentWordVO;
|
|
|
import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
|
|
|
import com.rongwei.rwadmincommon.system.service.SysOrganizationService;
|
|
|
import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.rwcommoncomponent.excel.aspose.ExcelExportUtil;
|
|
|
import com.rongwei.rwcommoncomponent.excel.utils.WordHelpUtils;
|
|
@@ -36,6 +40,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedInputStream;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
@@ -59,10 +64,14 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
private SysFileItemService sysFileItemService;
|
|
|
@Autowired
|
|
|
private SysOrganizationService sysOrganizationService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxDeptPeopleCountService zhcxDeptPeopleCountService;
|
|
|
|
|
|
@Value("${wz-provider.syncWzDataUrl}")
|
|
|
private String syncWzDataUrl;
|
|
|
|
|
|
+ private static final String DEPT_CODE = "0900";
|
|
|
+
|
|
|
@Override
|
|
|
public void wordExport(Map<String, Object> map, HttpServletResponse response) {
|
|
|
Object periodObj = map.get("period");
|
|
@@ -435,6 +444,145 @@ public class ZhcxPersistentManageServiceImpl extends ServiceImpl<ZhcxPersistentM
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ZhcxPersistentReportDto> reportData(Map<String, Object> map) {
|
|
|
+ Object yearObj = map.get("year");
|
|
|
+ Object monthObj = map.get("month");
|
|
|
+ if(ObjectUtil.isEmpty(yearObj) || ObjectUtil.isEmpty(monthObj)){
|
|
|
+ throw new CustomException("缺少查询参数");
|
|
|
+ }
|
|
|
+ String year = (String) yearObj;
|
|
|
+ String month = (String) monthObj;
|
|
|
+ SysOrganizationDo organization = sysOrganizationService.getOne(
|
|
|
+ new LambdaQueryWrapper<SysOrganizationDo>().eq(SysOrganizationDo::getCode, DEPT_CODE));
|
|
|
+
|
|
|
+ // 构造传入日期
|
|
|
+ LocalDate passedDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), 1);
|
|
|
+ // 获取当前日期的年和月
|
|
|
+ LocalDate currentDate = LocalDate.now().withDayOfMonth(1);
|
|
|
+ List<ZhcxPersistentReportDto> reportList = new ArrayList<>();
|
|
|
+ //ZhcxPersistentReportDto dto;
|
|
|
+ List<PersistentVo> reportData = zhcxPersistentManageDao.getReportData(year, month);
|
|
|
+ Map<String, PersistentVo> reportDataMap = reportData.stream()
|
|
|
+ .collect(Collectors.toMap(PersistentVo::getOrgId, data -> data));
|
|
|
+ // 比较当前日期和传入日期
|
|
|
+ if (currentDate.isAfter(passedDate)) {
|
|
|
+ //当前日期大于传入日期
|
|
|
+ processDeptUserCount(year, month, reportDataMap, reportList);
|
|
|
+ } else if (currentDate.isEqual(passedDate)) {
|
|
|
+ processOrgUserCount(organization.getId(),month, reportDataMap, reportList);
|
|
|
+ }
|
|
|
+ reportList.sort(Comparator.comparing(ZhcxPersistentReportDto::getSort,Comparator.reverseOrder()));
|
|
|
+ return reportList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveDeptUserCount() {
|
|
|
+ SysOrganizationDo organization = sysOrganizationService.getOne(
|
|
|
+ new LambdaQueryWrapper<SysOrganizationDo>().eq(SysOrganizationDo::getCode, DEPT_CODE));
|
|
|
+ List<OrganizationVo> orgUserCount = zhcxPersistentManageDao.getOrgUserCount(organization.getId());
|
|
|
+ Map<String, OrganizationVo> parentNodeMap = new HashMap<>();
|
|
|
+ orgUserCount.sort(Comparator.comparing(OrganizationVo::getOrgType));
|
|
|
+ for (OrganizationVo node : orgUserCount) {
|
|
|
+ if ("10".equals(node.getOrgType())) {
|
|
|
+ parentNodeMap.put(node.getOrgId(), node);
|
|
|
+ } else {
|
|
|
+ OrganizationVo parent = parentNodeMap.get(node.getPid());
|
|
|
+ if (parent != null) {
|
|
|
+ parent.setUserCount(parent.getUserCount() + node.getUserCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ZhcxDeptPeopleCountDo> list = new ArrayList<>();
|
|
|
+ parentNodeMap.forEach((key, value) -> {
|
|
|
+ ZhcxDeptPeopleCountDo deptPeopleCountDo = new ZhcxDeptPeopleCountDo();
|
|
|
+ deptPeopleCountDo.setId(SecurityUtil.getUUID());
|
|
|
+ deptPeopleCountDo.setOrgname(value.getOrgName());
|
|
|
+ deptPeopleCountDo.setOrgid(value.getOrgId());
|
|
|
+ deptPeopleCountDo.setNum(value.getUserCount());
|
|
|
+ deptPeopleCountDo.setYear(String.valueOf(LocalDate.now().getYear()));
|
|
|
+ deptPeopleCountDo.setMonth(String.valueOf(LocalDate.now().getMonthValue()));
|
|
|
+ deptPeopleCountDo.setSort(value.getSort());
|
|
|
+ deptPeopleCountDo.setOrgcode(DEPT_CODE);
|
|
|
+ list.add(deptPeopleCountDo);
|
|
|
+ });
|
|
|
+ LambdaQueryWrapper<ZhcxDeptPeopleCountDo> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(ZhcxDeptPeopleCountDo::getOrgcode, DEPT_CODE);
|
|
|
+ wrapper.eq(ZhcxDeptPeopleCountDo::getYear, String.valueOf(LocalDate.now().getYear()));
|
|
|
+ wrapper.eq(ZhcxDeptPeopleCountDo::getMonth, String.valueOf(LocalDate.now().getMonthValue()));
|
|
|
+ zhcxDeptPeopleCountService.remove(wrapper);
|
|
|
+ zhcxDeptPeopleCountService.saveOrUpdateBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理部门用户统计数据
|
|
|
+ private void processDeptUserCount(String year, String month, Map<String, PersistentVo> reportDataMap, List<ZhcxPersistentReportDto> reportList) {
|
|
|
+ List<OrganizationVo> deptUserCount = zhcxPersistentManageDao.getDeptUserCount(year, month, DEPT_CODE);
|
|
|
+ for (int i = 0; i < deptUserCount.size(); i++) {
|
|
|
+ OrganizationVo org = deptUserCount.get(i);
|
|
|
+ PersistentVo report = reportDataMap.get(org.getOrgId());
|
|
|
+ ZhcxPersistentReportDto dto = buildReportDto(i + 1, month, org, report);
|
|
|
+ reportList.add(dto);
|
|
|
+ }
|
|
|
+ if(deptUserCount.size() == 0){
|
|
|
+ SysOrganizationDo organization = sysOrganizationService.getOne(
|
|
|
+ new LambdaQueryWrapper<SysOrganizationDo>().eq(SysOrganizationDo::getCode, DEPT_CODE));
|
|
|
+
|
|
|
+ processOrgUserCount(organization.getId(),month, reportDataMap, reportList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 处理组织用户统计数据
|
|
|
+ private void processOrgUserCount(String orgId,String month, Map<String, PersistentVo> reportDataMap, List<ZhcxPersistentReportDto> reportList) {
|
|
|
+ List<OrganizationVo> orgUserCount = zhcxPersistentManageDao.getOrgUserCount(orgId);
|
|
|
+ Map<String, OrganizationVo> parentNodeMap = new HashMap<>();
|
|
|
+
|
|
|
+ orgUserCount.sort(Comparator.comparing(OrganizationVo::getOrgType)); // 按类型排序,父节点优先
|
|
|
+ for (OrganizationVo node : orgUserCount) {
|
|
|
+ if ("10".equals(node.getOrgType())) {
|
|
|
+ parentNodeMap.put(node.getOrgId(), node);
|
|
|
+ } else {
|
|
|
+ OrganizationVo parent = parentNodeMap.get(node.getPid());
|
|
|
+ if (parent != null) {
|
|
|
+ parent.setUserCount(parent.getUserCount() + node.getUserCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrganizationVo> filteredNodes = new ArrayList<>(parentNodeMap.values());
|
|
|
+ for (int i = 0; i < filteredNodes.size(); i++) {
|
|
|
+ OrganizationVo org = filteredNodes.get(i);
|
|
|
+ PersistentVo report = reportDataMap.get(org.getOrgId());
|
|
|
+ ZhcxPersistentReportDto dto = buildReportDto(i + 1, month, org, report);
|
|
|
+ reportList.add(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 构造 DTO
|
|
|
+ private ZhcxPersistentReportDto buildReportDto(int no, String month, OrganizationVo org, PersistentVo report) {
|
|
|
+ ZhcxPersistentReportDto dto = new ZhcxPersistentReportDto();
|
|
|
+ dto.setNo(no);
|
|
|
+ dto.setMonth(month);
|
|
|
+ dto.setSecondOrgName(org.getOrgName());
|
|
|
+ dto.setSecondOrgId(org.getOrgId());
|
|
|
+ dto.setNumber(org.getUserCount());
|
|
|
+ dto.setSort(org.getSort());
|
|
|
+ if (report != null) {
|
|
|
+ dto.setCheckNumber(report.getCheckNumber());
|
|
|
+ dto.setPunishNumber(report.getPunishNumber());
|
|
|
+ dto.setPunishTotalAmount(report.getPunishTotalAmount());
|
|
|
+ dto.setCheckNumberPer(calculateRatio(report.getCheckNumber(), org.getUserCount()));
|
|
|
+ dto.setPunishNumberPer(calculateRatio(report.getPunishNumber(), org.getUserCount()));
|
|
|
+ dto.setPunishTotalAmountPer(calculateRatio(report.getPunishTotalAmount(), org.getUserCount()));
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+ private double calculateRatio(Number numerator, int denominator) {
|
|
|
+ if (denominator == 0) {
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ return BigDecimal.valueOf(numerator.doubleValue() / denominator)
|
|
|
+ .setScale(1, RoundingMode.HALF_UP)
|
|
|
+ .doubleValue();
|
|
|
+ }
|
|
|
+
|
|
|
private void initWeekWord(Document[] doc, List<ZhcxPersistentManageDo> rewardListData, String tempId) {
|
|
|
if(rewardListData.size()>0){
|
|
|
Map<String, List<ZhcxPersistentManageDo>> collect = rewardListData.stream()
|