fangmingyue 2 years ago
parent
commit
d5fdff586a

+ 2
- 1
src/main/java/com/example/civilizedcity/controller/TaCheckController.java View File

5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
 import com.example.civilizedcity.common.*;
6
 import com.example.civilizedcity.common.*;
7
 import com.example.civilizedcity.entity.SysUser;
7
 import com.example.civilizedcity.entity.SysUser;
8
+import com.example.civilizedcity.entity.TaCheckItem;
8
 import com.example.civilizedcity.service.TaCheckItemService;
9
 import com.example.civilizedcity.service.TaCheckItemService;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
155
             return ResponseBean.error("未找到模拟测评信息");
156
             return ResponseBean.error("未找到模拟测评信息");
156
         }
157
         }
157
 
158
 
158
-        taCheckService.calcScore(taCheck);
159
+//        TaCheckItem taCheckItem = taCheckItemService.getById(id);
159
         return ResponseBean.success(taCheck);
160
         return ResponseBean.success(taCheck);
160
     }
161
     }
161
 
162
 

+ 3
- 0
src/main/java/com/example/civilizedcity/mapper/TaCheckItemMapper.java View File

3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.example.civilizedcity.entity.SysUser;
5
 import com.example.civilizedcity.entity.SysUser;
6
+import com.example.civilizedcity.entity.TaCheck;
6
 import org.apache.ibatis.annotations.Mapper;
7
 import org.apache.ibatis.annotations.Mapper;
7
 import org.apache.ibatis.annotations.Param;
8
 import org.apache.ibatis.annotations.Param;
8
 import com.example.civilizedcity.entity.TaCheckItem;
9
 import com.example.civilizedcity.entity.TaCheckItem;
28
     long copyItems(@Param("oldCheckId") String oldCheckId, @Param("newCheckId") String newCheckId);
29
     long copyItems(@Param("oldCheckId") String oldCheckId, @Param("newCheckId") String newCheckId);
29
 
30
 
30
     double sumScore(@Param("checkId") String checkId, @Param("itemType") String itemType);
31
     double sumScore(@Param("checkId") String checkId, @Param("itemType") String itemType);
32
+
33
+    double sumEvlScore(@Param("itemId") String itemId);
31
 }
34
 }

+ 3
- 2
src/main/java/com/example/civilizedcity/service/TaCheckService.java View File

1
 package com.example.civilizedcity.service;
1
 package com.example.civilizedcity.service;
2
 
2
 
3
 import com.example.civilizedcity.entity.TaCheck;
3
 import com.example.civilizedcity.entity.TaCheck;
4
+import com.example.civilizedcity.entity.TaCheckItem;
4
 
5
 
5
- /**
6
+/**
6
  * 模拟测评;(ta_mock_check)表服务接口
7
  * 模拟测评;(ta_mock_check)表服务接口
7
  * @author : http://njyunzhi.com
8
  * @author : http://njyunzhi.com
8
  * @date : 2022-12-12
9
  * @date : 2022-12-12
9
  */
10
  */
10
 public interface TaCheckService extends IBaseService<TaCheck> {
11
 public interface TaCheckService extends IBaseService<TaCheck> {
11
 
12
 
12
-     TaCheck calcScore(TaCheck taCheck);
13
+     TaCheck calcScore(TaCheck taCheck,TaCheckItem taCheckItem );
13
 
14
 
14
      TaCheck copy(TaCheck taCheck);
15
      TaCheck copy(TaCheck taCheck);
15
  }
16
  }

+ 9
- 0
src/main/java/com/example/civilizedcity/service/impl/TaCheckItemServiceImpl.java View File

27
     @Autowired
27
     @Autowired
28
     TaCheckItemQuMapper taCheckItemQuMapper;
28
     TaCheckItemQuMapper taCheckItemQuMapper;
29
 
29
 
30
+    @Autowired
31
+    TaCheckItemMapper taCheckItemMapper;
32
+
30
     @Autowired
33
     @Autowired
31
     TaCheckItemAnMapper taCheckItemAnMapper;
34
     TaCheckItemAnMapper taCheckItemAnMapper;
32
 
35
 
96
         // 并同步生成问题单
99
         // 并同步生成问题单
97
         double score = calcAnswerItems(sysUser, taCheckItem, taCheckAnswer, quList, answerItemList);
