Bläddra i källkod

王子文 专项培养

wangggziwen 3 år sedan
förälder
incheckning
4fd875c852

+ 186 - 3
master/src/main/java/com/ruoyi/project/training/spec/controller/TStFeedbackController.java

@@ -1,13 +1,15 @@
 package com.ruoyi.project.training.spec.controller;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.service.ISysUserService;
-import com.ruoyi.project.training.spec.domain.TStFeedbackVO;
-import com.ruoyi.project.training.spec.domain.TStPlan;
+import com.ruoyi.project.training.spec.domain.*;
 import com.ruoyi.project.training.spec.service.ITStPlanService;
+import com.ruoyi.project.training.spec.service.ITStQuestionAnswerService;
+import com.ruoyi.project.training.spec.service.ITStSuccessorScoreService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -20,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.project.training.spec.domain.TStFeedback;
 import com.ruoyi.project.training.spec.service.ITStFeedbackService;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
@@ -46,6 +47,188 @@ public class TStFeedbackController extends BaseController
     @Autowired
     private ISysUserService sysUserService;
 
+    @Autowired
+    private ITStQuestionAnswerService tStQuestionAnswerService;
+
+    @Autowired
+    private ITStSuccessorScoreService stSuccessorScoreService;
+
+    /**
+     * 保存季度反馈内容
+     * @param feedbackSeasonalVO 季度反馈数据传输对象
+     * @return
+     */
+    @PreAuthorize("@ss.hasPermi('spec:feedback:edit')")
+    @PutMapping("/saveSeasonalFeedback")
+    public AjaxResult saveSeasonalFeedback(@RequestBody TStFeedbackSeasonalVO feedbackSeasonalVO) {
+        // 反馈id
+        Long feedbackId = feedbackSeasonalVO.getFeedbackId();
+        // 导师反馈内容
+        String mentorFeedback = feedbackSeasonalVO.getMentorFeedback();
+        // 问卷内容
+        TStQuestionAnswer[] tStQuestionAnswerArray = feedbackSeasonalVO.gettStQuestionAnswerArray();
+        // 季度反馈对象
+        TStFeedback feedback = new TStFeedback();
+        feedback.setId(feedbackId);
+        feedback.setMentorFeedback(mentorFeedback);
+        // 当前导师评分(14题总分)
+        BigDecimal mentorFeedbackScoreSum = new BigDecimal("0.0");
+        // 遍历问卷内容数组
+        for (int i = 0; i < tStQuestionAnswerArray.length; i++) {
+            TStQuestionAnswer answer = new TStQuestionAnswer();
+            answer.setFeedbackId(feedbackId);
+            answer.setQuestionId(tStQuestionAnswerArray[i].getQuestionId());
+            answer.setAnswer(tStQuestionAnswerArray[i].getAnswer());
+            // 根据问题和答案获取TStQuestionAnswer对象
+            TStQuestionAnswer result = tStQuestionAnswerService.selectTStQuestionAnswer(answer);
+            // TStQuestionAnswer表中不存在记录
+            if (result == null) {
+                // 新增TStQuestionAnswer对象
+                tStQuestionAnswerService.insertTStQuestionAnswer(answer);
+            } else {
+                result.setAnswer(tStQuestionAnswerArray[i].getAnswer());
+                // 更新TStQuestionAnswer对象
+                tStQuestionAnswerService.updateTStQuestionAnswer(result);
+            }
+            // 导师评分累计
+            switch (tStQuestionAnswerArray[i].getAnswer()) {
+                case "1": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("100.0")); break;
+                case "2": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("75.0")); break;
+                case "3": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("50.0")); break;
+                case "4": mentorFeedbackScoreSum = mentorFeedbackScoreSum.add(new BigDecimal("25.0")); break;
+            }
+        }
+        // 当前导师评分(平均分)
+        BigDecimal mentorFeedbackScore = mentorFeedbackScoreSum.divide(new BigDecimal("14.0"),1,BigDecimal.ROUND_HALF_UP);
+        feedback.setFeedbackScore(mentorFeedbackScore.toString());
+        // 保存季度反馈
+        tStFeedbackService.updateTStFeedback(feedback);
+        // 更新季度平均分
+        this.updateSeasonalOverallScore(feedbackId);
+        return AjaxResult.success();
+    }
+
+    /**
+     * 更新季度平均分
+     * @param feedbackId 当前节点id
+     */
+    private void updateSeasonalOverallScore(
+            Long feedbackId
+    ) {
+        TStFeedback feedback = tStFeedbackService.selectTStFeedbackById(feedbackId);    // 当前节点
+        TStFeedback parentNode = null;  // 父节点
+        if (feedback.getParentId() == null) {   // 当前节点为父节点(本导师)
+            // 设置当前节点为父节点
+            parentNode = feedback;
+        } else {   // 当前节点为子节点(受邀导师)
+            // 根据当前节点parentId查询父节点
+            parentNode = tStFeedbackService.selectTStFeedbackById(feedback.getParentId());
+        }
+        TStFeedback queryObj = new TStFeedback();
+        queryObj.setParentId(parentNode.getId());
+        // 查询子节点
+        List<TStFeedback> childNodes = tStFeedbackService.selectTStFeedbackList(queryObj);
+        BigDecimal sum = new BigDecimal("0.0");    // 子节点总分
+        BigDecimal count = new BigDecimal("0.0");  // 子节点数量
+        BigDecimal avg = new BigDecimal("0.0");    // 子节点平均分
+        BigDecimal overall = new BigDecimal("0.0");    // 季度平均分
+        for (TStFeedback childNode : childNodes) {
+            count = count.add(new BigDecimal("1.0"));
+            sum = sum.add(new BigDecimal(childNode.getFeedbackScore()==null?"0.0":childNode.getFeedbackScore()));
+        }
+        // 计算子节点平均分
+        avg = sum.divide(count,1,BigDecimal.ROUND_HALF_UP);
+        // 计算季度平均分
+        if (parentNode.getFeedbackScore() == null) { // 父节点没有分数,取子节点分数
+            overall = avg;
+        } else if (new BigDecimal("0.0").equals(avg)) {  // 子节点没有分数,取父节点分数
+            overall = new BigDecimal(parentNode.getFeedbackScore());
+        } else {    // 父节点占比60%,子节点平均分占比40%
+            overall = (new BigDecimal(parentNode.getFeedbackScore()).multiply(new BigDecimal("0.6")))
+                    .add(avg.multiply(new BigDecimal("0.4")));
+        }
+        parentNode.setOverallScore(overall.toString());
+        // 更新季度平均分
+        tStFeedbackService.updateTStFeedback(parentNode);
+        // 更新继任者评分
+        this.updateSuccessorScore(parentNode);
+        return;
+    }
+
+    /**
+     * 更新继任者评分
+     * @param parentNode TStFeedback表父节点
+     */
+    private void updateSuccessorScore(TStFeedback parentNode) {
+        TStSuccessorScore stSuccessorScore = new TStSuccessorScore();
+        stSuccessorScore.setStaffId(parentNode.getSuccessorId());
+        // 根据学员id获取继任者评分
+        stSuccessorScore = stSuccessorScoreService.selectTStSuccessorScore(stSuccessorScore);
+        if (stSuccessorScore != null) { // TStSuccessorScore表中存在记录
+            switch (parentNode.getFeedbackSeason()) {   // 设置季度评分
+                case "1":   // 第一季度
+                    stSuccessorScore.setQuarterOne(parentNode.getOverallScore());
+                    break;
+                case "2":   // 第二季度
+                    stSuccessorScore.setQuarterTwo(parentNode.getOverallScore());
+                    break;
+                case "3":   // 第三季度
+                    stSuccessorScore.setQuarterThree(parentNode.getOverallScore());
+                    break;
+                case "4":   // 第四季度
+                    stSuccessorScore.setQuarterFour(parentNode.getOverallScore());
+                    // 总数
+                    BigDecimal count = new BigDecimal("0.0");
+                    // 总分
+                    BigDecimal sum = new BigDecimal("0.0");
+                    String quarterOneString = stSuccessorScore.getQuarterOne();
+                    String quarterTwoString = stSuccessorScore.getQuarterTwo();
+                    String quarterThreeString = stSuccessorScore.getQuarterThree();
+                    String quarterFourString = stSuccessorScore.getQuarterFour();
+                    if (quarterOneString != null) {
+                        count = count.add(new BigDecimal("1.0"));
+                        sum = sum.add(new BigDecimal(quarterOneString));
+                    }
+                    if (quarterTwoString != null) {
+                        count = count.add(new BigDecimal("1.0"));
+                        sum = sum.add(new BigDecimal(quarterTwoString));
+                    }
+                    if (quarterThreeString != null) {
+                        count = count.add(new BigDecimal("1.0"));
+                        sum = sum.add(new BigDecimal(quarterThreeString));
+                    }
+                    if (quarterFourString != null) {
+                        count = count.add(new BigDecimal("1.0"));
+                        sum = sum.add(new BigDecimal(quarterFourString));
+                    }
+                    // 年度评分 = 四季度总分 / 4
+                    BigDecimal year = sum.divide(count,1,BigDecimal.ROUND_HALF_UP);
+                    stSuccessorScore.setYear(year.toString());
+                    break;
+            }
+            // 更新继任者评分
+            stSuccessorScoreService.updateTStSuccessorScore(stSuccessorScore);
+        } else {
+            switch (parentNode.getFeedbackSeason()) {   // 设置季度评分
+                case "1":   // 第一季度
+                    stSuccessorScore.setQuarterOne(parentNode.getOverallScore());
+                    break;
+                case "2":   // 第二季度
+                    stSuccessorScore.setQuarterTwo(parentNode.getOverallScore());
+                    break;
+                case "3":   // 第三季度
+                    stSuccessorScore.setQuarterThree(parentNode.getOverallScore());
+                    break;
+                case "4":   // 第四季度
+                    stSuccessorScore.setQuarterFour(parentNode.getOverallScore());
+                    break;
+            }
+            // 新增继任者评分
+            stSuccessorScoreService.insertTStSuccessorScore(stSuccessorScore);
+        }
+        return;
+    }
+
     /**
      * 导师查询季度反馈列表
      */

