浏览代码

小程序 待办工单 接口优化

workOrder0626
陈璐 4 个月前
父节点
当前提交
72b2a48e67
共有 4 个文件被更改,包括 158 次插入92 次删除
  1. +3
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/InspectionFileMapper.java
  2. +7
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/entity/InspectionFile.java
  3. +130
    -92
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java
  4. +18
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/InspectionFileMapper.xml

+ 3
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/InspectionFileMapper.java 查看文件

@@ -5,6 +5,7 @@ import com.tuoheng.miniprogram.entity.InspectionFile;
import com.tuoheng.miniprogram.vo.SeeQuestionVo;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
@@ -21,4 +22,6 @@ public interface InspectionFileMapper extends BaseMapper<InspectionFile> {
Integer getInspectionFileHandleCount(@Param("today") String s,@Param("tenantId") String id);

int updateByIdList(Map<String, Object> map);

List<InspectionFile> selectFileDeatilByIds(@Param("idList") List<String> idList);
}

+ 7
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/entity/InspectionFile.java 查看文件

@@ -1,5 +1,6 @@
package com.tuoheng.miniprogram.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.tuoheng.common.core.common.BaseEntity;
@@ -141,6 +142,12 @@ public class InspectionFile extends BaseEntity {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date checkTime;

/**
* 工单ID
*/
@TableField(exist = false)
private String workOrderId;



}

+ 130
- 92
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java 查看文件

@@ -156,7 +156,13 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//登录用户信息
User user = CurrentUserUtil.getUserInfo();
// User user = CurrentUserUtil.getUserInfo();
User user = new User();
user.setDataPermission(1);
user.setTenantId("f9c3de911d228b6e51eafb510aeaea7d");
user.setId("0d695f6ff9441e0ba21cdd86d5cafcbd");
user.setDeptId("e2efb06b239beed004ef9672fed72934");

if (ObjectUtil.isNull(user)) {
return JsonResult.error(WorkOrderEnum.USER_IS_NOT_EXIST.getCode(), WorkOrderEnum.USER_IS_NOT_EXIST.getMsg());
}
@@ -179,31 +185,32 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
query.setOrderEndTime(endTime);
Integer type = user.getDataPermission();

