Yansen 2 年前
父节点
当前提交
05449042fd
共有 19 个文件被更改,包括 497 次插入121 次删除
  1. 35
    1
      db/.back_文明创办/文明创办-backup-202318151432.pdma.json
  2. 53
    2
      db/.back_文明创办/文明创办-backup-202318151439.pdma.json
  3. 18
    1
      db/文明创办.pdma.json
  4. 4
    0
      src/main/java/com/example/civilizedcity/common/Constants.java
  5. 4
    0
      src/main/java/com/example/civilizedcity/common/StringUtils.java
  6. 126
    59
      src/main/java/com/example/civilizedcity/controller/TaCheckItemController.java
  7. 7
    0
      src/main/java/com/example/civilizedcity/entity/TaCheckAnswer.java
  8. 28
    34
      src/main/java/com/example/civilizedcity/entity/TaCheckAnswerItem.java
  9. 6
    3
      src/main/java/com/example/civilizedcity/mapper/TaCheckAnswerItemMapper.java
  10. 6
    3
      src/main/java/com/example/civilizedcity/mapper/TaCheckAnswerMapper.java
  11. 9
    3
      src/main/java/com/example/civilizedcity/mapper/TaCheckItemAnMapper.java
  12. 6
    2
      src/main/java/com/example/civilizedcity/service/TaCheckAnswerService.java
  13. 3
    0
      src/main/java/com/example/civilizedcity/service/TaCheckItemService.java
  14. 13
    2
      src/main/java/com/example/civilizedcity/service/impl/TaCheckAnswerServiceImpl.java
  15. 138
    3
      src/main/java/com/example/civilizedcity/service/impl/TaCheckItemServiceImpl.java
  16. 1
    7
      src/main/java/com/example/civilizedcity/service/impl/TaCheckServiceImpl.java
  17. 9
    0
      src/main/resources/mapper/TaCheckAnswerItemMapper.xml
  18. 10
    0
      src/main/resources/mapper/TaCheckAnswerMapper.xml
  19. 21
    1
      src/main/resources/mapper/TaCheckItemAnMapper.xml

db/.back_文明创办/文明创办-backup-202317194605.pdma.json → db/.back_文明创办/文明创办-backup-202318151432.pdma.json 查看文件

4
   "avatar": "",
4
   "avatar": "",
5
   "version": "4.1.4",
5
   "version": "4.1.4",
6
   "createdTime": "2022-12-12 09:36:12",
6
   "createdTime": "2022-12-12 09:36:12",
7
-  "updatedTime": "2023-1-4 09:07:35",
7
+  "updatedTime": "2023-1-7 20:25:36",
8
   "dbConns": [],
8
   "dbConns": [],