+ 51 - 0
master/src/main/java/com/ruoyi/project/training/spec/domain/TStFeedbackSeasonalVO.java

@@ -0,0 +1,51 @@
+package com.ruoyi.project.training.spec.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.ruoyi.framework.aspectj.lang.annotation.Excel;
+import com.ruoyi.framework.web.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.Date;
+
+/**
+ * 季度反馈数据传输对象
+ *
+ * @author 王子文
+ * @date 2022年5月22日
+ */
+public class TStFeedbackSeasonalVO extends BaseEntity
+{
+    /** 反馈id */
+    Long feedbackId;
+
+    /** 导师反馈内容 */
+    String mentorFeedback;
+
+    /** 问卷内容 */
+    TStQuestionAnswer[] tStQuestionAnswerArray;
+
+    public Long getFeedbackId() {
+        return feedbackId;
+    }
+
+    public void setFeedbackId(Long feedbackId) {
+        this.feedbackId = feedbackId;
+    }
+
+    public String getMentorFeedback() {
+        return mentorFeedback;
+    }
+
+    public void setMentorFeedback(String mentorFeedback) {
+        this.mentorFeedback = mentorFeedback;
+    }
+
+    public TStQuestionAnswer[] gettStQuestionAnswerArray() {
+        return tStQuestionAnswerArray;
+    }
+
+    public void settStQuestionAnswerArray(TStQuestionAnswer[] tStQuestionAnswerArray) {
+        this.tStQuestionAnswerArray = tStQuestionAnswerArray;
+    }
+}

