Yansen 2 years ago
parent
commit
ee81287cdd

+ 3
- 3
src/main/java/com/example/civilizedcity/controller/TaCheckItemController.java View File

207
      * @param id 实例对象
207
      * @param id 实例对象
208
      * @return 实例对象
208
      * @return 实例对象
209
      */
209
      */
210
-    @ApiOperation("更新数据")
210
+    @ApiOperation("获取回答")
211
     @GetMapping("/taCheckItem/{id}/answer")
211
     @GetMapping("/taCheckItem/{id}/answer")
212
     public ResponseBean getAnswer(@ApiParam("对象ID") @PathVariable String id) throws Exception {
212
     public ResponseBean getAnswer(@ApiParam("对象ID") @PathVariable String id) throws Exception {
213
 
213
 
222
      * @param taCheckAnswer 实例对象
222
      * @param taCheckAnswer 实例对象
223
      * @return 实例对象
223
      * @return 实例对象
224
      */
224
      */
225
-    @ApiOperation("更新数据")
225
+    @ApiOperation("回答问题")
226
     @PutMapping("/taCheckItem/{id}/answer")
226
     @PutMapping("/taCheckItem/{id}/answer")
227
     public ResponseBean answer(@ApiParam("对象实体") @RequestBody TaCheckAnswer taCheckAnswer,
227
     public ResponseBean answer(@ApiParam("对象实体") @RequestBody TaCheckAnswer taCheckAnswer,
228
                                @ApiParam("对象ID") @PathVariable String id) throws Exception {
228
                                @ApiParam("对象ID") @PathVariable String id) throws Exception {
259
         taCheckAnswer.setCreateUser(sysUser.getUserId());
259
         taCheckAnswer.setCreateUser(sysUser.getUserId());
260
         taCheckAnswer.setCreateDate(LocalDateTime.now());
260
         taCheckAnswer.setCreateDate(LocalDateTime.now());
261
 
261
 
262
-        taCheckItemService.answer(taCheckItem, taCheckAnswer);
262
+        taCheckItemService.answer(taCheckItem, taCheckAnswer, sysUser);
263
         return ResponseBean.success(taCheckAnswer);
263
         return ResponseBean.success(taCheckAnswer);
264
     }
264
     }
265
 
265
 

+ 4
- 2
src/main/java/com/example/civilizedcity/controller/TaIssueApplyController.java View File

11
 import com.example.civilizedcity.entity.SysUser;
11
 import com.example.civilizedcity.entity.SysUser;
12
 import com.example.civilizedcity.service.TaIssueService;
12
 import com.example.civilizedcity.service.TaIssueService;
13
 import com.example.civilizedcity.service.TaOrgIssueService;
13
 import com.example.civilizedcity.service.TaOrgIssueService;
14
+import com.sun.org.apache.xpath.internal.operations.Bool;
14
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.ApiOperation;
16
 import io.swagger.annotations.ApiOperation;
16
 import io.swagger.annotations.ApiParam;
17
 import io.swagger.annotations.ApiParam;
97
                              @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
98
                              @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
98
                              @ApiParam("问题单ID") @RequestParam(value = "issueId", required = false) Integer issueId,
99
                              @ApiParam("问题单ID") @RequestParam(value = "issueId", required = false) Integer issueId,
99
                              @ApiParam("申请类型") @RequestParam(value = "applyType", required = false) String applyType,
100
                              @ApiParam("申请类型") @RequestParam(value = "applyType", required = false) String applyType,
100
-                             @ApiParam("问题单来源") @RequestParam(value = "sourceType", required = false) String sourceType) throws Exception {
101
+                             @ApiParam("问题单来源") @RequestParam(value = "sourceType", required = false) String sourceType,
102
+                             @ApiParam(value = "是否全部") @RequestParam(value = "isAll", defaultValue = "false") Boolean isAll) throws Exception {
101
 
103
 
102
         SysUser sysUser = currentUser();
104
         SysUser sysUser = currentUser();
103
         String orgId = isManager(sysUser) ? null : sysUser.getOrgId();
105
         String orgId = isManager(sysUser) ? null : sysUser.getOrgId();
104
 
106
 
105
         IPage<TaIssueApply> pg = new Page<>(pageNum, pageSize);
107
         IPage<TaIssueApply> pg = new Page<>(pageNum, pageSize);
106
-        IPage<TaIssueApply> result = taIssueApplyService.getPageBy(pg, issueId, applyType, orgId, sourceType);
108
+        IPage<TaIssueApply> result = taIssueApplyService.getPageBy(pg, issueId, applyType, orgId, sourceType, isAll);
107
 
109
 
108
         return ResponseBean.success(result);
110
         return ResponseBean.success(result);
109
     }
111
     }