100
         double score = calcAnswerItems(sysUser, taCheckItem, taCheckAnswer, quList, answerItemList);
98
         taCheckAnswer.setScore(score);
101
         taCheckAnswer.setScore(score);
102
+
103
+        //得到测评得分的值并且插入一条记录
104
+//        double evlScore = taCheckItemMapper.sumEvlScore(taCheckItem.getItemId());
105
+//        taCheckItem.setScore(evlScore);
106
+//        taCheckItemMapper.insert(taCheckItem);
107
+
99
         taCheckAnswerMapper.insert(taCheckAnswer);
108
         taCheckAnswerMapper.insert(taCheckAnswer);
100
     }
109
     }
101
 
110
 

+ 6
- 1
src/main/java/com/example/civilizedcity/service/impl/TaCheckServiceImpl.java View File

35
 
35
 
36
     @Transactional(rollbackFor = Exception.class)
36
     @Transactional(rollbackFor = Exception.class)
37
     @Override
37
     @Override
38
-    public TaCheck calcScore(TaCheck taCheck) {
38
+    public TaCheck calcScore(TaCheck taCheck,TaCheckItem taCheckItem) {
39
+
40
+        //计算测评得分
41
+//        double evlScore = taCheckItemMapper.sumEvlScore(taCheckItem.getItemId());
39
 
42
 
40
         // 调查问卷分数
43
         // 调查问卷分数
41
         double surveyScore = taCheckItemMapper.sumScore(taCheck.getCheckId(), Constants.CHECK_OF_SURVEY);
44
         double surveyScore = taCheckItemMapper.sumScore(taCheck.getCheckId(), Constants.CHECK_OF_SURVEY);
46
         taCheck.setLocScore(locScore);
49
         taCheck.setLocScore(locScore);
47
         taCheck.setSurveyScore(surveyScore);
50
         taCheck.setSurveyScore(surveyScore);
48
 
51
 
52
+//        taCheckItem.setScore(evlScore);
53
+
49
         updateById(taCheck);
54
         updateById(taCheck);
50
         return taCheck;
55
         return taCheck;
51
     }
56
     }

+ 37
- 3
src/main/resources/mapper/TaCheckItemMapper.xml View File

89
           AND t.item_type = #{itemType}
89
           AND t.item_type = #{itemType}
90
           AND t.`status` &gt; -1
90
           AND t.`status` &gt; -1
91
     </select>
91
     </select>
92
+    <select id="sumEvlScore" resultType="java.lang.Double">
93
+        SELECT
94
+        IF (
95
+            sum( m.cnt ) IS NULL OR sum( m.cnt ) = 0 , 0 , SUM( t.score ) / SUM( m.cnt )
96
+            ) as score
97
+        FROM
98
+        ta_check_item t
99
+            LEFT JOIN (
100
+                SELECT
101
+                    s.item_id,
102
+                    count(*) AS cnt
103
+                FROM
104
+                    ta_check_answer s
105
+                WHERE
106
+                    s.item_id = #{itemId}
107
+                ) m ON t.item_id = m.item_id
108
+        WHERE t.item_id = #{itemId};
109
+    </select>
92
     <select id="sumScore" resultType="java.lang.Double">
110
     <select id="sumScore" resultType="java.lang.Double">
93
         SELECT
111
         SELECT
94
-            SUM(t.score)
112
+            IF (
113
+                sum( m.cnt ) IS NULL OR sum( m.cnt ) = 0 ,
114
+                0 ,
115
+                SUM( t.score ) / SUM( m.cnt )
116
+            )
95
         FROM
117
         FROM
96
             ta_check_item t
118
             ta_check_item t
119
+                LEFT JOIN (
120
+                SELECT
121
+                    s.item_id,
122
+                    count(*) AS cnt
123
+                FROM
124
+                    ta_check_answer s
125
+                WHERE
126
+                    s.`status` > - 1
127
+                GROUP BY
128
+                    s.item_id
129
+                ) m ON t.item_id = m.item_id
97
         WHERE
130
         WHERE
98
             t.check_id = #{checkId}
131
             t.check_id = #{checkId}
99
           AND t.item_type = #{itemType}
132
           AND t.item_type = #{itemType}
100
-          AND t.`status` &gt; -1
101
-    </select>
133
+          AND t.`status` > - 1;
134
+</select>
135
+
102
 </mapper>
136
 </mapper>