Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

wanglt 4 месяцев назад
Родитель
Сommit
dd2fb4dd2b

+ 8 - 0
ygtx-gxt/src/main/java/com/ygtx/gxt/service/IGxtMonthFanInspectionService.java

@@ -27,6 +27,14 @@ public interface IGxtMonthFanInspectionService
      */
      */
     public List<GxtMonthFanInspection> selectGxtMonthFanInspectionList(GxtMonthFanInspection gxtMonthFanInspection);
     public List<GxtMonthFanInspection> selectGxtMonthFanInspectionList(GxtMonthFanInspection gxtMonthFanInspection);
 
 
+    /**
+     * 查询月度场站风机类型工单列表(用于新增)
+     * 
+     * @param gxtMonthFanInspection 月度场站风机类型工单
+     * @return 月度场站风机类型工单集合
+     */
+    public List<GxtMonthFanInspection> selectGxtMonthFanInspectionListByAdd(GxtMonthFanInspection gxtMonthFanInspection);
+
     /**
     /**
      * 新增月度场站风机类型工单
      * 新增月度场站风机类型工单
      * 
      * 

+ 8 - 0
ygtx-gxt/src/main/java/com/ygtx/gxt/service/IGxtMonthRepairProjectService.java

@@ -27,6 +27,14 @@ public interface IGxtMonthRepairProjectService
      */
      */
     public List<GxtMonthRepairProject> selectGxtMonthRepairProjectList(GxtMonthRepairProject gxtMonthRepairProject);
     public List<GxtMonthRepairProject> selectGxtMonthRepairProjectList(GxtMonthRepairProject gxtMonthRepairProject);
 
 