+ 3
- 0
src/main/java/com/example/civilizedcity/controller/TaIssueController.java View File

111
             // 已打回
111
             // 已打回
112
             queryWrapper.eq("process_node", Constants.PROCESS_APPLY_REJECT);
112
             queryWrapper.eq("process_node", Constants.PROCESS_APPLY_REJECT);
113
             queryWrapper.eq("process_status", Constants.APPLY_PASS);
113
             queryWrapper.eq("process_status", Constants.APPLY_PASS);
114
+        } else {
115
+            // 其余节点
116
+            queryWrapper.likeRight(!StringUtils.isEmpty(bizStatus), "process_node", bizStatus);
114
         }
117
         }
115
 
118
 
116
         if (mine) {
119
         if (mine) {

+ 2
- 1
src/main/java/com/example/civilizedcity/mapper/TaIssueApplyMapper.java View File

18
                                    @Param("issueId") Integer issueId,
18
                                    @Param("issueId") Integer issueId,
19
                                    @Param("applyType") String applyType,
19
                                    @Param("applyType") String applyType,
20
                                    @Param("orgId") String orgId,
20
                                    @Param("orgId") String orgId,
21
-                                   @Param("sourceType") String sourceType);
21
+                                   @Param("sourceType") String sourceType,
22
+                                   @Param("isAll") Boolean isAll);
22
  }
23
  }

+ 1
- 1
src/main/java/com/example/civilizedcity/service/TaCheckItemService.java View File

17
 
17
 
18
      void createNewItems(TaCheck taCheck);
18
      void createNewItems(TaCheck taCheck);
19
 
19
 
20
-     void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer) throws Exception;
20
+     void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer, SysUser sysUser) throws Exception;
21
  }
21
  }

+ 1
- 2
src/main/java/com/example/civilizedcity/service/TaIssueApplyService.java View File

1
 package com.example.civilizedcity.service;
1
 package com.example.civilizedcity.service;
2
 
2
 
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
-import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.example.civilizedcity.entity.SysUser;
4
 import com.example.civilizedcity.entity.SysUser;
6
 import com.example.civilizedcity.entity.TaIssueApply;
5
 import com.example.civilizedcity.entity.TaIssueApply;
7
 
6
 
14
 
13
 
15
      void createNewApply(TaIssueApply taIssueApply, SysUser sysUser) throws Exception;
14
      void createNewApply(TaIssueApply taIssueApply, SysUser sysUser) throws Exception;
16
 
15
 
17
-     IPage<TaIssueApply> getPageBy(IPage<TaIssueApply> pg, Integer issueId, String applyType, String orgId, String sourceType);
16
+     IPage<TaIssueApply> getPageBy(IPage<TaIssueApply> pg, Integer issueId, String applyType, String orgId, String sourceType, Boolean isAll);
18
 
17
 
19
      void verify(TaIssueApply taIssueApply, SysUser sysUser, TaIssueApply origin) throws Exception;
18
      void verify(TaIssueApply taIssueApply, SysUser sysUser, TaIssueApply origin) throws Exception;
20
  }
19
  }

+ 89
- 7
src/main/java/com/example/civilizedcity/service/impl/TaCheckItemServiceImpl.java View File

11
 import org.springframework.transaction.annotation.Transactional;
11
 import org.springframework.transaction.annotation.Transactional;
12
 
12
 
13
 import java.time.LocalDateTime;
13
 import java.time.LocalDateTime;
14
+import java.util.ArrayList;
14
 import java.util.List;
15
 import java.util.List;
16
+import java.util.stream.Collectors;
15
 
17
 
