|
@@ -2,8 +2,10 @@ package com.sysu.admin.controller.lz.ns.site;
|
|
|
|
|
|
import com.sysu.admin.controller.lz.ns.NsActionRecordService;
|
|
|
import com.sysu.admin.controller.lz.ns.NsActionTreeService;
|
|
|
+import com.sysu.admin.controller.lz.ns.NsTaskService;
|
|
|
import com.sysu.admin.controller.lz.ns.bean.NsActionRecord;
|
|
|
import com.sysu.admin.controller.lz.ns.bean.NsActionTree;
|
|
|
+import com.sysu.admin.controller.lz.ns.bean.NsTask;
|
|
|
import com.sysu.admin.controller.lz.ns.bean.NsType;
|
|
|
import com.sysu.admin.controller.lz.tree.LzTree;
|
|
|
import com.sysu.admin.controller.lz.tree.LzTreeService;
|
|
@@ -28,40 +30,37 @@ public class NsActionRecordController {
|
|
|
private NsActionTreeService actionTreeService;
|
|
|
@Autowired
|
|
|
private LzTreeService lzTreeService;
|
|
|
+ @Autowired
|
|
|
+ private NsTaskService nsTaskService;
|
|
|
|
|
|
@RequestMapping("/list")
|
|
|
public BaseResult list(@RequestBody CommonVo commonVo){
|
|
|
List<LzTree> treeList = lzTreeService.findListByAreaId(commonVo.getAreaId());
|
|
|
List<Integer> ids = new ArrayList<>(treeList.size());
|
|
|
treeList.stream().forEach(lzTree -> ids.add(lzTree.getId()));
|
|
|
+ List<NsTask> nsTaskList = nsTaskService.findAll();
|
|
|
+ List<NsActionRecord> res = nsActionRecordService.findAllByTreeIds(ids, commonVo.getFinished());
|
|
|
List<NsActionTree> nsActionTrees = actionTreeService.findAll();
|
|
|
Map<Integer, NsActionTree> integerNsActionTreeMap = listToMap(nsActionTrees);
|
|
|
- List<NsActionRecord> res = nsActionRecordService.findAllByTreeIds(ids, commonVo.getFinished());
|
|
|
- return R.succ(cast(res, integerNsActionTreeMap));
|
|
|
+ //把NsActionRecord 与 NsTask 合并
|
|
|
+ merge(nsTaskList, res, integerNsActionTreeMap );
|
|
|
+
|
|
|
+ return R.succ(cast(nsTaskList));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 把农事记录 List<NsActionRecord> 转换成 Map<TreeId, Map<NsTypeId, List<NsActionRecord>>>
|
|
|
- * @param res
|
|
|
- * @param integerNsActionTreeMap
|
|
|
+ * 把农事记录 List<NsActionRecord> 转换成 Map<TreeId, List<NsTask>>
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, Map<String,List<NsActionRecord>>> cast(List<NsActionRecord> res, Map<Integer, NsActionTree> integerNsActionTreeMap){
|
|
|
- Map<String, Map<String,List<NsActionRecord>>> resMap = new HashMap<>();
|
|
|
- res.stream().forEach(nsActionRecord -> {
|
|
|
- NsActionTree actionTree = integerNsActionTreeMap.get(nsActionRecord.getActionId());
|
|
|
- Map<String, List<NsActionRecord>> nsTypeMap = resMap.get(nsActionRecord.getTreeId().toString());
|
|
|
- if(nsTypeMap == null){
|
|
|
- nsTypeMap = new HashMap<>();
|
|
|
- resMap.put(nsActionRecord.getTreeId().toString(), nsTypeMap);
|
|
|
- }
|
|
|
- List<NsActionRecord> nsActionRecordList = nsTypeMap.get(actionTree.getTypeId().toString());
|
|
|
- if(nsActionRecordList == null){
|
|
|
- nsActionRecordList = new ArrayList<>();
|
|
|
- nsTypeMap.put(actionTree.getTypeId().toString(), nsActionRecordList);
|
|
|
+ private Map<String, List<NsTask>> cast( List<NsTask> nsTaskList){
|
|
|
+ Map<String, List<NsTask>> resMap = new HashMap<>();
|
|
|
+ nsTaskList.stream().forEach(nsTask -> {
|
|
|
+ List<NsTask> taskList = resMap.get(nsTask.getTreeId().toString());
|
|
|
+ if(taskList == null){
|
|
|
+ taskList = new ArrayList<>();
|
|
|
+ resMap.put(nsTask.getTreeId().toString(), taskList);
|
|
|
}
|
|
|
- nsActionRecordList.add(nsActionRecord);
|
|
|
- nsActionRecord.setActionName(actionTree.getName());
|
|
|
+ taskList.add(nsTask);
|
|
|
});
|
|
|
return resMap;
|
|
|
}
|
|
@@ -74,6 +73,19 @@ public class NsActionRecordController {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ public void merge(List<NsTask> nsTaskList, List<NsActionRecord> res, Map<Integer, NsActionTree> integerNsActionTreeMap){
|
|
|
+ Map<String, NsTask> nsTaskMap = new HashMap<>();
|
|
|
+ nsTaskList.stream().forEach(nsTask -> {
|
|
|
+ nsTaskMap.put(nsTask.getId().toString(), nsTask);
|
|
|
+ });
|
|
|
+ res.stream().forEach(nsActionRecord -> {
|
|
|
+ String actionName = integerNsActionTreeMap.get(nsActionRecord.getActionId()).getName();
|
|
|
+ nsActionRecord.setActionName(actionName);
|
|
|
+ NsTask nsTask = nsTaskMap.get(nsActionRecord.getTaskId().toString());
|
|
|
+ nsTask.getRecordList().add(nsActionRecord);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@RequestMapping("/save")
|
|
|
public BaseResult save(@RequestBody ActionRecordVo actionRecordVo){
|
|
@@ -81,12 +93,27 @@ public class NsActionRecordController {
|
|
|
Date now = new Date();
|
|
|
List<NsActionRecord> nsActionRecordList = new ArrayList<>();
|
|
|
treeList.stream().forEach(tree -> {
|
|
|
+ //先查有没有 同树 未完成的 同typeId 的任务
|
|
|
+ NsTask nsTask = nsTaskService.findByTreeIdAndNsTypeIdAndStatus(tree.getId(), actionRecordVo.getTypeId(), 0);
|
|
|
+ if(nsTask == null){
|
|
|
+ nsTask = new NsTask();
|
|
|
+ }
|
|
|
+ nsTask.setCreateDate(now);
|
|
|
+ nsTask.setContent(actionRecordVo.getContent());
|
|
|
+ nsTask.setUserId(-1);
|
|
|
+ nsTask.setNsTypeId(actionRecordVo.getTypeId());
|
|
|
+ nsTask.setStatus(0);
|
|
|
+ nsTask.setTreeId(tree.getId());
|
|
|
+ nsTask.setTitle(actionRecordVo.getTitle());
|
|
|
+ nsTaskService.saveAndFlush(nsTask);
|
|
|
+ Integer taskId = nsTask.getId();
|
|
|
+
|
|
|
actionRecordVo.getActionIds().stream().forEach(actionId -> {
|
|
|
- //先查有没有 未完成的 同actionId 的农事
|
|
|
NsActionRecord nsActionRecord = nsActionRecordService.findAllByTreeIdAndActionId(tree.getId(), actionId, 0);
|
|
|
if(nsActionRecord == null){
|
|
|
nsActionRecord = new NsActionRecord();
|
|
|
}
|
|
|
+ nsActionRecord.setTaskId(taskId);
|
|
|
nsActionRecord.setTreeId(tree.getId());
|
|
|
nsActionRecord.setActionId(actionId);
|
|
|
nsActionRecord.setFinished(actionRecordVo.getFinished());
|
|
@@ -104,16 +131,19 @@ public class NsActionRecordController {
|
|
|
public BaseResult remove(@RequestBody ActionRecordVo actionRecordVo){
|
|
|
List<LzTree> treeList = lzTreeService.findListByCodes(actionRecordVo.getCodes());
|
|
|
List<NsActionRecord> nsActionRecordList = new ArrayList<>();
|
|
|
+ Set<Integer> taskIdSet = new HashSet<>();
|
|
|
treeList.stream().forEach(tree -> {
|
|
|
actionRecordVo.getActionIds().stream().forEach(actionId -> {
|
|
|
//先查有没有 未完成的 同actionId 的农事
|
|
|
NsActionRecord nsActionRecord = nsActionRecordService.findAllByTreeIdAndActionId(tree.getId(), actionId, 0);
|
|
|
if(nsActionRecord != null){
|
|
|
nsActionRecordList.add(nsActionRecord);
|
|
|
+ taskIdSet.add(nsActionRecord.getTaskId());
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
nsActionRecordService.deleteAll(nsActionRecordList);
|
|
|
+ nsTaskService.delete(taskIdSet.toArray(new Integer[0]));
|
|
|
return R.succ();
|
|
|
}
|
|
|
}
|