+ 3 - 3
master/src/main/java/com/ruoyi/project/training/spec/domain/TStSuccessorScore.java

@@ -63,7 +63,7 @@ public class TStSuccessorScore extends BaseEntity
 
     /** 年度 */
     @Excel(name = "年度")
-    private Long year;
+    private String year;
 
     public void setId(Long id)
     {
@@ -164,12 +164,12 @@ public class TStSuccessorScore extends BaseEntity
     {
         return quarterFour;
     }
-    public void setYear(Long year)
+    public void setYear(String year)
     {
         this.year = year;
     }
 
-    public Long getYear()
+    public String getYear()
     {
         return year;
     }

+ 9 - 0
ui/src/api/training/spec/feedback.js

@@ -1,5 +1,14 @@
 import request from '@/utils/request'
 
+// 保存季度反馈
+export function saveSeasonalFeedback(data) {
+  return request({
+    url: '/spec/feedback/saveSeasonalFeedback',
+    method: 'put',
+    data: data
+  })
+}
+
 // 导师查询月度反馈列表
 export function listMentorSeasonalFeedback(query) {
   return request({

+ 1 - 1
ui/src/views/training/spec/myplan/index.vue

@@ -474,7 +474,7 @@ export default {
         // 获取导师反馈
         return getFeedbackByPlanId(row.id);
       }).then(response => {
-        console.log(response.data);
+        console.log();
         if (response.data != null) {
           this.mentorFeedback = response.data.mentorFeedback;
         }

+ 36 - 189
ui/src/views/training/spec/seasonalfeedback/index.vue

@@ -422,7 +422,7 @@
 import { getAnswer, addAnswer, updateAnswer, listAnswer } from "@/api/training/spec/answer";
 import { listScore, getScore, delScore, addScore, updateScore, exportScore, importTemplate} from "@/api/training/spec/score";
 import { allFileList, delCommonfile } from "@/api/common/commonfile";
-import { addFeedback, getFeedbackByParams, listInvitedSuccessor, updateFeedback, listFeedback, getFeedbackByPlanId } from "@/api/training/spec/feedback";
+import { saveSeasonalFeedback, addFeedback, getFeedbackByParams, listInvitedSuccessor, updateFeedback, listFeedback, getFeedbackByPlanId } from "@/api/training/spec/feedback";
 import { listMentors } from "@/api/training/spec/successor";
 import { listSuccessorsByMentorId, listPlanSeasonal } from "@/api/training/spec/plan";
 import { getToken } from "@/utils/auth";
@@ -682,6 +682,41 @@ export default {
     this.initPageData();
   },
   methods: {
+    /** 保存按钮处理 */
+    handleSave() {
+      // 问卷判空
+      if (this.isEmpty()) {
+        this.$message.error('问卷答案不能为空')
+        return;
+      }
+      // 保存季度反馈
+      saveSeasonalFeedback({
+        // 反馈id
+        feedbackId: this.feedbackId,
+        // 导师反馈内容
+        mentorFeedback: this.mentorFeedback,
+        // 问卷内容
+        tStQuestionAnswerArray: 
+        [
+          { questionId: 4, answer:this.radio1 },
+          { questionId: 5, answer:this.radio2 },
+          { questionId: 6, answer:this.radio3 },
+          { questionId: 7, answer:this.radio4 },
+          { questionId: 8, answer:this.radio5 },
+          { questionId: 9, answer:this.radio6 },
+          { questionId: 10, answer:this.radio7 },
+          { questionId: 11, answer:this.radio8 },
+          { questionId: 12, answer:this.radio9 },
+          { questionId: 13, answer:this.radio10 },
+          { questionId: 14, answer:this.radio11 },
+          { questionId: 15, answer:this.radio12 },
+          { questionId: 16, answer:this.radio13 },
+          { questionId: 17, answer:this.radio14 },
+        ]
+      }).then(() => {
+        this.msgSuccess("保存成功");
+      });
+    },
     /** 设置最后截止日期 */
     resetLastDay() {
       // 最后截止日期
@@ -918,194 +953,6 @@ export default {
         return false;
       }
     },
-    /** 计算导师评分 */
-    calcFeedbackScore() {
-      let mentorFeedbackScore = 0; // 本导师评分
-      let invitedMentorFeedbackScoreSum = 0; // 受邀导师总分
-      let invitedMentorFeedbackScoreAvg = 0; // 受邀导师平均分
-      let invitedMentors = 0; // 受邀导师人数
-      let overallScore = 0;  // 季度平均分
-      let feedbackId = null;  // 本导师反馈id
-      // 获取问题答案列表
-      listAnswer( { feedbackId: this.feedbackId } )
-      .then(response => {
-        let data = response.rows;
-        // 计算导师评分
-        let total = 0;  // 总分
-        for (let i = 0; i < data.length; i++) {
-          if(data[i].answer == "1") {
-            total += 100;
-          }
-          else if(data[i].answer == "2") {
-            total += 75;
-          }
-          else if(data[i].answer == "3") {
-            total += 50;
-          }
-          else if(data[i].answer == "4") {
-            total += 25;
-          }
-        }
-        let avg = total / 14; // 平均分
-        // 更新当前导师评分
-        return updateFeedback( { id: this.feedbackId, feedbackScore: avg } );
-      })
-      .then(() => {
-        // 获取本导师反馈
-        return getFeedbackByParams({
-          successorId: this.queryParams.successorId,
-          feedbackYear: this.queryParams.feedbackYear,
-          feedbackSeason: this.queryParams.feedbackSeason
-        })
-      })
-      .then(response => {
-        // 设置本导师反馈id
-        feedbackId = response.data.id;
-        // 设置导师评分
-        mentorFeedbackScore = response.data.feedbackScore;
-        // 获取受邀导师列表
-        return listFeedback( { parentId: feedbackId } );
-      })
-      .then(response => {
-        let data = response.rows;
-        for (let i = 0; i < data.length; i++) {
-          if (data[i].feedbackScore != null) {
-            invitedMentorFeedbackScoreSum += Number(data[i].feedbackScore);
-            invitedMentors += 1;
-          }
-        }
-        // 计算受邀导师平均分
-        if (invitedMentorFeedbackScoreSum == 0) { // 受邀导师未评分
-          invitedMentorFeedbackScoreAvg = 0;
-        } else {
-          // 受邀导师平均分 = 总分 / 人数
-          invitedMentorFeedbackScoreAvg = invitedMentorFeedbackScoreSum / invitedMentors;
-        }
-        // 计算季度平均分
-        if (invitedMentorFeedbackScoreSum == 0) { // 受邀导师未评分
-          overallScore = mentorFeedbackScore;
-        } else if (mentorFeedbackScore == 0) {  // 本导师未评分
-          overallScore = invitedMentorFeedbackScoreAvg;
-        } else {
-        // 季度平均分 = 本导师评分 * 60% + 受邀导师平均分 * 40%
-          overallScore = mentorFeedbackScore * 0.6 + invitedMentorFeedbackScoreAvg * 0.4;
-        }
-        // 更新季度平均分
-        updateFeedback({ id: feedbackId, overallScore: overallScore });
-        // 更新继任者评分表数据
-        getScore({
-          successorId: this.queryParams.successorId,
-          feedbackYear: this.queryParams.feedbackYear,
-          feedbackSeason: this.queryParams.feedbackSeason
-        })
-        .then(response => {
-          let data = response.data;
-          let score = {};
-          if (this.queryParams.feedbackSeason == "1") {
-            score.quarterOne = overallScore;
-          }
-          if (this.queryParams.feedbackSeason == "2") {
-            score.quarterTwo = overallScore;
-          }
-          if (this.queryParams.feedbackSeason == "3") {
-            score.quarterThree = overallScore;
-          }
-          if (this.queryParams.feedbackSeason == "4") {
-            score.quarterFour = overallScore;
-          }
-          if (data != null) { // 更新季度评分
-            score.id = data.id;
-            updateScore(score);
-          } else {  // 新增评分
-            score.staffId = this.queryParams.successorId;
-            score.feedbackYear = this.queryParams.feedbackYear;
-            score.feedbackSeason = this.queryParams.feedbackSeason;
-            addScore(score);
-          }
-          // return getScore({
-          //   successorId: this.queryParams.successorId,
-          //   feedbackYear: this.queryParams.feedbackYear,
-          //   feedbackSeason: this.queryParams.feedbackSeason
-          // });
-        })
-      //   .then(response => { // 计算年度评分
-      //     let data = response.data;
-      //     let count = 0;
-      //     let sum = 0;
-      //     if (data.quarterOne != null) {
-      //       count++;
-      //       sum += data.quarterOne;
-      //     }
-      //     if (data.quarterTwo != null) {
-      //       count++;
-      //       sum += data.quarterTwo;
-      //     }
-      //     if (data.quarterThree != null) {
-      //       count++;
-      //       sum += data.quarterThree;
-      //     }
-      //     if (data.quarterFour != null) {
-      //       count++;
-      //       sum += data.quarterFour;
-      //     }
-      //     let year = sum / count;
-      //     let score = {};
-      //     score.id = data.id;
-      //     score.year = year;
-      //     updateScore(score);
-      //   });
-      });
-    },
-    /** 保存反馈问题 */
-    saveAnswer(questionId, answer) {
-      let answerObj = {};
-      answerObj.feedbackId = this.feedbackId;
-      answerObj.questionId = questionId;
-      getAnswer(answerObj).then(response => {
-        let data = response.data;
-        answerObj.answer = answer;
-          if (data != null) {
-            if (response.answer == data.answer) { // 答案一致
-              return;
-            } else {  // 答案不一致
-              answerObj.id = data.id;
-              updateAnswer(answerObj).then(response => {
-                // 计算导师评分
-                this.calcFeedbackScore();
-              });
-            }
-          } else {
-            addAnswer(answerObj).then(response => {
-              // 计算导师评分
-              this.calcFeedbackScore();
-            });
-          }
-      });
-    },
-    /** 保存导师反馈内容 */
-    saveMentorFeedback() {
-      let feedback = {};
-      feedback.id = this.feedbackId;
-      feedback.mentorFeedback = this.mentorFeedback;
-      updateFeedback(feedback);
-    },
-    /** 保存按钮处理 */
-    handleSave() {
-      // 问卷判空
-      if (this.isEmpty()) {
-        this.$message.error('问卷答案不能为空')
-        return;
-      }
-      let radioArray = [ this.radio1, this.radio2, this.radio3, this.radio4, this.radio5, this.radio6, this.radio7, this.radio8, this.radio9, this.radio10, this.radio11, this.radio12, this.radio13, this.radio14 ];
-      let questionArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
-      // 保存问卷内容
-      for (let i = 0; i < radioArray.length; i++) {
-        this.saveAnswer(questionArray[i]+3, radioArray[i]);
-      }
-      // 保存导师反馈内容
-      this.saveMentorFeedback();
-      this.msgSuccess("保存成功");
-    },
     /** 培养计划详情处理 */
     handleFeedback(row) {
       // 加载反馈附件