16
 /**
18
 /**
17
  * 测评点位;(ta_check_item)表服务实现类
19
  * 测评点位;(ta_check_item)表服务实现类
37
     @Autowired
39
     @Autowired
38
     TaAttachMapper taAttachMapper;
40
     TaAttachMapper taAttachMapper;
39
 
41
 
42
+    @Autowired
43
+    SysUserMapper sysUserMapper;
44
+
45
+    @Autowired
46
+    TaIssueMapper taIssueMapper;
47
+
48
+    @Autowired
49
+    TaIssueProcessMapper taIssueProcessMapper;
50
+
40
     @Override
51
     @Override
41
     public IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType) {
52
     public IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType) {
42
         return baseMapper.getPageBy(pg, checkId, itemType);
53
         return baseMapper.getPageBy(pg, checkId, itemType);
56
 
67
 
57
     @Transactional(rollbackFor = Exception.class)
68
     @Transactional(rollbackFor = Exception.class)
58
     @Override
69
     @Override
59
-    public void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer) throws Exception {
70
+    public void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer, SysUser sysUser) throws Exception {
60
         List<TaCheckItemQu> quList = taCheckItemQuMapper.getListBy(taCheckItem.getItemId());
71
         List<TaCheckItemQu> quList = taCheckItemQuMapper.getListBy(taCheckItem.getItemId());
61
         if (null == quList || quList.size() < 1) {
72
         if (null == quList || quList.size() < 1) {
62
             throw new Exception("校验测评问题列表出错");
73
             throw new Exception("校验测评问题列表出错");
81
             }
92
             }
82
         }
93
         }
83
 
94
 
84
-
85
-        double[] scores = answerItems(taCheckItem, taCheckAnswer, quList, answerItemList);
95
+        // 答题的时候, 顺便把问题单生成好
96
+        double[] scores = answerItems(taCheckItem, taCheckAnswer, quList, answerItemList, sysUser);
86
 
97
 
87
         if (Constants.CHECK_OF_SURVEY.equals(taCheckItem.getItemType())) {
98
         if (Constants.CHECK_OF_SURVEY.equals(taCheckItem.getItemType())) {
88
             // 调查问卷不需要计算当前试卷的分数, 最后才能计算出来
99
             // 调查问卷不需要计算当前试卷的分数, 最后才能计算出来
124
      * @param taCheckAnswer
135
      * @param taCheckAnswer
125
      * @throws Exception
136
      * @throws Exception
126
      */
137
      */
