Quellcode durchsuchen

小程序批量添加工单

tags/v1.0.0^2
chengwang vor 1 Jahr
Ursprung
Commit
b369c60028
9 geänderte Dateien mit 314 neuen und 4 gelöschten Zeilen
  1. +10
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WorkOrderController.java
  2. +4
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/InspectionFileMapper.java
  3. +4
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/WorkOrderFileMapper.java
  4. +46
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/DataPermissionEnum.java
  5. +53
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/GenerateWorkorderCodeEnum.java
  6. +4
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IWorkOrderService.java
  7. +163
    -4
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java
  8. +19
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/InspectionFileMapper.xml
  9. +11
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/WorkOrderFileMapper.xml

+ 10
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/WorkOrderController.java Datei anzeigen

@@ -11,6 +11,8 @@ import com.tuoheng.miniprogram.service.IWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Author ChengWang
* @Date 2022/12/6
@@ -36,6 +38,14 @@ public class WorkOrderController extends BaseController {
return workOrderService.addInfo(dto);
}

/**
* 批量生成工单
*/
@PostMapping("/generate/{idList}")
public JsonResult generate(@PathVariable("idList") List<String> idList) {
return workOrderService.generate(idList);
}

/**
* 代办工单
* @param query

+ 4
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/InspectionFileMapper.java Datei anzeigen

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

import java.util.Map;

/**
* @Author ChengWang
* @Date 2022/11/23
@@ -17,4 +19,6 @@ public interface InspectionFileMapper extends BaseMapper<InspectionFile> {
Integer getInspectionFileCount(@Param("today") String s,@Param("userId") String id);

Integer getInspectionFileHandleCount(@Param("today") String s,@Param("tenantId") String id);

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

+ 4
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/dao/WorkOrderFileMapper.java Datei anzeigen

@@ -3,9 +3,13 @@ package com.tuoheng.miniprogram.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuoheng.miniprogram.entity.WorkOrderFile;

import java.util.List;

/**
* @Author ChengWang
* @Date 2022/12/6
*/
public interface WorkOrderFileMapper extends BaseMapper<WorkOrderFile> {

int insertBatch(List<WorkOrderFile> workOrderFileList);
}

+ 46
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/DataPermissionEnum.java Datei anzeigen

@@ -0,0 +1,46 @@
package com.tuoheng.miniprogram.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
* 用户类型
*
* @author wanjing
* @team tuoheng
* @date 2022-11-25
*/
public enum DataPermissionEnum {

ALL(1,"查看所有部门数据"),
DEPT_AND_SUB_DEPT(2,"查看本部门及子部门数据"),
DEPT(3,"查看本部门数据");

DataPermissionEnum(int code, String description){
this.code = code;
this.description = description;
}

@Getter
private int code;

@Getter
private String description;

private static Map<Integer, DataPermissionEnum> data = new HashMap<>();

static {
for (DataPermissionEnum type : DataPermissionEnum.values()) {
data.put(type.code, type);
}
}

public static DataPermissionEnum parse(int code) {
if (data.containsKey(code)) {
return data.get(code);
}
return null;
}
}

+ 53
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/GenerateWorkorderCodeEnum.java Datei anzeigen

@@ -0,0 +1,53 @@
package com.tuoheng.miniprogram.enums;

