diff --git a/server/src/main/java/com/aisino/iles/lawenforcement/service/QrCodeService.java b/server/src/main/java/com/aisino/iles/lawenforcement/service/QrCodeService.java new file mode 100644 index 0000000..879aacf --- /dev/null +++ b/server/src/main/java/com/aisino/iles/lawenforcement/service/QrCodeService.java @@ -0,0 +1,56 @@ +package com.aisino.iles.lawenforcement.service; + +import cn.hutool.json.JSONUtil; +import com.aisino.iles.core.exception.BusinessError; +import com.aisino.iles.lawenforcement.model.EnforcementInfo; +import com.aisino.iles.lawenforcement.repository.EnforcementInfoRepository; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.time.Duration; +import java.util.Optional; +import java.util.UUID; + +@Service +public class QrCodeService { + + private final EnforcementInfoRepository enforcementInfoRepository; + private final RedisTemplate redisTemplate; + + public QrCodeService(RedisTemplate redisTemplate, + EnforcementInfoRepository enforcementInfoRepository) { + this.redisTemplate = redisTemplate; + this.enforcementInfoRepository = enforcementInfoRepository; + } + + public String generateQrCode() { + String key = UUID.randomUUID().toString(); + redisTemplate.opsForValue().set(key, "unused", Duration.ofSeconds(600)); + return "https://58.144.217.62:50002/api/token/data?token=" + key; + } + + public void validateToken(String token, String enforcementId) { + String status = redisTemplate.opsForValue().get(token); + if (status == null) { + throw new BusinessError("二维码已过期"); + } + Optional optionalEnforcementInfo = enforcementInfoRepository.findById(enforcementId); + if (optionalEnforcementInfo.isPresent()) { + EnforcementInfo enforcementInfo = optionalEnforcementInfo.get(); + String rawData = JSONUtil.toJsonStr(enforcementInfo); + redisTemplate.opsForValue().set(token, rawData, Duration.ofSeconds(600)); + } + } + + public String checkStatus(String token) { + String data = redisTemplate.opsForValue().get(token); + if (data == null) { + // throw new BusinessError("token已过期"); + } + if ("unused".equals(data)) { + return "pending"; + } + return data; + } + +} diff --git a/server/src/main/java/com/aisino/iles/lawenforcement/service/RecipientInfoService.java b/server/src/main/java/com/aisino/iles/lawenforcement/service/RecipientInfoService.java new file mode 100644 index 0000000..5a6a70e --- /dev/null +++ b/server/src/main/java/com/aisino/iles/lawenforcement/service/RecipientInfoService.java @@ -0,0 +1,156 @@ +package com.aisino.iles.lawenforcement.service; + +import com.aisino.iles.common.util.Constants; +import com.aisino.iles.common.util.KmsServer; +import com.aisino.iles.common.util.PageableHelper; +import com.aisino.iles.core.repository.DictItemRepo; +import com.aisino.iles.lawenforcement.model.RecipientInfo; +import com.aisino.iles.lawenforcement.model.RecipientInfo_; +import com.aisino.iles.lawenforcement.model.query.DeliveryQuery; +import com.aisino.iles.lawenforcement.repository.RecipientInfoRepository; +import com.smartlx.sso.client.model.RemoteUserInfo; +import jakarta.persistence.criteria.Predicate; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +/** + * 受送人信息服务类 + */ +@Service +@Slf4j +public class RecipientInfoService { + private final RecipientInfoRepository recipientInfoRepo; + private final DictItemRepo dictItemRepo; + + public RecipientInfoService(RecipientInfoRepository recipientInfoRepo, + DictItemRepo dictItemRepo) { + this.recipientInfoRepo = recipientInfoRepo; + this.dictItemRepo = dictItemRepo; + } + + /** + * 保存受送人信息 + * + * @param recipientInfo 受送人信息 + * @return 保存后的受送人信息 + */ + @Transactional + public RecipientInfo saveRecipientInfo(RecipientInfo recipientInfo, RemoteUserInfo user, String type) { + LocalDateTime now = LocalDateTime.now(); + if ("add".equals(type)) { + recipientInfo.setCreateTime(now); + recipientInfo.setIsDeleted(false); + if (null != user) { + recipientInfo.setCreatedBy(user.getXm()); + recipientInfo.setCreatedAccountBy(user.getYhwybs()); + } + } + recipientInfo.setUpdateTime(now); + // 检验加密签名保存 + Optional.ofNullable(recipientInfo.getPhone()).filter(StringUtils::hasText).ifPresent(s-> recipientInfo.setSginData(KmsServer.kmsSign(s))); + return recipientInfoRepo.save(recipientInfo); + } + + /** + * 根据ID查询受送人信息 + * + * @param recipientInfoId 受送人ID + * @return 受送人信息 + */ + public Optional findRecipientInfoById(String recipientInfoId) { + return recipientInfoRepo.findById(recipientInfoId); + } + + + /** + * 根据查询条件分页查询受送人信息 + * + * @param query 查询条件 + * @return 分页受送人信息 + */ + public Page findRecipientInfoPage(DeliveryQuery query) { + return recipientInfoRepo.findAll(build(query), PageableHelper.buildPageRequest(query.page(), query.pageSize(), "updateTime", "desc")).map(this::itemRecipientInfo); + } + + private RecipientInfo itemRecipientInfo(RecipientInfo recipientInfo) { + Optional.ofNullable(recipientInfo.getSex()).filter(StringUtils::hasText) + .flatMap(sex -> dictItemRepo.findByDictDictCodeAndValue(Constants.Dicts.dictSex, sex)).ifPresent(o -> recipientInfo.setSexName(o.getDisplay())); + return recipientInfo; + } + + /** + * 构建查询条件 + * + * @param query 查询条件 + * @return 规格 + */ + private Specification build(DeliveryQuery query) { + return (root, criteriaQuery, criteriaBuilder) -> { + List predicates = new ArrayList<>(); + Optional.ofNullable(query.getIsDeleted()).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get("isDeleted"), o))); + Optional.ofNullable(query.getName()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(RecipientInfo_.name), "%" + o + "%"))); + Optional.ofNullable(query.getPhone()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(RecipientInfo_.phone), o))); + Optional.ofNullable(query.getAddress()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(RecipientInfo_.address), "%" + o + "%"))); + return criteriaBuilder.and(predicates.toArray(new Predicate[0])); + }; + } + + + /** + * 根据ID删除受送人信息 + * + * @param recipientInfoId 受送人ID + */ + @Transactional + public void deleteRecipientInfoById(String recipientInfoId) { + recipientInfoRepo.findById(recipientInfoId).ifPresent(recipientInfo -> { + recipientInfo.setIsDeleted(true); + recipientInfo.setUpdateTime(LocalDateTime.now()); + recipientInfoRepo.save(recipientInfo); + }); + } + + /** + * 受送人是否存在 + * + * @param recipientInfoId 受送人ID + * @return 是否存在 + */ + public boolean existsRecipientInfoById(String recipientInfoId) { + return recipientInfoRepo.existsById(recipientInfoId); + } + + /** + * 批量删除受送人 + * + * @param itemIds 受送人ID列表 + */ + @Transactional + public void deleteRecipientInfoByIds(List itemIds) { + recipientInfoRepo.findAllById(itemIds).forEach(recipientInfo -> { + recipientInfo.setIsDeleted(true); + recipientInfo.setUpdateTime(LocalDateTime.now()); + recipientInfoRepo.save(recipientInfo); + }); + } + + /** + * 根据查询条件获取受送人集合 + * + * @param query 查询条件 + * @return 受送人集合 + */ + public List getRecipientInfoList(DeliveryQuery query) { + return recipientInfoRepo.findAll(build(query)); + } + +} diff --git a/server/src/main/java/com/aisino/iles/lawenforcement/service/ReportCheckService.java b/server/src/main/java/com/aisino/iles/lawenforcement/service/ReportCheckService.java new file mode 100644 index 0000000..f7dd01a --- /dev/null +++ b/server/src/main/java/com/aisino/iles/lawenforcement/service/ReportCheckService.java @@ -0,0 +1,320 @@ +package com.aisino.iles.lawenforcement.service; + + +import com.aisino.iles.common.model.enums.IndustryCategoryForFile; +import com.aisino.iles.common.service.FtpService; +import com.aisino.iles.common.util.BeanUtils; +import com.aisino.iles.common.util.KmsServer; +import com.aisino.iles.core.exception.BusinessError; +import com.aisino.iles.lawenforcement.model.*; +import com.aisino.iles.lawenforcement.model.dto.EnforcementInfoDto; +import com.aisino.iles.lawenforcement.model.dto.FormDataDto; +import com.aisino.iles.lawenforcement.model.query.ReportCheckQuery; +import com.aisino.iles.lawenforcement.repository.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ghca.kms.thrift.api.KmsApi; +import com.smartlx.sso.client.model.RemoteUserInfo; +import jakarta.persistence.criteria.Predicate; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +/** + * 举报核查信息服务类 + */ +@Service +@Slf4j +public class ReportCheckService { + + private final ReportCheckRepository reportCheckRepo; + private final ReportCheckOperRepository reportCheckOperRepo; + private final EnterpriseRepository enterpriseRepo; + private final MaterialsRepository materialsRepo; + private final EnforcementInfoService enforcementInfoService; + private final AgencyRepository agencyRepo; + private final ObjectMapper objectMapper; + private final FtpService ftpService; + + public ReportCheckService(ReportCheckRepository reportCheckRepo, + ReportCheckOperRepository reportCheckOperRepo, + EnterpriseRepository enterpriseRepo, + MaterialsRepository materialsRepo, + EnforcementInfoService enforcementInfoService, + AgencyRepository agencyRepo, + ObjectMapper objectMapper, + FtpService ftpService) { + this.reportCheckRepo = reportCheckRepo; + this.reportCheckOperRepo = reportCheckOperRepo; + this.enterpriseRepo = enterpriseRepo; + this.materialsRepo = materialsRepo; + this.enforcementInfoService = enforcementInfoService; + this.agencyRepo = agencyRepo; + this.objectMapper = objectMapper; + this.ftpService = ftpService; + } + + /** + * 保存举报核查信息 + * + * @param formData 举报核查信息 + * @return 保存后的举报核查信息 + */ + @Transactional + public ReportCheck saveReportCheck(FormDataDto formData, RemoteUserInfo user, String type) { + LocalDateTime now = LocalDateTime.now(); + MultipartFile[] files = formData.getFiles(); + ReportCheck reportCheck = new ReportCheck(); + try { + reportCheck = objectMapper.readValue(formData.getFormDataJson(), ReportCheck.class); + } catch (JsonProcessingException e) { + log.error(e.getMessage(), e); + } + if ("add".equals(type)) { + reportCheck.setProcessStatus("0"); + reportCheck.setCreateTime(now); + reportCheck.setDataSource("1"); + reportCheck.setFeedbackNot("0"); + reportCheck.setComplainAcceptStatus("0"); + AtomicReference agency = new AtomicReference<>(); + agencyRepo.findByAgencyCode(user.getGajgjgdm()).ifPresent(o -> { + if (o.getAgencyLevel() > 2) { + agency.set(o); + } + }); + if (null != agency.get()) + reportCheck.setAgency(agency.get()); + } + reportCheck.setUpdateTime(now); + // 检验加密签名保存 + ReportCheck finalReportCheck = reportCheck; + Optional.ofNullable(reportCheck.getReporterPhone()).filter(StringUtils::hasText).ifPresent(s-> finalReportCheck.setSginData(KmsServer.kmsSign(s))); + ReportCheck save = reportCheckRepo.save(finalReportCheck); + saveOPer(save, user, "add".equals(type) ? "新增" : "普通修改", now); + if (null != files) { + for (MultipartFile file : files) { + String fileName = file.getOriginalFilename(); + Materials materials = new Materials(); + materials.setLrsj(now); + materials.setFileType(StringUtils.hasText(fileName) ? fileName.split("\\.")[1] : null); + materials.setName(fileName); + materials.setLinkId(save.getPcid()); + try { + String url = ftpService.uploadTempFile(IndustryCategoryForFile.pub, fileName, file.getInputStream()); + if (!StringUtils.hasText(url)) { + throw new BusinessError("举报核查材料返回失败:上传时异常"); + } + materials.setSavePath(url); + } catch (Exception e) { + throw new BusinessError("举报核查材料上传失败:" + e); + } + materials.setIsOriginal("1"); + materials.setMaterialsTypeCode("1"); + materials.setMaterialsTypeName("举报核查材料"); + materialsRepo.save(materials); + } + } + Set filelIds = reportCheck.getFilelIds(); + if (null != filelIds && !filelIds.isEmpty()) { + filelIds.forEach(id -> materialsRepo.findById(id).ifPresent(file -> { + String url = file.getSavePath(); + if (StringUtils.hasText(url)) + ftpService.deletePathFile(url); // 删除文件服务器上的文件 + materialsRepo.delete(file); + })); + } + return save; + } + + private void saveOPer(ReportCheck reportCheck, RemoteUserInfo user, String type, LocalDateTime now) { + ReportCheckOper oper = new ReportCheckOper(); + oper.setOperType(type); + if (null != user) { + oper.setOperBy(user.getXm()); + oper.setOperAccountBy(user.getYhwybs()); + } + oper.setPcid(reportCheck.getPcid()); + oper.setOperTime(now); + reportCheckOperRepo.save(oper); + } + + /** + * 根据ID查询举报核查信息 + * + * @param reportCheckId 举报核查ID + * @return 举报核查信息 + */ + public Optional findReportCheckById(String reportCheckId) { + return reportCheckRepo.findById(reportCheckId).map(reportCheck -> { + reportCheck.setDzcls(materialsRepo.findByLinkId(reportCheck.getPcid()).stream().peek(dzcl -> { + String dzclUrl = dzcl.getSavePath(); + if ("1".equals(dzcl.getIsOriginal()) && StringUtils.hasText(dzclUrl)) { + dzcl.setUrl(ftpService.getFileUrl(dzclUrl)); + dzcl.setDownloadUrl(ftpService.getFileDownloadUrl(dzclUrl)); + } + if ("2".equals(dzcl.getIsOriginal())) { + dzcl.setUrl(dzclUrl); + dzcl.setDownloadUrl(dzclUrl); + } + }).collect(Collectors.toList())); + return reportCheck; + }); + } + + /** + * 根据查询条件分页查询举报核查信息 + * + * @param query 查询条件 + * @return 分页举报核查信息 + */ + public Page findReportChecksPage(ReportCheckQuery query, RemoteUserInfo user) { + Specification spec = buildSpecification(query, user); + // 构建分页和排序 + PageRequest pageRequest; + if (StringUtils.hasText(query.sort())) { + Sort.Direction direction = "desc".equalsIgnoreCase(query.dir()) ? Sort.Direction.DESC : Sort.Direction.ASC; + Sort sort = Sort.by(direction, query.sort()); + pageRequest = PageRequest.of(query.page() - 1, query.pageSize(), sort); + } else { + Sort sort = Sort.by(Sort.Direction.DESC, "complainTime"); + pageRequest = PageRequest.of(query.page() - 1, query.pageSize(), sort); + } + + return reportCheckRepo.findAll(spec, pageRequest); + } + + /** + * 构建查询条件 + * + * @param query 查询条件 + * @return 规格 + */ + private Specification buildSpecification(ReportCheckQuery query, RemoteUserInfo user) { + return (root, criteriaQuery, criteriaBuilder) -> { + List predicates = new ArrayList<>(); + agencyRepo.findByAgencyCode(user.getGajgjgdm()).ifPresent(agency -> { + if (agency.getAgencyLevel() > 2) { + predicates.add(criteriaBuilder.like(root.get(ReportCheck_.agency).get(Agency_.agencyCode), com.aisino.iles.common.util.StringUtils.trimEven0(agency.getAgencyCode()) + "%")); + } + }); + Optional.ofNullable(query.getReporterName()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.like(root.get(ReportCheck_.reporterName), "%" + o + "%"))); + Optional.ofNullable(query.getReportCanal()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(ReportCheck_.reportCanal), o))); + Optional.ofNullable(query.getDataSource()).filter(StringUtils::hasText).ifPresent(o -> predicates.add(criteriaBuilder.equal(root.get(ReportCheck_.dataSource), o))); + return criteriaBuilder.and(predicates.toArray(new Predicate[0])); + }; + } + + /** + * 根据ID删除举报核查信息 + * + * @param reportCheckId 举报核查ID + */ + @Transactional + public void deleteReportCheckById(String reportCheckId) { + reportCheckRepo.deleteById(reportCheckId); + } + + /** + * 批量删除举报核查信息 + * + * @param reportCheckIds 举报核查ID列表 + */ + @Transactional + public void deleteReportChecksByIds(List reportCheckIds) { + reportCheckRepo.deleteAllById(reportCheckIds); + } + + /** + * 批量转交举报核查信息 + * + * @param reportCheckIds 举报核查ID列表 + */ + @Transactional + public void transferReportChecksByIds(List reportCheckIds, RemoteUserInfo user) { + Optional.ofNullable(reportCheckIds).ifPresent(ids -> { + LocalDateTime now = LocalDateTime.now(); + List ltdIds = new ArrayList<>(); + ids.forEach(id -> { + reportCheckRepo.findById(id).ifPresent(reportCheck -> { + if (!StringUtils.hasText(reportCheck.getEnterpriseId())) + throw new BusinessError("请选择被举报企业"); + enterpriseRepo.findById(reportCheck.getEnterpriseId()).ifPresent(enterprise -> reportCheck.setAgency(enterprise.getAgency())); + ltdIds.add(reportCheck.getEnterpriseId()); + reportCheck.setProcessStatus("1"); + if (null != user) { + reportCheck.setUpdateBy(user.getXm()); + reportCheck.setUpdateAccountBy(user.getYhwybs()); + } + reportCheck.setUpdateTime(now); + saveOPer(reportCheck, user, "转交", now); + }); + }); + //自动生成执法检查信息 + EnforcementInfoDto enforcementInfoDto = new EnforcementInfoDto(); + enforcementInfoDto.setEnterpriseIds(ltdIds); + enforcementInfoDto.setDataFrom("3");//举报核查转交 + enforcementInfoService.saveEnforcementInfo(enforcementInfoDto, user); + }); + } + + /** + * 反馈 + * + * @param reportCheckId 举报核查ID + * @param user 用户信息 + * @return 举报核查信息 + */ + @Transactional + public Optional backReportCheck(String reportCheckId, ReportCheck reportCheck, RemoteUserInfo user) { + return reportCheckRepo.findById(reportCheckId).map(o -> { + BeanUtils.copyProperties(reportCheck, o, "dzcls"); + o.setProcessStatus("2"); + LocalDateTime now = LocalDateTime.now(); + if (null != user) { + o.setUpdateBy(user.getXm()); + o.setUpdateAccountBy(user.getYhwybs()); + } + o.setUpdateTime(now); + o.setFeedbackNot("1"); + saveOPer(o, user, "反馈", now); + // 检验加密签名保存 + Optional.ofNullable(reportCheck.getReporterPhone()).filter(StringUtils::hasText).ifPresent(s-> o.setSginData(KmsServer.kmsSign(s))); + return reportCheckRepo.save(o); + }); + } + + /** + * 转交 + * + * @param check 举报核查信息 + * @param user 用户信息 + */ + @Transactional + public void transferReportChecksById(ReportCheck check, RemoteUserInfo user) { + reportCheckRepo.findById(check.getPcid()).ifPresent(reportCheck -> { + LocalDateTime now = LocalDateTime.now(); + reportCheck.setAgency(check.getAgency()); + reportCheck.setProcessStatus("1"); + if (null != user) { + reportCheck.setUpdateBy(user.getXm()); + reportCheck.setUpdateAccountBy(user.getYhwybs()); + } + reportCheck.setUpdateTime(now); + saveOPer(reportCheck, user, "转交", now); + }); + } +} diff --git a/server/src/main/java/com/aisino/iles/lawenforcement/service/StatisticService.java b/server/src/main/java/com/aisino/iles/lawenforcement/service/StatisticService.java new file mode 100644 index 0000000..2f099c7 --- /dev/null +++ b/server/src/main/java/com/aisino/iles/lawenforcement/service/StatisticService.java @@ -0,0 +1,899 @@ +package com.aisino.iles.lawenforcement.service; + + +import com.aisino.iles.common.util.Constants; +import com.aisino.iles.common.util.PageableHelper; +import com.aisino.iles.lawenforcement.model.Agency; +import com.aisino.iles.lawenforcement.model.EnforcementInfoHistory; +import com.aisino.iles.lawenforcement.model.query.CaseQuery; +import com.aisino.iles.lawenforcement.repository.AgencyRepository; +import com.aisino.iles.lawenforcement.repository.EnforcementInfoHistoryRepository; +import com.aisino.iles.lawenforcement.repository.StatisticRepository; +import com.aisino.iles.lawenforcement.repository.impl.StatisticCustomRepositoryImpl; +import com.smartlx.sso.client.model.RemoteUserInfo; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * 统计报表 + */ +@Service +public class StatisticService { + + private final StatisticRepository statisticRepository; + private final AgencyRepository agencyRepo; + private final EnforcementInfoHistoryRepository historyRepository; + private final StatisticCustomRepositoryImpl customRepository; + public StatisticService(StatisticRepository statisticRepository, AgencyRepository agencyRepo, EnforcementInfoHistoryRepository historyRepository, StatisticCustomRepositoryImpl customRepository) { + this.statisticRepository = statisticRepository; + this.agencyRepo = agencyRepo; + this.historyRepository = historyRepository; + this.customRepository = customRepository; + } + + + + public List> statisticByWeekForm(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + // 获取所在年的第一天(周一) + LocalDate firstDayOfYear = query.getStatisticDate()[0].with(java.time.temporal.TemporalAdjusters.firstDayOfYear()); + + List> result = new ArrayList<>(); + List> details = new ArrayList<>(); + List> detailsAll = new ArrayList<>(); + + List> histrorys = new ArrayList<>(); + List> histroryAll = new ArrayList<>(); + String districtName; + String agencyCode = user.getGajgjgdm(); + + + if(currentAgency.getAgencyLevel()==3){ + int index = currentAgency.getAgencyName().indexOf('区'); + if (index != -1) { + districtName = currentAgency.getAgencyName().substring(0, index); // 截取'x'前面的部分 + } else { + int index1 = currentAgency.getAgencyName().indexOf('县'); + if(index1 != -1) + districtName = currentAgency.getAgencyName().substring(0, index1); + else { + districtName = currentAgency.getAgencyName(); + } + } + + details = statisticRepository.statisticByWeekFormAndDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],agencyCode); + detailsAll = statisticRepository.statisticByWeekFormAndDistrict(firstDayOfYear,query.getStatisticDate()[1],agencyCode); + histrorys= historyRepository.statisticHistoryByWeekAndDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],agencyCode); + histroryAll = historyRepository.statisticHistoryByWeekAndDistrict(firstDayOfYear,query.getStatisticDate()[1],agencyCode); + }else{ + districtName = "西安市"; + details = statisticRepository.statisticByWeekForm(query.getStatisticDate()[0],query.getStatisticDate()[1]); + detailsAll = statisticRepository.statisticByWeekForm(firstDayOfYear,query.getStatisticDate()[1]); + histrorys= historyRepository.statisticHistoryByWeek(query.getStatisticDate()[0],query.getStatisticDate()[1]); + histroryAll = historyRepository.statisticHistoryByWeek(firstDayOfYear,query.getStatisticDate()[1]); + } + // 合并 两个列表 + List> combinedList = Stream.concat(details.stream(), histrorys.stream()) + .toList(); + List> combinedListAll = Stream.concat(detailsAll.stream(), histroryAll.stream()) + .toList(); + + + + DateTimeFormatter formatter= DateTimeFormatter.ofPattern("yyyy年MM月dd日"); + List> coditionList = combinedList.stream() + .collect(Collectors.groupingBy( + map -> map.get("industry_type"), + Collectors.collectingAndThen( + Collectors.toList(), + list -> { + Map summary = new HashMap<>(); + String industry_type = String.valueOf(list.get(0).get("industry_type")); + int qys = list.stream() + .mapToInt(map -> ((Number) map.get("qys")).intValue()) + .sum(); + int jcqysl = list.stream() + .mapToInt(map -> ((Number) map.get("jcqysl")).intValue()) + .sum(); + int jccsl = list.stream() + .mapToInt(map -> ((Number) map.get("jccsl")).intValue()) + .sum(); + int lajss = list.stream() + .mapToInt(map -> ((Number) map.get("lajss")).intValue()) + .sum(); + int lasl = list.stream() + .mapToInt(map -> ((Number) map.get("lasl")).intValue()) + .sum(); + int wfxwsl = list.stream() + .mapToInt(map -> ((Number) map.get("wfxwsl")).intValue()) + .sum(); + int yasfs = list.stream() + .mapToInt(map -> ((Number) map.get("yasfs")).intValue()) + .sum(); + float fkze = (float) list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("fkze"))))).sum(); + + float cfqy = (float)list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("cfqy"))))) + .sum(); + float cfgr = (float)list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("cfgr"))))) + .sum(); + int yjajs = list.stream() + .mapToInt(map -> ((Number) map.get("yjajs")).intValue()) + .sum(); + int sjrys = list.stream() + .mapToInt(map -> ((Number) map.get("sjrys")).intValue()) + .sum(); + int yts = list.stream() + .mapToInt(map -> ((Number) map.get("yts")).intValue()) + .sum(); + int tczds = list.stream() + .mapToInt(map -> ((Number) map.get("tczds")).intValue()) + .sum(); + int ytrs = list.stream() + .mapToInt(map -> ((Number) map.get("ytrs")).intValue()) + .sum(); + int tbs = list.stream() + .mapToInt(map -> ((Number) map.get("tbs")).intValue()) + .sum(); + int tbrs = list.stream() + .mapToInt(map -> ((Number) map.get("tbrs")).intValue()) + .sum(); + summary.put("industry_type",industry_type); + summary.put("qys", qys); + summary.put("jcqysl", jcqysl); + summary.put("jccsl", jccsl); + summary.put("lajss",lajss); + summary.put("lasl", lasl); + summary.put("wfxwsl", wfxwsl); + summary.put("yasfs", yasfs); + summary.put("fkze", new BigDecimal(fkze).setScale(2, RoundingMode.HALF_UP)); + summary.put("cfqy", new BigDecimal(cfqy).setScale(2, RoundingMode.HALF_UP)); + summary.put("cfgr", new BigDecimal(cfgr).setScale(2, RoundingMode.HALF_UP)); + summary.put("yjajs", yjajs); + summary.put("sjrys", sjrys); + summary.put("yts", yts); + summary.put("ytrs", ytrs); + summary.put("tbs", tbs); + summary.put("tbrs", tbrs); + summary.put("tczds", tczds); + return summary; + } + ) + )) + .values() // 获取所有分组的汇总结果 + .stream().toList(); + List> allList = combinedListAll.stream() + .collect(Collectors.groupingBy( + map -> map.get("industry_type"), + Collectors.collectingAndThen( + Collectors.toList(), + list -> { + Map summary = new HashMap<>(); + String industry_type = String.valueOf(list.get(0).get("industry_type")); + int qys = list.stream() + .mapToInt(map -> ((Number) map.get("qys")).intValue()) + .sum(); + int jcqysl = list.stream() + .mapToInt(map -> ((Number) map.get("jcqysl")).intValue()) + .sum(); + int jccsl = list.stream() + .mapToInt(map -> ((Number) map.get("jccsl")).intValue()) + .sum(); + int lajss = list.stream() + .mapToInt(map -> ((Number) map.get("lajss")).intValue()) + .sum(); + int lasl = list.stream() + .mapToInt(map -> ((Number) map.get("lasl")).intValue()) + .sum(); + int wfxwsl = list.stream() + .mapToInt(map -> ((Number) map.get("wfxwsl")).intValue()) + .sum(); + int yasfs = list.stream() + .mapToInt(map -> ((Number) map.get("yasfs")).intValue()) + .sum(); + float fkze = (float) list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("fkze"))))).sum(); + + float cfqy = (float)list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("cfqy"))))) + .sum(); + float cfgr = (float)list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("cfgr"))))) + .sum(); + int yjajs = list.stream() + .mapToInt(map -> ((Number) map.get("yjajs")).intValue()) + .sum(); + int sjrys = list.stream() + .mapToInt(map -> ((Number) map.get("sjrys")).intValue()) + .sum(); + int yts = list.stream() + .mapToInt(map -> ((Number) map.get("yts")).intValue()) + .sum(); + int tczds = list.stream() + .mapToInt(map -> ((Number) map.get("tczds")).intValue()) + .sum(); + int ytrs = list.stream() + .mapToInt(map -> ((Number) map.get("ytrs")).intValue()) + .sum(); + int tbs = list.stream() + .mapToInt(map -> ((Number) map.get("tbs")).intValue()) + .sum(); + int tbrs = list.stream() + .mapToInt(map -> ((Number) map.get("tbrs")).intValue()) + .sum(); + summary.put("industry_type",industry_type); + summary.put("qys", qys); + summary.put("jcqysl", jcqysl); + summary.put("jccsl", jccsl); + summary.put("lajss",lajss); + summary.put("lasl", lasl); + summary.put("wfxwsl", wfxwsl); + summary.put("yasfs", yasfs); + summary.put("fkze", new BigDecimal(fkze).setScale(2, RoundingMode.HALF_UP)); + summary.put("cfqy", new BigDecimal(cfqy).setScale(2, RoundingMode.HALF_UP)); + summary.put("cfgr", new BigDecimal(cfgr).setScale(2, RoundingMode.HALF_UP)); + summary.put("yjajs", yjajs); + summary.put("sjrys", sjrys); + summary.put("yts", yts); + summary.put("ytrs", ytrs); + summary.put("tbs", tbs); + summary.put("tbrs", tbrs); + summary.put("tczds", tczds); + return summary; + } + ) + )) + .values() // 获取所有分组的汇总结果 + .stream().toList(); + Integer rowCountWeek= coditionList.size(); + Integer rowCountAll= allList.size(); + coditionList.forEach(stringObjectMap -> { + Map modifiableMap = new HashMap<>(stringObjectMap); + modifiableMap.put("rowCountWeek",rowCountWeek); + modifiableMap.put("rowCountAll",rowCountAll); + modifiableMap.put("district",districtName); + modifiableMap.put("statisticDate","统计周:"+query.getStatisticDate()[0].format(formatter)+"-"+query.getStatisticDate()[1].format(formatter)); + + modifiableMap.put("tjsjd", query.getStatisticDate()); + String industryType = String.valueOf(modifiableMap.get("industry_type")); + if(Constants.DictDisplay.hylbMap.get(industryType)==null) + modifiableMap.put("hylb",""); + else + modifiableMap.put("hylb",Constants.DictDisplay.hylbMap.get(industryType)); + + result.add(modifiableMap); + }); + allList.forEach(stringObjectMap -> { + Map modifiableMap = new HashMap<>(stringObjectMap); + modifiableMap.put("rowCountWeek",rowCountWeek); + modifiableMap.put("rowCountAll",rowCountAll); + modifiableMap.put("district",districtName); + modifiableMap.put("tjsjd",new LocalDate[]{firstDayOfYear,query.getStatisticDate()[1]}); + modifiableMap.put("statisticDate","统计周:"+firstDayOfYear.format(formatter)+"-"+query.getStatisticDate()[1].format(formatter)); + String industryType = String.valueOf(modifiableMap.get("industry_type")); + if(Constants.DictDisplay.hylbMap.get(industryType)==null) + modifiableMap.put("hylb",""); + else + modifiableMap.put("hylb",Constants.DictDisplay.hylbMap.get(industryType)); + + result.add(modifiableMap); + }); + + + return result; + } + + public List> statisticEnforceCheckForm(CaseQuery query, RemoteUserInfo user) { + //判断周期类型组装日期条件 + Optional.ofNullable(query.getPeriod()).ifPresent(o -> { + if("month".equals(o)){ + LocalDate statisticDateStart = query.getYd(); + LocalDate statisticDateEnd = query.getYd().with(TemporalAdjusters.lastDayOfMonth()); + LocalDate[] statisticDate = new LocalDate[]{statisticDateStart, statisticDateEnd}; + query.setStatisticDate(statisticDate); + } + else if("quarter".equals(o)){ + if(query.getJd()==1){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 1, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 3, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==2){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 4, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 6, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==3){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 7, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 9, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==4){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 10, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 12, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + } + } + }); + + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + List> details = new ArrayList<>(); + List> historydetails = new ArrayList<>(); + if(currentAgency.getAgencyLevel()==3){ + details = statisticRepository.statisticEnforceCheckByDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],currentAgency.getAgencyCode()); + historydetails = historyRepository.statisticHistoryEnforceCheckByDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],currentAgency.getAgencyCode()); + }else{ + details = statisticRepository.statisticEnforceCheck(query.getStatisticDate()[0],query.getStatisticDate()[1]); + historydetails = historyRepository.statisticHistoryEnforceCheck(query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + // 合并 两个列表 + List> combinedList = Stream.concat(details.stream(), historydetails.stream()) + .toList(); + // 按结构编码分组并计算每个组的数量 + List> result = combinedList.stream() + .collect(Collectors.groupingBy( + map -> map.get("agency_code"), + Collectors.collectingAndThen( + Collectors.toList(), + list -> { + Map summary = new HashMap<>(); + String agencyLevel = String.valueOf(list.get(0).get("agency_level")); + String agencyName = String.valueOf(list.get(0).get("agency_name")); + if("2".equals(agencyLevel)){ + int index = agencyName.indexOf("市"); + if (index != -1) { // 确保找到了字符 + summary.put("agencyName", agencyName.substring(0, index+1)); + } + }else{ + summary.put("agencyName", agencyName); + int index = agencyName.indexOf("区"); + if (index != -1) { // 确保找到了字符 + summary.put("agencyName", agencyName.substring(0, index)); + } + int index1 = agencyName.indexOf("县"); + if (index1 != -1) { // 确保找到了字符 + summary.put("agencyName", agencyName.substring(0, index1)); + } + } + summary.put("agency_code", list.get(0).get("agency_code")); + summary.put("agency_name", list.get(0).get("agency_name")); + summary.put("agency_level", list.get(0).get("agency_level")); + int jccs = list.stream() + .mapToInt(map -> ((Number) map.get("jccs")).intValue()) + .sum(); + int jcqysl = list.stream() + .mapToInt(map -> ((Number) map.get("jcqysl")).intValue()) + .sum(); + int yhzs = list.stream() + .mapToInt(map -> ((Number) map.get("yhzs")).intValue()) + .sum(); + int zdyhs = list.stream() + .mapToInt(map -> ((Number) map.get("zdyhs")).intValue()) + .sum(); + int ybyhs = list.stream() + .mapToInt(map -> ((Number) map.get("ybyhs")).intValue()) + .sum(); + int xcclcss = list.stream() + .mapToInt(map -> ((Number) map.get("xcclcss")).intValue()) + .sum(); + int zlxqzgs = list.stream() + .mapToInt(map -> ((Number) map.get("zlxqzgs")).intValue()) + .sum(); + int zgfcyjs = list.stream() + .mapToInt(map -> ((Number) map.get("zgfcyjs")).intValue()) + .sum(); + int qtwss = list.stream() + .mapToInt(map -> ((Number) map.get("qtwss")).intValue()) + .sum(); + int wszs = list.stream() + .mapToInt(map -> ((Number) map.get("wszs")).intValue()) + .sum(); + + summary.put("jccs", jccs); + summary.put("jcqysl", jcqysl); + summary.put("yhzs", yhzs); + summary.put("zdyhs", zdyhs); + summary.put("ybyhs", ybyhs); + summary.put("xcclcss", xcclcss); + summary.put("zlxqzgs", zlxqzgs); + summary.put("zgfcyjs", zgfcyjs); + summary.put("qtwss", qtwss); + summary.put("wszs", wszs); + return summary; + } + ) + )) + .values() // 获取所有分组的汇总结果 + .stream() .sorted(Comparator.comparing(map -> ((String) map.get("agency_code")))) + .collect(Collectors.toList()); + return result; + } + + public List> statisticByQuarterForm(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(query.getJd()==1){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 1, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 3, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==2){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 4, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 6, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==3){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 7, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 9, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==4){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 10, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 12, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + } + + + List> details = new ArrayList<>(); + List> historys = new ArrayList<>(); + if(currentAgency.getAgencyLevel()==3){ + details = statisticRepository.statisticByQuarterFormAndDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],currentAgency.getAgencyCode()); + historys = historyRepository.statisticHistoryByQuarterAndDistrict(query.getStatisticDate()[0],query.getStatisticDate()[1],currentAgency.getAgencyCode()); + }else{ + details = statisticRepository.statisticByQuarterForm(query.getStatisticDate()[0],query.getStatisticDate()[1]); + historys = historyRepository.statisticHistoryByQuarter(query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + // 合并 两个列表 + List> combinedList = Stream.concat(details.stream(), historys.stream()) + .toList(); + List> result = new ArrayList<>(combinedList.stream() + .collect(Collectors.groupingBy( + map -> map.get("industry_type"), + Collectors.collectingAndThen( + Collectors.toList(), + list -> { + Map summary = new HashMap<>(); + String industryType = String.valueOf(list.get(0).get("industry_type")); + if (Constants.DictDisplay.hylbMap.get(industryType) == null) + summary.put("hylb", "其他"); + else + summary.put("hylb", Constants.DictDisplay.hylbMap.get(industryType)); + + String industry_type = String.valueOf(list.get(0).get("industry_type")); + int jcqysl = list.stream() + .mapToInt(map -> ((Number) map.get("jcqysl")).intValue()) + .sum(); + int zdyhs = list.stream() + .mapToInt(map -> ((Number) map.get("zdyhs")).intValue()) + .sum(); + int ybyhs = list.stream() + .mapToInt(map -> ((Number) map.get("ybyhs")).intValue()) + .sum(); + int yhzs = list.stream() + .mapToInt(map -> ((Number) map.get("yhzs")).intValue()) + .sum(); + int xcclcss = list.stream() + .mapToInt(map -> ((Number) map.get("xcclcss")).intValue()) + .sum(); + int zlxqzgs = list.stream() + .mapToInt(map -> ((Number) map.get("zlxqzgs")).intValue()) + .sum(); + int zgfcyjs = list.stream() + .mapToInt(map -> ((Number) map.get("zgfcyjs")).intValue()) + .sum(); + float fkze = (float) list.stream() + .mapToDouble(map -> (Float.parseFloat(String.valueOf(map.get("fkze"))))).sum(); + + int xzcfjdssl = list.stream() + .mapToInt(map -> ((Number) map.get("xzcfjdssl")).intValue()) + .sum(); + int qtwss = list.stream() + .mapToInt(map -> ((Number) map.get("qtwss")).intValue()) + .sum(); + int wszs = list.stream() + .mapToInt(map -> ((Number) map.get("wszs")).intValue()) + .sum(); + int wfxwsl = list.stream() + .mapToInt(map -> ((Number) map.get("wfxwsl")).intValue()) + .sum(); + int yjajs = list.stream() + .mapToInt(map -> ((Number) map.get("yjajs")).intValue()) + .sum(); + int sfyts = list.stream() + .mapToInt(map -> ((Number) map.get("sfyts")).intValue()) + .sum(); + int sfzkzzs = list.stream() + .mapToInt(map -> ((Number) map.get("sfzkzzs")).intValue()) + .sum(); + int sfzltczds = list.stream() + .mapToInt(map -> ((Number) map.get("sfzltczds")).intValue()) + .sum(); + int sfgbs = list.stream() + .mapToInt(map -> ((Number) map.get("sfgbs")).intValue()) + .sum(); + summary.put("industry_type", industry_type); + summary.put("jcqysl", jcqysl); + summary.put("zdyhs", zdyhs); + summary.put("ybyhs", ybyhs); + summary.put("yhzs", yhzs); + summary.put("xcclcss", xcclcss); + summary.put("zlxqzgs", zlxqzgs); + summary.put("zgfcyjs", zgfcyjs); + summary.put("xzcfjdssl", xzcfjdssl); + summary.put("qtwss", qtwss); + summary.put("wszs", wszs); + summary.put("wfxwsl", wfxwsl); + summary.put("fkze", new BigDecimal(fkze).setScale(2, RoundingMode.HALF_UP)); + summary.put("yjajs", yjajs); + summary.put("sfyts", sfyts); + summary.put("sfzkzzs", sfzkzzs); + summary.put("sfzltczds", sfzltczds); + summary.put("sfgbs", sfgbs); + summary.put("tjsjd",query.getStatisticDate()); + return summary; + } + ) + )) + .values()); + + Map filteredMap = Constants.DictDisplay.hylbMap.entrySet().stream() + .filter(entry -> !result.stream() + .map(obj -> obj.get("industry_type")) + .toList() + .contains(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + List> lackList = new ArrayList<>(); + filteredMap.forEach((key, value) -> { + Map summary = new HashMap<>(); + summary.put("industry_type", key); + summary.put("hylb", value); + summary.put("jcqysl", 0); + summary.put("zdyhs", 0); + summary.put("ybyhs", 0); + summary.put("yhzs", 0); + summary.put("xcclcss", 0); + summary.put("zlxqzgs", 0); + summary.put("zgfcyjs", 0); + summary.put("xzcfjdssl", 0); + summary.put("qtwss", 0); + summary.put("wszs", 0); + summary.put("wfxwsl", 0); + summary.put("fkze", 0); + summary.put("yjajs", 0); + summary.put("sfyts", 0); + summary.put("sfzkzzs", 0); + summary.put("sfzltczds", 0); + summary.put("sfgbs", 0); + summary.put("tjsjd",query.getStatisticDate()); + lackList.add(summary); + }); + + return Stream.concat(result.stream(), lackList.stream()) + .toList(); + } + + @Transactional(readOnly = true) + public Page getPageJcqk(CaseQuery query, RemoteUserInfo user) { + //判断周期类型组装日期条件 + Optional.ofNullable(query.getPeriod()).ifPresent(o -> { + if("month".equals(o)){ + LocalDate statisticDateStart = query.getYd(); + LocalDate statisticDateEnd = query.getYd().with(TemporalAdjusters.lastDayOfMonth()); + LocalDate[] statisticDate = new LocalDate[]{statisticDateStart, statisticDateEnd}; + query.setStatisticDate(statisticDate); + } + else if("quarter".equals(o)){ + if(query.getJd()==1){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 1, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 3, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==2){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 4, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 6, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==3){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 7, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 9, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==4){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 10, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 12, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + } + } + }); + return customRepository.jcqyqkDetail(query.page(),query.pageSize(), query.sort(), query.dir(),query.getGxdwbm(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r-> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + + @Transactional(readOnly = true) + public Page getPageJccsqk(CaseQuery query, RemoteUserInfo user) { + //判断周期类型组装日期条件 + Optional.ofNullable(query.getPeriod()).ifPresent(o -> { + if("month".equals(o)){ + LocalDate statisticDateStart = query.getYd(); + LocalDate statisticDateEnd = query.getYd().with(TemporalAdjusters.lastDayOfMonth()); + LocalDate[] statisticDate = new LocalDate[]{statisticDateStart, statisticDateEnd}; + query.setStatisticDate(statisticDate); + } + else if("quarter".equals(o)){ + if(query.getJd()==1){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 1, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 3, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==2){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 4, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 6, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==3){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 7, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 9, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==4){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 10, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 12, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + } + } + }); + return customRepository.jccsqkDetail(query.page(),query.pageSize(), query.sort(), query.dir(),query.getGxdwbm(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r-> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + + @Transactional(readOnly = true) + public ListgetjcqkDetail(CaseQuery query, RemoteUserInfo user) { + //判断周期类型组装日期条件 + Optional.ofNullable(query.getPeriod()).ifPresent(o -> { + if("month".equals(o)){ + LocalDate statisticDateStart = query.getYd(); + LocalDate statisticDateEnd = query.getYd().with(TemporalAdjusters.lastDayOfMonth()); + LocalDate[] statisticDate = new LocalDate[]{statisticDateStart, statisticDateEnd}; + query.setStatisticDate(statisticDate); + } + else if("quarter".equals(o)){ + if(query.getJd()==1){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 1, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 3, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==2){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 4, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 6, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==3){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 7, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 9, 30); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + }else if(query.getJd()==4){ + LocalDate start = LocalDate.of(LocalDate.now().getYear(), 10, 1); + LocalDate end = LocalDate.of(LocalDate.now().getYear(), 12, 31); + LocalDate[] statisticDate = new LocalDate[] {start, end}; + query.setStatisticDate(statisticDate); + } + } + }); + return customRepository.jcqkDetail(query.getGxdwbm(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + + @Transactional(readOnly = true) + public Page getPagezbbjgqyDetail (CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.zbbjgqyDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType()).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.zbbjgqyDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType()).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + @Transactional(readOnly = true) + public Page getPagejcqyqkByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.jcqyqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.jcqyqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + @Transactional(readOnly = true) + public Page getPagejccsqkByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.jccsqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.jccsqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + @Transactional(readOnly = true) + public Page getPagelaqkByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.laqyqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.laqyqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + @Transactional(readOnly = true) + public Page getPagelaslByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.laqyslByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.laqyslByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + @Transactional(readOnly = true) + public List getlaqkByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.laqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + }else{ + return customRepository.laqkByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + } + + @Transactional(readOnly = true) + public List getjbbwsyhDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.jbbwsyhDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + }else{ + return customRepository.jbbwsyhDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + } + + @Transactional(readOnly = true) + public List getjbbwfxwfkDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.jbbwfxwfkDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + }else{ + return customRepository.jbbwfxwfkDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]); + } + } + + @Transactional(readOnly = true) + public Page getPagelaytqyByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.laytqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.laytqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + @Transactional(readOnly = true) + public Page getPagelazkzzqyByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.lazkzzqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.lazkzzqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + @Transactional(readOnly = true) + public Page getPagelatczdqyByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.latczdqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.latczdqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + @Transactional(readOnly = true) + public Page getPagelagbqyByindustryTypeDetail(CaseQuery query, RemoteUserInfo user) { + Agency currentAgency = agencyRepo.findByAgencyCode(user.getGajgjgdm()).orElseThrow(() -> new RuntimeException("当前用户机构数据错误,请检查!")); + if(currentAgency.getAgencyLevel()==3){ + return customRepository.lagbqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), currentAgency.getAgencyCode(), query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + }else{ + return customRepository.lagbqyByindustryTypeDetail(query.page(), query.pageSize(), query.sort(), query.dir(), "", query.getIndustryType(),query.getStatisticDate()[0],query.getStatisticDate()[1]).map(r -> { + String industryTypeName = Constants.DictDisplay.hylbMap.get(r.getIndustryType()); + r.setIndustryType(industryTypeName); + return r; + }); + } + } + + + + +}