127
-    private double[] answerItems(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer, List<TaCheckItemQu> quList, List<TaCheckAnswerItem> answerItemList) throws Exception {
128
-
138
+    private double[] answerItems(TaCheckItem taCheckItem,
139
+                                 TaCheckAnswer taCheckAnswer,
140
+                                 List<TaCheckItemQu> quList,
141
+                                 List<TaCheckAnswerItem> answerItemList,
142
+                                 SysUser sysUser
143
+    ) throws Exception {
129
         LocalDateTime now = LocalDateTime.now();
144
         LocalDateTime now = LocalDateTime.now();
130
         double negativeScore = 0.0; // 扣分
145
         double negativeScore = 0.0; // 扣分
131
         double positiveScore = 0.0; // 得分
146
         double positiveScore = 0.0; // 得分
132
         for(TaCheckAnswerItem item : answerItemList) {
147
         for(TaCheckAnswerItem item : answerItemList) {
133
             // 找到对应的题目
148
             // 找到对应的题目
134
             TaCheckItemQu qu = getQu(quList, item.getQuId());
149
             TaCheckItemQu qu = getQu(quList, item.getQuId());
150
+            // 如果是选择题, 对应的答案
151
+            TaCheckItemAn standAn = null;
135
             // + 代表得分, 否则代表扣分
152
             // + 代表得分, 否则代表扣分
136
             int sign = "+".equals(qu.getComputeType()) ? 1 : -1;
153
             int sign = "+".equals(qu.getComputeType()) ? 1 : -1;
137
 
154
 
146
 
163
 
147
                 score *= sign;
164
                 score *= sign;
148
             } else if (Constants.QU_OF_RADIO.equals(qu.getQuType())) {
165
             } else if (Constants.QU_OF_RADIO.equals(qu.getQuType())) {
149
-                // 如果是选择题, 找到对应的答案
150
-                TaCheckItemAn standAn = taCheckItemAnMapper.getOneBy(qu.getQuId(), item.getAnswerCode());
166
+                // 如果是选择题, 找到对应的答案
167
+                standAn = taCheckItemAnMapper.getOneBy(qu.getQuId(), item.getAnswerCode());
151
 
168
 
152
                 score = standAn.getScore();
169
                 score = standAn.getScore();
153
                 if (score > qu.getMaxScore()) {
170
                 if (score > qu.getMaxScore()) {
174
             // 保存附件
191
             // 保存附件
175
             if (null != item.getAttachList()) {
192
             if (null != item.getAttachList()) {
176
                 for (TaAttach taAttach : item.getAttachList()) {
193
                 for (TaAttach taAttach : item.getAttachList()) {
194
+                    taAttach.setAttachId(null);
177
                     taAttach.setOwnerType(Constants.SOURCE_CHECK_ANSWER);
195
                     taAttach.setOwnerType(Constants.SOURCE_CHECK_ANSWER);
178
                     taAttach.setOwnerId(item.getItemId());
196
                     taAttach.setOwnerId(item.getItemId());
179
                     taAttach.setStatus(Constants.STATUS_NORMAL);
197
                     taAttach.setStatus(Constants.STATUS_NORMAL);
182
                     taAttachMapper.insert(taAttach);
200
                     taAttachMapper.insert(taAttach);
183
                 }
201
                 }
184
             }
202
             }
203
+
204
+            // 如果得分小于0, 说明是扣分项, 生成问题单
205
+            if (score < 0 && Constants.CHECK_OF_LOC.equals(taCheckItem.getItemType())) {
206
+                createNewIssue(sysUser, taCheckItem, qu, standAn, item);
207
+            }
185
         }
208
         }
186
 
209
 
187
         return new double[] {positiveScore, negativeScore};
210
         return new double[] {positiveScore, negativeScore};
188
     }
211
     }
189
 
212
 
213
+    private void createNewIssue(SysUser sysUser,
214
+                                   TaCheckItem taCheckItem,
215
+                                   TaCheckItemQu qu,
216
+                                   TaCheckItemAn an,
217
+                                   TaCheckAnswerItem answer) {
218
+        LocalDateTime now = LocalDateTime.now();
219
+        TaIssue taIssue = new TaIssue();
220
+        taIssue.setLocId(taCheckItem.getTypeId());
221
+        taIssue.setLocName(taCheckItem.getName());
222
+
223
+        // 如果是选择题, 答案 answer 的内容只是代码, 所以需要从 TaCheckItemAn 把对应的文字拿出来
224
+        // 如果是填空题, 那么文字是 答案(数字) + 单位(fillUnit) , 最后结果类似 5 处。
225
+        String answerStr = Constants.QU_OF_FILL.equals(qu.getQuType())
226
+                ? an.getAnswer()
227
+                : String.format("%s %s", answer.getAnswer(), qu.getFillUnit());
228
+        taIssue.setContent(String.format("%s 测评结果 %s", qu.getTitle(), answerStr));
229
+        taIssue.setProcessNode(Constants.PROCESS_START);
230
+        taIssue.setProcessStatus(Constants.APPLY_PASS); // 模拟测评的不需要审核
231
+        taIssue.setProcessNum(0);
232
+        taIssue.setOrgId(null);
233
+        taIssue.setSourceType(Constants.SOURCE_CHECK);
234
+        taIssue.setSourceTarget(answer.getItemId()); // 实际作答的ID, 非测评项目表 ID
235
+        taIssue.setStatus(Constants.STATUS_NORMAL);
236
+        taIssue.setCreateUser(sysUser.getUserId());
237
+        taIssue.setUserName(sysUser.getName());
238
+        taIssue.setCreateDate(now);
239
+        taIssueMapper.insert(taIssue);
240
+
241
+        // 保存文件
242
+        List<TaAttach> attachList = answer.getAttachList();
243
+        if (null != attachList && attachList.size() > 0) {
244
+            for (TaAttach item : attachList) {
245
+                // 生成新对象, 目的是不影响 item;
246
+                TaAttach newItem = new TaAttach();
247
+                newItem.setAttachId(null);
248
+                newItem.setFileType(item.getFileType());
249
+                newItem.setName(item.getName());
250
+                newItem.setUrl(item.getUrl());
251
+                newItem.setOwnerType(Constants.SOURCE_ISSUE);
252
+                newItem.setOwnerId(taIssue.getIssueId().toString());
253
+                newItem.setStatus(Constants.STATUS_NORMAL);
254
+                newItem.setCreateDate(now);
255
+                taAttachMapper.insert(newItem);
256
+            }
257
+        }
258
+
259
+        // 流程开始
260
+        TaIssueProcess process = new TaIssueProcess();
261
+        process.setIssueId(taIssue.getIssueId());
262
+        process.setOrgId(sysUser.getOrgId());
263
+        process.setProcessNode(taIssue.getProcessNode());
264
+        process.setProcessStatus(taIssue.getProcessStatus());
265
+        process.setStatus(Constants.STATUS_NORMAL);
266
+        process.setCreateUser(sysUser.getUserId());
267
+        process.setUserName(sysUser.getName());
268
+        process.setCreateDate(LocalDateTime.now());
269
+        taIssueProcessMapper.insert(process);
270
+    }
271
+
190
     private TaCheckItemQu getQu(List<TaCheckItemQu> quList, String quId) {
272
     private TaCheckItemQu getQu(List<TaCheckItemQu> quList, String quId) {
191
         return quList.stream().filter(q -> q.getQuId().equals(quId)).findFirst().orElse(null);
273
         return quList.stream().filter(q -> q.getQuId().equals(quId)).findFirst().orElse(null);
192
     }
274
     }

+ 6
- 4
src/main/java/com/example/civilizedcity/service/impl/TaIssueApplyServiceImpl.java View File

1
 package com.example.civilizedcity.service.impl;
1
 package com.example.civilizedcity.service.impl;
2
 
2
 
3
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.example.civilizedcity.common.Constants;
4
 import com.example.civilizedcity.common.Constants;
6
-import com.example.civilizedcity.common.ResponseBean;
7
 import com.example.civilizedcity.entity.*;
5
 import com.example.civilizedcity.entity.*;
8
 import com.example.civilizedcity.event.MessagEvent;
6
 import com.example.civilizedcity.event.MessagEvent;
9
 import com.example.civilizedcity.mapper.*;
7
 import com.example.civilizedcity.mapper.*;
79
     }
77
     }