/**
* 生成工单返回码
* 模块代码:26(工单管理)
* 接口代码:01 (生成工单)
*
* @author wanjing
* @team tuoheng
* @date 2022-12-07
*/
public enum GenerateWorkorderCodeEnum {

GENERATE_IS_FAILED(1260100, "生成工单失败"),
ID_LIST_IS_NULL(1260101, "任务问题id列表为空"),
INSPECTION_FILE_ID_LIST_IS_NOT_EXIST(1260102, "任务问题不存在"),
INCLUDE_NO_CONFIRMED_INSPECTION(1260103, "包含非确认状态任务问题"),
ADMIN_NOT_GENERATE_CHILD_WORKORDER(1260104, "管理员不能生成子部门工单"),
ORDINARY_USER_NO_PERMISSION_TO_GENERATE(1260105, "普通用户不能生成工单"),
;

/**
* 错误码
*/
private int code;

/**
* 错误信息
*/
private String msg;

GenerateWorkorderCodeEnum(int code, String msg){
this.code = code;
this.msg = msg;
}

public int getCode() {
return code;
}

public void setCode(int code) {
this.code = code;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

}

+ 4
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IWorkOrderService.java Datei anzeigen

@@ -7,6 +7,8 @@ import com.tuoheng.miniprogram.entity.dto.WorkOrderDto;
import com.tuoheng.miniprogram.entity.query.HandleQuery;
import com.tuoheng.miniprogram.entity.query.WorkOrderQuery;

import java.util.List;

/**
* @Author ChengWang
* @Date 2022/12/6
@@ -27,4 +29,6 @@ public interface IWorkOrderService extends IBaseService<WorkOrder> {
JsonResult weekCount();

JsonResult mothCount();

JsonResult generate(List<String> idList);
}

+ 163
- 4
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/WorkOrderServiceImpl.java Datei anzeigen

@@ -33,10 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

/**
@@ -736,6 +733,168 @@ public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrderMapper, WorkO
return JsonResult.success(vo);
}

/**
*批量生成工单
* @param idList
* @return
*/
@Override
public JsonResult generate(List<String> idList) {
log.info("进入生成工单业务, idList:{}", idList);
String userId = CurrentUserUtil.getUserId();
String tenantId = CurrentUserUtil.getTenantId();
JsonResult result = this.check(idList);
if (0 != result.getCode()) {
log.info("进入生成工单业务:校验失败:{}", result.getMsg());
return result;
}
List<InspectionFile> inspectionFileList = (List<InspectionFile>) result.getData();
List<String> inspectionIdList = inspectionFileList.stream().map(o -> o.getInspectionId()).collect(Collectors.toList());
List<Inspection> inspectionList = inspectionMapper.selectBatchIds(inspectionIdList);
User user = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(User::getTenantId, tenantId)
.eq(User::getId, userId)
.eq(User::getMark, 1));
result = checkPermission(user, inspectionList);

if (0 != result.getCode()) {
log.info("进入生成工单务:校验权限失败:{}", result.getMsg());
return result;
}

WorkOrder workOrder = this.insertWorkOrder(user);

this.insertWorkOrderFile(workOrder, idList);

this.updateInspectionFileStatus(userId, idList);

return JsonResult.success();
}

/**
* 判断是否有生成工单权限
* 1)、超级管理员可选择所有部门问题生成工单
* 2)、部门管理员仅可生成本部门工单,无法生成子部门工单
* 3)、普通用户无生成工单权限
* 目前小程序不做权限控制
*
* @param user
* @param inspectionList
* @return
*/
private JsonResult checkPermission(User user, List<Inspection> inspectionList) {
// if (DataPermissionEnum.ALL.getCode() == user.getDataPermission()) {
// return JsonResult.success(user);
// } else if (DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == user.getDataPermission()) {
// for (Inspection inspection : inspectionList) {
// if (!user.getDeptId().equals(inspection.getDeptId())) {
// return JsonResult.error(GenerateWorkorderCodeEnum.ADMIN_NOT_GENERATE_CHILD_WORKORDER.getCode(), GenerateWorkorderCodeEnum.ADMIN_NOT_GENERATE_CHILD_WORKORDER.getMsg());
// }
// }
// return JsonResult.success(user);
// } else if (DataPermissionEnum.DEPT.getCode() == user.getDataPermission()) {
// return JsonResult.error(GenerateWorkorderCodeEnum.ORDINARY_USER_NO_PERMISSION_TO_GENERATE.getCode(), GenerateWorkorderCodeEnum.ORDINARY_USER_NO_PERMISSION_TO_GENERATE.getMsg());
// }
return JsonResult.success(user);
}

/**
* 检查参数
*
* @param idList
* @return
*/
private JsonResult check(List<String> idList) {
// 判断任务问题id是否为空
if (CollectionUtil.isEmpty(idList)) {
return JsonResult.error(GenerateWorkorderCodeEnum.ID_LIST_IS_NULL.getCode(), GenerateWorkorderCodeEnum.ID_LIST_IS_NULL.getMsg());
}
List<InspectionFile> inspectionFileList = inspectionFileMapper.selectBatchIds(idList);
if (CollectionUtil.isEmpty(inspectionFileList)) {
return JsonResult.error(GenerateWorkorderCodeEnum.INSPECTION_FILE_ID_LIST_IS_NOT_EXIST.getCode(), GenerateWorkorderCodeEnum.INSPECTION_FILE_ID_LIST_IS_NOT_EXIST.getMsg());
}
for (InspectionFile inspectionFile : inspectionFileList) {
if (inspectionFile.getStatus() != InspectionFileStatusEnum.CONFIRMED.getCode()) {
return JsonResult.error(GenerateWorkorderCodeEnum.INCLUDE_NO_CONFIRMED_INSPECTION.getCode(), GenerateWorkorderCodeEnum.INCLUDE_NO_CONFIRMED_INSPECTION.getMsg());
}
}
return JsonResult.success(inspectionFileList);
}

