提交 af4d6ee7 authored 作者: Matrix's avatar Matrix

feat(核查模块): 修正了自动办结,审阅的相关机制

- 省退回之后,新的任务显示应该是`无` 而不是`未通过` - 省本级的任务完成之后,自动触发省审核通过 - 省审核通过之后,检验整个节点树是否所有节点都是审核通过,如果是,则自动完结任务。
上级 6bf7450d
...@@ -44,6 +44,7 @@ import com.tykj.dev.device.user.subject.entity.Units; ...@@ -44,6 +44,7 @@ import com.tykj.dev.device.user.subject.entity.Units;
import com.tykj.dev.device.user.subject.entity.User; import com.tykj.dev.device.user.subject.entity.User;
import com.tykj.dev.device.user.subject.entity.bto.AreaUnit; import com.tykj.dev.device.user.subject.entity.bto.AreaUnit;
import com.tykj.dev.device.user.subject.service.AuService; import com.tykj.dev.device.user.subject.service.AuService;
import com.tykj.dev.device.user.subject.service.UnitsService;
import com.tykj.dev.device.user.subject.service.UserService; import com.tykj.dev.device.user.subject.service.UserService;
import com.tykj.dev.device.user.util.AuthenticationUtils; import com.tykj.dev.device.user.util.AuthenticationUtils;
import com.tykj.dev.misc.base.ResultObj; import com.tykj.dev.misc.base.ResultObj;
...@@ -134,6 +135,8 @@ public class DeviceCheckController { ...@@ -134,6 +135,8 @@ public class DeviceCheckController {
private MessageService messageService; private MessageService messageService;
@Autowired @Autowired
private TaskLogService taskLogService; private TaskLogService taskLogService;
@Autowired
private UnitsService unitsService;
@GetMapping("/area/{fatherId}") @GetMapping("/area/{fatherId}")
@ApiOperation(value = "查询指定区域下的所有区域信息") @ApiOperation(value = "查询指定区域下的所有区域信息")
...@@ -548,19 +551,21 @@ public class DeviceCheckController { ...@@ -548,19 +551,21 @@ public class DeviceCheckController {
finalTime = System.currentTimeMillis(); finalTime = System.currentTimeMillis();
log.info("[TEST] COST {} MS", finalTime - startTime); log.info("[TEST] COST {} MS", finalTime - startTime);
} }
// check type = 1 检查页面 看见的是自查 // check type = 1 检查页面 看见的是自查 1=省核查,2=省检查,3=3级结构下的市检查,4=2级结构下的市检查
if (ctVo.getCheckType() == 1) { if (ctVo.getCheckType() == 1) {
Integer createUserId = ctVo.getCreateUserId(); Integer createUserId = ctVo.getCreateUserId();
if (userIsProv(createUserId)) { Integer ownUnit = rootTask.getOwnUnit();
if (unitsService.isProvUnit(ownUnit)) {
linkVo.setType(2); linkVo.setType(2);
} else { } else if (rootTask.getParentTaskId() != 0) {
linkVo.setType(3); linkVo.setType(3);
} else {
linkVo.setType(4);
} }
// 找到所有的子节点 // 找到所有的子节点
List<Task> childTask = taskRepo.findAllByParentTaskId(rootTask.getId()); List<Task> childTask = taskRepo.findAllByParentTaskId(rootTask.getId());
//核查组成员和名称 找到父亲级节点 然后找到父节点的统计节点 //核查组成员和名称 找到父亲级节点 然后找到父节点的统计节点
String[] checkArray = ctVo.getRemark().split("\\|");// x,a |x ,b String[] checkArray = ctVo.getRemark().split("\\|");// x,a |x ,b
List<String> groupNames = new ArrayList<>(); List<String> groupNames = new ArrayList<>();
...@@ -1214,8 +1219,13 @@ public class DeviceCheckController { ...@@ -1214,8 +1219,13 @@ public class DeviceCheckController {
log.info("[核查模块] 详情任务推进到下个阶段..."); log.info("[核查模块] 详情任务推进到下个阶段...");
taskService.moveToNext(currentTask); taskService.moveToNext(currentTask);
summaryDetail(currentTask, currentDetail); summaryDetail(currentTask, currentDetail);
// // 检查该exam任务是否可以完结推进了 // 检查该exam任务是否可以完结推进了
advanceExamTask(currentTask.getParentTaskId()); advanceExamTask(currentTask.getParentTaskId(), true);
// 如果是省本级的自查任务,则自动触发省审核通过
if (unitsService.isProvUnit(currentTask.getOwnUnit())) {
provAudit(currentDetail.getId(), true);
}
} }
} else { } else {
//不通过则回到第一阶段 //不通过则回到第一阶段
...@@ -1257,7 +1267,7 @@ public class DeviceCheckController { ...@@ -1257,7 +1267,7 @@ public class DeviceCheckController {
currentDetail = detailRepo.save(currentDetail); currentDetail = detailRepo.save(currentDetail);
summaryDetail(currentTask, currentDetail); summaryDetail(currentTask, currentDetail);
// // 检查该exam任务是否可以完结推进了 // // 检查该exam任务是否可以完结推进了
advanceExamTask(currentTask.getParentTaskId()); advanceExamTask(currentTask.getParentTaskId(), false);
return ResponseEntity.ok("市专管员审核通过,结束" + currentDetail.getCheckUnit() + " 区的自查任务并汇总数据"); return ResponseEntity.ok("市专管员审核通过,结束" + currentDetail.getCheckUnit() + " 区的自查任务并汇总数据");
} else { } else {
...@@ -1625,7 +1635,7 @@ public class DeviceCheckController { ...@@ -1625,7 +1635,7 @@ public class DeviceCheckController {
String remark = task.getRemark(); String remark = task.getRemark();
if (situation.equals("无")) { if (situation.equals("无")) {
if (Objects.nonNull(remark) && remark.contains("ROLLBACK")) { if (Objects.nonNull(remark) && remark.contains("ROLLBACK")) {
situation = "未通过"; situation = "";
} }
} }
...@@ -1735,9 +1745,16 @@ public class DeviceCheckController { ...@@ -1735,9 +1745,16 @@ public class DeviceCheckController {
* *
* @param exam的taskId * @param exam的taskId
*/ */
private void advanceExamTask(Integer examTaskId) { private void advanceExamTask(Integer examTaskId, boolean exec) {
TaskBto parentTask = taskService.findByTaskId(examTaskId); TaskBto parentTask = taskService.findByTaskId(examTaskId);
if (parentTask.getBillStatus().equals(CHECK_EXAM_STAT_1.id) && parentTask.getParentTaskId() != 0 && taskService.TaskTreeIsOver(examTaskId)) { if (exec) {
exec = parentTask.getParentTaskId() != 0;
} else {
exec = true;
}
// && parentTask.getParentTaskId() != 0
if (parentTask.getBillStatus().equals(CHECK_EXAM_STAT_1.id) && exec && taskService.TaskTreeIsOver(examTaskId)) {
log.info("[核查模块] 检测到task id = {}的检查任务已经可以自动推进了,自动推进至下一步", examTaskId); log.info("[核查模块] 检测到task id = {}的检查任务已经可以自动推进了,自动推进至下一步", examTaskId);
statConfirm(parentTask.getBillId()); statConfirm(parentTask.getBillId());
} }
...@@ -1779,13 +1796,14 @@ public class DeviceCheckController { ...@@ -1779,13 +1796,14 @@ public class DeviceCheckController {
// 添加阅知信息 // 添加阅知信息
List<Integer> involveUserIds = node.parse2Bto().getInvolveUserIdList(); List<Integer> involveUserIds = node.parse2Bto().getInvolveUserIdList();
int lastUserId = involveUserIds.get(involveUserIds.size() - 1) == null ? 0 : involveUserIds.get(involveUserIds.size() - 1); int lastUserId = involveUserIds.get(involveUserIds.size() - 1) == null ? 0 : involveUserIds.get(involveUserIds.size() - 1);
List<Integer> msgUserIds; List<Integer> msgUserIds = new ArrayList<>();
if (lastUserId == 0) { if (lastUserId == 0) {
msgUserIds = userService.findByUniteId(node.getOwnUnit()).stream() msgUserIds = userService.findByUniteId(node.getOwnUnit()).stream()
.map(UserShenRe::getUserId) .map(UserShenRe::getUserId)
.collect(toList()); .collect(toList());
} else { } else {
msgUserIds = new ArrayList<>(lastUserId); msgUserIds = new ArrayList<>();
msgUserIds.add(lastUserId);
} }
MessageBto msgBto = new MessageBto(node.getId(), node.getBusinessType(), shutDownMsg, msgUserIds); MessageBto msgBto = new MessageBto(node.getId(), node.getBusinessType(), shutDownMsg, msgUserIds);
messageService.add(msgBto); messageService.add(msgBto);
...@@ -1845,6 +1863,7 @@ public class DeviceCheckController { ...@@ -1845,6 +1863,7 @@ public class DeviceCheckController {
cDetail.setCheckDetail(initalDetail); cDetail.setCheckDetail(initalDetail);
cDetail.setCheckFiles(""); cDetail.setCheckFiles("");
cDetail.setCheckFileList(Lists.newArrayList()); cDetail.setCheckFileList(Lists.newArrayList());
cDetail.setReview(false);
cDetail = detailRepo.save(cDetail); cDetail = detailRepo.save(cDetail);
// 创建新的任务(被拒绝的自查单位如果是区则是140状态,否则是160状态 ) // 创建新的任务(被拒绝的自查单位如果是区则是140状态,否则是160状态 )
String unitName = cDetail.getCheckUnit(); String unitName = cDetail.getCheckUnit();
...@@ -1893,6 +1912,14 @@ public class DeviceCheckController { ...@@ -1893,6 +1912,14 @@ public class DeviceCheckController {
//4.父级任务变为进行中 如果父级是核查,变成111,如果父级是检查,变成131 //4.父级任务变为进行中 如果父级是核查,变成111,如果父级是检查,变成131
if (fatherTask.getCustomInfo().contains("exam")) { if (fatherTask.getCustomInfo().contains("exam")) {
fatherTask.setBillStatus(CHECK_EXAM_STAT_1.id); fatherTask.setBillStatus(CHECK_EXAM_STAT_1.id);
// 父级的父级也要设置 exam的父级是check
if (fatherTask.getParentTaskId() != 0) {
Task checkTask = taskRepo.findById(fatherTask.getParentTaskId())
.orElseThrow(() -> new ApiException(String.format("没有找到核查任务,子Task id %d", fatherTask.getId())));
log.info("[核查模块] 回滚核查任务 taskId = {}", checkTask.getId());
checkTask.setBillStatus(CHECK_STAT_1.id);
taskRepo.save(checkTask);
}
} else if (fatherTask.getCustomInfo().contains("check")) { } else if (fatherTask.getCustomInfo().contains("check")) {
fatherTask.setBillStatus(CHECK_STAT_1.id); fatherTask.setBillStatus(CHECK_STAT_1.id);
} }
...@@ -1914,6 +1941,7 @@ public class DeviceCheckController { ...@@ -1914,6 +1941,7 @@ public class DeviceCheckController {
String updatedString = changeHunds(detail.getCheckDetail(), 2); String updatedString = changeHunds(detail.getCheckDetail(), 2);
detail.setCheckDetail(updatedString); detail.setCheckDetail(updatedString);
detail.setUserCId(authenticationUtils.getAuthentication().getCurrentUserInfo().getUserId()); detail.setUserCId(authenticationUtils.getAuthentication().getCurrentUserInfo().getUserId());
detail.setReview(true);
log.info("[核查模块] 审核通过 - 更新后的detailString形如 {}", updatedString.split(",")[0]); log.info("[核查模块] 审核通过 - 更新后的detailString形如 {}", updatedString.split(",")[0]);
detailRepo.save(detail); detailRepo.save(detail);
...@@ -1931,10 +1959,53 @@ public class DeviceCheckController { ...@@ -1931,10 +1959,53 @@ public class DeviceCheckController {
} }
} }
} }
// 检验整个节点树是否所有节点都是审核通过,如果是,则自动完结任务
TaskBto topNode = taskService.getTopNode(currentTask.getId());
if (allDetailIsReview(topNode)) {
log.info("[核查模块] 该节点树的时候自查节点都已经完结,完结整个节点树,触发的子节点id = {},顶节点id = {}", currentTask.getId(), topNode.getId());
shutDown(topNode.getBillId());
}
return ResponseEntity.ok(new ResultObj<>("审核通过!")); return ResponseEntity.ok(new ResultObj<>("审核通过!"));
}
/**
* 查询该节点所在的节点树的所有detail是否都已经被查阅
*
* @param topTask
* @return
*/
private boolean allDetailIsReview(TaskBto topTask) {
// 获取顶节点
List<Task> c1Tasks = taskRepo.findAllByParentTaskId(topTask.getId());
// 获取detailList 根据detailList的checkUnit分组,取id最大的一条,每个组里必须为true才能触发
List<Integer> detailIdList = new ArrayList<>();
// 所有的检查任务是否都完结了
boolean examIsDone = true;
boolean detailIsDone = true;
for (Task c1 : c1Tasks) {
if (c1.getCustomInfo().equals("manual")) {
detailIdList.add(c1.getBillId());
}
if (c1.getCustomInfo().equals("exam")) {
if (!(c1.getBillStatus().equals(END.id) || c1.getBillStatus().equals(CHECK_SHUT_DOWN.id))) {
examIsDone = false;
}
Collection<Integer> regionDetailIds = taskRepo.findAllByParentTaskId(c1.getId()).stream()
.filter(t -> t.getCustomInfo().equals("manual"))
.collect(groupingBy(Task::getOwnUnit,
collectingAndThen(maxBy(Comparator.comparing(Task::getId)), task -> task.get().getBillId())))
.values();
detailIdList.addAll(regionDetailIds);
}
}
detailIsDone = detailRepo.findAllById(detailIdList).stream()
.allMatch(DeviceCheckDetail::isReview);
return detailIsDone && examIsDone;
} }
private void removeDetailFromDcs(DeviceCheckDetail detail, DeviceCheckStat dcs) { private void removeDetailFromDcs(DeviceCheckDetail detail, DeviceCheckStat dcs) {
......
...@@ -131,6 +131,12 @@ public class DeviceCheckDetail extends BaseEntity { ...@@ -131,6 +131,12 @@ public class DeviceCheckDetail extends BaseEntity {
@ApiModelProperty(value = "备注") @ApiModelProperty(value = "备注")
private String remark; private String remark;
/**
* true-已审阅,false-未审阅
*/
@ApiModelProperty(value = "省是否审阅")
private boolean review = false;
/** /**
* 预留字段2 现在用来记录该自查任务的初始状态号 * 预留字段2 现在用来记录该自查任务的初始状态号
*/ */
...@@ -199,29 +205,6 @@ public class DeviceCheckDetail extends BaseEntity { ...@@ -199,29 +205,6 @@ public class DeviceCheckDetail extends BaseEntity {
this.remark = remark; this.remark = remark;
} }
public void updateDevice(List<DeviceLibrary> devInLib,List<DeviceLibrary> devNotInLib){
//构造checkDetail 分当前在库与不在库的 赋予不同状态
String goodCheckDetail = "";
if (!CollectionUtils.isEmpty(devInLib)) {
goodCheckDetail = devInLib.stream()
.map(device -> device.getId() + "-9")
.collect(Collectors.joining(","));
}
String badCheckDetail = "";
if (!CollectionUtils.isEmpty(devNotInLib)) {
badCheckDetail = devNotInLib.stream()
.map(device -> device.getId() + "-3")
.collect(Collectors.joining(","));
}
//如果不在库的不为空,则拼接,否则没必要
String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail;
this.checkDetail = checkDetail;
}
/** /**
* @param checkUnit 要核查的单位 * @param checkUnit 要核查的单位
* @param devInLib 所属与所在均在本单位的装备集合 * @param devInLib 所属与所在均在本单位的装备集合
...@@ -275,7 +258,30 @@ public class DeviceCheckDetail extends BaseEntity { ...@@ -275,7 +258,30 @@ public class DeviceCheckDetail extends BaseEntity {
); );
} }
public DeviceCheckDetail copyWithoutId(){ public void updateDevice(List<DeviceLibrary> devInLib, List<DeviceLibrary> devNotInLib) {
//构造checkDetail 分当前在库与不在库的 赋予不同状态
String goodCheckDetail = "";
if (!CollectionUtils.isEmpty(devInLib)) {
goodCheckDetail = devInLib.stream()
.map(device -> device.getId() + "-9")
.collect(Collectors.joining(","));
}
String badCheckDetail = "";
if (!CollectionUtils.isEmpty(devNotInLib)) {
badCheckDetail = devNotInLib.stream()
.map(device -> device.getId() + "-3")
.collect(Collectors.joining(","));
}
//如果不在库的不为空,则拼接,否则没必要
String checkDetail = StringUtils.isEmpty(badCheckDetail) ? goodCheckDetail : goodCheckDetail + "," + badCheckDetail;
this.checkDetail = checkDetail;
}
public DeviceCheckDetail copyWithoutId() {
ModelMapper mapper = BeanHelper.getUserMapper(); ModelMapper mapper = BeanHelper.getUserMapper();
DeviceCheckDetail detail = mapper.map(this, DeviceCheckDetail.class); DeviceCheckDetail detail = mapper.map(this, DeviceCheckDetail.class);
this.setCreateTime(LocalDateTime.now()); this.setCreateTime(LocalDateTime.now());
......
...@@ -313,7 +313,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine ...@@ -313,7 +313,7 @@ public class ConfirmCheckServiceImpl implements ConfirmCheckService, CommandLine
List<TaskBto> topStatList = taskService.findBillType(7); List<TaskBto> topStatList = taskService.findBillType(7);
List<Integer> topIdList = topStatList.stream() List<Integer> topIdList = topStatList.stream()
.filter(taskBto -> taskBto.getParentTaskId().equals(0) || taskBto.getParentTaskId() == null) .filter(taskBto -> taskBto.getParentTaskId().equals(0) || taskBto.getParentTaskId() == null || taskBto.getCustomInfo().equals("exam"))
.map(TaskBto::getBillId) .map(TaskBto::getBillId)
.collect(toList()); .collect(toList());
......
...@@ -43,8 +43,7 @@ import java.util.function.Function; ...@@ -43,8 +43,7 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.tykj.dev.misc.base.StatusEnum.*; import static com.tykj.dev.misc.base.StatusEnum.*;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.toMap;
/** /**
* ObjTransUtil. * ObjTransUtil.
...@@ -146,10 +145,12 @@ public class ObjTransUtil { ...@@ -146,10 +145,12 @@ public class ObjTransUtil {
boolean flag = false; boolean flag = false;
// 3/3 -> 统计待确认 -> 省统计任务待完结 // 3/3 -> 统计待确认 -> 省统计任务待完结
childTask = childTask.stream() childTask = childTask.stream()
.filter(task -> !task.getTitle().contains("统计数据待办任务")) .filter(task -> !task.getTitle().contains("统计数据待办任务"))
.filter(task -> !task.getTitle().contains("统计数据确认任务")) .filter(task -> !task.getTitle().contains("统计数据确认任务"))
.collect(groupingBy(Task::getOwnUnit,
collectingAndThen(maxBy(Comparator.comparing(Task::getId)), Optional::get)))
.values().stream()
.collect(toList()); .collect(toList());
long total = childTask.size(); long total = childTask.size();
...@@ -192,7 +193,7 @@ public class ObjTransUtil { ...@@ -192,7 +193,7 @@ public class ObjTransUtil {
checkUserNames, checkUserNames,
stat.getCreateTime(), stat.getCreateTime(),
completion, completion,
stat.getCheckType().CT_CHECK.getId(), stat.getCheckType().getId(),
joiner.toString() joiner.toString()
); );
......
...@@ -180,6 +180,13 @@ public interface TaskService { ...@@ -180,6 +180,13 @@ public interface TaskService {
*/ */
boolean TaskTreeIsStart(int rootId,boolean currentIsOver); boolean TaskTreeIsStart(int rootId,boolean currentIsOver);
/**
* 获得该task树下的最顶部节点
* @param taskId 任务主键id
* @return 最顶部的节点
*/
TaskBto getTopNode(Integer taskId);
/** /**
......
...@@ -1033,6 +1033,27 @@ public class TaskServiceImpl implements TaskService { ...@@ -1033,6 +1033,27 @@ public class TaskServiceImpl implements TaskService {
} }
/**
* 获得该task树下的最顶部节点
*
* @param taskId 任务主键id
* @return 最顶部的节点
*/
@Override
public TaskBto getTopNode(Integer taskId) {
Task task = taskDao.findById(taskId).orElseThrow(() -> new ApiException(String.format("没有找到taskId = %d 的节点", taskId)));
Task rootTask = task;
while (true){
if (rootTask.getParentTaskId() == 0 || rootTask.getParentTaskId() == null) {
break;
}else {
rootTask = taskDao.findById(rootTask.getParentTaskId()).get();
}
}
return rootTask.parse2Bto();
}
/** /**
* @param oldUserId 旧专管员id * @param oldUserId 旧专管员id
* @param newUserId 新交接专管员id * @param newUserId 新交接专管员id
......
...@@ -178,4 +178,6 @@ public interface UnitsService extends PublicService<Units> { ...@@ -178,4 +178,6 @@ public interface UnitsService extends PublicService<Units> {
Units findNameUnit(UnitNameVo unitNameVo); Units findNameUnit(UnitNameVo unitNameVo);
void addUnitSortMap(); void addUnitSortMap();
boolean isProvUnit(Integer unitId);
} }
package com.tykj.dev.device.user.subject.service.impl; package com.tykj.dev.device.user.subject.service.impl;
import com.tykj.dev.config.domin.SystemConfig;
import com.tykj.dev.config.service.SystemConfigService; import com.tykj.dev.config.service.SystemConfigService;
import com.tykj.dev.device.user.base.req.UnitNameVo; import com.tykj.dev.device.user.base.req.UnitNameVo;
import com.tykj.dev.device.user.base.ret.*; import com.tykj.dev.device.user.base.ret.*;
...@@ -44,6 +43,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -44,6 +43,7 @@ public class UnitsServiceImpl implements UnitsService {
@Autowired @Autowired
SystemConfigService systemConfigService; SystemConfigService systemConfigService;
@Override @Override
public Units findById(Integer unitId) { public Units findById(Integer unitId) {
Optional<Units> unit = unitsDao.findById(unitId); Optional<Units> unit = unitsDao.findById(unitId);
...@@ -74,17 +74,18 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -74,17 +74,18 @@ public class UnitsServiceImpl implements UnitsService {
* 根据所在区域是省还是市 * 根据所在区域是省还是市
* 省 则把下属市以及市下属都区都单位统一放入市AreaVo 在放入List<AreaVo> 集合中。 * 省 则把下属市以及市下属都区都单位统一放入市AreaVo 在放入List<AreaVo> 集合中。
* 市 则把下属区都单位放入市都AreaVo对象中 * 市 则把下属区都单位放入市都AreaVo对象中
*
* @param thisArea 本单位区域 * @param thisArea 本单位区域
* @param areas 下级区域列表 * @param areas 下级区域列表
*/ */
private List<LeftNavigation> provinceAndCity(Area thisArea,List<Area> areas,List<LeftNavigation> leftNavigationList){ private List<LeftNavigation> provinceAndCity(Area thisArea, List<Area> areas, List<LeftNavigation> leftNavigationList) {
if (thisArea.getType()==1) { if (thisArea.getType() == 1) {
areas.forEach(area -> { areas.forEach(area -> {
LeftNavigation leftNavigation = area.toLeftNavigation(); LeftNavigation leftNavigation = area.toLeftNavigation();
List<LeftNavigation> leftNavigationList1 = new ArrayList<>(); List<LeftNavigation> leftNavigationList1 = new ArrayList<>();
unitsDao.findAllByAreaId(area.getId()).forEach( unitsDao.findAllByAreaId(area.getId()).forEach(
units -> { units -> {
LeftNavigation leftNavigation1=units.toLeftNavigation(); LeftNavigation leftNavigation1 = units.toLeftNavigation();
leftNavigation1.setTheirId(units.getAreaId()); leftNavigation1.setTheirId(units.getAreaId());
leftNavigationList1.add(leftNavigation1); leftNavigationList1.add(leftNavigation1);
} }
...@@ -95,7 +96,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -95,7 +96,7 @@ public class UnitsServiceImpl implements UnitsService {
countys.forEach( countys.forEach(
area1 -> unitsDao.findAllByAreaId(area1.getId()).forEach( area1 -> unitsDao.findAllByAreaId(area1.getId()).forEach(
units -> { units -> {
LeftNavigation leftNavigation1=units.toLeftNavigation(); LeftNavigation leftNavigation1 = units.toLeftNavigation();
leftNavigation1.setTheirId(area.getId()); leftNavigation1.setTheirId(area.getId());
leftNavigationList1.add(leftNavigation1); leftNavigationList1.add(leftNavigation1);
} }
...@@ -103,21 +104,21 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -103,21 +104,21 @@ public class UnitsServiceImpl implements UnitsService {
) )
); );
} }
leftNavigation.setLeftNavigations(leftNavigationList1.stream().sorted(Comparator.comparing(LeftNavigation::getOrder,Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList())); leftNavigation.setLeftNavigations(leftNavigationList1.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
leftNavigationList.add(leftNavigation); leftNavigationList.add(leftNavigation);
}); });
}else if (thisArea.getType()==2){ } else if (thisArea.getType() == 2) {
areas.forEach(area -> { areas.forEach(area -> {
unitsDao.findAllByAreaId(area.getId()).forEach( unitsDao.findAllByAreaId(area.getId()).forEach(
units -> { units -> {
LeftNavigation leftNavigation1=units.toLeftNavigation(); LeftNavigation leftNavigation1 = units.toLeftNavigation();
leftNavigation1.setTheirId(thisArea.getId()); leftNavigation1.setTheirId(thisArea.getId());
leftNavigationList.add(leftNavigation1); leftNavigationList.add(leftNavigation1);
} }
); );
}); });
}else { } else {
return leftNavigationList; return leftNavigationList;
} }
return leftNavigationList; return leftNavigationList;
...@@ -133,16 +134,16 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -133,16 +134,16 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<Integer> findListSubordinateId(Integer unitsId) { public List<Integer> findListSubordinateId(Integer unitsId) {
Integer areaId = unitsDao.findById(unitsId).get().getAreaId(); Integer areaId = unitsDao.findById(unitsId).get().getAreaId();
List<Integer> areaIds=areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::getUnitId).collect(Collectors.toList()); return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::getUnitId).collect(Collectors.toList());
} }
@Override @Override
public List<UnitsVo> findListVoSubordinateAreaId(Integer areaId) { public List<UnitsVo> findListVoSubordinateAreaId(Integer areaId) {
List<UnitsVo> unitsVos=new ArrayList<>(); List<UnitsVo> unitsVos = new ArrayList<>();
List<Integer> areaIds=areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
if (areaIds.size() != 0) { if (areaIds.size() != 0) {
unitsVos= unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::toVo).collect(Collectors.toList()); unitsVos = unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::toVo).collect(Collectors.toList());
} }
return unitsVos; return unitsVos;
} }
...@@ -155,13 +156,13 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -155,13 +156,13 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId) { public List<UnitsTrainVo> findListUnitsTrainVo(Integer unitsId) {
Integer areaId = unitsDao.findById(unitsId).get().getAreaId(); Integer areaId = unitsDao.findById(unitsId).get().getAreaId();
List<Integer> areaIds=areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::toUnitsTrainVo).collect(Collectors.toList()); return unitsDao.findAllByAreaIdIn(areaIds).stream().map(Units::toUnitsTrainVo).collect(Collectors.toList());
} }
@Override @Override
public List<Integer> findSuperiorByunitsId(Integer unitsId) { public List<Integer> findSuperiorByunitsId(Integer unitsId) {
Area area= areaDao.findById(this.findById(unitsId).getAreaId()).get(); Area area = areaDao.findById(this.findById(unitsId).getAreaId()).get();
return unitsDao.findAllByAreaId(area.getFatherId()).stream().map(Units::getUnitId).collect(Collectors.toList()); return unitsDao.findAllByAreaId(area.getFatherId()).stream().map(Units::getUnitId).collect(Collectors.toList());
} }
...@@ -179,9 +180,9 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -179,9 +180,9 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<Units> findBySubordinate(Integer unitsId) { public List<Units> findBySubordinate(Integer unitsId) {
Units units = unitsDao.findById(unitsId).get(); Units units = unitsDao.findById(unitsId).get();
List<Integer> areaIds= areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
List<Units> units1= unitsDao.findAllByAreaIdIn(areaIds); List<Units> units1 = unitsDao.findAllByAreaIdIn(areaIds);
if (units.getLevel()==1){ if (units.getLevel() == 1) {
units1.add(units); units1.add(units);
units1.addAll(unitsDao.findAllByType(2)); units1.addAll(unitsDao.findAllByType(2));
} }
...@@ -203,9 +204,9 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -203,9 +204,9 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<Units> findBySubordinateNotOneself(Integer unitsId) { public List<Units> findBySubordinateNotOneself(Integer unitsId) {
Units units = unitsDao.findById(unitsId).get(); Units units = unitsDao.findById(unitsId).get();
List<Integer> areaIds= areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
List<Units> units1= unitsDao.findAllByAreaIdIn(areaIds); List<Units> units1 = unitsDao.findAllByAreaIdIn(areaIds);
if (units.getLevel()==1){ if (units.getLevel() == 1) {
// units1.add(units); // units1.add(units);
units1.addAll(unitsDao.findAllByType(2)); units1.addAll(unitsDao.findAllByType(2));
} }
...@@ -216,7 +217,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -216,7 +217,7 @@ public class UnitsServiceImpl implements UnitsService {
public List<String> findBySubordinateUnitName(Integer unitsId) { public List<String> findBySubordinateUnitName(Integer unitsId) {
Units units = unitsDao.findById(unitsId).get(); Units units = unitsDao.findById(unitsId).get();
List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().map(Area::getId).collect(Collectors.toList());
List<String> list=new ArrayList<>(); List<String> list = new ArrayList<>();
list.add(units.getName()); list.add(units.getName());
unitsDao.findAllByAreaIdIn(areaIds).forEach( unitsDao.findAllByAreaIdIn(areaIds).forEach(
units1 -> list.add(units1.getName()) units1 -> list.add(units1.getName())
...@@ -228,7 +229,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -228,7 +229,7 @@ public class UnitsServiceImpl implements UnitsService {
public List<Units> findBySubordinateUnit(Integer unitsId) { public List<Units> findBySubordinateUnit(Integer unitsId) {
Units units = unitsDao.findById(unitsId).get(); Units units = unitsDao.findById(unitsId).get();
List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().map(Area::getId).collect(Collectors.toList());
List<Units> list= unitsDao.findAllByAreaIdIn(areaIds); List<Units> list = unitsDao.findAllByAreaIdIn(areaIds);
list.add(units); list.add(units);
return list; return list;
} }
...@@ -237,15 +238,13 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -237,15 +238,13 @@ public class UnitsServiceImpl implements UnitsService {
public UnitsPage selectPage(Integer page, Integer size) { public UnitsPage selectPage(Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size, Sort.Direction.ASC, "level"); Pageable pageable = PageRequest.of(page, size, Sort.Direction.ASC, "level");
Page<Units> unitsPage = unitsDao.findAll(pageable); Page<Units> unitsPage = unitsDao.findAll(pageable);
List<Units> list=unitsPage.getContent(); List<Units> list = unitsPage.getContent();
list.forEach(units -> { list.forEach(units -> {
if (units.getAreaId()>0) { if (units.getAreaId() > 0) {
units.setAreaName(areaDao.findById(units.getAreaId()).get().getName()); units.setAreaName(areaDao.findById(units.getAreaId()).get().getName());
} } else if (units.getType() == 2) {
else if (units.getType()==2){
units.setAreaName("浙江省"); units.setAreaName("浙江省");
} } else {
else {
units.setAreaName("-"); units.setAreaName("-");
} }
}); });
...@@ -260,12 +259,12 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -260,12 +259,12 @@ public class UnitsServiceImpl implements UnitsService {
public List<Units> findByUserIdUnitsTrainListVo(Integer unitsId) { public List<Units> findByUserIdUnitsTrainListVo(Integer unitsId) {
Optional<Units> unitsOptional = unitsDao.findById(unitsId); Optional<Units> unitsOptional = unitsDao.findById(unitsId);
if (unitsOptional.isPresent()) { if (unitsOptional.isPresent()) {
Units units=unitsOptional.get(); Units units = unitsOptional.get();
List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
List<Units> unitsList= unitsDao.findAllByAreaIdIn(areaIds); List<Units> unitsList = unitsDao.findAllByAreaIdIn(areaIds);
unitsList.add(units); unitsList.add(units);
return unitsList; return unitsList;
}else { } else {
throw new ApiException(ResponseEntity.status(500).body("单位没有查到")); throw new ApiException(ResponseEntity.status(500).body("单位没有查到"));
} }
} }
...@@ -282,30 +281,30 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -282,30 +281,30 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public LeftNavigation findLeftNavigation(SecurityUser securityUser) { public LeftNavigation findLeftNavigation(SecurityUser securityUser) {
LeftNavigation leftNavigation=new LeftNavigation(); LeftNavigation leftNavigation = new LeftNavigation();
List<LeftNavigation> leftNavigationList=new ArrayList<>(); List<LeftNavigation> leftNavigationList = new ArrayList<>();
Integer areaId=securityUser.getCurrentUserInfo().getUnits().getAreaId(); Integer areaId = securityUser.getCurrentUserInfo().getUnits().getAreaId();
Area belongsArea= areaDao.findById(areaId).get(); Area belongsArea = areaDao.findById(areaId).get();
if (belongsArea.getType()==1|| belongsArea.getType()==2){ if (belongsArea.getType() == 1 || belongsArea.getType() == 2) {
leftNavigation = belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList= unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList()); leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
} }
if (belongsArea.getType()==1){ if (belongsArea.getType() == 1) {
//把省直属组合一下 直属单位(type=2) 处室单位(type=4) //把省直属组合一下 直属单位(type=2) 处室单位(type=4)
// leftNavigationList.addAll(unitsDao.findAllByType(4).stream().map(Units::toLeftNavigation).collect(Collectors.toList())); // leftNavigationList.addAll(unitsDao.findAllByType(4).stream().map(Units::toLeftNavigation).collect(Collectors.toList()));
List<LeftNavigation> leftNavigationList2=unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省应急小组")&& !units1.getName().equals("省机科技管理处")&& !units1.getName().equals("省机通信报务处") && units1.getEscrow()==1).map(Units::toLeftNavigation).collect(Collectors.toList()); List<LeftNavigation> leftNavigationList2 = unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省应急小组") && !units1.getName().equals("省机科技管理处") && !units1.getName().equals("省机通信报务处") && units1.getEscrow() == 1).map(Units::toLeftNavigation).collect(Collectors.toList());
LeftNavigation leftNavigation2=new LeftNavigation(0,"省直属",leftNavigationList2, UUID.randomUUID().toString(),1,22,null); LeftNavigation leftNavigation2 = new LeftNavigation(0, "省直属", leftNavigationList2, UUID.randomUUID().toString(), 1, 22, null);
leftNavigationList.add(leftNavigation2); leftNavigationList.add(leftNavigation2);
} }
List<Area> areas= areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList()); List<Area> areas = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList());
if (areas.size()!=0) { if (areas.size() != 0) {
provinceAndCity(belongsArea,areas,leftNavigationList); provinceAndCity(belongsArea, areas, leftNavigationList);
}else { } else {
leftNavigation= belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList= unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList()); leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
} }
leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder,Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList())); leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
return leftNavigation; return leftNavigation;
} }
...@@ -313,40 +312,40 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -313,40 +312,40 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public LeftNavigation findLeftNavigation1(SecurityUser securityUser) { public LeftNavigation findLeftNavigation1(SecurityUser securityUser) {
LeftNavigation leftNavigation=new LeftNavigation(); LeftNavigation leftNavigation = new LeftNavigation();
List<LeftNavigation> leftNavigationList=new ArrayList<>(); List<LeftNavigation> leftNavigationList = new ArrayList<>();
Integer areaId=securityUser.getCurrentUserInfo().getUnits().getAreaId(); Integer areaId = securityUser.getCurrentUserInfo().getUnits().getAreaId();
Area belongsArea= areaDao.findById(areaId).get(); Area belongsArea = areaDao.findById(areaId).get();
if (belongsArea.getType()==1){ if (belongsArea.getType() == 1) {
leftNavigation = belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
LeftNavigation units=securityUser.getCurrentUserInfo().getUnits().toLeftNavigation(); LeftNavigation units = securityUser.getCurrentUserInfo().getUnits().toLeftNavigation();
List<LeftNavigation> leftNavigationList1=new ArrayList<>(); List<LeftNavigation> leftNavigationList1 = new ArrayList<>();
systemConfigService.getStorageLocationMap().forEach( systemConfigService.getStorageLocationMap().forEach(
(k,v)->{ (k, v) -> {
leftNavigationList1.add(new LeftNavigation(0,v,null,v,3,k,units.getId())); leftNavigationList1.add(new LeftNavigation(0, v, null, v, 3, k, units.getId()));
} }
); );
units.setLeftNavigations( leftNavigationList1.stream().sorted(Comparator.comparing(LeftNavigation::getOrder,Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList())); units.setLeftNavigations(leftNavigationList1.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
leftNavigationList.add(units); leftNavigationList.add(units);
//把省直属组合一下 直属单位(type=2) 处室单位(type=4) //把省直属组合一下 直属单位(type=2) 处室单位(type=4)
// leftNavigationList.addAll(unitsDao.findAllByType(4).stream().map(Units::toLeftNavigation).collect(Collectors.toList())); // leftNavigationList.addAll(unitsDao.findAllByType(4).stream().map(Units::toLeftNavigation).collect(Collectors.toList()));
List<LeftNavigation> leftNavigationList2=unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省应急小组")&& !units1.getName().equals("省机科技管理处")&& !units1.getName().equals("省机通信报务处") && units1.getEscrow()==1).map(Units::toLeftNavigation).collect(Collectors.toList()); List<LeftNavigation> leftNavigationList2 = unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省应急小组") && !units1.getName().equals("省机科技管理处") && !units1.getName().equals("省机通信报务处") && units1.getEscrow() == 1).map(Units::toLeftNavigation).collect(Collectors.toList());
LeftNavigation leftNavigation2=new LeftNavigation(0,"省直属",leftNavigationList2, UUID.randomUUID().toString(),1,22,null); LeftNavigation leftNavigation2 = new LeftNavigation(0, "省直属", leftNavigationList2, UUID.randomUUID().toString(), 1, 22, null);
leftNavigationList.add(leftNavigation2); leftNavigationList.add(leftNavigation2);
} }
if ( belongsArea.getType()==2){ if (belongsArea.getType() == 2) {
leftNavigation = belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList()); leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
} }
List<Area> areas= areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList()); List<Area> areas = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList());
if (areas.size()!=0) { if (areas.size() != 0) {
provinceAndCity(belongsArea,areas,leftNavigationList); provinceAndCity(belongsArea, areas, leftNavigationList);
}else { } else {
leftNavigation= belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
leftNavigationList= unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList()); leftNavigationList = unitsDao.findAllByAreaId(belongsArea.getId()).stream().map(Units::toLeftNavigation).collect(Collectors.toList());
} }
leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder,Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList())); leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
return leftNavigation; return leftNavigation;
} }
...@@ -354,50 +353,50 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -354,50 +353,50 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public LeftNavigation findLeftNavigation2(SecurityUser securityUser) { public LeftNavigation findLeftNavigation2(SecurityUser securityUser) {
List<LeftNavigation> leftNavigationList2=unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省机科技管理处")&& !units1.getName().equals("省机通信报务处") && units1.getEscrow()==1).map(Units::toLeftNavigation).collect(Collectors.toList()); List<LeftNavigation> leftNavigationList2 = unitsDao.findAllByType(2).stream().filter(units1 -> !units1.getName().equals("省机科技管理处") && !units1.getName().equals("省机通信报务处") && units1.getEscrow() == 1).map(Units::toLeftNavigation).collect(Collectors.toList());
LeftNavigation leftNavigation2=new LeftNavigation(0,"省直属",leftNavigationList2, UUID.randomUUID().toString(),1,22,null); LeftNavigation leftNavigation2 = new LeftNavigation(0, "省直属", leftNavigationList2, UUID.randomUUID().toString(), 1, 22, null);
return leftNavigation2; return leftNavigation2;
} }
@Override @Override
public LeftNavigation findLeftNavigationNotDirectlyUnit(SecurityUser securityUser) { public LeftNavigation findLeftNavigationNotDirectlyUnit(SecurityUser securityUser) {
LeftNavigation leftNavigation=new LeftNavigation(); LeftNavigation leftNavigation = new LeftNavigation();
List<LeftNavigation> leftNavigationList=new ArrayList<>(); List<LeftNavigation> leftNavigationList = new ArrayList<>();
Integer areaId=securityUser.getCurrentUserInfo().getUnits().getAreaId(); Integer areaId = securityUser.getCurrentUserInfo().getUnits().getAreaId();
Area belongsArea= areaDao.findById(areaId).get(); Area belongsArea = areaDao.findById(areaId).get();
if (belongsArea.getType()==1|| belongsArea.getType()==2){ if (belongsArea.getType() == 1 || belongsArea.getType() == 2) {
leftNavigation = belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
List<LeftNavigation> leftNavigationList1=new ArrayList<>(); List<LeftNavigation> leftNavigationList1 = new ArrayList<>();
unitsDao.findAllByAreaId(belongsArea.getId()).forEach( unitsDao.findAllByAreaId(belongsArea.getId()).forEach(
units -> { units -> {
LeftNavigation leftNavigation1=units.toLeftNavigation(); LeftNavigation leftNavigation1 = units.toLeftNavigation();
leftNavigation1.setTheirId(belongsArea.getId()); leftNavigation1.setTheirId(belongsArea.getId());
leftNavigationList1.add(leftNavigation1); leftNavigationList1.add(leftNavigation1);
} }
); );
leftNavigationList=leftNavigationList1; leftNavigationList = leftNavigationList1;
} }
List<Area> areas= areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList()); List<Area> areas = areaDao.findAllByFatherId(areaId).stream().filter(area -> area.getType() <= 3).collect(Collectors.toList());
if (areas.size()!=0) { if (areas.size() != 0) {
provinceAndCity(belongsArea,areas,leftNavigationList); provinceAndCity(belongsArea, areas, leftNavigationList);
}else { } else {
leftNavigation= belongsArea.toLeftNavigation(); leftNavigation = belongsArea.toLeftNavigation();
List<LeftNavigation> leftNavigationList1=new ArrayList<>(); List<LeftNavigation> leftNavigationList1 = new ArrayList<>();
unitsDao.findAllByAreaId(belongsArea.getId()).forEach( unitsDao.findAllByAreaId(belongsArea.getId()).forEach(
units -> { units -> {
LeftNavigation leftNavigation1=units.toLeftNavigation(); LeftNavigation leftNavigation1 = units.toLeftNavigation();
leftNavigation1.setTheirId(belongsArea.getId()); leftNavigation1.setTheirId(belongsArea.getId());
leftNavigationList1.add(leftNavigation1); leftNavigationList1.add(leftNavigation1);
} }
); );
leftNavigationList=leftNavigationList1; leftNavigationList = leftNavigationList1;
} }
leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder,Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList())); leftNavigation.setLeftNavigations(leftNavigationList.stream().sorted(Comparator.comparing(LeftNavigation::getOrder, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList()));
return leftNavigation; return leftNavigation;
} }
...@@ -410,7 +409,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -410,7 +409,7 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<Units> findDirectlyUnder() { public List<Units> findDirectlyUnder() {
List<Units> unitsList= unitsDao.findAllByType(2); List<Units> unitsList = unitsDao.findAllByType(2);
unitsList.addAll(unitsDao.findAllByType(4)); unitsList.addAll(unitsDao.findAllByType(4));
return unitsList; return unitsList;
} }
...@@ -419,7 +418,7 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -419,7 +418,7 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public List<Units> findSubordinateList(Integer unitsId) { public List<Units> findSubordinateList(Integer unitsId) {
Units units = unitsDao.findById(unitsId).get(); Units units = unitsDao.findById(unitsId).get();
List<Integer> areaIds= areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList()); List<Integer> areaIds = areaDao.findAllByFatherId(units.getAreaId()).stream().filter(area -> area.getType() <= 3).map(Area::getId).collect(Collectors.toList());
return unitsDao.findAllByAreaIdIn(areaIds); return unitsDao.findAllByAreaIdIn(areaIds);
} }
...@@ -430,14 +429,30 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -430,14 +429,30 @@ public class UnitsServiceImpl implements UnitsService {
@Override @Override
public void addUnitSortMap() { public void addUnitSortMap() {
DeviceModelSort.mapUnitSort=unitsDao.findAll().stream().collect(Collectors.toMap(Units::getName,Units::getShowOrder)); DeviceModelSort.mapUnitSort = unitsDao.findAll().stream().collect(Collectors.toMap(Units::getName, Units::getShowOrder));
DeviceModelSort.mapUnitNameToDisName=unitsDao.findAll().stream().collect(Collectors.toMap(Units::getName,Units::getUnitDesc)); DeviceModelSort.mapUnitNameToDisName = unitsDao.findAll().stream().collect(Collectors.toMap(Units::getName, Units::getUnitDesc));
}
/**
* 判断该unit是否是省本级单位
*
* @param unitId 单位主键id
* @return true = 省本级单位 , false = 不是省本级单位
*/
@Override
public boolean isProvUnit(Integer unitId) {
Units units = unitsDao.findById(unitId).get();
if (units.getLevel() == 1 && units.getType() == 1) {
return true;
} else {
return false;
}
} }
@Override @Override
public Units save(Units units) { public Units save(Units units) {
if (units.getAreaId()!=null&&units.getAreaId()!=0) { if (units.getAreaId() != null && units.getAreaId() != 0) {
Optional<Area> optionalArea = areaDao.findById(units.getAreaId()); Optional<Area> optionalArea = areaDao.findById(units.getAreaId());
if (optionalArea.isPresent()) { if (optionalArea.isPresent()) {
units.setLevel(optionalArea.get().getType()); units.setLevel(optionalArea.get().getType());
...@@ -445,13 +460,12 @@ public class UnitsServiceImpl implements UnitsService { ...@@ -445,13 +460,12 @@ public class UnitsServiceImpl implements UnitsService {
} else { } else {
throw new ApiException(ResponseEntity.ok("[单位] 没找到对应的区域,请检查")); throw new ApiException(ResponseEntity.ok("[单位] 没找到对应的区域,请检查"));
} }
} } else {
else {
units.setLevel(4); units.setLevel(4);
units.setType(3); units.setType(3);
} }
Integer maxShowCode= unitsDao.findTopByOrderByShowOrderDesc().getShowOrder(); Integer maxShowCode = unitsDao.findTopByOrderByShowOrderDesc().getShowOrder();
units.setShowOrder(maxShowCode+1); units.setShowOrder(maxShowCode + 1);
Units units1 = unitsDao.save(units); Units units1 = unitsDao.save(units);
unitsCache.refresh(unitsDao.findAll()); unitsCache.refresh(unitsDao.findAll());
return units1; return units1;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论