//查询分配我的待处理工单
List<WorkOrderInfoVo> workOrderVo = this.myWorkOrderList(user,query);
List<WorkOrderInfoVo> list = new ArrayList<>();
//数据权限为1当前租户下的数据
if (RoleEnum.SUPER_ADMIN.getCode() == type) {
//查询当前租户下所有工单数据
long b = System.currentTimeMillis();
IPage<WorkOrder> workPageData = workOrderMapper.selectPage(page, Wrappers.<WorkOrder>lambdaQuery()
.in(WorkOrder::getStatus, 5)
.eq(WorkOrder::getTenantId, tenantId)
.between(null != query.getOrderStartTime() && null != query.getOrderEndTime(), WorkOrder::getCreateTime, query.getOrderStartTime(), query.getOrderEndTime())
.eq(WorkOrder::getMark, MarkEnum.VALID.getCode())
.orderByDesc(WorkOrder::getCreateTime));
if (null == workPageData.getRecords()) {
List<WorkOrder> records = workPageData.getRecords();
if (null == records) {
return JsonResult.success("数据为空");
}

List<WorkOrderInfoVo> getWorkOrderVo = this.getWorkOrderList(workPageData,user);
if(CollectionUtil.isNotEmpty(workOrderVo) || workOrderVo.size() != 0){
list.addAll(workOrderVo);
}
if(CollectionUtil.isNotEmpty(getWorkOrderVo) || getWorkOrderVo.size() != 0){
list.addAll(getWorkOrderVo);
}
pageData.setRecords(list);

//查询属于分配自己的数据
List<WorkOrder> workOrders = myWorkList(user, query);
records.addAll(workOrders);

list = this.getWorkOrderList(records,user);
//按照时间+分配人排序
List<WorkOrderInfoVo> newList =
list.stream().sorted(Comparator.comparing(WorkOrderInfoVo::getCreateTime).thenComparing(WorkOrderInfoVo::getAssignUserName).reversed()).collect(Collectors.toList());
pageData.setRecords(newList);
long c = System.currentTimeMillis() - b;
System.out.printf("花费时间b:" + c);
return JsonResult.success(pageData);
}

@@ -228,17 +235,18 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
.between(null != query.getOrderStartTime() && null != query.getOrderEndTime(), WorkOrder::getCreateTime, query.getOrderStartTime(), query.getOrderEndTime())
.eq(WorkOrder::getMark, MarkEnum.VALID.getCode())
.orderByDesc(WorkOrder::getCreateTime));
if (null == workPageData.getRecords()) {
List<WorkOrder> records = workPageData.getRecords();
if (null == records) {
return JsonResult.success("数据为空");
}
List<WorkOrderInfoVo> getWorkOrderVo = this.getWorkOrderList(workPageData,user);
if(CollectionUtil.isNotEmpty(workOrderVo) || workOrderVo.size() != 0){
list.addAll(workOrderVo);
}
if(CollectionUtil.isNotEmpty(getWorkOrderVo) || getWorkOrderVo.size() != 0){
list.addAll(getWorkOrderVo);
}
//查询属于分配自己的数据
List<WorkOrder> workOrders = myWorkList(user, query);
records.addAll(workOrders);
list = this.getWorkOrderList(records,user);
//按照时间+分配人排序
List<WorkOrderInfoVo> newList =
list.stream().sorted(Comparator.comparing(WorkOrderInfoVo::getCreateTime).thenComparing(WorkOrderInfoVo::getAssignUserName)).collect(Collectors.toList());
pageData.setRecords(newList);
pageData.setRecords(list);

return JsonResult.success(pageData);
@@ -257,17 +265,18 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
.between(null != query.getOrderStartTime() && null != query.getOrderEndTime(), WorkOrder::getCreateTime, query.getOrderStartTime(), query.getOrderEndTime())
.eq(WorkOrder::getMark, MarkEnum.VALID.getCode())
.orderByDesc(WorkOrder::getCreateTime));
if (null == workPageData.getRecords()) {
List<WorkOrder> records = workPageData.getRecords();
if (null == records) {
return JsonResult.success("数据为空");
}
List<WorkOrderInfoVo> getWorkOrderVo = this.getWorkOrderList(workPageData,user);
if(CollectionUtil.isNotEmpty(workOrderVo) || workOrderVo.size() != 0){
list.addAll(workOrderVo);
}
if(CollectionUtil.isNotEmpty(getWorkOrderVo) || getWorkOrderVo.size() != 0){
list.addAll(getWorkOrderVo);
}
//查询属于分配自己的数据
List<WorkOrder> workOrders = myWorkList(user, query);
records.addAll(workOrders);
list = this.getWorkOrderList(records,user);
//按照时间+分配人排序
List<WorkOrderInfoVo> newList =
list.stream().sorted(Comparator.comparing(WorkOrderInfoVo::getCreateTime).thenComparing(WorkOrderInfoVo::getAssignUserName)).collect(Collectors.toList());
pageData.setRecords(newList);
pageData.setRecords(list);

return JsonResult.success(pageData);
@@ -303,22 +312,66 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
if (null == workPageData.getRecords()) {
return null;
}
workOrderInfoList = this.getWorkOrderList(workPageData, user);
workOrderInfoList = this.getWorkOrderList(workPageData.getRecords(), user);
System.out.println("------->" + workOrderInfoList);
}
return workOrderInfoList;
}