9
   "profile": {
9
   "profile": {
10
     "default": {
10
     "default": {
4748
           "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
4748
           "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
4749
           "id": "0EF50BA7-C44F-4D9E-A28D-F94C3D15350F"
4749
           "id": "0EF50BA7-C44F-4D9E-A28D-F94C3D15350F"
4750
         },
4750
         },
4751
+        {
4752
+          "defKey": "loc_score",
4753
+          "defName": "实地测评得分",
4754
+          "comment": "",
4755
+          "type": "DECIMAL",
4756
+          "len": 6,
4757
+          "scale": 2,
4758
+          "primaryKey": false,
4759
+          "notNull": false,
4760
+          "autoIncrement": false,
4761
+          "defaultValue": "",
4762
+          "hideInGraph": false,
4763
+          "refDict": "",
4764
+          "extProps": {},
4765
+          "domain": "",
4766
+          "id": "D4F39D10-19B6-49F6-A398-D9278355E747"
4767
+        },
4768
+        {
4769
+          "defKey": "survey_score",
4770
+          "defName": "调查问卷得分",
4771
+          "comment": "",
4772
+          "type": "DECIMAL",
4773
+          "len": 6,
4774
+          "scale": 2,
4775
+          "primaryKey": false,
4776
+          "notNull": false,
4777
+          "autoIncrement": false,
4778
+          "defaultValue": "",
4779
+          "hideInGraph": false,
4780
+          "refDict": "",
4781
+          "extProps": {},
4782
+          "domain": "",
4783
+          "id": "F2E17D81-03A9-42C4-8DD7-732C8D40DC59"
4784
+        },
4751
         {
4785
         {
4752
           "defKey": "start_date",
4786
           "defKey": "start_date",
4753
           "defName": "开始日期",
4787
           "defName": "开始日期",

db/.back_文明创办/文明创办-backup-202314090735.pdma.json → db/.back_文明创办/文明创办-backup-202318151439.pdma.json 查看文件

2
   "name": "文明创办",
2
   "name": "文明创办",
3
   "describe": "文明创办",
3
   "describe": "文明创办",
4
   "avatar": "",
4
   "avatar": "",
5
-  "version": "4.2.0",
5
+  "version": "4.1.4",
6
   "createdTime": "2022-12-12 09:36:12",
6
   "createdTime": "2022-12-12 09:36:12",
7
-  "updatedTime": "2023-1-2 22:36:59",
7
+  "updatedTime": "2023-1-8 15:14:32",
8
   "dbConns": [],
8
   "dbConns": [],
9
   "profile": {
9
   "profile": {
10
     "default": {
10
     "default": {
4748
           "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
4748
           "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
4749
           "id": "0EF50BA7-C44F-4D9E-A28D-F94C3D15350F"
4749
           "id": "0EF50BA7-C44F-4D9E-A28D-F94C3D15350F"
4750
         },
4750
         },
4751
+        {
4752
+          "defKey": "loc_score",
4753
+          "defName": "实地测评得分",
4754
+          "comment": "",
4755
+          "type": "DECIMAL",
4756
+          "len": 6,
4757
+          "scale": 2,
4758
+          "primaryKey": false,
4759
+          "notNull": false,
4760
+          "autoIncrement": false,
4761
+          "defaultValue": "",
4762
+          "hideInGraph": false,
4763
+          "refDict": "",
4764
+          "extProps": {},
4765
+          "domain": "",
4766
+          "id": "D4F39D10-19B6-49F6-A398-D9278355E747"
4767
+        },
4768
+        {
4769
+          "defKey": "survey_score",
4770
+          "defName": "调查问卷得分",
4771
+          "comment": "",
4772
+          "type": "DECIMAL",
4773
+          "len": 6,
4774
+          "scale": 2,
4775
+          "primaryKey": false,
4776
+          "notNull": false,
4777
+          "autoIncrement": false,
4778
+          "defaultValue": "",
4779
+          "hideInGraph": false,
4780
+          "refDict": "",
4781
+          "extProps": {},
4782
+          "domain": "",
4783
+          "id": "F2E17D81-03A9-42C4-8DD7-732C8D40DC59"
4784
+        },
4751
         {
4785
         {
4752
           "defKey": "start_date",
4786
           "defKey": "start_date",
4753
           "defName": "开始日期",
4787
           "defName": "开始日期",
6449
           "domain": "16120F75-6AA7-4483-868D-F07F511BB081",
6483
           "domain": "16120F75-6AA7-4483-868D-F07F511BB081",
6450
           "id": "0B03C02D-84EC-4306-8CEA-2BAF04806409"
6484
           "id": "0B03C02D-84EC-4306-8CEA-2BAF04806409"
6451
         },
6485
         },
6486
+        {
6487
+          "defKey": "answer_code",
6488
+          "defName": "答案选项",
6489
+          "comment": "",
6490
+          "type": "VARCHAR",
6491
+          "len": 10,
6492
+          "scale": "",
6493
+          "primaryKey": false,
6494
+          "notNull": false,
6495
+          "autoIncrement": false,
6496
+          "defaultValue": "",
6497
+          "hideInGraph": false,
6498
+          "refDict": "",
6499
+          "extProps": {},
6500
+          "domain": "",
6501
+          "id": "DD78B024-C9B8-4418-BD1B-8F033743F253"
6502
+        },
6452
         {
6503
         {
6453
           "defKey": "answer",
6504
           "defKey": "answer",
6454
           "defName": "答案",
6505
           "defName": "答案",

+ 18
- 1
db/文明创办.pdma.json 查看文件

4
   "avatar": "",
4
   "avatar": "",
5
   "version": "4.1.4",
5
   "version": "4.1.4",
6
   "createdTime": "2022-12-12 09:36:12",
6
   "createdTime": "2022-12-12 09:36:12",
7
-  "updatedTime": "2023-1-7 20:25:36",
7
+  "updatedTime": "2023-1-8 15:14:39",
8
   "dbConns": [],
8
   "dbConns": [],
9
   "profile": {
9
   "profile": {
10
     "default": {
10
     "default": {
6483
           "domain": "16120F75-6AA7-4483-868D-F07F511BB081",
6483
           "domain": "16120F75-6AA7-4483-868D-F07F511BB081",
6484
           "id": "0B03C02D-84EC-4306-8CEA-2BAF04806409"
6484
           "id": "0B03C02D-84EC-4306-8CEA-2BAF04806409"
6485
         },
6485
         },
6486
+        {
6487
+          "defKey": "answer_code",
6488
+          "defName": "答案选项",
6489
+          "comment": "",
6490
+          "type": "VARCHAR",
6491
+          "len": 10,
6492
+          "scale": "",
6493
+          "primaryKey": false,
6494
+          "notNull": false,
6495
+          "autoIncrement": false,
6496
+          "defaultValue": "",
6497
+          "hideInGraph": false,
6498
+          "refDict": "",
6499
+          "extProps": {},
6500
+          "domain": "",
6501
+          "id": "DD78B024-C9B8-4418-BD1B-8F033743F253"
6502
+        },
6486
         {
6503
         {
6487
           "defKey": "answer",
6504
           "defKey": "answer",
6488
           "defName": "答案",
6505
           "defName": "答案",

+ 4
- 0
src/main/java/com/example/civilizedcity/common/Constants.java 查看文件

86
     // 调查问卷
86
     // 调查问卷
87
     public final static String CHECK_OF_LOC = "loc"; // 实地调查
87
     public final static String CHECK_OF_LOC = "loc"; // 实地调查
88
     public final static String CHECK_OF_SURVEY = "survey"; // 调查问卷
88
     public final static String CHECK_OF_SURVEY = "survey"; // 调查问卷
89
+
90
+    // 题型
91
+    public final static String QU_OF_FILL = "fill"; // 填空题
92
+    public final static String QU_OF_RADIO = "radio"; // 选择题
89
 }
93
 }

+ 4
- 0
src/main/java/com/example/civilizedcity/common/StringUtils.java 查看文件

53
         return sb.toString();
53
         return sb.toString();
54
     }
54
     }
55
 
55
 
56
+    public static String uuid() {
57
+        return UUID.randomUUID().toString().replaceAll("-", "");
58
+    }
59
+
56
     public static String urlEncode(String str) {
60
     public static String urlEncode(String str) {
57
         if (isEmpty(str)) return str;
61
         if (isEmpty(str)) return str;
58
 
62
 

+ 126
- 59
src/main/java/com/example/civilizedcity/controller/TaCheckItemController.java 查看文件

3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.example.civilizedcity.common.BaseController;
7
-import com.example.civilizedcity.common.Constants;
8
-import com.example.civilizedcity.common.ResponseBean;
6
+import com.example.civilizedcity.common.*;
9
 
7
 
10
 import java.time.LocalDateTime;
8
 import java.time.LocalDateTime;
11
 import java.util.List;
9
 import java.util.List;
12
 
10
 
13
-import com.example.civilizedcity.common.StringUtils;
14
-import com.example.civilizedcity.entity.TdLocType;
11
+import com.example.civilizedcity.entity.*;
12
+import com.example.civilizedcity.service.TaCheckAnswerService;
13
+import com.example.civilizedcity.service.TaCheckService;
15
 import com.example.civilizedcity.service.TdLocTypeService;
14
 import com.example.civilizedcity.service.TdLocTypeService;
16
 import io.swagger.annotations.Api;
15
 import io.swagger.annotations.Api;
17
 import io.swagger.annotations.ApiOperation;
16
 import io.swagger.annotations.ApiOperation;
18
 import io.swagger.annotations.ApiParam;
17
 import io.swagger.annotations.ApiParam;
19
 import org.springframework.beans.factory.annotation.Autowired;
18
 import org.springframework.beans.factory.annotation.Autowired;
20
 import org.springframework.web.bind.annotation.*;
19
 import org.springframework.web.bind.annotation.*;
21
-import com.example.civilizedcity.entity.TaCheckItem;
22
 import com.example.civilizedcity.service.TaCheckItemService;
20
 import com.example.civilizedcity.service.TaCheckItemService;
23
 
21
 
24
- /**
22
+/**
25
  * 测评点位;(ta_check_item)表控制层
23
  * 测评点位;(ta_check_item)表控制层
24
+ *
26
  * @author : http://njyunzhi.com
25
  * @author : http://njyunzhi.com
27
  * @date : 2022-12-13
26
  * @date : 2022-12-13
28
  */
27
  */
30
 @RestController
29
 @RestController
31
 @RequestMapping("/")
30
 @RequestMapping("/")
32
 public class TaCheckItemController extends BaseController {
31
 public class TaCheckItemController extends BaseController {
33
-    
32
+
34
     @Autowired
33
     @Autowired
35
     private TaCheckItemService taCheckItemService;
34
     private TaCheckItemService taCheckItemService;
36
 
35
 
37
     @Autowired
36
     @Autowired
38
     private TdLocTypeService tdLocTypeService;
37
     private TdLocTypeService tdLocTypeService;
39
-    
38
+
39
+    @Autowired
40
+    private TaCheckService taCheckService;
41
+
42
+    @Autowired
43
+    private TaCheckAnswerService taCheckAnswerService;
44
+
40
     /**
45
     /**
41
      * 通过ID查询单条数据
46
      * 通过ID查询单条数据
42
      *
47
      *
49
         return ResponseBean.success(taCheckItemService.getById(id));
54
         return ResponseBean.success(taCheckItemService.getById(id));
50
     }
55
     }
51
 
56
 
52
-     /**
53
-      * 通过测评以及点位查询数据
54
-      *
55
-      * @param checkId 测评ID
56
-      * @param typeId 点位ID
57
-      * @return 实例对象
58
-      */
59
-     @ApiOperation("通过测评以及点位查询数据")
60
-     @GetMapping("/taCheck/{checkId}/item/{typeId}")
61
-     public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
62
-                                        @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
63
-
64
-         return ResponseBean.success(getByCheckAndType(checkId, typeId));
65
-     }
66
-
67
-     private TaCheckItem getByCheckAndType(String checkId, String typeId) {
68
-         QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
69
-         queryWrapper.eq("check_id", checkId);
70
-         queryWrapper.eq("item_type", Constants.CHECK_OF_LOC); // 只查点位
71
-         queryWrapper.eq("type_id", typeId);
72
-         queryWrapper.gt("status", Constants.STATUS_DELETE);
57
+    /**
58
+     * 通过测评以及点位查询数据
59
+     *
60
+     * @param checkId 测评ID
61
+     * @param typeId  点位ID
62
+     * @return 实例对象
63
+     */
64
+    @ApiOperation("通过测评以及点位查询数据")
65
+    @GetMapping("/taCheck/{checkId}/item/{typeId}")
66
+    public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
67
+                                       @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
68
+
69
+        return ResponseBean.success(getByCheckAndType(checkId, typeId));
70
+    }
71
+
72
+    private TaCheckItem getByCheckAndType(String checkId, String typeId) {
73
+        QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
74
+        queryWrapper.eq("check_id", checkId);
75
+        queryWrapper.eq("item_type", Constants.CHECK_OF_LOC); // 只查点位
76
+        queryWrapper.eq("type_id", typeId);
77
+        queryWrapper.gt("status", Constants.STATUS_DELETE);
73
 
78
 
74
         return taCheckItemService.getOne(queryWrapper);
79
         return taCheckItemService.getOne(queryWrapper);
75
-     }
76
-    
77
-    /** 
80
+    }
81
+
82
+    /**
78
      * 分页查询
83
      * 分页查询
79
      *
84
      *
80
-     * @param pageNum 当前页码
85
+     * @param pageNum  当前页码
81
      * @param pageSize 每页条数
86
      * @param pageSize 每页条数
82
      * @return 查询结果
87
      * @return 查询结果
83
      */
88
      */
84
     @ApiOperation("分页查询")
89
     @ApiOperation("分页查询")
85
     @GetMapping("/taCheckItem")
90
     @GetMapping("/taCheckItem")
86
-    public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
87
-                             @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
88
-                             @ApiParam("模拟测评ID") @RequestParam(value ="checkId") String checkId,
89
-                             @ApiParam("项目类型") @RequestParam(value ="itemType") String itemType) throws Exception {
90
-        
91
+    public ResponseBean list(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
92
+                             @ApiParam("单页数据量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
93
+                             @ApiParam("模拟测评ID") @RequestParam(value = "checkId") String checkId,
94
+                             @ApiParam("项目类型") @RequestParam(value = "itemType") String itemType) throws Exception {
95
+
91
         IPage<TaCheckItem> pg = new Page<>(pageNum, pageSize);
96
         IPage<TaCheckItem> pg = new Page<>(pageNum, pageSize);
92
         IPage<TaCheckItem> result = taCheckItemService.getPageBy(pg, checkId, itemType);
97
         IPage<TaCheckItem> result = taCheckItemService.getPageBy(pg, checkId, itemType);
93
-        
98
+
94
         return ResponseBean.success(result);
99
         return ResponseBean.success(result);
95
     }
100
     }
96
-    
97
-    /** 
101
+
102
+    /**
98
      * 新增数据
103
      * 新增数据
99
      *
104
      *
100
      * @param taCheckItem 实例对象
105
      * @param taCheckItem 实例对象
135
 
140
 
136
         return ResponseBean.success(taCheckItem);
141
         return ResponseBean.success(taCheckItem);
137
     }
142
     }
138
-    
139
-//    /**
140
-//     * 更新数据
141
-//     *
142
-//     * @param taCheckItem 实例对象
143
-//     * @return 实例对象
144
-//     */
145
-//    @ApiOperation("更新数据")
146
-//    @PutMapping("/taCheckItem/{id}")
147
-//    public ResponseBean edit(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem,
148
-//                            @ApiParam("对象ID") @PathVariable String id ) throws Exception {
149
-//        taCheckItemService.updateById(taCheckItem);
150
-//        return ResponseBean.success(taCheckItem);
151
-//    }
152
-    
153
-    /** 
143
+
144
+    @ApiOperation("答卷检测")
145
+    @PutMapping("/taCheckItem/{id}/answer/pre-check")
146
+    public ResponseBean checkAnswer(@ApiParam("对象ID") @PathVariable String id) throws Exception {
147
+        TaCheckItem taCheckItem = taCheckItemService.getById(id);
148
+        if (null == taCheckItem || taCheckItem.getStatus() == Constants.STATUS_DELETE) {
149
+            return ResponseBean.error("未找到有效的答题信息");
150
+        }
151
+
152
+        TaCheck taCheck = taCheckService.getById(taCheckItem.getCheckId());
153
+        if (null == taCheck || taCheck.getStatus() == Constants.STATUS_DELETE) {
154
+            return ResponseBean.error("未找到有效的测评信息");
155
+        }
156
+
157
+        if (LocalDateTime.now().isAfter(DateUtils.day2LocalDateime(taCheck.getEndDate()))) {
158
+            return ResponseBean.error("本次测评已结束");
159
+        }
160
+
161
+        SysUser sysUser = currentUser();
162
+        int count = taCheckAnswerService.getCountByUser(taCheckItem.getItemId(), sysUser.getUserId());
163
+        if (count > 0) {
164
+            return ResponseBean.error("本次测题您已作答完毕");
165
+        }
166
+
167
+        if (Constants.CHECK_OF_LOC.equals(taCheckItem.getItemType())) {
168
+            // 如果是实地问卷
169
+            int cnt = taCheckAnswerService.countByItem(taCheckItem.getItemId());
170
+            if (cnt >= taCheckItem.getNum()) {
171
+                return ResponseBean.error("当前实地问卷已收齐, 无须作答");
172
+            }
173
+        }
174
+
175
+        return ResponseBean.success(null);
176
+    }
177
+
178
+    /**
179
+     * 回答问题
180
+     *
181
+     * @param taCheckAnswer 实例对象
182
+     * @return 实例对象
183
+     */
184
+    @ApiOperation("更新数据")
185
+    @PutMapping("/taCheckItem/{id}/answer")
186
+    public ResponseBean answer(@ApiParam("对象实体") @RequestBody TaCheckAnswer taCheckAnswer,
187
+                               @ApiParam("对象ID") @PathVariable String id) throws Exception {
188
+
189
+        TaCheckItem taCheckItem = taCheckItemService.getById(id);
190
+        if (null == taCheckItem || taCheckItem.getStatus() == Constants.STATUS_DELETE) {
191
+            return ResponseBean.error("未找到有效的答题信息");
192
+        }
193
+
194
+        TaCheck taCheck = taCheckService.getById(taCheckItem.getCheckId());
195
+        if (null == taCheck || taCheck.getStatus() == Constants.STATUS_DELETE) {
196
+            return ResponseBean.error("未找到有效的测评信息");
197
+        }
198
+
199
+        if (LocalDateTime.now().isAfter(DateUtils.day2LocalDateime(taCheck.getEndDate()))) {
200
+            return ResponseBean.error("本次测评已结束");
201
+        }
202
+
203
+        if (StringUtils.isEmpty(taCheckAnswer.getAddr())) {
204
+            return ResponseBean.error("测评地点详情或小区名称未填写");
205
+        }
206
+
207
+        SysUser sysUser = currentUser();
208
+        taCheckAnswer.setAnswerId(StringUtils.uuid());
209
+        taCheckAnswer.setCheckId(taCheck.getCheckId());
210
+        taCheckAnswer.setItemId(id);
211
+        taCheckAnswer.setStatus(Constants.STATUS_NORMAL);
212
+        taCheckAnswer.setOrgId(sysUser.getOrgId());
213
+        taCheckAnswer.setCreateUser(sysUser.getUserId());
214
+        taCheckAnswer.setCreateDate(LocalDateTime.now());
215
+
216
+        taCheckItemService.answer(taCheckItem, taCheckAnswer);
217
+        return null;
218
+    }
219
+
220
+    /**
154
      * 通过主键删除数据
221
      * 通过主键删除数据
155
      *
222
      *
156
      * @param itemId 主键
223
      * @param itemId 主键
158
      */
225
      */
159
     @ApiOperation("通过主键删除数据")
226
     @ApiOperation("通过主键删除数据")
160
     @DeleteMapping("/taCheckItem/{id}")
227
     @DeleteMapping("/taCheckItem/{id}")
161
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
228
+    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id) {
162
         taCheckItemService.removeLogicById(id);
229
         taCheckItemService.removeLogicById(id);
163
         return ResponseBean.success("success");
230
         return ResponseBean.success("success");
164
     }
231
     }

+ 7
- 0
src/main/java/com/example/civilizedcity/entity/TaCheckAnswer.java 查看文件

1
 package com.example.civilizedcity.entity;
1
 package com.example.civilizedcity.entity;
2
 
2
 
3
+import com.baomidou.mybatisplus.annotation.TableField;
3
 import io.swagger.annotations.ApiModel;
4
 import io.swagger.annotations.ApiModel;
4
 import io.swagger.annotations.ApiModelProperty;
5
 import io.swagger.annotations.ApiModelProperty;
5
 import com.baomidou.mybatisplus.annotation.IdType;
6
 import com.baomidou.mybatisplus.annotation.IdType;
7
 import com.baomidou.mybatisplus.annotation.TableId;
8
 import com.baomidou.mybatisplus.annotation.TableId;
8
 import java.io.Serializable;
9
 import java.io.Serializable;
9
 import java.time.LocalDateTime;
10
 import java.time.LocalDateTime;
11
+import java.util.List;
12
+
10
 import lombok.Data;
13
 import lombok.Data;
11
 import lombok.EqualsAndHashCode;
14
 import lombok.EqualsAndHashCode;
12
 import lombok.experimental.Accessors;
15
 import lombok.experimental.Accessors;
60
     @ApiModelProperty(name = "作答时间",notes = "")
63
     @ApiModelProperty(name = "作答时间",notes = "")
61
     private LocalDateTime createDate ;
64
     private LocalDateTime createDate ;
62
 
65
 
66
+    @TableField(exist = false)
67
+    @ApiModelProperty(name = "答案列表",notes = "")
68
+    private List<TaCheckAnswerItem> answerItemList ;
69
+
63
 }
70
 }

+ 28
- 34
src/main/java/com/example/civilizedcity/entity/TaCheckAnswerItem.java 查看文件

22
 @ApiModel(value = "测评作答详情",description = "")
22
 @ApiModel(value = "测评作答详情",description = "")
23
 @TableName("ta_check_answer_item")
23
 @TableName("ta_check_answer_item")
24
 public class TaCheckAnswerItem implements Serializable,Cloneable{
24
 public class TaCheckAnswerItem implements Serializable,Cloneable{
25
-    /** 答案ID */
26
-    @ApiModelProperty(name = "答案ID",notes = "")
27
-    @TableId(value = "item_id", type = IdType.INPUT)
28
-    private String itemId ;
29
-    /** 问题ID;来源点位为题 */
30
-    @ApiModelProperty(name = "问题ID",notes = "来源点位为题")
31
-    private String quId ;
32
-    /** 作答ID;来源测评作答 */
33
-    @ApiModelProperty(name = "作答ID",notes = "来源测评作答")
34
-    private String answerId ;
35
-    /** 其他问题;其他问题时, qu_id 不存在 */
36
-    @ApiModelProperty(name = "其他问题",notes = "其他问题时, qu_id 不存在")
37
-    private Integer isCustom ;
38
-    /** 问题描述 */
39
-    @ApiModelProperty(name = "问题描述",notes = "")
40
-    private String quTitle ;
41
-    /** 标准答案 */
42
-    @ApiModelProperty(name = "标准答案",notes = "")
43
-    private String standAnswer ;
44
-    /** 答案 */
45
-    @ApiModelProperty(name = "答案",notes = "")
46
-    private String answer ;
47
-    /** 得分 */
48
-    @ApiModelProperty(name = "得分",notes = "")
49
-    private Double score ;
50
-    /** 状态 */
51
-    @ApiModelProperty(name = "状态",notes = "")
52
-    private Integer status ;
53
-    /** 作答人 */
54
-    @ApiModelProperty(name = "作答人",notes = "")
55
-    private String createUser ;
56
-    /** 作答时间 */
57
-    @ApiModelProperty(name = "作答时间",notes = "")
58
-    private LocalDateTime createDate ;
25
+     /** 答案ID */
26
+     @ApiModelProperty(name = "答案ID",notes = "")
27
+     @TableId(value = "item_id", type = IdType.ASSIGN_UUID)
28
+     private String itemId ;
29
+     /** 问题ID;来源点位问题 */
30
+     @ApiModelProperty(name = "问题ID",notes = "来源点位问题")
31
+     private String quId ;
32
+     /** 作答ID;来源测评作答 */
33
+     @ApiModelProperty(name = "作答ID",notes = "来源测评作答")
34
+     private String answerId ;
35
+     /** 答案选项 */
36
+     @ApiModelProperty(name = "答案选项",notes = "")
37
+     private String answerCode ;
38
+     /** 答案 */
39
+     @ApiModelProperty(name = "答案",notes = "")
40
+     private String answer ;
41
+     /** 得分 */
42
+     @ApiModelProperty(name = "得分",notes = "")
43
+     private Double score ;
44
+     /** 状态 */
45
+     @ApiModelProperty(name = "状态",notes = "")
46
+     private Integer status ;
47
+     /** 作答人 */
48
+     @ApiModelProperty(name = "作答人",notes = "")
49
+     private String createUser ;
50
+     /** 作答时间 */
51
+     @ApiModelProperty(name = "作答时间",notes = "")
52
+     private LocalDateTime createDate ;
59
 
53
 
60
 }
54
 }

+ 6
- 3
src/main/java/com/example/civilizedcity/mapper/TaCheckAnswerItemMapper.java 查看文件

9
 
9
 
10
 /**
10
 /**
11
  * 测评作答详情;(ta_check_answer_item)表数据库访问层
11
  * 测评作答详情;(ta_check_answer_item)表数据库访问层
12
+ *
12
  * @author : http://njyunzhi.com
13
  * @author : http://njyunzhi.com
13
  * @date : 2022-12-13
14
  * @date : 2022-12-13
14
  */
15
  */
15
 @Mapper
16
 @Mapper
16
-public interface TaCheckAnswerItemMapper  extends BaseMapper<TaCheckAnswerItem>{
17
+public interface TaCheckAnswerItemMapper extends BaseMapper<TaCheckAnswerItem> {
17
 
18
 
18
-     List<TaCheckAnswerItem> getListBy(@Param("answerId") String answerId);
19
- }
19
+    List<TaCheckAnswerItem> getListBy(@Param("answerId") String answerId);
20
+
21
+    int getCountByAnswer(@Param("answerId") String answerId);
22
+}

+ 6
- 3
src/main/java/com/example/civilizedcity/mapper/TaCheckAnswerMapper.java 查看文件

9
 
9
 
10
 /**
10
 /**
11
  * 测评作答;(ta_check_answer)表数据库访问层
11
  * 测评作答;(ta_check_answer)表数据库访问层
12
+ *
12
  * @author : http://njyunzhi.com
13
  * @author : http://njyunzhi.com
13
  * @date : 2022-12-13
14
  * @date : 2022-12-13
14
  */
15
  */
15
 @Mapper
16
 @Mapper
16
-public interface TaCheckAnswerMapper  extends BaseMapper<TaCheckAnswer>{
17
+public interface TaCheckAnswerMapper extends BaseMapper<TaCheckAnswer> {
17
 
18
 
18
-     Integer countByItem(@Param("itemId") String itemId);
19
+    Integer countByItem(@Param("itemId") String itemId);
19
 
20
 
20
-     List<TaCheckAnswer> getListBy(@Param("itemId") String itemId);
21
+    List<TaCheckAnswer> getListBy(@Param("itemId") String itemId);
21
 
22
 
22
     Double sumScore(@Param("itemId") String itemId, @Param("num") Integer num);
23
     Double sumScore(@Param("itemId") String itemId, @Param("num") Integer num);
24
+
25
+    int getCountByUser(@Param("itemId") String itemId, @Param("userId") String userId);
23
 }
26
 }

+ 9
- 3
src/main/java/com/example/civilizedcity/mapper/TaCheckItemAnMapper.java 查看文件

5
 import org.apache.ibatis.annotations.Param;
5
 import org.apache.ibatis.annotations.Param;
6
 import com.example.civilizedcity.entity.TaCheckItemAn;
6
 import com.example.civilizedcity.entity.TaCheckItemAn;
7
 
7
 
8
- /**
8
+import java.util.List;
9
+
10
+/**
9
  * 项目问题答案;(ta_check_item_an)表数据库访问层
11
  * 项目问题答案;(ta_check_item_an)表数据库访问层
12
+ *
10
  * @author : http://njyunzhi.com
13
  * @author : http://njyunzhi.com
11
  * @date : 2022-12-16
14
  * @date : 2022-12-16
12
  */
15
  */
13
 @Mapper
16
 @Mapper
14
-public interface TaCheckItemAnMapper  extends BaseMapper<TaCheckItemAn>{
15
-    
17
+public interface TaCheckItemAnMapper extends BaseMapper<TaCheckItemAn> {
18
+
19
+    List<TaCheckItemAn> getListBy(@Param("quId") String quId);
20
+
21
+    TaCheckItemAn getOneBy(@Param("quId") String quId, @Param("answerCode") String answerCode);
16
 }
22
 }

+ 6
- 2
src/main/java/com/example/civilizedcity/service/TaCheckAnswerService.java 查看文件

3
 import com.baomidou.mybatisplus.extension.service.IService;
3
 import com.baomidou.mybatisplus.extension.service.IService;
4
 import com.example.civilizedcity.entity.TaCheckAnswer;
4
 import com.example.civilizedcity.entity.TaCheckAnswer;
5
 
5
 
6
- /**
6
+/**
7
  * 测评作答;(ta_check_answer)表服务接口
7
  * 测评作答;(ta_check_answer)表服务接口
8
+ *
8
  * @author : http://njyunzhi.com
9
  * @author : http://njyunzhi.com
9
  * @date : 2022-12-13
10
  * @date : 2022-12-13
10
  */
11
  */
11
 public interface TaCheckAnswerService extends IBaseService<TaCheckAnswer> {
12
 public interface TaCheckAnswerService extends IBaseService<TaCheckAnswer> {
12
-    
13
+
14
+    int getCountByUser(String itemId, String userId);
15
+
16
+    int countByItem(String itemId);
13
 }
17
 }

+ 3
- 0
src/main/java/com/example/civilizedcity/service/TaCheckItemService.java 查看文件

2
 
2
 
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.example.civilizedcity.entity.TaCheck;
4
 import com.example.civilizedcity.entity.TaCheck;
5
+import com.example.civilizedcity.entity.TaCheckAnswer;
5
 import com.example.civilizedcity.entity.TaCheckItem;
6
 import com.example.civilizedcity.entity.TaCheckItem;
6
 
7
 
7
  /**
8
  /**
14
      IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType);
15
      IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType);
15
 
16
 
16
      void createNewItems(TaCheck taCheck);
17
      void createNewItems(TaCheck taCheck);
18
+
19
+     void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer) throws Exception;
17
  }
20
  }

+ 13
- 2
src/main/java/com/example/civilizedcity/service/impl/TaCheckAnswerServiceImpl.java 查看文件

5
 import com.example.civilizedcity.entity.TaCheckAnswer;
5
 import com.example.civilizedcity.entity.TaCheckAnswer;
6
 import com.example.civilizedcity.mapper.TaCheckAnswerMapper;
6
 import com.example.civilizedcity.mapper.TaCheckAnswerMapper;
7
 import com.example.civilizedcity.service.TaCheckAnswerService;
7
 import com.example.civilizedcity.service.TaCheckAnswerService;
8
- /**
8
+
9
+/**
9
  * 测评作答;(ta_check_answer)表服务实现类
10
  * 测评作答;(ta_check_answer)表服务实现类
11
+ *
10
  * @author : http://www.chiner.pro
12
  * @author : http://www.chiner.pro
11
  * @date : 2022-12-13
13
  * @date : 2022-12-13
12
  */
14
  */
13
 @Service
15
 @Service
14
 public class TaCheckAnswerServiceImpl extends BaseServiceImpl<TaCheckAnswerMapper, TaCheckAnswer> implements TaCheckAnswerService {
16
 public class TaCheckAnswerServiceImpl extends BaseServiceImpl<TaCheckAnswerMapper, TaCheckAnswer> implements TaCheckAnswerService {
15
-    
17
+
18
+    @Override
19
+    public int getCountByUser(String itemId, String userId) {
20
+        return baseMapper.getCountByUser(itemId, userId);
21
+    }
22
+
23
+    @Override
24
+    public int countByItem(String itemId) {
25
+        return baseMapper.countByItem(itemId);
26
+    }
16
 }
27
 }

+ 138
- 3
src/main/java/com/example/civilizedcity/service/impl/TaCheckItemServiceImpl.java 查看文件

2
 
2
 
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
3
 import com.baomidou.mybatisplus.core.metadata.IPage;
4
 import com.example.civilizedcity.common.Constants;
4
 import com.example.civilizedcity.common.Constants;
5
-import com.example.civilizedcity.entity.TaCheck;
5
+import com.example.civilizedcity.common.StringUtils;
6
+import com.example.civilizedcity.entity.*;
7
+import com.example.civilizedcity.mapper.*;
6
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Service;
9
 import org.springframework.stereotype.Service;
8
-import com.example.civilizedcity.entity.TaCheckItem;
9
-import com.example.civilizedcity.mapper.TaCheckItemMapper;
10
 import com.example.civilizedcity.service.TaCheckItemService;
10
 import com.example.civilizedcity.service.TaCheckItemService;
11
+import org.springframework.transaction.annotation.Transactional;
12
+
13
+import java.util.List;
11
 
14
 
12
 /**
15
 /**
13
  * 测评点位;(ta_check_item)表服务实现类
16
  * 测评点位;(ta_check_item)表服务实现类
18
 @Service
21
 @Service
19
 public class TaCheckItemServiceImpl extends BaseServiceImpl<TaCheckItemMapper, TaCheckItem> implements TaCheckItemService {
22
 public class TaCheckItemServiceImpl extends BaseServiceImpl<TaCheckItemMapper, TaCheckItem> implements TaCheckItemService {
20
 
23
 
24
+    @Autowired
25
+    TaCheckItemQuMapper taCheckItemQuMapper;
26
+
27
+    @Autowired
28
+    TaCheckItemAnMapper taCheckItemAnMapper;
29
+
30
+    @Autowired
31
+    TaCheckAnswerItemMapper taCheckAnswerItemMapper;
32
+
33
+    @Autowired
34
+    TaCheckAnswerMapper taCheckAnswerMapper;
35
+
21
     @Override
36
     @Override
22
     public IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType) {
37
     public IPage<TaCheckItem> getPageBy(IPage<TaCheckItem> pg, String checkId, String itemType) {
23
         return baseMapper.getPageBy(pg, checkId, itemType);
38
         return baseMapper.getPageBy(pg, checkId, itemType);
34
         taCheckItem.setName("调查问卷");
49
         taCheckItem.setName("调查问卷");
35
         save(taCheckItem);
50
         save(taCheckItem);
36
     }
51
     }
52
+
53
+    @Transactional(rollbackFor = Exception.class)
54
+    @Override
55
+    public void answer(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer) throws Exception {
56
+        List<TaCheckItemQu> quList = taCheckItemQuMapper.getListBy(taCheckItem.getItemId());
57
+        if (null == quList || quList.size() < 1) {
58
+            throw new Exception("校验测评问题列表出错");
59
+        }
60
+
61
+        List<TaCheckAnswerItem> answerItemList = taCheckAnswer.getAnswerItemList();
62
+        if (null == answerItemList || answerItemList.size() != quList.size()) {
63
+            throw new Exception("未完成全部测评问题");
64
+        }
65
+
66
+        // 答案列表如果没有关联问题ID
67
+        long cnt = answerItemList.stream().filter(f -> null == f.getQuId()).count();
68
+        if (cnt > 0) {
69
+            throw new Exception("验证部分题干信息出错");
70
+        }
71
+
72
+        if (Constants.CHECK_OF_LOC.equals(taCheckItem.getItemType())) {
73
+            // 如果是实地问卷, 试卷份数不能多于规定份数
74
+            int count = taCheckAnswerMapper.countByItem(taCheckItem.getItemId());
75
+            if (count >= taCheckItem.getNum()) {
76
+                throw new Exception("当前实地问卷已收齐, 无须作答");
77
+            }
78
+        }
79
+
80
+        double[] scores = answerItems(taCheckItem, taCheckAnswer, quList, answerItemList);
81
+
82
+        if (Constants.CHECK_OF_SURVEY.equals(taCheckItem.getItemType())) {
83
+            // 调查问卷不需要计算当前试卷的分数, 最后才能计算出来
84
+            taCheckAnswerMapper.insert(taCheckAnswer);
85
+
86
+            // 但是需要更新答卷份数
87
+            int count = taCheckAnswerMapper.countByItem(taCheckItem.getItemId());
88
+            taCheckItem.setNum(count);
89
+            updateById(taCheckItem);
90
+            return;
91
+        }
92
+
93
+        if (Constants.CHECK_OF_LOC.equals(taCheckItem.getItemType())) {
94
+            // 实地调查, 需要计算当前这份试卷的份数
95
+            double positiveScore = scores[0];
96
+            double negativeScore = scores[1];
97
+
98
+            // 每份试卷的得分 = 总分 / 份数
99
+            double maxScore = taCheckItem.getFullScore()  / taCheckItem.getNum();
100
+            double totalScore = maxScore + negativeScore + positiveScore;
101
+
102
+            if (0 > totalScore) {
103
+                // 如果扣分项太多
104
+                totalScore = 0.0;
105
+            }
106
+            if (totalScore > maxScore) {
107
+                // 如果得分超过总分
108
+                totalScore = maxScore;
109
+            }
110
+
111
+            taCheckAnswer.setScore(totalScore);
112
+            taCheckAnswerMapper.insert(taCheckAnswer);
113
+        }
114
+    }
115
+
116
+    /**
117
+     * 计算每份试卷份数
118
+     * @param taCheckItem
119
+     * @param taCheckAnswer
120
+     * @throws Exception
121
+     */
122
+    private double[] answerItems(TaCheckItem taCheckItem, TaCheckAnswer taCheckAnswer, List<TaCheckItemQu> quList, List<TaCheckAnswerItem> answerItemList) throws Exception {
123
+
124
+        double negativeScore = 0.0; // 扣分
125
+        double positiveScore = 0.0; // 得分
126
+        for(TaCheckAnswerItem item : answerItemList) {
127
+            // 找到对应的题目
128
+            TaCheckItemQu qu = getQu(quList, item.getQuId());
129
+            // + 代表得分, 否则代表扣分
130
+            int sign = "+".equals(qu.getComputeType()) ? 1 : -1;
131
+
132
+            double score = 0.0;
133
+            if (Constants.QU_OF_FILL.equals(qu.getQuType())) {
134
+                // 如果是填空题, 用户填的应该是数字, 没填就是 0
135
+                Double an = StringUtils.isEmpty(item.getAnswer()) ? 0.0 : Double.parseDouble(item.getAnswer());
136
+                score = an * qu.getAnScore();
137
+                if (score > qu.getMaxScore()) {
138
+                    score = qu.getMaxScore();
139
+                }
140
+
141
+                score *= sign;
142
+            } else if (Constants.QU_OF_RADIO.equals(qu.getQuType())) {
143
+                // 如果是选择题, 先找到对应的答案
144
+                TaCheckItemAn standAn = taCheckItemAnMapper.getOneBy(qu.getQuId(), item.getAnswerCode());
145
+
146
+                score = standAn.getScore();
147
+                if (score > qu.getMaxScore()) {
148
+                    score = qu.getMaxScore();
149
+                }
150
+
151
+                score *= sign;
152
+            }
153
+
154
+            item.setItemId(StringUtils.uuid());
155
+            item.setAnswerId(taCheckAnswer.getAnswerId());
156
+            item.setScore(score);
157
+            taCheckAnswerItemMapper.insert(item);
158
+
159
+            if (score > 0) {
160
+                positiveScore += score;
161
+            } else {
162
+                negativeScore += score;
163
+            }
164
+        }
165
+
166
+        return new double[] {positiveScore, negativeScore};
167
+    }
168
+
169
+    private TaCheckItemQu getQu(List<TaCheckItemQu> quList, String quId) {
170
+        return quList.stream().filter(q -> q.getQuId().equals(quId)).findFirst().orElse(null);
171
+    }
37
 }
172
 }

+ 1
- 7
src/main/java/com/example/civilizedcity/service/impl/TaCheckServiceImpl.java 查看文件

155
     }
155
     }
156
 
156
 
157
     private TaCheckItemQu getQu(List<TaCheckItemQu> quList, String quId) {
157
     private TaCheckItemQu getQu(List<TaCheckItemQu> quList, String quId) {
158
-        for (TaCheckItemQu qu : quList) {
159
-            if (qu.getQuId().equals(quId)) {
160
-                return qu;
161
-            }
162
-        }
163
-
164
-        return null;
158
+        return quList.stream().filter(q -> q.getQuId().equals(quId)).findFirst().orElse(null);
165
     }
159
     }
166
 
160
 
167
     private boolean isZero(Double d) {
161
     private boolean isZero(Double d) {

+ 9
- 0
src/main/resources/mapper/TaCheckAnswerItemMapper.xml 查看文件

12
             t.answer_id = #{answerId}
12
             t.answer_id = #{answerId}
13
           AND t.`status` &gt; -1
13
           AND t.`status` &gt; -1
14
     </select>
14
     </select>
15
+    <select id="getCountByAnswer" resultType="java.lang.Integer">
16
+        SELECT
17
+            count(*)
18
+        FROM
19
+            ta_check_answer_item t
20
+        WHERE
21
+            t.answer_id = #{answerId}
22
+          AND t.`status` &gt; -1
23
+    </select>
15
 </mapper>
24
 </mapper>

+ 10
- 0
src/main/resources/mapper/TaCheckAnswerMapper.xml 查看文件

33
             t.create_date ASC
33
             t.create_date ASC
34
         LIMIT #{num}
34
         LIMIT #{num}
35
     </select>
35
     </select>
36
+    <select id="getCountByUser" resultType="java.lang.Integer">
37
+        SELECT
38
+            count( 1 )
39
+        FROM
40
+            ta_check_answer t
41
+        WHERE
42
+            t.item_id = #{itemId}
43
+          AND t.create_user = #{userId}
44
+          AND t.`status` &gt; -1
45
+    </select>
36
 </mapper>
46
 </mapper>

+ 21
- 1
src/main/resources/mapper/TaCheckItemAnMapper.xml 查看文件

2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
 
3
 
4
 <mapper namespace="com.example.civilizedcity.mapper.TaCheckItemAnMapper">
4
 <mapper namespace="com.example.civilizedcity.mapper.TaCheckItemAnMapper">
5
-    
5
+
6
+    <select id="getListBy" resultType="com.example.civilizedcity.entity.TaCheckItemAn">
7
+        SELECT
8
+            *
9
+        FROM
10
+            ta_check_item_an t
11
+        WHERE
12
+            t.qu_id = #{quId}
13
+        ORDER BY
14
+            t.sort_no ASC
15
+    </select>
16
+    <select id="getOneBy" resultType="com.example.civilizedcity.entity.TaCheckItemAn">
17
+        SELECT
18
+            *
19
+        FROM
20
+            ta_check_item_an t
21
+        WHERE
22
+            t.qu_id = #{quId}
23
+          AND t.answer_code = #{answerCode}
24
+        LIMIT 1
25
+    </select>
6
 </mapper>
26
 </mapper>