80
 
78
 
81
     @Override
79
     @Override
82
-    public IPage<TaIssueApply> getPageBy(IPage<TaIssueApply> pg, Integer issueId, String applyType, String orgId, String sourceType) {
83
-        return baseMapper.getPageBy(pg, issueId, applyType, orgId, sourceType);
80
+    public IPage<TaIssueApply> getPageBy(IPage<TaIssueApply> pg, Integer issueId, String applyType, String orgId, String sourceType, Boolean isAll) {
81
+
82
+        // 如果 isAll 是 false
83
+        // 那么只查询还未审核的
84
+
85
+        return baseMapper.getPageBy(pg, issueId, applyType, orgId, sourceType, isAll);
84
     }
86
     }
85
 
87
 
86
     @Transactional(rollbackFor = Exception.class)
88
     @Transactional(rollbackFor = Exception.class)

+ 3
- 0
src/main/resources/mapper/TaIssueApplyMapper.xml View File

28
         <if test="sourceType != null and sourceType != 'feedback'">
28
         <if test="sourceType != null and sourceType != 'feedback'">
29
             AND s.source_type != 'feedback'
29
             AND s.source_type != 'feedback'
30
         </if>
30
         </if>
31
+        <if test="isAll == null or !isAll">
32
+            AND t.verify_date is null
33
+        </if>
31
         ORDER BY
34
         ORDER BY
32
             IFNULL(t.verify_status, -1) ASC,
35
             IFNULL(t.verify_status, -1) ASC,
33
             t.create_date DESC
36
             t.create_date DESC