/**
*
* 添加工单
*
*/
private WorkOrder insertWorkOrder(User user) {
WorkOrder workOrder = new WorkOrder();
String code = DateUtils.generateCode("XJGD");
workOrder.setCode(code);
workOrder.setTenantId(user.getTenantId());
workOrder.setDeptId(user.getDeptId());
workOrder.setStatus(WorkOrderStatusEnum.STATUS_ALLOCATED.getCode());
//分配人员为当前登录用户
workOrder.setDistributionId(user.getId());
//指派人员目前临时是当前登录用户
workOrder.setAssignUser(user.getId());
workOrder.setAssignContact(user.getMobile());
workOrder.setAssignTime(DateUtils.now());
workOrder.setCreateUser(user.getId());
workOrder.setCreateTime(DateUtils.now());
Integer rowCount = workOrderMapper.insert(workOrder);
if (rowCount <= 0) {
log.info("添加工单表失败");
}
return workOrder;
}

/**
*
* 添加工单子表
*
*/
private void insertWorkOrderFile(WorkOrder workOrder, List<String> idList) {
List<WorkOrderFile> workOrderFileList = new ArrayList<>();
WorkOrderFile workOrderFile;
for (String id : idList) {
workOrderFile = new WorkOrderFile();
workOrderFile.setTenantId(workOrder.getTenantId());
workOrderFile.setWorkOrderId(workOrder.getId());
workOrderFile.setInspectionFileId(id);
workOrderFileList.add(workOrderFile);
}

if (CollectionUtil.isEmpty(workOrderFileList)) {
return;
}
Integer rowCount = workOrderFileMapper.insertBatch(workOrderFileList);
if (rowCount <= 0) {
log.info("添加工单子表失败");
}
}

/**
*
* 问题状态,改为已生成工单
*
* @param userId
* @param idList
*/
private JsonResult updateInspectionFileStatus(String userId, List<String> idList) {
Map<String, Object> map = new HashMap<>();
map.put("status", InspectionFileStatusEnum.GENERATE_ORDER.getCode());
map.put("updateUser", userId);
map.put("updateTime", DateUtils.now());
map.put("idList", idList);

Integer rowCount = inspectionFileMapper.updateByIdList(map);
if (rowCount <= 0) {
log.info("修改任务问题状态, 确认失败");
return JsonResult.error(GenerateWorkorderCodeEnum.GENERATE_IS_FAILED.getCode(), GenerateWorkorderCodeEnum.GENERATE_IS_FAILED.getMsg());
}
return JsonResult.success();
}


/**
* 传入两个时间范围,返回这两个时间范围内的所有时间,并保存在一个集合中

+ 19
- 0
tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/InspectionFileMapper.xml Datei anzeigen

@@ -38,4 +38,23 @@
and mark = 1
and tenant_id = #{tenantId}
</select>

<update id="updateByIdList" parameterType="hashmap">
update th_inspection_file
<trim prefix="SET" suffixOverrides=",">
<if test="status != null"> status = #{status}, </if>
<if test="updateUser != null and updateUser != ''"> update_user = #{updateUser}, </if>
<if test="updateTime != null"> update_time = #{updateTime}, </if>
<if test="checkUser != null and checkUser != ''"> check_user = #{checkUser}, </if>
<if test="checkTime != null"> check_time = #{checkTime}, </if>
</trim>
<where>
<if test="idList != null and idList.size() > 0">
and id in
<foreach collection="idList" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
</where>
</update>
</mapper>

+ 11
- 0
tuoheng-service/tuoheng-miniprogram/src/main/resources/mapper/WorkOrderFileMapper.xml Datei anzeigen

@@ -4,4 +4,15 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuoheng.miniprogram.dao.WorkOrderFileMapper">


<!-- 批量新增数据 -->
<insert id="insertBatch" parameterType="com.tuoheng.miniprogram.entity.WorkOrderFile">
insert into th_work_order_file (tenant_id, work_order_id, inspection_file_id)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
( #{item.tenantId, jdbcType=INTEGER},
#{item.workOrderId, jdbcType=VARCHAR},
#{item.inspectionFileId, jdbcType=VARCHAR} )
</foreach>
</insert>
</mapper>

Laden…
Abbrechen
Speichern