From 91ebbdc5ef67699d166498f6cf5fcc21058817dd Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期二, 25 二月 2025 19:59:50 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java |  156 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 127 insertions(+), 29 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
index a5fab15..0819eb4 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/service/impl/ComplaintServiceImpl.java
@@ -31,12 +31,13 @@
 import lombok.RequiredArgsConstructor;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 import static cn.hutool.core.util.ObjectUtil.isNull;
@@ -50,18 +51,17 @@
  * @since 2025-02-22
  */
 @Service
-@RequiredArgsConstructor
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements IComplaintService {
     private final ISystemUserService systemUserService;
-    @Lazy
-    @Resource
-    private IComplaintFlowService complaintFlowService;
+    private final IComplaintFlowService complaintFlowService;
     private final IComplaintProgressService complaintProgressService;
 
     private final IComplaintAuditRecordService complaintAuditRecordService;
     private final IBcRegionService bcRegionService;
     private final IComStreetService comStreetService;
     private final IComActService comActService;
+    private final IWorkOrderItemConfigService workOrderItemConfigService;
 
     @Override
     public void saveComplaint(Complaint complaint, Long userId) {
@@ -94,7 +94,12 @@
         complaint.setCreateBy(userId);
         complaint.setUpdateBy(userId);
         complaint.setUpdateTime(new Date(System.currentTimeMillis()));
-
+        //查询系统配置诉求处理期限,设置截止日期
+        WorkOrderItemConfig config = workOrderItemConfigService.lambdaQuery().orderByDesc(WorkOrderItemConfig::getId).last("LIMIT 1").one();
+        if (Objects.isNull(config)){
+            throw new ServiceException("工单事项未配置,请联系管理员");
+        }
+        complaint.setClosingTime(new Date(System.currentTimeMillis() + config.getDemandProcessingTime() * 24 * 60 * 60 * 1000));
         // 保存诉求记录
         save(complaint);
     }
@@ -139,6 +144,7 @@
             targetId = loginUserInfoVO.getUserId().toString();
         }
         //查询对应诉求
+        query.setUserId(loginUserInfoVO.getUserId());//当前登录用户id
         page = baseMapper.selectComplaintPage(page, query, targetId,isSuperior);
         return page;
     }
@@ -173,7 +179,7 @@
         ComplaintProgress complaintProgress = BeanUtil.copyProperties(dto, ComplaintProgress.class);
         complaintProgress.setCreateTime(new Date());
         complaintProgress.setCreateBy(loginUserInfoVO.getUserId());
-        complaintProgress.setCreateByName(loginUserInfoVO.getName());
+        complaintProgress.setCreateByName(loginUserInfoVO.getNickName());
         complaintProgressService.save(complaintProgress);
     }
 
@@ -188,7 +194,8 @@
         Complaint complaint = BeanUtil.copyProperties(dto, Complaint.class);
         complaint.setUpdateTime(new Date());
         complaint.setCompletionUserId(loginUserInfoVO.getUserId());
-        complaint.setCompletionUsername(loginUserInfoVO.getName());
+        complaint.setCompletionUsername(loginUserInfoVO.getNickName());
+        complaint.setCompletionUserPhone(loginUserInfoVO.getPhone());
         complaint.setCompletionTime(new Date());
         this.updateById(complaint);
     }