+    /**
+     * 查询月度场站维修项目工单列表(用于新增)
+     * 
+     * @param gxtMonthRepairProject 月度场站维修项目工单
+     * @return 月度场站维修项目工单集合
+     */
+    public List<GxtMonthRepairProject> selectGxtMonthRepairProjectListByAdd(GxtMonthRepairProject gxtMonthRepairProject);
+
     /**
     /**
      * 新增月度场站维修项目工单
      * 新增月度场站维修项目工单
      * 
      * 

+ 12 - 0
ygtx-gxt/src/main/java/com/ygtx/gxt/service/impl/GxtMonthFanInspectionServiceImpl.java

@@ -43,6 +43,18 @@ public class GxtMonthFanInspectionServiceImpl implements IGxtMonthFanInspectionS
         return gxtMonthFanInspectionMapper.selectGxtMonthFanInspectionList(gxtMonthFanInspection);
         return gxtMonthFanInspectionMapper.selectGxtMonthFanInspectionList(gxtMonthFanInspection);
     }
     }
 
 
+    /**
+     * 查询月度场站风机类型工单列表(用于新增)
+     * 
+     * @param gxtMonthFanInspection 月度场站风机类型工单
+     * @return 月度场站风机类型工单集合
+     */
+    @Override
+    public List<GxtMonthFanInspection> selectGxtMonthFanInspectionListByAdd(GxtMonthFanInspection gxtMonthFanInspection)
+    {
+        return gxtMonthFanInspectionMapper.selectGxtMonthFanInspectionListByAdd(gxtMonthFanInspection);
+    }
+
     /**
     /**
      * 新增月度场站风机类型工单
      * 新增月度场站风机类型工单
      * 
      * 

+ 12 - 0
ygtx-gxt/src/main/java/com/ygtx/gxt/service/impl/GxtMonthRepairProjectServiceImpl.java

@@ -43,6 +43,18 @@ public class GxtMonthRepairProjectServiceImpl implements IGxtMonthRepairProjectS
         return gxtMonthRepairProjectMapper.selectGxtMonthRepairProjectList(gxtMonthRepairProject);
         return gxtMonthRepairProjectMapper.selectGxtMonthRepairProjectList(gxtMonthRepairProject);
     }
     }
 
 
+    /**
+     * 查询月度场站维修项目工单列表(用于新增)
+     * 
+     * @param gxtMonthRepairProject 月度场站维修项目工单
+     * @return 月度场站维修项目工单集合
+     */
+    @Override
+    public List<GxtMonthRepairProject> selectGxtMonthRepairProjectListByAdd(GxtMonthRepairProject gxtMonthRepairProject)
+    {
+        return gxtMonthRepairProjectMapper.selectGxtMonthRepairProjectListByAdd(gxtMonthRepairProject);
+    }
+
     /**
     /**
      * 新增月度场站维修项目工单
      * 新增月度场站维修项目工单
      * 
      * 

+ 517 - 1
ygtx-gxt/src/main/java/com/ygtx/gxt/service/impl/GxtOrderScoreServiceImpl.java

@@ -1,12 +1,15 @@
 package com.ygtx.gxt.service.impl;
 package com.ygtx.gxt.service.impl;
 
 
 import com.ygtx.common.constant.Constants;
 import com.ygtx.common.constant.Constants;
+import com.ygtx.common.core.domain.entity.SysDept;
 import com.ygtx.common.utils.DateUtils;
 import com.ygtx.common.utils.DateUtils;
 import com.ygtx.common.utils.SecurityUtils;
 import com.ygtx.common.utils.SecurityUtils;
 import com.ygtx.common.utils.StringUtils;
 import com.ygtx.common.utils.StringUtils;
+import com.ygtx.common.utils.spring.SpringUtils;
 import com.ygtx.gxt.domain.*;
 import com.ygtx.gxt.domain.*;
 import com.ygtx.gxt.mapper.GxtOrderScoreMapper;
 import com.ygtx.gxt.mapper.GxtOrderScoreMapper;
 import com.ygtx.gxt.service.*;
 import com.ygtx.gxt.service.*;
+import com.ygtx.system.mapper.SysDeptMapper;
 import com.ygtx.system.service.ISysConfigService;
 import com.ygtx.system.service.ISysConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -18,6 +21,7 @@ import com.ygtx.system.mapper.SysUserMapper;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
@@ -52,8 +56,23 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
     @Autowired
     @Autowired
     private IGxtRepairOrderFlowService repairOrderFlowService;
     private IGxtRepairOrderFlowService repairOrderFlowService;
 
 
+    @Autowired
+    private IGxtMonthRepairProjectService gxtMonthRepairProjectService;
+    
+    @Autowired
+    private IGxtMonthFanInspectionService gxtMonthFanInspectionService;
+    
+    @Autowired
+    private IGxtUserScoreService gxtUserScoreService;
+
     @Autowired
     @Autowired
     private IGxtWorkOrderFlowService gxtWorkOrderFlowService;
     private IGxtWorkOrderFlowService gxtWorkOrderFlowService;
+    
+    @Autowired
+    private IGxtMonthScoreService gxtMonthScoreService;
+
+    @Autowired
+    private SysDeptMapper sysDeptMapper;
 
 
     /**
     /**
      * 查询合并的工单列表(维修工单和维保工单)
      * 查询合并的工单列表(维修工单和维保工单)
@@ -654,7 +673,8 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
                     flow.setActionRemark("系统自动归档工单");
                     flow.setActionRemark("系统自动归档工单");
                     repairOrderFlowService.insertGxtRepairOrderFlow(flow);
                     repairOrderFlowService.insertGxtRepairOrderFlow(flow);
                 }
                 }
-
+                // 更新月度统计数据
+                updateMonthlyScoreData(orderScoreInfo);
                 return result;
                 return result;
             } else if (orderScoreInfo.getOrderType() == 2) {
             } else if (orderScoreInfo.getOrderType() == 2) {
                 // 维保工单复评
                 // 维保工单复评
@@ -792,6 +812,10 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
                     flow.setActionRemark("系统自动归档工单");
                     flow.setActionRemark("系统自动归档工单");
                     repairOrderFlowService.insertGxtRepairOrderFlow(flow);
                     repairOrderFlowService.insertGxtRepairOrderFlow(flow);
                 }
                 }
+                
+                // 更新月度统计数据(仅更新用户得分)
+                updateMonthlyScoreDataForFinalEval(orderScoreInfo);
+                
                 return 1;
                 return 1;
             } else if (orderScoreInfo.getOrderType() == 2) {
             } else if (orderScoreInfo.getOrderType() == 2) {
                 // 维保工单终评
                 // 维保工单终评
@@ -859,6 +883,10 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
                     flow.setActionRemark("系统自动归档工单");
                     flow.setActionRemark("系统自动归档工单");
                     gxtWorkOrderFlowService.insertGxtWorkOrderFlow(flow);
                     gxtWorkOrderFlowService.insertGxtWorkOrderFlow(flow);
                 }
                 }
+                
+                // 更新月度统计数据
+                updateMonthlyScoreData(orderScoreInfo);
+                
                 return 1;
                 return 1;
             }
             }
             return 0;
             return 0;
@@ -867,6 +895,494 @@ public class GxtOrderScoreServiceImpl implements IGxtOrderScoreService {
         }
         }
     }
     }
 
 
+    /**
+     * 更新月度统计数据
+     * @param orderScoreInfo 工单对象
+     */
+    private void updateMonthlyScoreData(OrderScoreInfo orderScoreInfo) {
+        try {
+            if (orderScoreInfo.getOrderType() == 1) {
+                // 维修工单
+                GxtRepairOrder order = gxtRepairOrderService.selectGxtRepairOrderById(orderScoreInfo.getId());
+                // 获取工单完成时间所在的月份
+                if (order.getOccurTime() != null) {
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+                    String monthPeriod = sdf.format(order.getOccurTime());
+
+                    // 获取场站ID
+                    Long deptId = order.getPcsStationPid();
+
+                    // 获取月度统计信息 - 使用简单查询替代复杂的 getGxtMonthScoreByParams 方法
+                    GxtMonthScore queryScore = new GxtMonthScore();
+                    queryScore.setDeptId(deptId);
+                    queryScore.setMonthPeriod(monthPeriod);
+                    List<GxtMonthScore> scoreList = gxtMonthScoreService.selectGxtMonthScoreList(queryScore);
+                    GxtMonthScore monthScore = null;
+                    if (!scoreList.isEmpty()) {
+                        monthScore = scoreList.get(0);
+                    }
+
+                    if (monthScore == null) {
+                        // 新增monthScore
+                        monthScore = new GxtMonthScore();
+                        monthScore.setDeptId(deptId);
+                        monthScore.setMonthPeriod(monthPeriod);
+                        monthScore.setStatus(0); // 初始状态
+                        monthScore.setPersionId(SecurityUtils.getUserId());
+                        monthScore.setCreateBy(SecurityUtils.getUsername());
+                        monthScore.setCreateTime(new Date());
+                        gxtMonthScoreService.insertGxtMonthScore(monthScore);
+                        // 直接查询刚插入的记录
+                        queryScore = new GxtMonthScore();
+                        queryScore.setDeptId(deptId);
+                        queryScore.setMonthPeriod(monthPeriod);
+                        scoreList = gxtMonthScoreService.selectGxtMonthScoreList(queryScore);
+                        if (!scoreList.isEmpty()) {
+                            monthScore = scoreList.get(0);
+                        }
+                    }
+                    // 更新月度场站维修项目工单统计
+                    updateMonthRepairProject(monthScore, order);
+
+                    // 更新用户评分统计
+                    updateUserScores(monthScore, order);
+                }
+            } else if (orderScoreInfo.getOrderType() == 2) {
+                // 维保工单
+                GxtWorkOrder order = gxtWorkOrderService.selectGxtWorkOrderById(orderScoreInfo.getId());
+                // 获取工单完成时间所在的月份
+                if (order.getCreateTime() != null) {
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+                    String monthPeriod = sdf.format(order.getCreateTime());
+
+                    // 获取场站ID
+                    Long deptId = order.getPcsStationPid();
+
+                    // 获取月度统计信息 - 使用简单查询替代复杂的 getGxtMonthScoreByParams 方法
+                    GxtMonthScore queryScore = new GxtMonthScore();
+                    queryScore.setDeptId(deptId);
+                    queryScore.setMonthPeriod(monthPeriod);
+                    List<GxtMonthScore> scoreList = gxtMonthScoreService.selectGxtMonthScoreList(queryScore);
+                    GxtMonthScore monthScore = null;
+                    if (!scoreList.isEmpty()) {
+                        monthScore = scoreList.get(0);
+                    }
+
+                    if (monthScore == null) {
+                        // 新增monthScore
+                        monthScore = new GxtMonthScore();
+                        monthScore.setDeptId(deptId);
+                        monthScore.setMonthPeriod(monthPeriod);
+                        monthScore.setStatus(0); // 初始状态
+                        monthScore.setPersionId(SecurityUtils.getUserId());
+                        monthScore.setCreateBy(SecurityUtils.getUsername());
+                        monthScore.setCreateTime(new Date());
+                        gxtMonthScoreService.insertGxtMonthScore(monthScore);
+                        // 直接查询刚插入的记录
+                        queryScore = new GxtMonthScore();
+                        queryScore.setDeptId(deptId);
+                        queryScore.setMonthPeriod(monthPeriod);
+                        scoreList = gxtMonthScoreService.selectGxtMonthScoreList(queryScore);
+                        if (!scoreList.isEmpty()) {
+                            monthScore = scoreList.get(0);
+                        }
+                    }
+                    // 更新月度场站风机类型工单统计
+                    updateMonthFanInspection(monthScore, order);
+
+                    // 更新用户评分统计
+                    updateUserScores(monthScore, order);
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * 更新月度场站风机类型工单统计
+     * @param monthScore 月度统计信息
+     * @param order 工单对象
+     */
+    private void updateMonthFanInspection(GxtMonthScore monthScore, GxtWorkOrder order) {
+        try {
+            /*if (order.getItemCompletionFactorSum().compareTo(BigDecimal.ONE) < 0) {
+                return;
+            }*/
+            // 创建查询条件,查找与当前工单相关的风机检查类型统计
+            GxtMonthFanInspection queryFanInspection = new GxtMonthFanInspection();
+            queryFanInspection.setMonthScoreId(monthScore.getId());
+            queryFanInspection.setDeptId(order.getPcsStationPid());
+            queryFanInspection.setMonthPeriod(monthScore.getMonthPeriod());
+            // 查询所有该月度统计下的风机检查类型统计记录
+            List<GxtMonthFanInspection> fanInspections = gxtMonthFanInspectionService.selectGxtMonthFanInspectionList(queryFanInspection);
+            
+            // 在结果中查找匹配当前工单model和inspectionType的记录
+            GxtMonthFanInspection matchedRecord = null;
+            for (GxtMonthFanInspection fanInspection : fanInspections) {
+                if (order.getModel() != null && order.getModel().equals(fanInspection.getModel()) 
+                    && order.getInspectionType() != null && order.getInspectionType().equals(fanInspection.getInspectionTypeId())) {
+                    matchedRecord = fanInspection;
+                    break;
+                }
+            }
+            
+            if (matchedRecord != null) {
+                // 如果存在记录,则更新设备数量和计算得分
+                matchedRecord.setDeviceCount(matchedRecord.getDeviceCount() != null ? matchedRecord.getDeviceCount() + 1 : 1);
+                
+                // 如果有项目分值,则重新计算得分
+                if (matchedRecord.getFanInspectionScore() != null) {
+                    BigDecimal calculatedScore = matchedRecord.getFanInspectionScore()
+                        .multiply(new BigDecimal(matchedRecord.getDeviceCount()));
+                    matchedRecord.setCalculatedScore(calculatedScore);
+                }
+                matchedRecord.setUpdateBy(SecurityUtils.getUsername());
+                matchedRecord.setUpdateTime(new Date());
+                gxtMonthFanInspectionService.updateGxtMonthFanInspection(matchedRecord);
+            } else {
+                // 如果不存在记录,则通过selectGxtMonthFanInspectionListByAdd获取初始化数据后插入
+                
+                // 构造查询条件以从数据库获取待插入的数据
+                GxtMonthFanInspection templateQuery = new GxtMonthFanInspection();
+                templateQuery.setDeptId(order.getPcsStationPid());
+                templateQuery.setMonthPeriod(monthScore.getMonthPeriod());
+                
+                // 使用selectGxtMonthFanInspectionListByAdd方法获取模板数据
+                List<GxtMonthFanInspection> templateList = gxtMonthFanInspectionService.selectGxtMonthFanInspectionListByAdd(templateQuery);
+
+                // 在templateList中查找与当前工单匹配的记录
+                for (GxtMonthFanInspection templateItem : templateList) {
+                    if (order.getModel() != null && order.getModel().equals(templateItem.getModel()) 
+                        && order.getInspectionType() != null && order.getInspectionType().equals(templateItem.getInspectionTypeId())) {
+                        SysDept dept = sysDeptMapper.selectDeptById(order.getPcsStationPid());
+                        // 设置关联的月度统计ID和其他必要字段
+                        templateItem.setMonthScoreId(monthScore.getId());
+                        templateItem.setDeptId(order.getPcsStationPid());
+                        templateItem.setDeptName(dept.getDeptName());
+                        templateItem.setMonthPeriod(monthScore.getMonthPeriod());
+                        templateItem.setStatus(0);
+                        templateItem.setCreateBy(SecurityUtils.getUsername());
+                        templateItem.setCreateTime(new Date());
+                        // 插入新记录
+                        gxtMonthFanInspectionService.insertGxtMonthFanInspection(templateItem);
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * 更新月度场站维修项目工单统计
+     * @param monthScore 月度统计信息
+     * @param order 工单对象
+     */
+    private void updateMonthRepairProject(GxtMonthScore monthScore, GxtRepairOrder order) {
+        try {
+            // 创建查询条件,查找与当前工单相关的维修项目统计
+            GxtMonthRepairProject queryRepairProject = new GxtMonthRepairProject();
+            queryRepairProject.setMonthScoreId(monthScore.getId());
+            queryRepairProject.setDeptId(order.getPcsStationPid());
+            queryRepairProject.setMaintenanceType(order.getMaintenanceType());
+            queryRepairProject.setMonthPeriod(monthScore.getMonthPeriod());
+            // 查询所有该月度统计下的维修项目统计记录
+            List<GxtMonthRepairProject> repairProjects = gxtMonthRepairProjectService.selectGxtMonthRepairProjectList(queryRepairProject);
+
+            GxtMonthRepairProject matchedRecord = null;
+            
+            if (repairProjects != null && !repairProjects.isEmpty()) {
+                matchedRecord = repairProjects.get(0);
+                // 如果存在记录,则更新工单数量和计算得分
+                matchedRecord.setOrderCount(matchedRecord.getOrderCount() != null ? matchedRecord.getOrderCount() + 1 : 1);
+                
+                // 如果有项目分值,则重新计算得分
+                if (matchedRecord.getProjectScore() != null) {
+                    BigDecimal calculatedScore = matchedRecord.getProjectScore()
+                        .multiply(new BigDecimal(matchedRecord.getOrderCount()));
+                    matchedRecord.setCalculatedScore(calculatedScore);
+                }
+                matchedRecord.setUpdateBy(SecurityUtils.getUsername());
+                matchedRecord.setUpdateTime(new Date());
+                gxtMonthRepairProjectService.updateGxtMonthRepairProject(matchedRecord);
+            } else {
+                // 如果不存在记录,则通过selectGxtMonthRepairProjectListByAdd获取初始化数据后插入
+                
+                // 构造查询条件以从数据库获取待插入的数据
+                GxtMonthRepairProject templateQuery = new GxtMonthRepairProject();
+                templateQuery.setDeptId(order.getPcsStationPid());
+                templateQuery.setMonthPeriod(monthScore.getMonthPeriod());
+                
+                // 使用selectGxtMonthRepairProjectListByAdd方法获取模板数据
+                List<GxtMonthRepairProject> templateList = gxtMonthRepairProjectService.selectGxtMonthRepairProjectListByAdd(templateQuery);
+
+                // 在templateList中查找与当前工单匹配的记录
+                for (GxtMonthRepairProject templateItem : templateList) {
+                    if (order.getMaintenanceType() != null && order.getMaintenanceType().equals(templateItem.getMaintenanceType())) {
+                        SysDept dept = sysDeptMapper.selectDeptById(order.getPcsStationPid());
+                        // 设置关联的月度统计ID和其他必要字段
+                        templateItem.setMonthScoreId(monthScore.getId());
+                        templateItem.setDeptId(order.getPcsStationPid());
+                        templateItem.setDeptName(dept.getDeptName());
+                        templateItem.setMonthPeriod(monthScore.getMonthPeriod());
+                        templateItem.setCreateBy(SecurityUtils.getUsername());
+                        templateItem.setCreateTime(new Date());
+                        // 插入新记录
+                        gxtMonthRepairProjectService.insertGxtMonthRepairProject(templateItem);
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    
+    /**
+     * 更新用户评分统计(维修工单)
+     * @param monthScore 月度统计信息
+     * @param order 工单对象
+     */
+    private void updateUserScores(GxtMonthScore monthScore, GxtRepairOrder order) {
+        try {
+            // 获取参与该工单的所有人员
+            List<GxtRepairOrderPerson> orderPersons = gxtRepairOrderService.selectRepairOrderPersonListByOrderId(order.getId());
+            
+            // 获取现有的用户评分统计列表
+            GxtUserScore queryUserScore = new GxtUserScore();
+            queryUserScore.setMonthScoreId(monthScore.getId());
+            List<GxtUserScore> userScores = gxtUserScoreService.selectGxtUserScoreList(queryUserScore);
+            
+            if (userScores != null && !orderPersons.isEmpty()) {
+                // 遍历工单中的每个人员
+                for (GxtRepairOrderPerson orderPerson : orderPersons) {
+                    boolean found = false;
+                    // 在月度统计中查找该用户
+                    for (GxtUserScore userScore : userScores) {
+                        // 使用userName进行匹配
+                        if (orderPerson.getNickName() != null && orderPerson.getNickName().equals(userScore.getUserName())) {
+                            // 更新维修工单总分
+                            BigDecimal repairScore = (orderPerson.getScore() != null) ?
+                                 orderPerson.getScore(): BigDecimal.ZERO;
+                            
+                            BigDecimal currentRepairTotal = (userScore.getRepairTotalScore() != null) ? 
+                                userScore.getRepairTotalScore() : BigDecimal.ZERO;
+                                
+                            userScore.setRepairTotalScore(currentRepairTotal.add(repairScore));
+                            
+                            // 更新最终评分
+                            BigDecimal maintenanceScore = (userScore.getMaintenanceTotalScore() != null) ? 
+                                userScore.getMaintenanceTotalScore() : BigDecimal.ZERO;
+                                
+                            BigDecimal finalScore = maintenanceScore.add(currentRepairTotal.add(repairScore));
+                            userScore.setFinalScore(finalScore);
+                            userScore.setUpdateBy(SecurityUtils.getUsername());
+                            userScore.setUpdateTime(new Date());
+                            gxtUserScoreService.updateGxtUserScore(userScore);
+                            found = true;
+                            break;
+                        }
+                    }
+                    
+                    // 如果没找到用户记录,则创建新记录
+                    if (!found) {
+                        GxtUserScore newUserScore = new GxtUserScore();
+                        newUserScore.setMonthScoreId(monthScore.getId());
+                        newUserScore.setUserName(orderPerson.getNickName());
+                        newUserScore.setMonthPeriod(monthScore.getMonthPeriod());
+                        
+                        // 设置维修工单得分
+                        BigDecimal repairScore = (orderPerson.getScore() != null) ?
+                                orderPerson.getScore() : BigDecimal.ZERO;
+                        newUserScore.setRepairTotalScore(repairScore);
+                        
+                        // 维保得分默认为0
+                        newUserScore.setMaintenanceTotalScore(BigDecimal.ZERO);
+                        newUserScore.setFinalScore(repairScore);
+                        newUserScore.setStatus(0);
+                        newUserScore.setCreateBy(SecurityUtils.getUsername());
+                        newUserScore.setCreateTime(new Date());
+                        // 插入新记录
+                        gxtUserScoreService.insertGxtUserScore(newUserScore);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * 更新用户评分统计(维保工单)
+     * @param monthScore 月度统计信息
+     * @param order 工单对象
+     */
+    private void updateUserScores(GxtMonthScore monthScore, GxtWorkOrder order) {
+        try {
+            // 获取参与该工单的所有人员
+            List<GxtWorkOrderPerson> orderPersons = gxtWorkOrderService.selectWorkOrderPersonListByOrderId(order.getId());
+            
+            // 获取现有的用户评分统计列表
+            GxtUserScore queryUserScore = new GxtUserScore();
+            queryUserScore.setMonthScoreId(monthScore.getId());
+            List<GxtUserScore> userScores = gxtUserScoreService.selectGxtUserScoreList(queryUserScore);
+            
+            if (userScores != null && !orderPersons.isEmpty()) {
+                // 遍历工单中的每个人员
+                for (GxtWorkOrderPerson orderPerson : orderPersons) {
+                    boolean found = false;
+                    // 在月度统计中查找该用户
+                    for (GxtUserScore userScore : userScores) {
+                        // 使用userName进行匹配
+                        if (orderPerson.getNickName() != null && orderPerson.getNickName().equals(userScore.getUserName())) {
+                            // 更新维保工单总分
+                            BigDecimal maintenanceScore = (orderPerson.getScore() != null) ?
+                                    orderPerson.getScore() : BigDecimal.ZERO;
+                            
+                            BigDecimal currentMaintenanceTotal = (userScore.getMaintenanceTotalScore() != null) ? 
+                                userScore.getMaintenanceTotalScore() : BigDecimal.ZERO;
+                                
+                            userScore.setMaintenanceTotalScore(currentMaintenanceTotal.add(maintenanceScore));
+                            
+                            // 更新最终评分
+                            BigDecimal repairScore = (userScore.getRepairTotalScore() != null) ? 
+                                userScore.getRepairTotalScore() : BigDecimal.ZERO;
+                                
+                            BigDecimal finalScore = repairScore.add(currentMaintenanceTotal.add(maintenanceScore));
+                            userScore.setFinalScore(finalScore);
+                            userScore.setUpdateBy(SecurityUtils.getUsername());
+                            userScore.setUpdateTime(new Date());
+                            gxtUserScoreService.updateGxtUserScore(userScore);
+                            found = true;
+                            break;
+                        }
+                    }
+                    
+                    // 如果没找到用户记录,则创建新记录
+                    if (!found) {
+                        GxtUserScore newUserScore = new GxtUserScore();
+                        newUserScore.setMonthScoreId(monthScore.getId());
+                        newUserScore.setUserName(orderPerson.getNickName());
+                        newUserScore.setMonthPeriod(monthScore.getMonthPeriod());
+                        
+                        // 设置维保工单得分
+                        BigDecimal maintenanceScore = (orderPerson.getScore() != null) ?
+                                orderPerson.getScore() : BigDecimal.ZERO;
+                        newUserScore.setMaintenanceTotalScore(maintenanceScore);
+                        
+                        // 维修得分默认为0
+                        newUserScore.setRepairTotalScore(BigDecimal.ZERO);
+                        newUserScore.setFinalScore(maintenanceScore);
+                        newUserScore.setStatus(0);
+                        newUserScore.setCreateBy(SecurityUtils.getUsername());
+                        newUserScore.setCreateTime(new Date());
+                        // 插入新记录
+                        gxtUserScoreService.insertGxtUserScore(newUserScore);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /**
+     * 更新月度统计数据(终评专用版本,仅更新用户得分)
+     * @param orderScoreInfo 工单对象
+     */
+    private void updateMonthlyScoreDataForFinalEval(OrderScoreInfo orderScoreInfo) {
+        try {
+            if (orderScoreInfo.getOrderType() == 1) {
+                // 维修工单
+                GxtRepairOrder order = gxtRepairOrderService.selectGxtRepairOrderById(orderScoreInfo.getId());
+                // 获取工单完成时间所在的月份
+                if (order.getOccurTime() != null) {
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+                    String monthPeriod = sdf.format(order.getOccurTime());
+
+                    // 获取场站ID
+                    Long deptId = order.getPcsStationPid();
+
+                    // 获取月度统计信息
+                    GxtMonthScore queryScore = new GxtMonthScore();
+                    queryScore.setDeptId(deptId);
+                    queryScore.setMonthPeriod(monthPeriod);
+                    List<GxtMonthScore> scoreList = gxtMonthScoreService.selectGxtMonthScoreList(queryScore);
+                    GxtMonthScore monthScore = null;
+                    if (!scoreList.isEmpty()) {
+                        monthScore = scoreList.get(0);
+                    }
+
+                    if (monthScore != null) {
+                        // 仅更新用户评分统计(基于reviewScore和finalScore的差值)
+                        updateUserScoresForFinalEval(monthScore, order);
+                    }
+                }
+            } else if (orderScoreInfo.getOrderType() == 2) {
+                // 维保工单保持不变
+                updateMonthlyScoreData(orderScoreInfo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 更新用户评分统计(终评专用版本,基于reviewScore和finalScore的差值)
+     * @param monthScore 月度统计信息
+     * @param order 工单对象
+     */
+    private void updateUserScoresForFinalEval(GxtMonthScore monthScore, GxtRepairOrder order) {
+        try {
+            // 获取参与该工单的所有人员(当前数据库中的最新数据)
+            List<GxtRepairOrderPerson> orderPersons = gxtRepairOrderService.selectRepairOrderPersonListByOrderId(order.getId());
+            
+            // 获取现有的用户评分统计列表
+            GxtUserScore queryUserScore = new GxtUserScore();
+            queryUserScore.setMonthScoreId(monthScore.getId());
+            List<GxtUserScore> userScores = gxtUserScoreService.selectGxtUserScoreList(queryUserScore);
+            
+            if (userScores != null && !orderPersons.isEmpty()) {
+                // 遍历工单中的每个人员
+                for (GxtRepairOrderPerson orderPerson : orderPersons) {
+                    // 计算差值:finalScore - reviewScore
+                    Double reviewScore = orderPerson.getReviewScore() != null ? orderPerson.getReviewScore() : 0.0;
+                    Double finalScore = orderPerson.getFinalScore() != null ? orderPerson.getFinalScore() : 0.0;
+                    BigDecimal scoreDiff = new BigDecimal(String.valueOf(finalScore - reviewScore));
+                    
+                    // 在月度统计中查找该用户
+                    for (GxtUserScore userScore : userScores) {
+                        // 使用userName进行匹配
+                        if (orderPerson.getNickName() != null && orderPerson.getNickName().equals(userScore.getUserName())) {
+                            // 更新维修工单总分(应用差值)
+                            BigDecimal currentRepairTotal = (userScore.getRepairTotalScore() != null) ? 
+                                userScore.getRepairTotalScore() : BigDecimal.ZERO;
+                                
+                            userScore.setRepairTotalScore(currentRepairTotal.add(scoreDiff));
+                            
+                            // 更新最终评分
+                            BigDecimal maintenanceScore = (userScore.getMaintenanceTotalScore() != null) ? 
+                                userScore.getMaintenanceTotalScore() : BigDecimal.ZERO;
+                                
+                            BigDecimal finalScoreTotal = maintenanceScore.add(currentRepairTotal).add(scoreDiff);
+                            userScore.setFinalScore(finalScoreTotal);
+                            userScore.setUpdateBy(SecurityUtils.getUsername());
+                            userScore.setUpdateTime(new Date());
+                            gxtUserScoreService.updateGxtUserScore(userScore);
+                            break;
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
     /**
     /**
      * 保存确认信息
      * 保存确认信息
      *
      *

+ 70 - 70
ygtx-gxt/src/main/resources/mapper/gxt/GxtMonthFanInspectionMapper.xml

@@ -66,87 +66,87 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 LEFT JOIN sys_user u ON wo.accept_user_id = u.user_id
                 LEFT JOIN sys_user u ON wo.accept_user_id = u.user_id
         WHERE
         WHERE
             u.dept_id = #{deptId}
             u.dept_id = #{deptId}
-            AND wo.work_order_status='archived'
+            AND (wo.work_order_status='archived' or wo.scoring_status='to_archive')
             AND ((wo.create_time >= STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s')
             AND ((wo.create_time >= STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s')
                 AND wo.create_time <![CDATA[<]]> DATE_ADD(STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s'), INTERVAL 1 MONTH)
                 AND wo.create_time <![CDATA[<]]> DATE_ADD(STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s'), INTERVAL 1 MONTH)
             ) OR wo.is_deferred=1)
             ) OR wo.is_deferred=1)
-            AND wo.item_completion_factor_sum=1
+            <!-- AND wo.item_completion_factor_sum=1 -->
             AND (wo.repair_method IS NULL OR wo.repair_method != '2')
             AND (wo.repair_method IS NULL OR wo.repair_method != '2')
         GROUP BY
         GROUP BY
             sfi.id
             sfi.id
     </select>
     </select>
 
 
-    <select id="selectGxtMonthFanInspectionById" parameterType="Long" resultMap="GxtMonthFanInspectionResult">
-        <include refid="selectGxtMonthFanInspectionVo"/>
-        where id = #{id}
-    </select>
+<select id="selectGxtMonthFanInspectionById" parameterType="Long" resultMap="GxtMonthFanInspectionResult">
+    <include refid="selectGxtMonthFanInspectionVo"/>
+    where id = #{id}
+</select>
 
 
-    <insert id="insertGxtMonthFanInspection" parameterType="GxtMonthFanInspection" useGeneratedKeys="true" keyProperty="id">
-        insert into gxt_month_fan_inspection
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="monthScoreId != null">month_score_id,</if>
-            <if test="deptId != null">dept_id,</if>
-            <if test="deptName != null and deptName != ''">dept_name,</if>
-            <if test="fanInspectionId != null">fan_inspection_id,</if>
-            <if test="deviceCount != null">device_count,</if>
-            <if test="fanInspectionScore != null">fan_inspection_score,</if>
-            <if test="calculatedScore != null">calculated_score,</if>
-            <if test="monthPeriod != null and monthPeriod != ''">month_period,</if>
-            <if test="status != null">status,</if>
-            <if test="createBy != null and createBy != ''">create_by,</if>
-            <if test="createTime != null">create_time,</if>
-            <if test="updateBy != null and updateBy != ''">update_by,</if>
-            <if test="updateTime != null">update_time,</if>
-            <if test="remark != null">remark,</if>
-         </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="monthScoreId != null">#{monthScoreId},</if>
-            <if test="deptId != null">#{deptId},</if>
-            <if test="deptName != null and deptName != ''">#{deptName},</if>
-            <if test="fanInspectionId != null">#{fanInspectionId},</if>
-            <if test="deviceCount != null">#{deviceCount},</if>
-            <if test="fanInspectionScore != null">#{fanInspectionScore},</if>
-            <if test="calculatedScore != null">#{calculatedScore},</if>
-            <if test="monthPeriod != null and monthPeriod != ''">#{monthPeriod},</if>
-            <if test="status != null">#{status},</if>
-            <if test="createBy != null and createBy != ''">#{createBy},</if>
-            <if test="createTime != null">#{createTime},</if>
-            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
-            <if test="updateTime != null">#{updateTime},</if>
-            <if test="remark != null">#{remark},</if>
-         </trim>
-    </insert>
+<insert id="insertGxtMonthFanInspection" parameterType="GxtMonthFanInspection" useGeneratedKeys="true" keyProperty="id">
+    insert into gxt_month_fan_inspection
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+        <if test="monthScoreId != null">month_score_id,</if>
+        <if test="deptId != null">dept_id,</if>
+        <if test="deptName != null and deptName != ''">dept_name,</if>
+        <if test="fanInspectionId != null">fan_inspection_id,</if>
+        <if test="deviceCount != null">device_count,</if>
+        <if test="fanInspectionScore != null">fan_inspection_score,</if>
+        <if test="calculatedScore != null">calculated_score,</if>
+        <if test="monthPeriod != null and monthPeriod != ''">month_period,</if>
+        <if test="status != null">status,</if>
+        <if test="createBy != null and createBy != ''">create_by,</if>
+        <if test="createTime != null">create_time,</if>
+        <if test="updateBy != null and updateBy != ''">update_by,</if>
+        <if test="updateTime != null">update_time,</if>
+        <if test="remark != null">remark,</if>
+     </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+        <if test="monthScoreId != null">#{monthScoreId},</if>
+        <if test="deptId != null">#{deptId},</if>
+        <if test="deptName != null and deptName != ''">#{deptName},</if>
+        <if test="fanInspectionId != null">#{fanInspectionId},</if>
+        <if test="deviceCount != null">#{deviceCount},</if>
+        <if test="fanInspectionScore != null">#{fanInspectionScore},</if>
+        <if test="calculatedScore != null">#{calculatedScore},</if>
+        <if test="monthPeriod != null and monthPeriod != ''">#{monthPeriod},</if>
+        <if test="status != null">#{status},</if>
+        <if test="createBy != null and createBy != ''">#{createBy},</if>
+        <if test="createTime != null">#{createTime},</if>
+        <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
+        <if test="updateTime != null">#{updateTime},</if>
+        <if test="remark != null">#{remark},</if>
+     </trim>
+</insert>
 
 
-    <update id="updateGxtMonthFanInspection" parameterType="GxtMonthFanInspection">
-        update gxt_month_fan_inspection
-        <trim prefix="SET" suffixOverrides=",">
-            <if test="monthScoreId != null">month_score_id = #{monthScoreId},</if>
-            <if test="deptId != null">dept_id = #{deptId},</if>
-            <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
-            <if test="fanInspectionId != null">fan_inspection_id = #{fanInspectionId},</if>
-            <if test="deviceCount != null">device_count = #{deviceCount},</if>
-            <if test="fanInspectionScore != null">fan_inspection_score = #{fanInspectionScore},</if>
-            <if test="calculatedScore != null">calculated_score = #{calculatedScore},</if>
-            <if test="monthPeriod != null and monthPeriod != ''">month_period = #{monthPeriod},</if>
-            <if test="status != null">status = #{status},</if>
-            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
-            <if test="createTime != null">create_time = #{createTime},</if>
-            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
-            <if test="updateTime != null">update_time = #{updateTime},</if>
-            <if test="remark != null">remark = #{remark},</if>
-        </trim>
-        where id = #{id}
-    </update>
+<update id="updateGxtMonthFanInspection" parameterType="GxtMonthFanInspection">
+    update gxt_month_fan_inspection
+    <trim prefix="SET" suffixOverrides=",">
+        <if test="monthScoreId != null">month_score_id = #{monthScoreId},</if>
+        <if test="deptId != null">dept_id = #{deptId},</if>
+        <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
+        <if test="fanInspectionId != null">fan_inspection_id = #{fanInspectionId},</if>
+        <if test="deviceCount != null">device_count = #{deviceCount},</if>
+        <if test="fanInspectionScore != null">fan_inspection_score = #{fanInspectionScore},</if>
+        <if test="calculatedScore != null">calculated_score = #{calculatedScore},</if>
+        <if test="monthPeriod != null and monthPeriod != ''">month_period = #{monthPeriod},</if>
+        <if test="status != null">status = #{status},</if>
+        <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
+        <if test="createTime != null">create_time = #{createTime},</if>
+        <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+        <if test="updateTime != null">update_time = #{updateTime},</if>
+        <if test="remark != null">remark = #{remark},</if>
+    </trim>
+    where id = #{id}
+</update>
 
 
-    <delete id="deleteGxtMonthFanInspectionById" parameterType="Long">
-        delete from gxt_month_fan_inspection where id = #{id}
-    </delete>
+<delete id="deleteGxtMonthFanInspectionById" parameterType="Long">
+    delete from gxt_month_fan_inspection where id = #{id}
+</delete>
 
 
-    <delete id="deleteGxtMonthFanInspectionByIds" parameterType="Long">
-        delete from gxt_month_fan_inspection where id in
-        <foreach item="id" collection="array" open="(" separator="," close=")">
-            #{id}
-        </foreach>
-    </delete>
+<delete id="deleteGxtMonthFanInspectionByIds" parameterType="Long">
+    delete from gxt_month_fan_inspection where id in
+    <foreach item="id" collection="array" open="(" separator="," close=")">
+        #{id}
+    </foreach>
+</delete>
 
 
 </mapper>
 </mapper>

+ 1 - 1
ygtx-gxt/src/main/resources/mapper/gxt/GxtMonthRepairProjectMapper.xml

@@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 LEFT JOIN sys_user u ON ro.accept_user_id = u.user_id
                 LEFT JOIN sys_user u ON ro.accept_user_id = u.user_id
         WHERE
         WHERE
             u.dept_id = #{deptId}
             u.dept_id = #{deptId}
-            AND ro.work_order_status='archived'
+            AND (ro.work_order_status='archived' or ro.scoring_status='to_archive')
             AND ro.occur_time >= STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s')
             AND ro.occur_time >= STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s')
             AND ro.occur_time <![CDATA[<]]> DATE_ADD(STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s'), INTERVAL 1 MONTH)
             AND ro.occur_time <![CDATA[<]]> DATE_ADD(STR_TO_DATE(CONCAT(#{monthPeriod}, '-01 00:00:00'), '%Y-%m-%d %H:%i:%s'), INTERVAL 1 MONTH)
             AND (ro.repair_method IS NULL OR ro.repair_method != '2')
             AND (ro.repair_method IS NULL OR ro.repair_method != '2')