|
|
|
@@ -0,0 +1,406 @@
|
|
|
|
|
package me.iiv.agent.mcp.tool;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|
|
|
|
import me.iiv.agent.entity.m0.User;
|
|
|
|
|
import me.iiv.agent.entity.m2.InstallOrderUser;
|
|
|
|
|
import me.iiv.agent.entity.m2.OrderProcess;
|
|
|
|
|
import me.iiv.agent.entity.m2.RelocationOrder;
|
|
|
|
|
import me.iiv.agent.entity.m2.RelocationOrderDetail;
|
|
|
|
|
import me.iiv.agent.entity.m2.WarehouseInOutPic;
|
|
|
|
|
import me.iiv.agent.mapper.m2.InstallOrderUserMapper;
|
|
|
|
|
import me.iiv.agent.mapper.m2.OrderProcessMapper;
|
|
|
|
|
import me.iiv.agent.mapper.m2.RelocationOrderDetailMapper;
|
|
|
|
|
import me.iiv.agent.mapper.m2.RelocationOrderMapper;
|
|
|
|
|
import me.iiv.agent.mapper.m2.WarehouseInOutPicMapper;
|
|
|
|
|
import me.iiv.agent.mcp.McpErrorCode;
|
|
|
|
|
import me.iiv.agent.mcp.ToolCallException;
|
|
|
|
|
import me.iiv.agent.mcp.ToolObject;
|
|
|
|
|
import me.iiv.agent.mcp.XqTool;
|
|
|
|
|
import me.iiv.agent.permission.PermissionService;
|
|
|
|
|
import me.iiv.agent.security.AuthContextHolder;
|
|
|
|
|
import org.springframework.ai.tool.annotation.Tool;
|
|
|
|
|
import org.springframework.ai.tool.annotation.ToolParam;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.time.format.DateTimeParseException;
|
|
|
|
|
import java.time.format.ResolverStyle;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/** 移机工单查询工具,对齐老系统 /relocationOrder/pageList 与 /lookDetails。 */
|
|
|
|
|
@Component
|
|
|
|
|
public class RelocationOrderTools implements ToolObject {
|
|
|
|
|
|
|
|
|
|
private static final int DEFAULT_ROWS = 20;
|
|
|
|
|
private static final int MAX_ROWS = 100;
|
|
|
|
|
private static final int RELOCATION_ORDER_TYPE = 4;
|
|
|
|
|
private static final int RELOCATION_USER_TYPE = 2;
|
|
|
|
|
private static final int COMPLETION_AGGREGATE_TYPE = 15;
|
|
|
|
|
private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
private static final DateTimeFormatter DATE_FORMATTER =
|
|
|
|
|
DateTimeFormatter.ISO_LOCAL_DATE.withResolverStyle(ResolverStyle.STRICT);
|
|
|
|
|
private static final DateTimeFormatter TIME_FORMATTER =
|
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(BUSINESS_ZONE);
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, String> ORDER_STATE_TEXT = Map.of(
|
|
|
|
|
0, "待提交", 1, "待审核", 2, "被驳回", 3, "调度中",
|
|
|
|
|
4, "作业中", 5, "已完成", 6, "已取消");
|
|
|
|
|
private static final Map<Integer, String> DEVICE_TYPE_TEXT = Map.of(
|
|
|
|
|
0, "出纸机", 1, "空感", 2, "泡沫机");
|
|
|
|
|
private static final Map<Integer, String> POSITION_TYPE_TEXT = Map.of(0, "厕所", 1, "厕位");
|
|
|
|
|
private static final Map<Integer, String> GENDER_TEXT = Map.of(
|
|
|
|
|
0, "男厕", 1, "女厕", 2, "母婴室", 3, "残障卫生间",
|
|
|
|
|
4, "第三卫生间", 5, "其他");
|
|
|
|
|
private static final Map<Integer, String> DETAIL_STATE_TEXT = Map.of(
|
|
|
|
|
0, "未执行", 1, "已执行", 2, "执行失败");
|
|
|
|
|
private static final Map<Integer, String> SCHEDULE_STATE_TEXT = Map.of(
|
|
|
|
|
0, "无需待办", 1, "待办", 2, "已办");
|
|
|
|
|
private static final Map<Integer, String> AUDIT_STATE_TEXT = Map.of(0, "审核驳回", 1, "审核通过");
|
|
|
|
|
private static final Map<Integer, String> OPERATION_THEME_TEXT = Map.of(
|
|
|
|
|
0, "移机申请", 1, "部门内审核", 2, "运营调度",
|
|
|
|
|
3, "移机协同", 6, "结单", 7, "取消");
|
|
|
|
|
|
|
|
|
|
final RelocationOrderMapper orderMapper;
|
|
|
|
|
final RelocationOrderDetailMapper detailMapper;
|
|
|
|
|
final OrderProcessMapper processMapper;
|
|
|
|
|
final InstallOrderUserMapper userMapper;
|
|
|
|
|
final WarehouseInOutPicMapper picMapper;
|
|
|
|
|
final PermissionService permissionService;
|
|
|
|
|
|
|
|
|
|
public RelocationOrderTools(RelocationOrderMapper orderMapper,
|
|
|
|
|
RelocationOrderDetailMapper detailMapper,
|
|
|
|
|
OrderProcessMapper processMapper,
|
|
|
|
|
InstallOrderUserMapper userMapper,
|
|
|
|
|
WarehouseInOutPicMapper picMapper,
|
|
|
|
|
PermissionService permissionService) {
|
|
|
|
|
this.orderMapper = orderMapper;
|
|
|
|
|
this.detailMapper = detailMapper;
|
|
|
|
|
this.processMapper = processMapper;
|
|
|
|
|
this.userMapper = userMapper;
|
|
|
|
|
this.picMapper = picMapper;
|
|
|
|
|
this.permissionService = permissionService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@XqTool(category = "workorder", kind = "read")
|
|
|
|
|
@Tool(name = "relocation.order.list.query", description = "分页查询当前用户可见的移机工单,对齐老系统 /relocationOrder/pageList。"
|
|
|
|
|
+ "支持工单号、代理、项目、申请/移机/协同人员、状态及申请/审核/调度/完成日期范围。"
|
|
|
|
|
+ "日期格式 yyyy-MM-dd,结束日期含当天;page 默认1,rows 默认20、上限100;固定按 id 倒序。")
|
|
|
|
|
public Map<String, Object> relocationOrderListQuery(
|
|
|
|
|
@ToolParam(required = false, description = "移机工单号,模糊匹配") String relocationOrderNo,
|
|
|
|
|
@ToolParam(required = false, description = "所属代理商 id,精确匹配") Long agentId,
|
|
|
|
|
@ToolParam(required = false, description = "项目名称,模糊匹配") String districtName,
|
|
|
|
|
@ToolParam(required = false, description = "申请人,模糊匹配") String applyUserName,
|
|
|
|
|
@ToolParam(required = false, description = "移机人员,模糊匹配") String maintenanceUserName,
|
|
|
|
|
@ToolParam(required = false, description = "协同人员,模糊匹配") String cooperateUserName,
|
|
|
|
|
@ToolParam(required = false, description = "状态:0待提交 1待审核 2被驳回 3调度中 4作业中 5已完成 6已取消") Integer orderState,
|
|
|
|
|
@ToolParam(required = false, description = "申请日期起,yyyy-MM-dd") String applyDateFrom,
|
|
|
|
|
@ToolParam(required = false, description = "申请日期止,yyyy-MM-dd,含当天") String applyDateTo,
|
|
|
|
|
@ToolParam(required = false, description = "审核日期起,yyyy-MM-dd") String auditDateFrom,
|
|
|
|
|
@ToolParam(required = false, description = "审核日期止,yyyy-MM-dd,含当天") String auditDateTo,
|
|
|
|
|
@ToolParam(required = false, description = "调度日期起,yyyy-MM-dd") String dispatchDateFrom,
|
|
|
|
|
@ToolParam(required = false, description = "调度日期止,yyyy-MM-dd,含当天") String dispatchDateTo,
|
|
|
|
|
@ToolParam(required = false, description = "完成日期起,yyyy-MM-dd") String finishDateFrom,
|
|
|
|
|
@ToolParam(required = false, description = "完成日期止,yyyy-MM-dd,含当天") String finishDateTo,
|
|
|
|
|
@ToolParam(required = false, description = "页码,从1开始,默认1") Integer page,
|
|
|
|
|
@ToolParam(required = false, description = "每页条数,默认20,上限100") Integer rows) {
|
|
|
|
|
validateCode(orderState, Set.of(0, 1, 2, 3, 4, 5, 6), "orderState");
|
|
|
|
|
LocalDate applyFrom = parseDate(applyDateFrom, "applyDateFrom");
|
|
|
|
|
LocalDate applyTo = parseDate(applyDateTo, "applyDateTo");
|
|
|
|
|
LocalDate auditFrom = parseDate(auditDateFrom, "auditDateFrom");
|
|
|
|
|
LocalDate auditTo = parseDate(auditDateTo, "auditDateTo");
|
|
|
|
|
LocalDate dispatchFrom = parseDate(dispatchDateFrom, "dispatchDateFrom");
|
|
|
|
|
LocalDate dispatchTo = parseDate(dispatchDateTo, "dispatchDateTo");
|
|
|
|
|
LocalDate finishFrom = parseDate(finishDateFrom, "finishDateFrom");
|
|
|
|
|
LocalDate finishTo = parseDate(finishDateTo, "finishDateTo");
|
|
|
|
|
validateRange(applyFrom, applyTo, "applyDateFrom", "applyDateTo");
|
|
|
|
|
validateRange(auditFrom, auditTo, "auditDateFrom", "auditDateTo");
|
|
|
|
|
validateRange(dispatchFrom, dispatchTo, "dispatchDateFrom", "dispatchDateTo");
|
|
|
|
|
validateRange(finishFrom, finishTo, "finishDateFrom", "finishDateTo");
|
|
|
|
|
|
|
|
|
|
int pageNo = page == null || page < 1 ? 1 : page;
|
|
|
|
|
boolean truncated = rows != null && rows > MAX_ROWS;
|
|
|
|
|
int pageSize = rows == null || rows < 1 ? DEFAULT_ROWS : Math.min(rows, MAX_ROWS);
|
|
|
|
|
LambdaQueryWrapper<RelocationOrder> wrapper = new LambdaQueryWrapper<RelocationOrder>()
|
|
|
|
|
.eq(RelocationOrder::getSoftDelete, 0)
|
|
|
|
|
.eq(agentId != null, RelocationOrder::getAgentId, agentId)
|
|
|
|
|
.eq(orderState != null, RelocationOrder::getOrderState, orderState)
|
|
|
|
|
.ge(applyFrom != null, RelocationOrder::getApplyTime, startOfDay(applyFrom))
|
|
|
|
|
.lt(applyTo != null, RelocationOrder::getApplyTime, nextDayStart(applyTo))
|
|
|
|
|
.ge(auditFrom != null, RelocationOrder::getAuditTime, startOfDay(auditFrom))
|
|
|
|
|
.lt(auditTo != null, RelocationOrder::getAuditTime, nextDayStart(auditTo))
|
|
|
|
|
.ge(dispatchFrom != null, RelocationOrder::getDispatchTime, startOfDay(dispatchFrom))
|
|
|
|
|
.lt(dispatchTo != null, RelocationOrder::getDispatchTime, nextDayStart(dispatchTo))
|
|
|
|
|
.ge(finishFrom != null, RelocationOrder::getFinishTime, startOfDay(finishFrom))
|
|
|
|
|
.lt(finishTo != null, RelocationOrder::getFinishTime, nextDayStart(finishTo));
|
|
|
|
|
like(wrapper, RelocationOrder::getOrderNo, relocationOrderNo);
|
|
|
|
|
like(wrapper, RelocationOrder::getDistrictName, districtName);
|
|
|
|
|
like(wrapper, RelocationOrder::getApplyUserName, applyUserName);
|
|
|
|
|
like(wrapper, RelocationOrder::getMaintenanceUserName, maintenanceUserName);
|
|
|
|
|
like(wrapper, RelocationOrder::getCooperateUserName, cooperateUserName);
|
|
|
|
|
permissionService.applyRelocationOrderRowFilter(wrapper, currentUser());
|
|
|
|
|
|
|
|
|
|
long total = orderMapper.selectCount(wrapper);
|
|
|
|
|
List<RelocationOrder> orders = orderMapper.selectList(wrapper.orderByDesc(RelocationOrder::getId)
|
|
|
|
|
.last("LIMIT " + (long) (pageNo - 1) * pageSize + "," + pageSize));
|
|
|
|
|
Map<String, Object> result = new LinkedHashMap<>();
|
|
|
|
|
result.put("total", total);
|
|
|
|
|
result.put("page", pageNo);
|
|
|
|
|
result.put("rows", pageSize);
|
|
|
|
|
if (truncated) {
|
|
|
|
|
result.put("notice", "rows 超过上限 100,已截断为 100");
|
|
|
|
|
}
|
|
|
|
|
result.put("records", orders.stream().map(this::orderRecord).collect(Collectors.toList()));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@XqTool(category = "workorder", kind = "read")
|
|
|
|
|
@Tool(name = "relocation.order.detail.query", description = "按 id 或移机工单号查询详情。"
|
|
|
|
|
+ "两者至少传一个,同时传入时必须匹配同一条记录;行级权限与列表一致。"
|
|
|
|
|
+ "不存在或无权查看统一返回 NOT_FOUND_OR_FORBIDDEN。返回主单、设备明细、人员、已办流程与结单凭证;附件仅返回 bucket/objectKey/fileName。")
|
|
|
|
|
public Map<String, Object> relocationOrderDetailQuery(
|
|
|
|
|
@ToolParam(required = false, description = "移机工单主键 id,与 relocationOrderNo 至少传一个") Long id,
|
|
|
|
|
@ToolParam(required = false, description = "移机工单号,与 id 至少传一个") String relocationOrderNo) {
|
|
|
|
|
if ((id == null || id <= 0) && !StringUtils.hasText(relocationOrderNo)) {
|
|
|
|
|
throw new IllegalArgumentException("id、relocationOrderNo 至少传一个");
|
|
|
|
|
}
|
|
|
|
|
if (id != null && id <= 0) {
|
|
|
|
|
throw new IllegalArgumentException("id 必须为正整数");
|
|
|
|
|
}
|
|
|
|
|
LambdaQueryWrapper<RelocationOrder> wrapper = new LambdaQueryWrapper<RelocationOrder>()
|
|
|
|
|
.eq(RelocationOrder::getSoftDelete, 0)
|
|
|
|
|
.eq(id != null, RelocationOrder::getId, id)
|
|
|
|
|
.eq(StringUtils.hasText(relocationOrderNo), RelocationOrder::getOrderNo,
|
|
|
|
|
StringUtils.hasText(relocationOrderNo) ? relocationOrderNo.trim() : relocationOrderNo);
|
|
|
|
|
permissionService.applyRelocationOrderRowFilter(wrapper, currentUser());
|
|
|
|
|
List<RelocationOrder> visible = orderMapper.selectList(
|
|
|
|
|
wrapper.orderByDesc(RelocationOrder::getId).last("LIMIT 1"));
|
|
|
|
|
if (visible.isEmpty()) {
|
|
|
|
|
throw new ToolCallException(McpErrorCode.NOT_FOUND_OR_FORBIDDEN,
|
|
|
|
|
"移机工单不存在或当前身份无权查看");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RelocationOrder order = visible.get(0);
|
|
|
|
|
String orderNo = order.getOrderNo();
|
|
|
|
|
List<RelocationOrderDetail> details = detailMapper.selectList(
|
|
|
|
|
new LambdaQueryWrapper<RelocationOrderDetail>()
|
|
|
|
|
.eq(RelocationOrderDetail::getSoftDelete, 0)
|
|
|
|
|
.eq(RelocationOrderDetail::getOrderNo, orderNo)
|
|
|
|
|
.orderByAsc(RelocationOrderDetail::getId));
|
|
|
|
|
List<InstallOrderUser> users = userMapper.selectList(new LambdaQueryWrapper<InstallOrderUser>()
|
|
|
|
|
.eq(InstallOrderUser::getSoftDelete, 0)
|
|
|
|
|
.eq(InstallOrderUser::getInstallOrderNo, orderNo)
|
|
|
|
|
.eq(InstallOrderUser::getType, RELOCATION_USER_TYPE)
|
|
|
|
|
.orderByAsc(InstallOrderUser::getId));
|
|
|
|
|
List<OrderProcess> processes = processMapper.selectList(new LambdaQueryWrapper<OrderProcess>()
|
|
|
|
|
.eq(OrderProcess::getSoftDelete, 0)
|
|
|
|
|
.eq(OrderProcess::getOrderNo, orderNo)
|
|
|
|
|
.eq(OrderProcess::getOrderType, RELOCATION_ORDER_TYPE)
|
|
|
|
|
.eq(OrderProcess::getScheduleState, 2)
|
|
|
|
|
.ne(OrderProcess::getOperationTheme, 12)
|
|
|
|
|
.orderByAsc(OrderProcess::getOperationTime)
|
|
|
|
|
.orderByAsc(OrderProcess::getId));
|
|
|
|
|
Map<Long, List<InstallOrderUser>> processUsers = processUsers(processes);
|
|
|
|
|
List<WarehouseInOutPic> certificates = completionCertificates(processes);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new LinkedHashMap<>();
|
|
|
|
|
result.put("record", orderRecord(order));
|
|
|
|
|
result.put("relocationDetails", details.stream().map(this::detailRecord).collect(Collectors.toList()));
|
|
|
|
|
result.put("maintenanceUsers", personnel(users, 0));
|
|
|
|
|
result.put("cooperateUsers", personnel(users, 1));
|
|
|
|
|
result.put("processes", processes.stream().map(process -> processRecord(process,
|
|
|
|
|
processUsers.getOrDefault(process.getId(), List.of()))).collect(Collectors.toList()));
|
|
|
|
|
result.put("completionCertificates", certificates.stream().map(this::fileRecord)
|
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, List<InstallOrderUser>> processUsers(List<OrderProcess> processes) {
|
|
|
|
|
if (processes.isEmpty()) return Map.of();
|
|
|
|
|
List<Long> ids = processes.stream().map(OrderProcess::getId).collect(Collectors.toList());
|
|
|
|
|
return userMapper.selectList(new LambdaQueryWrapper<InstallOrderUser>()
|
|
|
|
|
.eq(InstallOrderUser::getSoftDelete, 0)
|
|
|
|
|
.eq(InstallOrderUser::getType, RELOCATION_USER_TYPE)
|
|
|
|
|
.in(InstallOrderUser::getInstallOrderProcessId, ids)
|
|
|
|
|
.orderByAsc(InstallOrderUser::getId)).stream()
|
|
|
|
|
.collect(Collectors.groupingBy(InstallOrderUser::getInstallOrderProcessId,
|
|
|
|
|
LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<WarehouseInOutPic> completionCertificates(List<OrderProcess> processes) {
|
|
|
|
|
List<Long> completionIds = processes.stream()
|
|
|
|
|
.filter(process -> Integer.valueOf(6).equals(process.getOperationTheme()))
|
|
|
|
|
.map(OrderProcess::getId).collect(Collectors.toList());
|
|
|
|
|
if (completionIds.isEmpty()) return List.of();
|
|
|
|
|
return picMapper.selectList(new LambdaQueryWrapper<WarehouseInOutPic>()
|
|
|
|
|
.eq(WarehouseInOutPic::getSoftDelete, 0)
|
|
|
|
|
.in(WarehouseInOutPic::getAggregateId, completionIds)
|
|
|
|
|
.eq(WarehouseInOutPic::getInOutAllocationType, COMPLETION_AGGREGATE_TYPE)
|
|
|
|
|
.orderByAsc(WarehouseInOutPic::getId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> orderRecord(RelocationOrder order) {
|
|
|
|
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
|
|
|
record.put("id", order.getId());
|
|
|
|
|
record.put("relocationOrderNo", order.getOrderNo());
|
|
|
|
|
record.put("orderState", order.getOrderState());
|
|
|
|
|
record.put("orderStateText", text(ORDER_STATE_TEXT, order.getOrderState()));
|
|
|
|
|
record.put("applyAgentId", order.getApplyAgentId());
|
|
|
|
|
record.put("applyAgentName", order.getApplyAgentName());
|
|
|
|
|
record.put("agentId", order.getAgentId());
|
|
|
|
|
record.put("agentName", order.getAgentName());
|
|
|
|
|
record.put("propertyId", order.getPropertyId());
|
|
|
|
|
record.put("propertyName", order.getPropertyName());
|
|
|
|
|
record.put("districtId", order.getDistrictId());
|
|
|
|
|
record.put("districtName", order.getDistrictName());
|
|
|
|
|
record.put("hopeRelocationDate", order.getHopeRelocationDate());
|
|
|
|
|
record.put("trueRelocationDate", order.getTrueRelocationDate());
|
|
|
|
|
record.put("relocationReason", order.getRelocationReason());
|
|
|
|
|
record.put("customerContact", order.getCustomerContact());
|
|
|
|
|
record.put("contactMobile", order.getContactMobile());
|
|
|
|
|
record.put("projectAddress", order.getProjectAddress());
|
|
|
|
|
record.put("projectMemo", order.getProjectMemo());
|
|
|
|
|
record.put("applyUserId", order.getApplyUserId());
|
|
|
|
|
record.put("applyUserName", order.getApplyUserName());
|
|
|
|
|
record.put("auditUserName", order.getAuditUserName());
|
|
|
|
|
record.put("dispatchUserName", order.getDispatchUserName());
|
|
|
|
|
record.put("maintenanceUserName", order.getMaintenanceUserName());
|
|
|
|
|
record.put("cooperateUserName", order.getCooperateUserName());
|
|
|
|
|
record.put("scheduleUserName", order.getScheduleUserName());
|
|
|
|
|
record.put("hopeRelocationCount", order.getHopeRelocationCount());
|
|
|
|
|
record.put("trueRelocationCount", order.getTrueRelocationCount());
|
|
|
|
|
record.put("applyTime", formatTime(order.getApplyTime()));
|
|
|
|
|
record.put("auditTime", formatTime(order.getAuditTime()));
|
|
|
|
|
record.put("dispatchTime", formatTime(order.getDispatchTime()));
|
|
|
|
|
record.put("finishTime", formatTime(order.getFinishTime()));
|
|
|
|
|
record.put("cancelTime", formatTime(order.getCancelTime()));
|
|
|
|
|
record.put("createTime", formatTime(order.getCreateTime()));
|
|
|
|
|
record.put("modifyTime", formatTime(order.getModifyTime()));
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> detailRecord(RelocationOrderDetail detail) {
|
|
|
|
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
|
|
|
record.put("id", detail.getId());
|
|
|
|
|
record.put("deviceType", detail.getDeviceType());
|
|
|
|
|
record.put("deviceTypeText", text(DEVICE_TYPE_TEXT, detail.getDeviceType()));
|
|
|
|
|
record.put("snCode", detail.getSnCode());
|
|
|
|
|
record.put("sourcePositionType", detail.getSourcePositionType());
|
|
|
|
|
record.put("sourcePositionTypeText", text(POSITION_TYPE_TEXT, detail.getSourcePositionType()));
|
|
|
|
|
record.put("sourcePositionId", detail.getSourcePositionId());
|
|
|
|
|
record.put("sourcePosition", detail.getSourcePosition());
|
|
|
|
|
record.put("sourceGender", detail.getSourceGender());
|
|
|
|
|
record.put("sourceGenderText", text(GENDER_TEXT, detail.getSourceGender()));
|
|
|
|
|
record.put("targetSourceSnCode", detail.getTargetSourceSnCode());
|
|
|
|
|
record.put("targetPositionType", detail.getTargetPositionType());
|
|
|
|
|
record.put("targetPositionTypeText", text(POSITION_TYPE_TEXT, detail.getTargetPositionType()));
|
|
|
|
|
record.put("targetPositionId", detail.getTargetPositionId());
|
|
|
|
|
record.put("targetPosition", detail.getTargetPosition());
|
|
|
|
|
record.put("targetGender", detail.getTargetGender());
|
|
|
|
|
record.put("targetGenderText", text(GENDER_TEXT, detail.getTargetGender()));
|
|
|
|
|
record.put("state", detail.getState());
|
|
|
|
|
record.put("stateText", text(DETAIL_STATE_TEXT, detail.getState()));
|
|
|
|
|
record.put("memo", detail.getMemo());
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> processRecord(OrderProcess process, List<InstallOrderUser> users) {
|
|
|
|
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
|
|
|
record.put("id", process.getId());
|
|
|
|
|
record.put("userId", process.getUserId());
|
|
|
|
|
record.put("userName", process.getUserName());
|
|
|
|
|
record.put("operationTime", formatTime(process.getOperationTime()));
|
|
|
|
|
record.put("scheduleState", process.getScheduleState());
|
|
|
|
|
record.put("scheduleStateText", text(SCHEDULE_STATE_TEXT, process.getScheduleState()));
|
|
|
|
|
record.put("auditState", process.getAuditState());
|
|
|
|
|
record.put("auditStateText", text(AUDIT_STATE_TEXT, process.getAuditState()));
|
|
|
|
|
record.put("auditLevel", process.getAuditLevel());
|
|
|
|
|
record.put("operationTheme", process.getOperationTheme());
|
|
|
|
|
record.put("operationThemeText", text(OPERATION_THEME_TEXT, process.getOperationTheme()));
|
|
|
|
|
record.put("operationType", process.getOperationType());
|
|
|
|
|
record.put("memo", process.getMemo());
|
|
|
|
|
record.put("maintenanceUsers", personnel(users, 0));
|
|
|
|
|
record.put("cooperateUsers", personnel(users, 1));
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> personnel(List<InstallOrderUser> users, int userType) {
|
|
|
|
|
return users.stream().filter(user -> Integer.valueOf(userType).equals(user.getUserType()))
|
|
|
|
|
.map(user -> {
|
|
|
|
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
|
|
|
record.put("id", user.getId());
|
|
|
|
|
record.put("userId", user.getUserId());
|
|
|
|
|
record.put("userName", user.getUserName());
|
|
|
|
|
record.put("userType", user.getUserType());
|
|
|
|
|
return record;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> fileRecord(WarehouseInOutPic pic) {
|
|
|
|
|
Map<String, Object> record = new LinkedHashMap<>();
|
|
|
|
|
record.put("id", pic.getId());
|
|
|
|
|
record.put("processId", pic.getAggregateId());
|
|
|
|
|
record.put("fileName", pic.getFileName());
|
|
|
|
|
record.put("bucket", pic.getOssbucketname());
|
|
|
|
|
record.put("objectKey", nullToEmpty(pic.getOssfolder()) + nullToEmpty(pic.getFileName()));
|
|
|
|
|
return record;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static User currentUser() {
|
|
|
|
|
return AuthContextHolder.get().getUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void like(LambdaQueryWrapper<RelocationOrder> wrapper,
|
|
|
|
|
SFunction<RelocationOrder, ?> column, String value) {
|
|
|
|
|
if (StringUtils.hasText(value)) wrapper.like(column, value.trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void validateCode(Integer value, Set<Integer> accepted, String name) {
|
|
|
|
|
if (value != null && !accepted.contains(value)) {
|
|
|
|
|
throw new IllegalArgumentException(name + " 取值不合法");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static LocalDate parseDate(String value, String name) {
|
|
|
|
|
if (!StringUtils.hasText(value)) return null;
|
|
|
|
|
try {
|
|
|
|
|
return LocalDate.parse(value.trim(), DATE_FORMATTER);
|
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
|
throw new IllegalArgumentException(name + " 格式必须为 yyyy-MM-dd");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void validateRange(LocalDate from, LocalDate to, String fromName, String toName) {
|
|
|
|
|
if (from != null && to != null && from.isAfter(to)) {
|
|
|
|
|
throw new IllegalArgumentException(fromName + " 不能晚于 " + toName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Date startOfDay(LocalDate date) {
|
|
|
|
|
return date == null ? null : Date.from(date.atStartOfDay(BUSINESS_ZONE).toInstant());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Date nextDayStart(LocalDate date) {
|
|
|
|
|
return date == null ? null : Date.from(date.plusDays(1).atStartOfDay(BUSINESS_ZONE).toInstant());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String text(Map<Integer, String> values, Integer code) {
|
|
|
|
|
return code == null ? null : values.getOrDefault(code, "未知");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String formatTime(Date value) {
|
|
|
|
|
return value == null ? null : TIME_FORMATTER.format(value.toInstant());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String nullToEmpty(String value) {
|
|
|
|
|
return value == null ? "" : value;
|
|
|
|
|
}
|
|
|
|
|
}
|