@@ -205,30 +212,34 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void saveReport(ComplaintReportDTO dto, LoginUserInfoVO loginUserInfoVO) {
         String phone = loginUserInfoVO.getPhone();
 
         SystemUser adminUser = systemUserService.getOne(new LambdaQueryWrapper<SystemUser>()
                 .eq(SystemUser::getPhone, phone)
                 .eq(SystemUser::getIsAdmin, 1)
-                .eq(SystemUser::getStatus, 3)
+                .ne(SystemUser::getStatus, 3)
                 .last("LIMIT 1"));
 
         Long superiorId;
         int reportType;
         if (adminUser == null) {
             superiorId = loginUserInfoVO.getCommunityId();
+            if (Objects.isNull(superiorId)){
+                throw new ServiceException("上报失败,请绑定社区");
+            }
             reportType = ReportTypeEnum.COMMUNITY.getCode();
         } else {
             int accountLevel = adminUser.getAccountLevel(); // 改为基本类型
             if (accountLevel == 1) {
                 throw new ServiceException("市级账号,无法上报!");
             }
-            reportType = accountLevel + 1;
+            reportType = accountLevel - 1;
 
             // 使用基本类型比较并补充默认分支
             if (accountLevel == ReportTypeEnum.COMMUNITY.getCode()) {
-                superiorId = adminUser.getStreetId().longValue();
+                superiorId = Long.parseLong(adminUser.getStreetId());
             } else if (accountLevel == ReportTypeEnum.STREET.getCode()) {
                 superiorId = Long.parseLong(adminUser.getDistrictsCode());
             } else if (accountLevel == ReportTypeEnum.DISTRICT.getCode()) {
@@ -250,35 +261,35 @@
                 .set(ComplaintAuditRecord::getLatestFlag,false));
 
         // 添加审核记录
-        complaintAuditRecordService.createComplaintAuditRecord(dto.getComplaintId(), 2, dto.getComment(), loginUserInfoVO.getUserId());
+        complaintAuditRecordService.createComplaintAuditRecord(dto.getComplaintId(), 2, dto.getComment(), loginUserInfoVO,adminUser);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void saveDispatch(ComplaintDispatch dto, LoginUserInfoVO loginUserInfoVO) {
         String phone = loginUserInfoVO.getPhone();
         SystemUser adminUser = systemUserService.getOne(new LambdaQueryWrapper<SystemUser>()
                 .eq(SystemUser::getPhone, phone)
                 .eq(SystemUser::getIsAdmin, 1)
-                .eq(SystemUser::getStatus, 3)
+                .ne(SystemUser::getStatus, 3)
                 .last("LIMIT 1"));
 
         if (adminUser == null) {
             throw new ServiceException("无权下派");
         }
 
+
         long superiorId;
-        int reportType;
         int accountLevel = adminUser.getAccountLevel(); // 改为基本类型
-        if (accountLevel == 1) {
-            throw new ServiceException("市级账号,无法上报!");
+        if (accountLevel == 4) {
+            throw new ServiceException("社区账号,无法下派!");
         }
-        reportType = accountLevel - 1;
 
         // 使用基本类型比较并补充默认分支
         if (accountLevel == ReportTypeEnum.STREET.getCode()) {
             superiorId = adminUser.getCommunityId().longValue();
         } else if (accountLevel == ReportTypeEnum.DISTRICT.getCode()) {
-            superiorId = adminUser.getStreetId().longValue();
+            superiorId = Long.parseLong(adminUser.getStreetId());
         } else if (accountLevel == ReportTypeEnum.CITY.getCode()) {
             superiorId = Long.parseLong(adminUser.getDistrictsCode());
         } else {
@@ -286,40 +297,127 @@
             throw new ServiceException("未知的账号等级");
         }
 
+        Long superiorOrgId;
         Complaint complaint = getById(dto.getComplaintId());
-        complaint.setReportType(reportType);
+        superiorOrgId = complaint.getSuperiorId();
+        complaint.setReportType(accountLevel + 1);
         complaint.setSuperiorId(superiorId);
         updateById(complaint);
 
         // 添加流转记录
-        complaintFlowService.createFlow(dto.getComplaintId(), 1, loginUserInfoVO.getUserId());
+        complaintFlowService.createFlow(dto.getComplaintId(), superiorOrgId, accountLevel, 1, loginUserInfoVO.getUserId());
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void reportAudit(ComplaintReporAuditDTO complaintReporAuditDTO, LoginUserInfoVO loginUserInfoVO) {
-        complaintAuditRecordService.audit(complaintReporAuditDTO.getId(), loginUserInfoVO.getUserId(),
+        Optional<SystemUser> systemUserByPhone = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone());
+        if (!systemUserByPhone.isPresent()) {
+            throw new ServiceException("无权审核");
+        }
+        //查询上报审核记录
+        ComplaintAuditRecord complaintAuditRecord = complaintAuditRecordService.lambdaQuery().eq(ComplaintAuditRecord::getComplaintId, complaintReporAuditDTO.getId())
+                .eq(ComplaintAuditRecord::getAuditType, 2)
+                .eq(ComplaintAuditRecord::getLatestFlag, true)
+                .last("LIMIT 1").one();
+        if (Objects.isNull(complaintAuditRecord)) {
+            throw new ServiceException("上报申请记录不存在");
+        }
+        //查询待审核诉求
+        complaintAuditRecordService.audit(complaintAuditRecord,  loginUserInfoVO.getUserId(),
                 complaintReporAuditDTO.getAuditResult(), complaintReporAuditDTO.getRejectReason());
 
         // 添加流转记录
-        ComplaintAuditRecord complaintAuditRecord = complaintAuditRecordService.getById(complaintReporAuditDTO.getId());
-        complaintFlowService.createFlow(complaintAuditRecord.getComplaintId(), 0, loginUserInfoVO.getUserId());
+        Complaint complaint = getById(complaintAuditRecord.getComplaintId());
+
+        Long superiorId = null;
+        if (Objects.nonNull(complaint)) {
+            superiorId = complaint.getCreateBy();
+            if (Objects.nonNull(complaint.getSuperiorId())) {
+                superiorId = complaint.getSuperiorId();
+            }
+            complaintFlowService.createFlow(complaintAuditRecord.getComplaintId(), superiorId,complaint.getReportType(),0, loginUserInfoVO.getUserId());
+        }
+        //审核通过后,将诉求转移给上级
+        if (complaintAuditRecord.getAuditType().equals(2) && complaintAuditRecord.getAuditStatus().equals(1)){
+            SystemUser systemUser = systemUserByPhone.get();
+                switch (systemUser.getAccountLevel()) {
+                    case 1:
+                        superiorId = 510400L;//默认市级
+                        break;
+                    case 2:
+                        superiorId = Long.parseLong(systemUser.getDistrictsCode());
+                        break;
+                    case 3:
+                        superiorId = Long.parseLong(systemUser.getStreetId());
+                        break;
+                    case 4:
+                        superiorId = systemUser.getCommunityId();
+                        break;
+                }
+            }
+            complaint.setSuperiorId(superiorId);
+            updateById(complaint );
     }
 
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void saveDelay(ComplaintDelayDTO dto, LoginUserInfoVO loginUserInfoVO) {
         // 标记最新
         complaintAuditRecordService.update(new LambdaUpdateWrapper<ComplaintAuditRecord>()
                 .eq(ComplaintAuditRecord::getComplaintId, dto.getComplaintId())
                 .set(ComplaintAuditRecord::getLatestFlag,false));
+        SystemUser systemUser = systemUserService.getSystemUserByPhone(loginUserInfoVO.getPhone()).orElse(null);
+        Long superiorId;
+        int reportType;
+        if (systemUser == null) {
+            superiorId = loginUserInfoVO.getCommunityId();
+            if (Objects.isNull(superiorId)){
+                throw new ServiceException("上报失败,请绑定社区");
+            }
+            reportType = ReportTypeEnum.COMMUNITY.getCode();
+        } else {
+            int accountLevel = systemUser.getAccountLevel(); // 改为基本类型
+            if (accountLevel == 1) {
+                throw new ServiceException("市级账号,无法上报!");
+            }
+            reportType = accountLevel + 1;
+
+            // 使用基本类型比较并补充默认分支
+            if (accountLevel == ReportTypeEnum.COMMUNITY.getCode()) {
+                superiorId = Long.parseLong(systemUser.getStreetId());
+            } else if (accountLevel == ReportTypeEnum.STREET.getCode()) {
+                superiorId = Long.parseLong(systemUser.getDistrictsCode());
+            } else if (accountLevel == ReportTypeEnum.DISTRICT.getCode()) {
+                superiorId = 510400L; // 攀枝花市
+            } else {
+                // 处理未预期的账号等级
+                throw new ServiceException("未知的账号等级");
+            }
+        }
+
+        Complaint complaint = getById(dto.getComplaintId());
+        complaint.setReportType(reportType);
+        complaint.setSuperiorId(superiorId);
+        updateById(complaint);
         // 添加审核记录
-        complaintAuditRecordService.createComplaintAuditRecord(dto.getComplaintId(), 1, dto.getComment(), loginUserInfoVO.getUserId());
+        complaintAuditRecordService.createComplaintAuditRecord(dto.getComplaintId(), 1, dto.getComment(), loginUserInfoVO, systemUser);
     }
 
 
     @Override
     public void delayAudit(ComplaintDelayAuditDTO complaintDelayAuditDTO, LoginUserInfoVO loginUserInfoVO) {
-        complaintAuditRecordService.audit(complaintDelayAuditDTO.getId(), loginUserInfoVO.getUserId(),
+        //查询待审核诉求
+        ComplaintAuditRecord complaintAuditRecord = complaintAuditRecordService.lambdaQuery().eq(ComplaintAuditRecord::getComplaintId, complaintDelayAuditDTO.getComplaintId())
+                .eq(ComplaintAuditRecord::getAuditType, 1)
+                .eq(ComplaintAuditRecord::getAuditStatus, 0)
+                .eq(ComplaintAuditRecord::getLatestFlag, true)
+                .last("LIMIT 1").one();
+        if (Objects.isNull(complaintAuditRecord)) {
+            throw new ServiceException("诉求延期申请不存在");
+        }
+        complaintAuditRecordService.audit(complaintAuditRecord, loginUserInfoVO.getUserId(),
                 complaintDelayAuditDTO.getAuditResult(), complaintDelayAuditDTO.getRejectReason());
     }
 
@@ -330,16 +428,16 @@
         SystemUser adminUser = systemUserService.getOne(new LambdaQueryWrapper<SystemUser>()
                 .eq(SystemUser::getPhone, phone)
                 .eq(SystemUser::getIsAdmin, 1)
-                .eq(SystemUser::getStatus, 3)
+                .ne(SystemUser::getStatus, 3)
                 .last("LIMIT 1"));
 
         if (adminUser == null) {
             throw new ServiceException("无权下派");
         }
         int accountLevel = adminUser.getAccountLevel(); // 改为基本类型
-        if (accountLevel == 1) {
+      /*  if (accountLevel == 1) {
             throw new ServiceException("市级账号,无法上报!");
-        }
+        }*/
 
         // 使用基本类型比较并补充默认分支
         List<DispatchVO> dispatchVOList = new ArrayList<>();
@@ -361,7 +459,7 @@
             }
         } else if (accountLevel == ReportTypeEnum.CITY.getCode()) {
             List<BcRegion> list = bcRegionService.list(new LambdaQueryWrapper<BcRegion>()
-                    .eq(BcRegion::getHierarchyOrder, 3));
+                    .eq(BcRegion::getHierarchyOrder, 3).eq(BcRegion::getParentId, 510400));//获取攀枝花市下的区县
             for (BcRegion region : list) {
                 DispatchVO dispatchVO = new DispatchVO();
                 dispatchVO.setId(Long.valueOf(region.getRegionCode()));

--
Gitblit v1.7.1