@@ -1,5 +1,6 @@ | |||
package com.tuoheng.admin.controller; | |||
import com.tuoheng.admin.request.workorder.DistributionWorkorderRequest; | |||
import com.tuoheng.admin.request.workorder.QueryWorkOrderPageListRequest; | |||
import com.tuoheng.admin.service.workorder.IWorkorderService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -27,8 +28,8 @@ public class WorkOrderController { | |||
* @param idList | |||
* @return | |||
*/ | |||
@PostMapping("/generate/workorder/{idList}") | |||
public JsonResult generateWorkorder(@PathVariable("idList") List<String> idList) { | |||
@PostMapping("/generate/{idList}") | |||
public JsonResult generate(@PathVariable("idList") List<String> idList) { | |||
return iWorkorderService.generate(idList); | |||
} | |||
@@ -46,10 +47,18 @@ public class WorkOrderController { | |||
/** | |||
* 获取工单详情信息 | |||
*/ | |||
@GetMapping(value = "/details/{id}") | |||
@GetMapping("/details/{id}") | |||
public JsonResult getDetails(@PathVariable("id") String id) { | |||
log.info("进入查询任务详情接口, id={}", id); | |||
log.info("进入工单详情接口, id={}", id); | |||
return iWorkorderService.getDetails(id); | |||
} | |||
/** | |||
* 分配工单 | |||
*/ | |||
@PostMapping("/distribution") | |||
public JsonResult distribution(@RequestBody DistributionWorkorderRequest request) { | |||
log.info("进入分配工单接口, request={}", request); | |||
return iWorkorderService.distribution(request); | |||
} | |||
} |
@@ -0,0 +1,55 @@ | |||
package com.tuoheng.admin.enums.code.workorder; | |||
/** | |||
* 分配工单返回码 | |||
* 模块代码:26(工单管理) | |||
* 接口代码:04 (分配工单) | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-08 | |||
*/ | |||
public enum DistributionWorkorderCodeEnum { | |||
DISTRIBUTION_IS_FAILED(1260400, "分配工单失败"), | |||
ID_LIST_IS_NULL(1260401, "工单id列表为空"), | |||
WORK_ORDER_IS_NOT_EXIST(1260402, "工单不存在"), | |||
ASSIGN_DEPT_ID_IS_NULL(1260403, "指派部门ID为空"), | |||
ASSIGN_USER_ID_IS_NULL(1260404, "指派负责人"), | |||
ASSIGN_USER_ID_IS_NOT_EXIST(1260405, "指派负责人不存在"), | |||
SUPER_ADMIN_NOT_DISTRIBUTION(1260406, "超级管理员不能分配工单"), | |||
ADMIN_NOT_DISTRIBUTION_CHILD_DEPT_WORK_ORDER(1260407, "管理员不能分配子部门工单"), | |||
ORDINARY_USER_NOT_DISTRIBUTION(1260408, "普通用户不能分配工单"); | |||
/** | |||
* 错误码 | |||
*/ | |||
private int code; | |||
/** | |||
* 错误信息 | |||
*/ | |||
private String msg; | |||
DistributionWorkorderCodeEnum(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; | |||
} | |||
} |
@@ -3,21 +3,24 @@ package com.tuoheng.admin.mapper; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.entity.InspectionFileExtend; | |||
import com.tuoheng.admin.entity.WorkOrder; | |||
import com.tuoheng.admin.request.inspectionfile.QueryInspectionFilePageListRequest; | |||
import com.tuoheng.admin.request.workorder.QueryWorkOrderPageListRequest; | |||
import org.apache.ibatis.annotations.Param; | |||
/** | |||
* 巡检工单Mapper接口 | |||
* | |||
* @team tuoheng | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-07 | |||
*/ | |||
public interface WorkOrderMapper extends BaseMapper<WorkOrder> { | |||
/** | |||
* 分配工单 | |||
*/ | |||
Integer update(WorkOrder workOrder); | |||
/** | |||
* 查询工单分页列表 | |||
* |
@@ -0,0 +1,30 @@ | |||
package com.tuoheng.admin.request.workorder; | |||
import lombok.Data; | |||
/** | |||
* 分配工单请求实体 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-08 | |||
*/ | |||
@Data | |||
public class DistributionWorkorderRequest { | |||
/** | |||
* 工单Id | |||
*/ | |||
private String workorderId; | |||
/** | |||
* 指派部门ID | |||
*/ | |||
private String assignDeptId; | |||
/** | |||
* 指派负责人 | |||
*/ | |||
private String assignUserIds; | |||
} |
@@ -1,5 +1,6 @@ | |||
package com.tuoheng.admin.service.workorder; | |||
import com.tuoheng.admin.request.workorder.DistributionWorkorderRequest; | |||
import com.tuoheng.admin.request.workorder.QueryWorkOrderPageListRequest; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -39,4 +40,11 @@ public interface IWorkorderService { | |||
*/ | |||
JsonResult getDetails(String id); | |||
/** | |||
* 分配工单 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult distribution(DistributionWorkorderRequest request); | |||
} |
@@ -1,6 +1,8 @@ | |||
package com.tuoheng.admin.service.workorder; | |||
import com.tuoheng.admin.request.workorder.DistributionWorkorderRequest; | |||
import com.tuoheng.admin.request.workorder.QueryWorkOrderPageListRequest; | |||
import com.tuoheng.admin.service.workorder.distribution.DistributionWorkorderService; | |||
import com.tuoheng.admin.service.workorder.generate.GenerateWorkorderService; | |||
import com.tuoheng.admin.service.workorder.query.QueryWorkOrderDetailsService; | |||
import com.tuoheng.admin.service.workorder.query.QueryWorkOrderPageListService; | |||
@@ -31,6 +33,9 @@ public class WorkorderServiceImpl implements IWorkorderService { | |||
@Autowired | |||
private QueryWorkOrderDetailsService queryWorkOrderDetailsService; | |||
@Autowired | |||
private DistributionWorkorderService distributionWorkorderService; | |||
@Override | |||
public JsonResult generate(List<String> idList) { | |||
return generateWorkorderService.generate(idList); | |||
@@ -59,4 +64,14 @@ public class WorkorderServiceImpl implements IWorkorderService { | |||
return queryWorkOrderDetailsService.getDetails(id); | |||
} | |||
/** | |||
* 分配工单 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult distribution(DistributionWorkorderRequest request) { | |||
return distributionWorkorderService.distribution(request); | |||
} | |||
} |
@@ -0,0 +1,160 @@ | |||
package com.tuoheng.admin.service.workorder.distribution; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.entity.User; | |||
import com.tuoheng.admin.entity.WorkOrder; | |||
import com.tuoheng.admin.enums.UserTypeEnum; | |||
import com.tuoheng.admin.enums.WorkOrderStatusEnum; | |||
import com.tuoheng.admin.enums.code.workorder.DistributionWorkorderCodeEnum; | |||
import com.tuoheng.admin.enums.code.workorder.GenerateWorkorderCodeEnum; | |||
import com.tuoheng.admin.mapper.InspectionFileMapper; | |||
import com.tuoheng.admin.mapper.UserMapper; | |||
import com.tuoheng.admin.mapper.WorkOrderFileMapper; | |||
import com.tuoheng.admin.mapper.WorkOrderMapper; | |||
import com.tuoheng.admin.request.workorder.DistributionWorkorderRequest; | |||
import com.tuoheng.admin.utils.ShiroUtils; | |||
import com.tuoheng.common.core.utils.DateUtils; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
/** | |||
* 分配工单业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-12-08 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class DistributionWorkorderService { | |||
@Autowired | |||
private UserMapper userMapper; | |||
@Autowired | |||
private WorkOrderMapper workOrderMapper; | |||
/** | |||
* 生成工单 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
@Transactional | |||
public JsonResult distribution(DistributionWorkorderRequest request) { | |||
log.info("进入分配工单业务, request:{}", request); | |||
String userId = ShiroUtils.getUserId(); | |||
String tenantId = ShiroUtils.getTenantId(); | |||
JsonResult result = this.check(request); | |||
if (0 != result.getCode()) { | |||
log.info("进入分配工单业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
WorkOrder workOrder = (WorkOrder) result.getData(); | |||
// 检查权限 | |||
result = checkPermission(userId, tenantId, workOrder); | |||
if (0 != result.getCode()) { | |||
log.info("进入分配工单:校验权限失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
result = this.distributionWorkOrder(userId, request); | |||
if (0 != result.getCode()) { | |||
log.info("进入分配工单:分配工单失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 检查参数 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(DistributionWorkorderRequest request) { | |||
// 判断工单id是否为空 | |||
if (StringUtils.isEmpty(request.getWorkorderId())) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.ID_LIST_IS_NULL.getCode(), DistributionWorkorderCodeEnum.ID_LIST_IS_NULL.getMsg()); | |||
} | |||
// 判断指派部门ID是否为空 | |||
if (StringUtils.isEmpty(request.getAssignDeptId())) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.ASSIGN_DEPT_ID_IS_NULL.getCode(), DistributionWorkorderCodeEnum.ASSIGN_DEPT_ID_IS_NULL.getMsg()); | |||
} | |||
// 判断指派负责人是否为空 | |||
if (StringUtils.isEmpty(request.getAssignUserIds())) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.ASSIGN_USER_ID_IS_NULL.getCode(), DistributionWorkorderCodeEnum.ASSIGN_USER_ID_IS_NULL.getMsg()); | |||
} | |||
WorkOrder workOrder = workOrderMapper.selectOne(new LambdaQueryWrapper<WorkOrder>() | |||
.eq(WorkOrder::getId, request.getWorkorderId()) | |||
.eq(WorkOrder::getMark, 1)); | |||
if (null == workOrder) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.WORK_ORDER_IS_NOT_EXIST.getCode(), DistributionWorkorderCodeEnum.WORK_ORDER_IS_NOT_EXIST.getMsg()); | |||
} | |||
return JsonResult.success(workOrder); | |||
} | |||
/** | |||
* 判断是否有分配工单权限 | |||
* 1)、超级管理员不能分配工单 | |||
* 2)、部门管理员仅可分配本部门工单,无法分配子部门工单 | |||
* 3)、普通用户不能分配工单 | |||
* | |||
* @param userId | |||
* @param workOrder | |||
* @return | |||
*/ | |||
private JsonResult checkPermission(String userId, String tenantId, WorkOrder workOrder) { | |||
User user = userMapper.selectOne(new LambdaQueryWrapper<User>() | |||
.eq(User::getId, userId) | |||
.eq(User::getTenantId, tenantId) | |||
.eq(User::getMark, 1)); | |||
user.setType(UserTypeEnum.ADMIN.getCode()); | |||
if (UserTypeEnum.SUPER_ADMIN.getCode() == user.getType()) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.SUPER_ADMIN_NOT_DISTRIBUTION.getCode(), DistributionWorkorderCodeEnum.SUPER_ADMIN_NOT_DISTRIBUTION.getMsg()); | |||
} else if (UserTypeEnum.ADMIN.getCode() == user.getType()) { | |||
if (!user.getDeptId().equals(workOrder.getDeptId())) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.ADMIN_NOT_DISTRIBUTION_CHILD_DEPT_WORK_ORDER.getCode(), DistributionWorkorderCodeEnum.ADMIN_NOT_DISTRIBUTION_CHILD_DEPT_WORK_ORDER.getMsg()); | |||
} | |||
return JsonResult.success(user); | |||
} else if (UserTypeEnum.ORDINARY_USER.getCode() == user.getType()) { | |||
return JsonResult.error(DistributionWorkorderCodeEnum.ORDINARY_USER_NOT_DISTRIBUTION.getCode(), DistributionWorkorderCodeEnum.ORDINARY_USER_NOT_DISTRIBUTION.getMsg()); | |||
} | |||
return JsonResult.error(); | |||
} | |||
/** | |||
* | |||
* 分配工单 | |||
* 1)、修改分配字段信息 | |||
* 2)、修改工单状态 | |||
* 3)、修改更新字段 | |||
* | |||
* @param userId | |||
* @param request | |||
*/ | |||
private JsonResult distributionWorkOrder(String userId, DistributionWorkorderRequest request) { | |||
WorkOrder workOrder = new WorkOrder(); | |||
workOrder.setId(request.getWorkorderId()); | |||
workOrder.setUpdateUser(userId); | |||
workOrder.setUpdateTime(DateUtils.now()); | |||
workOrder.setStatus(WorkOrderStatusEnum.PROCESSING.getCode()); | |||
workOrder.setAssignDeptId(request.getAssignDeptId()); | |||
workOrder.setAssignUser(request.getAssignUserIds()); | |||
Integer rowCount = workOrderMapper.update(workOrder); | |||
if (rowCount <= 0) { | |||
log.info("修改工单状态, 确认失败"); | |||
return JsonResult.error(GenerateWorkorderCodeEnum.GENERATE_IS_FAILED.getCode(), GenerateWorkorderCodeEnum.GENERATE_IS_FAILED.getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -27,6 +27,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | |||
from th_work_order | |||
</sql> | |||
<update id="update" parameterType="com.tuoheng.admin.entity.WorkOrder"> | |||
update th_work_order | |||
<trim prefix="SET" suffixOverrides=","> | |||
<if test="assignDeptId != null and assignDeptId !='' "> assign_dept_id = #{assignDeptId}, </if> | |||
<if test="assignUser != null and assignUser !='' "> assign_user = #{assignUser}, </if> | |||
<if test="assignContact != null and assignContact !='' "> assign_contact = #{assignContact}, </if> | |||
<if test="assignNote != null and assignNote !='' "> assign_note = #{assignNote}, </if> | |||
<if test="assignTime != null"> assign_time = #{assignTime}, </if> | |||
<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> | |||
</trim> | |||
where id = #{id} | |||
</update> | |||
<select id="selectPageList" parameterType="com.tuoheng.admin.request.workorder.QueryWorkOrderPageListRequest" resultMap="WorkOrderResult"> | |||
<include refid="selectThWorkOrderVo"/> | |||
<where> |