/**
* vo数据封装
* @param workPageData
* 获取我的待处理工单数据
* @param user
* @param query
* @return
*/
private List<WorkOrderInfoVo> getWorkOrderList(IPage<WorkOrder> workPageData,User user) {
private List<WorkOrder> myWorkList(User user,WorkOrderQuery query) {
Integer type = user.getDataPermission();
IPage<WorkOrder> page = new Page<>(query.getPage(), query.getLimit());
List<WorkOrder> list = new ArrayList<>();
if (RoleEnum.SUPER_ADMIN.getCode() == type || RoleEnum.ADMIN.getCode() == type || RoleEnum.ORDINARY_USER.getCode() == type) {
String deptId = user.getDeptId();
if (StringUtils.isEmpty(deptId)) {
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取当前分配人对应的工单分页数据
IPage<WorkOrder> workPageData = workOrderMapper.selectPage(page, Wrappers.<WorkOrder>lambdaQuery()
.eq(WorkOrder::getAssignDeptId, deptId)
.in(WorkOrder::getStatus,10,12)
.like(StringUtils.isNotEmpty(user.getId()), WorkOrder::getAssignUser, user.getId())
.eq(WorkOrder::getTenantId, user.getTenantId())
.between(null != query.getOrderStartTime() && null != query.getOrderEndTime(), WorkOrder::getCreateTime, query.getOrderStartTime(), query.getOrderEndTime())
.eq(WorkOrder::getMark, MarkEnum.VALID.getCode())
.orderByDesc(WorkOrder::getCreateTime));
if (null == workPageData.getRecords()) {
return null;
}
list = workPageData.getRecords();
System.out.println("------->" + list);
}
return list;
}




/**
* vo数据封装
* @param records
* @return
*/
private List<WorkOrderInfoVo> getWorkOrderList(List<WorkOrder> records,User user) {
List<WorkOrderInfoVo> WorkOrderInfoList = new ArrayList<>();
//设置每条工单对应的各状态问题数量
List<WorkOrderInfoVo> workOrderList = workPageData.getRecords().stream().map(x -> {
//获取 问题总数 + 待处理 + 已处理问题集合
List<String> wordkerIdList = records.stream().map(WorkOrder::getId).collect(Collectors.toList());
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectFileDeatilByIds(wordkerIdList);
Map<String, List<InspectionFile>> fileMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(inspectionFileList)){
fileMap = inspectionFileList.stream().collect(Collectors.groupingBy(InspectionFile::getWorkOrderId));
}
Map<String, List<InspectionFile>> finalFileMap = fileMap;
List<WorkOrderInfoVo> workOrderList = records.stream().map(x -> {
WorkOrderInfoVo vo = new WorkOrderInfoVo();
BeanUtils.copyProperties(x, vo);
vo.setCreateTime(x.getCreateTime());
@@ -329,70 +382,55 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
return null;
}
List<String> list = new ArrayList<>();
for (String userId : assignUserId) {
User userInfo = userMapper.selectById(userId);
if (ObjectUtil.isNotNull(userInfo)) {
list.add(userInfo.getRealname());
}
//代码优化
List<User> users =
userMapper.selectList(new LambdaQueryWrapper<User>().in(User::getId, assignUserId));
if (CollectionUtils.isNotEmpty(users)){
list = users.stream().map(User::getRealname).collect(Collectors.toList());
String usernames = list.stream().map(String::valueOf).collect(Collectors.joining("、"));
vo.setAssignUserName(usernames);
}
String usernames = list.stream().map(String::valueOf).collect(Collectors.joining("、"));
vo.setAssignUserName(usernames);
//问题总数
List<WorkOrderFile> workOrderFiles = workOrderFileMapper.selectList(Wrappers.<WorkOrderFile>lambdaQuery()
.eq(WorkOrderFile::getWorkOrderId, x.getId()));
if (CollectionUtil.isEmpty(workOrderFiles)) {
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
vo.setPromTotal(workOrderFiles.size());
//对应的问题id集合
List<String> inspectionFiledIds = workOrderFiles.stream().map(o -> o.getInspectionFileId()).collect(Collectors.toList());
if (CollectionUtil.isEmpty(inspectionFiledIds)) {
throw new ServiceException(ServiceExceptionEnum.PARAMETER_IS_NULL);
}
//获取问题集合
List<InspectionFile> inspectionFileList = new ArrayList<>();
for (String inspectionFiledId : inspectionFiledIds) {
InspectionFile inspectionFile = inspectionFileMapper.selectById(inspectionFiledId);
LambdaQueryWrapper<InspectionFileHandle> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InspectionFileHandle::getInspectionFileId, inspectionFiledId);
InspectionFileHandle inspectionFileHandle = inspectionFileHandleMapper.selectOne(queryWrapper);
if (Objects.nonNull(inspectionFileHandle ) && inspectionFileHandle.getAudit().equals(AuditEnum.TWO.getCode())){
inspectionFile.setStatus(20);
//处理问题结果集
if (CollectionUtils.isNotEmpty(finalFileMap.get(x.getId()))){
List<InspectionFile> inspectionFiles = finalFileMap.get(x.getId());
vo.setPromTotal(inspectionFiles.size());

if(CollectionUtil.isEmpty(inspectionFiles) || inspectionFiles.size() == 0){
throw new ServiceException("问题数据查询为空");
}
inspectionFileList.add(inspectionFile);
}
if(CollectionUtil.isEmpty(inspectionFileList) || inspectionFileList.size() == 0){
throw new ServiceException("问题数据查询为空");
}
log.info("问题列表为:inspectionFileList={}",inspectionFileList.toString());
//待处理问题总数
long count = inspectionFileList.stream().filter(t -> t.getStatus() == 20).count();
log.info("待处理问题总数为:count={}",count);
if(ArrayUtil.isNotEmpty(count)){
vo.setPromTodo((int) count);
}
//已处理问题总数
long count1 = inspectionFileList.stream().filter(t -> t.getStatus() == 25).count();
log.info("已处理问题总数为:count1={}",count1);
if(ArrayUtil.isNotEmpty(count1)){
vo.setPromProcessed((int) count1);
log.info("问题列表为:inspectionFileList={}",inspectionFiles.toString());
//待处理问题总数
long count = inspectionFiles.stream().filter(t -> Objects.nonNull(t.getStatus()) && t.getStatus() == 20).count();
log.info("待处理问题总数为:count={}",count);
if(ArrayUtil.isNotEmpty(count)){
vo.setPromTodo((int) count);
}
//已处理问题总数
long count1 = inspectionFiles.stream().filter(t -> Objects.nonNull(t.getStatus()) && t.getStatus() == 25).count();
log.info("已处理问题总数为:count1={}",count1);
if(ArrayUtil.isNotEmpty(count1)){
vo.setPromProcessed((int) count1);
}
}else {
List<InspectionFile> inspectionFiles = finalFileMap.get(x.getId());
}

return vo;
}).collect(Collectors.toList());
//当待处理问题总数为0时,此工单不出现在代办工单列表并且工单状态修改为15已完成
List<WorkOrderInfoVo> collect = workOrderList.stream().filter(f -> f.getPromTodo() == 0 && !f.getStatus().equals(WorkOrderStatusEnum.PENDING_REJECT.getCode())).collect(Collectors.toList());
if (null != collect) {
for (WorkOrderInfoVo workOrderInfoVo : collect) {
//每一个工单对应的状态发生改变,一个工单id对应一个工单
WorkOrder workOrder = workOrderMapper.selectById(workOrderInfoVo.getId());
if (ObjectUtil.isNotNull(workOrder)) {
//问题处理完 状态改为待审核 新需求
workOrder.setStatus(WorkOrderStatusEnum.STATUS_PENDING_REVIEW.getCode());
workOrder.setUpdateTime(DateUtils.now());
workOrder.setUpdateUser(user.getId());
super.update(workOrder);
}
if (CollectionUtils.isNotEmpty(collect)) {
List<String> idList = collect.stream().map(WorkOrderInfoVo::getId).collect(Collectors.toList());
//问题处理完 状态改为待审核 新需求
List<WorkOrder> workOrders = workOrderMapper.selectList(new LambdaQueryWrapper<WorkOrder>().in(WorkOrder::getId, idList));
if (CollectionUtils.isNotEmpty(workOrders)){
workOrders.forEach(item->{
item.setStatus(WorkOrderStatusEnum.STATUS_PENDING_REVIEW.getCode());
item.setUpdateTime(DateUtils.now());
item.setUpdateUser(user.getId());
});
this.updateBatchById(workOrders);
}
}
//工单的待处理问题个数不为0时 重新返回

+ 18
- 0
tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/InspectionFileMapper.xml 查看文件

@@ -60,4 +60,22 @@
</if>
</where>
</update>


<select id="selectFileDeatilByIds" resultType="com.tuoheng.miniprogram.entity.InspectionFile">
select
twof.work_order_id as workOrderId,
tf.id AS id,
if(tfh.audit = 2, 20, tf.STATUS) AS status,
tfh.audit AS audit
from
th_work_order_file twof
left join th_inspection_file as tf on twof.inspection_file_id = tf.id
left join th_inspection_file_handle AS tfh on tf.id = tfh.inspection_file_id and tfh.
where twof.work_order_id in
<foreach item="id" collection="idList" open="(" separator="," close=")">
#{id}
</foreach>
</select>

</mapper>

正在加载...
取消
保存