提交 701979ad authored 作者: Matrix's avatar Matrix

[核查模块] 修复了统计数据的统计两次的问题

上级 39d43e47
......@@ -55,7 +55,7 @@ import static java.util.stream.Collectors.*;
@RestController
@RequestMapping(value = "/check/confirm")
@AutoDocument
@Api(tags = "核查模块", value = "核查模块")
@Api(tags = "核查模块", description = "核查模块")
@Transactional
@Slf4j
public class DeviceCheckController {
......
......@@ -59,8 +59,7 @@ public class CheckAreaStatVo {
this.areaName = other.getAreaName();
this.areaStatId = other.getAreaStatId();
this.areaDetailId = other.getAreaDetailId();
this.actualCount = other.getActualCount() + other.getActualCount();
this.supposeCount = other.getSupposeCount() + other.getSupposeCount();
this.actualCount += other.getActualCount();
this.comProgress = other.getComProgress();
this.comSituation = other.getComSituation();
......
......@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
......@@ -72,7 +73,7 @@ public class CheckDeviceStatVo {
areaMap.computeIfPresent(otherArea.getAreaName(), (k, v) -> v.add(otherArea));
}
areaStatList = (List<CheckAreaStatVo>) areaMap.values();
areaStatList = new ArrayList<>(areaMap.values());
return this;
}
......
......@@ -116,7 +116,7 @@ public class CheckStatVo {
oriModelMap.computeIfPresent(vo.getDeviceModel(), (k, v) -> v.add(vo));
}
deviceStatVoList = (List<CheckDeviceStatVo>) oriModelMap.values();
deviceStatVoList = new ArrayList<>(oriModelMap.values());
return this;
}
......
package com.tykj.dev.misc.exception;
import com.tykj.dev.misc.base.ResultObj;
import org.springframework.http.ResponseEntity;
/**
* 全局错误处理类,用于处理一些不容易定义的错误
*
* @author HuangXiahao
**/
public class ApiException extends RuntimeException {
......@@ -14,6 +16,15 @@ public class ApiException extends RuntimeException {
this.responseEntity = responseEntity;
}
public ApiException(String message) {
this.responseEntity = ResponseEntity.status(400).body(new ResultObj(message));
}
public ApiException(String message, Object data) {
this.responseEntity = ResponseEntity.status(400).body(new ResultObj(data, message));
}
public ResponseEntity getResponseEntity() {
return responseEntity;
}
......
......@@ -33,6 +33,7 @@ public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(Exception.class)
public ResponseEntity errorMessage(Exception e) {
log.error("[其他异常] {}", e.toString());
e.printStackTrace();
return ResultUtil.failed();
}
......@@ -46,9 +47,8 @@ public class GlobalExceptionHandler {
@ExceptionHandler(ApiException.class)
public ResponseEntity errorMessage(ApiException e) {
log.warn("[自定义异常] {}", e.toString());
log.error("错误详情:{}",e.getMessage());
if (e.getResponseEntity() != null) {
return ResponseEntity.status(400).body(e.getResponseEntity().getBody());
return e.getResponseEntity();
}
return ResultUtil.failed();
}
......@@ -61,6 +61,7 @@ public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(BindException.class)
public ResponseEntity errorMessage(BindException e) {
log.error("[参数异常] 检测到用户访问接口没有提供正确的参数 {}", e.toString());
e.printStackTrace();
BindingResult bindingResult = e.getBindingResult();
String message = null;
......@@ -81,7 +82,7 @@ public class GlobalExceptionHandler {
@ResponseBody
@ExceptionHandler(AuthenticationException.class)
public ResponseEntity errorMessage(AuthenticationException e) {
e.printStackTrace();
log.warn("[未登录异常] 检测到用户没有登录");
return ResultUtil.unauthorized();
}
......@@ -94,6 +95,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity errorMessage(AccessDeniedException e) {
e.printStackTrace();
log.warn("[权限异常] {}", e.toString());
return ResponseEntity.status(403).body(new ResultObj(e.getMessage()));
}
......
......@@ -38,7 +38,7 @@ public class ResultUtil<T> {
* 失败返回结果
*/
public static <T> ResponseEntity failed() {
return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(500).body(new ResultObj("服务器内部发生错误"));
}
/**
......
......@@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Optional;
/**
* @author dengdiyi
......@@ -17,7 +18,7 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE
* @param businessType 业务类型
* 根据账单Id和业务类型查询task
*/
Task findByBillIdAndBusinessType(Integer billId, Integer businessType);
Optional<Task> findByBillIdAndBusinessType(Integer billId, Integer businessType);
/**
* 根据账单id、业务类型、任务状态查询task
......
......@@ -72,6 +72,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到下一个状态</p>
* <li>不指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param customInfo 自定义信息
*/
@Override
......@@ -93,6 +94,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到下一个状态(指定待办用户)</p>
* <li>指定待办用户</li>
*
* @param userId 待办用户Id
*/
@Override
......@@ -113,6 +115,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到下一个状态(指定待办用户)</p>
* <li>指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param userId 待办用户Id
* @param customInfo 自定义信息
*/
......@@ -134,6 +137,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到特殊状态</p>
* <li>不指定待办用户</li>
*
* @param statusEnum 状态枚举
*/
@Override
......@@ -154,6 +158,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到特殊状态</p>
* <li>不指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param statusEnum 状态枚举
* @param customInfo 自定义信息
*/
......@@ -176,6 +181,7 @@ public class TaskServiceImpl implements TaskService {
/**
* <p>业务进行到特殊状态</p>
* <li>指定待办用户</li>
*
* @param statusEnum 状态枚举
* @param userId 待办用户Id
*/
......@@ -197,6 +203,7 @@ public class TaskServiceImpl implements TaskService {
* <p>业务进行到特殊状态</p>
* <li>指定待办用户</li>
* <li>添加自定义信息</li>
*
* @param statusEnum 状态枚举
* @param userId 待办用户Id
* @param customInfo 自定义信息
......@@ -274,12 +281,13 @@ public class TaskServiceImpl implements TaskService {
*/
@Override
public TaskBto get(Integer billId, Integer businessType) {
return taskDao.findByBillIdAndBusinessType(billId, businessType).parse2Bto();
return taskDao.findByBillIdAndBusinessType(billId, businessType)
.orElseThrow(() -> new ApiException(String.format("要查询的数据不存在,查询的billId为 %d,businessType为 %d", billId, businessType)))
.parse2Bto();
}
/**
* @param taskSelectVo
* 获取跟踪和待办业务列表
* @param taskSelectVo 获取跟踪和待办业务列表
*/
@Override
public List<TaskUserVo> getList(TaskSelectVo taskSelectVo) {
......@@ -314,7 +322,7 @@ public class TaskServiceImpl implements TaskService {
Integer num = taskSelectVo.getSelectNum();
Integer userId = userUtils.getCurrentUserId();
//业务管理中的待办和跟踪
if (num==2||num==3){
if (num == 2 || num == 3) {
//查询出符合筛选条件的所有task
List<TaskUserVo> list = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
......@@ -322,10 +330,10 @@ public class TaskServiceImpl implements TaskService {
.collect(Collectors.toList());
//查询当前用户的跟踪和待办并和list按id取交集
List<TaskUserVo> taskUserVos = getList(taskSelectVo).stream()
.filter(taskUserVo -> find(taskUserVo.getId(),list)>-1)
.filter(taskUserVo -> find(taskUserVo.getId(), list) > -1)
.collect(Collectors.toList());
//判断是否需要按发起时间排序
if (taskSelectVo.getOrders()!=null) {
if (taskSelectVo.getOrders() != null) {
if ("createTime".equals(taskSelectVo.getOrders().get(0).getCoulmn())) {
if ("ASC".equals(taskSelectVo.getOrders().get(0).getDirection().toString())) {
return taskUtils.orderByCreateTimeAsc2(taskUserVos);
......@@ -337,21 +345,21 @@ public class TaskServiceImpl implements TaskService {
}
return taskUserVos;
}
if (num==4||num==5||num==1||num==0) {
if (num == 4 || num == 5 || num == 1 || num == 0) {
//获取单位等级
Integer level = userUtils.getCurrentUnitLevel();
//获取该单位以及下属单位所有用户Id
List<Integer> idLists = userPublicService.findAllUserIdByUnitsName(userUtils.getCurrentUserUnitName());
List<TaskUserVo> taskUserVos = new ArrayList<>();
//省能看到所有业务
if (level==1) {
if (level == 1) {
taskUserVos = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
.map(TaskBto::toVo)
.collect(Collectors.toList());
}
//市或县只能看到涉及人员和idLists有交集的
if (level==2||level==3){
if (level == 2 || level == 3) {
taskUserVos = taskDao.findAll(getSelectSpecification(taskSelectVo)).stream()
.map(Task::parse2Bto)
.map(TaskBto::toVo)
......@@ -359,7 +367,7 @@ public class TaskServiceImpl implements TaskService {
.collect(Collectors.toList());
}
//set经办人,置顶以及阅读情况
for (TaskUserVo taskUserVo:taskUserVos) {
for (TaskUserVo taskUserVo : taskUserVos) {
List<Integer> idList = taskUserVo.getUserReadDetailList();
List<Integer> idList2 = taskUserVo.getTopFlagDetailList();
if (taskUserVo.getInvolveUserIdList() != null && taskUserVo.getInvolveUserIdList().size() > 0) {
......@@ -380,7 +388,7 @@ public class TaskServiceImpl implements TaskService {
}
}
//判断是否需要按发起时间排序
if (taskSelectVo.getOrders()!=null) {
if (taskSelectVo.getOrders() != null) {
if ("createTime".equals(taskSelectVo.getOrders().get(0).getCoulmn())) {
if ("ASC".equals(taskSelectVo.getOrders().get(0).getDirection().toString())) {
return taskUtils.orderByCreateTimeAsc2(taskUserVos);
......@@ -391,8 +399,7 @@ public class TaskServiceImpl implements TaskService {
}
}
return taskUserVos;
}
else {
} else {
throw new ApiException(ResultUtil.failed("selectNum只能为0,1,2,3,4,5"));
}
}
......@@ -403,12 +410,12 @@ public class TaskServiceImpl implements TaskService {
*/
@Override
public TaskBto addInvolveUser(TaskBto taskBto, Integer userId) {
List<Integer> list = taskBto.getInvolveUserIdList();
List<Integer> list = taskBto.getInvolveUserIdList();
//添加涉及用户Id
list.add(userId);
taskBto.setInvolveUserIdList(list);
//指针后移
taskBto.setCurrentPoint(taskBto.getCurrentPoint()+1);
taskBto.setCurrentPoint(taskBto.getCurrentPoint() + 1);
update(taskBto);
return taskBto;
}
......@@ -439,7 +446,7 @@ public class TaskServiceImpl implements TaskService {
public void workHandover(Integer oldUserId, Integer newUserId) {
//筛选出未完结和未封存业务,映射成bto
List<TaskBto> taskBtos = taskDao.findAll().stream()
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id))&&(!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id)) && (!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.map(Task::parse2Bto)
.collect(Collectors.toList());
//查询待办
......@@ -454,21 +461,21 @@ public class TaskServiceImpl implements TaskService {
//替换用户id
taskBtoList.forEach(taskBto -> {
List<Integer> ids = taskBto.getInvolveUserIdList();
ids.set(taskBto.getCurrentPoint(),newUserId);
ids.set(taskBto.getCurrentPoint(), newUserId);
taskBto.setInvolveUserIdList(ids);
update(taskBto);
});
//查询跟踪
//涉及人员包括旧用户且指针对应UserId不是旧用户
List<TaskBto> taskBtos1 = taskBtos.stream()
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(oldUserId)&&!oldUserId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(oldUserId) && !oldUserId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.collect(Collectors.toList());
//替换用户id
taskBtos1.forEach(taskBto -> {
List<Integer> ids = taskBto.getInvolveUserIdList();
for (int i =0;i<ids.size();i++){
if (ids.get(i).equals(oldUserId)){
ids.set(i,newUserId);
for (int i = 0; i < ids.size(); i++) {
if (ids.get(i).equals(oldUserId)) {
ids.set(i, newUserId);
}
}
taskBto.setInvolveUserIdList(ids);
......@@ -478,7 +485,7 @@ public class TaskServiceImpl implements TaskService {
/**
* @param taskSelectVo 查询vo
* 查询跟踪和待办列表
* 查询跟踪和待办列表
* @return taskUserVo列表
*/
private List<TaskUserVo> getTaskUserVoList(TaskSelectVo taskSelectVo) {
......@@ -487,7 +494,7 @@ public class TaskServiceImpl implements TaskService {
Integer unitId = userUtils.getCurrentUnitId();
//筛选出未完结和未封存业务,映射成bto
List<TaskBto> taskBtos = taskDao.findAll().stream()
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id))&&(!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.filter(task -> (!task.getBillStatus().equals(StatusEnum.END.id)) && (!task.getBillStatus().equals(StatusEnum.ARCHIVE.id)))
.map(Task::parse2Bto)
.collect(Collectors.toList());
//查询待办
......@@ -505,15 +512,15 @@ public class TaskServiceImpl implements TaskService {
//查询所有的业务
if (bussinessType == null) {
List<TaskUserVo> taskUserVos = taskBtoList.stream().map(TaskBto::toVo).collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
} else {
//查询工作台其它业务
if (bussinessType == 0) {
List<TaskUserVo> taskUserVos = taskBtoList.stream()
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3,4,5,6)).contains(taskBto.getBusinessType()))
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3, 4, 5, 6)).contains(taskBto.getBusinessType()))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
}
//查询某一业务
else {
......@@ -521,7 +528,7 @@ public class TaskServiceImpl implements TaskService {
.filter(taskBto -> taskBto.getBusinessType().equals(bussinessType))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,0);
return setTaskUserVo(taskUserVos, 0);
}
}
}
......@@ -529,25 +536,25 @@ public class TaskServiceImpl implements TaskService {
if (taskSelectVo.getSelectNum() == 3) {
//涉及人员包括当前用户且指针对应UserId不是当前用户
List<TaskBto> taskBtoList = taskBtos.stream()
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(userId)&&!userId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.filter(taskBto -> taskBto.getInvolveUserIdList().contains(userId) && !userId.equals(taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())))
.collect(Collectors.toList());
//涉及人员当前指针为-1,且所属单位为当前单位
List<TaskBto> taskBtos1 = taskBtos.stream()
.filter(taskBto -> !taskBto.getInvolveUserIdList().contains(userId)&&taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint())==-1&&taskBto.getOwnUnit().equals(unitId))
.filter(taskBto -> !taskBto.getInvolveUserIdList().contains(userId) && taskBto.getInvolveUserIdList().get(taskBto.getCurrentPoint()) == -1 && taskBto.getOwnUnit().equals(unitId))
.collect(Collectors.toList());
taskBtoList.addAll(taskBtos1);
//查询所有业务
if (bussinessType == null) {
List<TaskUserVo> taskUserVos = taskBtoList.stream().map(TaskBto::toVo).collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
} else {
//查询工作台其它业务
if (bussinessType == 0) {
List<TaskUserVo> taskUserVos = taskBtoList.stream()
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3,4,5,6)).contains(taskBto.getBusinessType()))
.filter(taskBto -> !new ArrayList<>(Arrays.asList(3, 4, 5, 6)).contains(taskBto.getBusinessType()))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
}
//查询某一业务
else {
......@@ -555,7 +562,7 @@ public class TaskServiceImpl implements TaskService {
.filter(taskBto -> taskBto.getBusinessType().equals(bussinessType))
.map(TaskBto::toVo)
.collect(Collectors.toList());
return setTaskUserVo(taskUserVos,1);
return setTaskUserVo(taskUserVos, 1);
}
}
} else {
......@@ -566,7 +573,7 @@ public class TaskServiceImpl implements TaskService {
/**
* @param list taskUserVos
* @param type 0:set待办 1:set跟踪
* set一些输出给前端的值
* set一些输出给前端的值
*/
private List<TaskUserVo> setTaskUserVo(List<TaskUserVo> list, int type) {
Integer userId = userUtils.getCurrentUserId();
......@@ -603,8 +610,7 @@ public class TaskServiceImpl implements TaskService {
if (userTime == null) {
taskUserVo.setUserTime("0天0小时");
taskUserVo.setUserTimeDate(new Date(0));
}
else {
} else {
long time = System.currentTimeMillis() - userTime.getTime();
int day = new Long(time / 86_400_000).intValue();
int hour = new Long((time % 86_400_000) / 3_600_000).intValue();
......@@ -618,54 +624,52 @@ public class TaskServiceImpl implements TaskService {
/**
* @param taskId 业务id
* 获取当前用户上次处理业务时间
* 获取当前用户上次处理业务时间
*/
private Date getUserTime(Integer taskId) {
List<TaskLog> list = taskLogDao.getAllByTaskId(taskId);
if (list.size()>0) {
if (list.size() > 0) {
//筛选出当前用户操作该业务的所有日志,根据业务日志的创建时间降序排列,得到最新的上一次操作时间
List<TaskLog> taskLogs = taskUtils.orderByCreateTimeDesc(list.stream().filter(taskLog -> taskLog.getCreateUserId().equals(userUtils.getCurrentUserId())).collect(Collectors.toList()));
return taskLogs.get(0).getCreateTime();
}
else {
} else {
return null;
}
}
/**
* @param taskSelectVo
* task查询器
* @param taskSelectVo task查询器
*/
private Specification<Task> getSelectSpecification(TaskSelectVo taskSelectVo){
private Specification<Task> getSelectSpecification(TaskSelectVo taskSelectVo) {
PredicateBuilder<Task> predicateBuilder = Specifications.and();
if (taskSelectVo.getBusinessType()!=null){
if (taskSelectVo.getBusinessType() != null) {
predicateBuilder.eq("businessType", taskSelectVo.getBusinessType());
}
if (taskSelectVo.getContent()!=null){
if (taskSelectVo.getContent() != null) {
Class<Task> taskEntityClass = Task.class;
Field[] declaredFields = taskEntityClass.getDeclaredFields();
PredicateBuilder<Task> p = Specifications.or();
for (Field field : declaredFields) {
if (field.getType().equals(String.class)&&field.getAnnotation(Transient.class)==null) {
if (field.getType().equals(String.class) && field.getAnnotation(Transient.class) == null) {
p.like(field.getName(), "%" + taskSelectVo.getContent() + "%");
}
}
predicateBuilder.predicate(p.build());
}
if (taskSelectVo.getStartTime()!=null){
if (taskSelectVo.getStartTime() != null) {
predicateBuilder.gt("createTime", taskSelectVo.getStartTime());
}
if (taskSelectVo.getEndTime()!=null){
if (taskSelectVo.getEndTime() != null) {
predicateBuilder.lt("createTime", taskSelectVo.getEndTime());
}
if (taskSelectVo.getSelectNum()==4){
predicateBuilder.eq("billStatus",StatusEnum.END.id);
if (taskSelectVo.getSelectNum() == 4) {
predicateBuilder.eq("billStatus", StatusEnum.END.id);
}
if (taskSelectVo.getSelectNum()==5){
predicateBuilder.eq("billStatus",StatusEnum.ARCHIVE.id);
if (taskSelectVo.getSelectNum() == 5) {
predicateBuilder.eq("billStatus", StatusEnum.ARCHIVE.id);
}
if (taskSelectVo.getSelectNum()==1){
predicateBuilder.eq("createUserId",userUtils.getCurrentUserId());
if (taskSelectVo.getSelectNum() == 1) {
predicateBuilder.eq("createUserId", userUtils.getCurrentUserId());
}
return predicateBuilder.build();
}
......@@ -673,11 +677,11 @@ public class TaskServiceImpl implements TaskService {
/**
* 判断list中是否包含某个id的taskUserVo,若不存在返回-1,存在则返回第一次出现的索引值
*/
int find(Integer id,List<TaskUserVo> list){
int find(Integer id, List<TaskUserVo> list) {
int index = -1;
if (list!=null&&list.size()>0){
for (int i=0;i<list.size();i++){
if (list.get(i).getId().equals(id)){
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getId().equals(id)) {
index = i;
break;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论