自动创建保养单,自动创建维修单
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
package org.nl.wms.sb.auToTask;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.security.service.dto.JwtUserDto;
|
||||
import org.nl.modules.system.util.CodeUtil;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
import org.nl.wql.core.bean.WQLObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 自动创建维修单
|
||||
* @author Liuxy
|
||||
* @date 2022-06-27
|
||||
**/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AutoCreateRepair {
|
||||
public void run() {
|
||||
WQLObject fileTab = WQLObject.getWQLObject("EM_BI_EquipmentFile"); // 档案表
|
||||
WQLObject planMstTab = WQLObject.getWQLObject("EM_BI_DeviceRepairPlanMst"); // 设备维修计划主表
|
||||
WQLObject repairMstTab = WQLObject.getWQLObject("EM_BI_DeviceRepairMst"); // 设备维修单主表
|
||||
|
||||
// 1.查询 设备档案表 中状态为:正常10、闲置11、故障20、维修30、保养40状态的设备
|
||||
JSONArray fileArr = fileTab.query("status in (10,11,20,30,40)").getResultJSONArray(0);
|
||||
|
||||
// 2.根据查询出来的记录 查询 设备维修计划表 中启用状态 = 启用的记录
|
||||
for (int i = 0; i < fileArr.size(); i++) {
|
||||
JSONObject json = fileArr.getJSONObject(i);
|
||||
String devicerecord_id = json.getString("devicerecord_id");
|
||||
|
||||
JSONObject jsonPlanMst = planMstTab.query("devicerecord_id = '" + devicerecord_id + "' and is_active = '1'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonPlanMst)) {
|
||||
// 2.1 判断维修计划表中:实际开始时间、实际结束时间 为空
|
||||
String real_start_date = jsonPlanMst.getString("real_start_date");
|
||||
String real_end_date = jsonPlanMst.getString("real_end_date");
|
||||
|
||||
// 2.2 根据源单号为维修计划id查询 维修单 --条件未删除、未审核
|
||||
JSONObject jsonRepairMst = repairMstTab.query("source_bill_id = '" + jsonPlanMst.getString("repair_plan_id") + "' and is_delete = '0' and invstatus != '99'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(real_start_date) && ObjectUtil.isEmpty(real_end_date)) {
|
||||
if (ObjectUtil.isEmpty(jsonRepairMst)) {
|
||||
// 2.3 判断周期
|
||||
String maintenancecycle = jsonPlanMst.getString("maintenancecycle");
|
||||
String plan_start_date = jsonPlanMst.getString("plan_start_date").replace("-", "");
|
||||
String today = DateUtil.today().replace("-", "");
|
||||
// 准备参数
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("devicerecord_id",jsonPlanMst.getString("devicerecord_id"));
|
||||
param.put("maintenancecycle","01");
|
||||
param.put("plan_start_date",jsonPlanMst.getString("plan_start_date"));
|
||||
param.put("source_bill_id",jsonPlanMst.getString("repair_plan_id"));
|
||||
param.put("source_bill_code",jsonPlanMst.getString("repair_plan_code"));
|
||||
|
||||
// 计算 当前日期 - 维修计划日期 后的天数
|
||||
String num = String.valueOf(NumberUtil.sub(today, plan_start_date));
|
||||
|
||||
// 周期为年 :当前日期-维修计划开始时间 <= 15 天时,新增维修单
|
||||
if (StrUtil.equals(maintenancecycle,"01")) {
|
||||
if (Integer.parseInt(num) <= 15) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为季度 :当前日期-维修计划开始时间 <= 10 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"02")) {
|
||||
if (Integer.parseInt(num) <= 10) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为月 :当前日期-维修计划开始时间 <= 7 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"03")) {
|
||||
if (Integer.parseInt(num) <= 7) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为周 :当前日期-维修计划开始时间 <= 3 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"04")) {
|
||||
if (Integer.parseInt(num) <= 3) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 3 如果保养实际开始时间 和 保养实际结束时间不为空 并且查不到对应单据
|
||||
if (ObjectUtil.isEmpty(jsonRepairMst)) {
|
||||
// 取维修实际结束日期:用当前日期 - 维修实际结束日期
|
||||
String maintenancecycle = jsonPlanMst.getString("maintenancecycle");
|
||||
String rep_real_end_date = jsonPlanMst.getString("real_end_date").replace("-", "");
|
||||
String today = DateUtil.today().replace("-", "");
|
||||
|
||||
// 准备参数
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("devicerecord_id",jsonPlanMst.getString("devicerecord_id"));
|
||||
param.put("maintenancecycle","01");
|
||||
param.put("plan_start_date",jsonPlanMst.getString("plan_start_date"));
|
||||
param.put("source_bill_id",jsonPlanMst.getString("repair_plan_id"));
|
||||
param.put("source_bill_code",jsonPlanMst.getString("repair_plan_code"));
|
||||
// 计算 当前日期 - 维修实际结束 后的天数
|
||||
String num = String.valueOf(NumberUtil.sub(today, rep_real_end_date));
|
||||
|
||||
// 周期为年 :当前日期-维修实际结束 <= 15 天时,新增维修单
|
||||
if (StrUtil.equals(maintenancecycle,"01")) {
|
||||
if (Integer.parseInt(num) <= 15) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为季度 :当前日期-维修实际结束 <= 10 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"02")) {
|
||||
if (Integer.parseInt(num) <= 10) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为月 :当前日期-维修实际结束 <= 7 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"03")) {
|
||||
if (Integer.parseInt(num) <= 7) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
// 周期为周 :当前日期-维修实际结束 <= 3 天时,新增维修单
|
||||
} else if (StrUtil.equals(maintenancecycle,"04")) {
|
||||
if (Integer.parseInt(num) <= 3) {
|
||||
this.createRepair(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建维修单共用方法
|
||||
* json: {
|
||||
* 设备档案标识:devicerecord_id,
|
||||
* 单据类型:maintenancecycle,
|
||||
* 计划开始日期:plan_start_date,
|
||||
* 来源单据标识:source_bill_id,
|
||||
* 来源单据编码:source_bill_code,
|
||||
* }
|
||||
*/
|
||||
public void createRepair(JSONObject json) {
|
||||
Long currentUserId = 1L;
|
||||
String nickName = "管理员";
|
||||
Long deptId = 1L;
|
||||
|
||||
WQLObject repaiMstTab = WQLObject.getWQLObject("EM_BI_DeviceRepairMst"); // 设备维修单主表
|
||||
WQLObject repaiDtlTab = WQLObject.getWQLObject("EM_BI_DeviceRepairDtl"); // 设备维修单主明细表
|
||||
WQLObject planDtlTab = WQLObject.getWQLObject("EM_BI_DeviceRepairPlanDtl"); // 设备维修计划明细表
|
||||
|
||||
JSONArray planDtlArr = planDtlTab.query("repair_plan_id = '" + json.getString("source_bill_id") + "'").getResultJSONArray(0);
|
||||
|
||||
// 维修单主表
|
||||
JSONObject jsonRepaiMst = new JSONObject();
|
||||
jsonRepaiMst.put("repair_id", IdUtil.getSnowflake(1,1).nextId());
|
||||
jsonRepaiMst.put("repair_code", CodeUtil.getNewCode("REPAIR_CODE"));
|
||||
jsonRepaiMst.put("devicerecord_id",json.get("devicerecord_id"));
|
||||
jsonRepaiMst.put("maintenancecycle",json.getString("maintenancecycle"));
|
||||
jsonRepaiMst.put("invstatus","01");
|
||||
jsonRepaiMst.put("fault_level","01");
|
||||
jsonRepaiMst.put("plan_start_date",json.getString("plan_start_date"));
|
||||
jsonRepaiMst.put("detail_count",planDtlArr.size());
|
||||
jsonRepaiMst.put("source_bill_id",json.get("source_bill_id"));
|
||||
jsonRepaiMst.put("source_bill_type","WXJH");
|
||||
jsonRepaiMst.put("source_bill_code",json.getString("source_bill_code"));
|
||||
jsonRepaiMst.put("input_optid",currentUserId);
|
||||
jsonRepaiMst.put("input_optname",nickName);
|
||||
jsonRepaiMst.put("input_time", DateUtil.now());
|
||||
jsonRepaiMst.put("sysdeptid", deptId);
|
||||
jsonRepaiMst.put("syscompanyid", deptId);
|
||||
repaiMstTab.insert(jsonRepaiMst);
|
||||
|
||||
// 维修单明细表
|
||||
for (int i = 0; i < planDtlArr.size(); i++) {
|
||||
JSONObject jsonObject = planDtlArr.getJSONObject(i);
|
||||
JSONObject jsonMainDtl = new JSONObject();
|
||||
jsonMainDtl.put("repair_dtl_id", IdUtil.getSnowflake(1,1).nextId());
|
||||
jsonMainDtl.put("repair_id", jsonRepaiMst.get("repair_id"));
|
||||
jsonMainDtl.put("repair_item_id", jsonObject.get("repair_item_id"));
|
||||
repaiDtlTab.insert(jsonMainDtl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,172 @@
|
||||
package org.nl.wms.sb.auToTask;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.security.service.dto.JwtUserDto;
|
||||
import org.nl.modules.system.util.CodeUtil;
|
||||
import org.nl.utils.SecurityUtils;
|
||||
import org.nl.wql.core.bean.WQLObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 自动创建保养单
|
||||
* @author Liuxy
|
||||
* @date 2022-06-27
|
||||
**/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class AutoCreateUpkeep {
|
||||
public void run () {
|
||||
// 1.查询 设备档案表 中状态为:正常10、闲置11、故障20、维修30、保养40状态的设备
|
||||
// 2.根据查询出来的记录 查询 设备保养计划表 中启用状态 = 启用的记录
|
||||
// 3.
|
||||
public void run() {
|
||||
WQLObject fileTab = WQLObject.getWQLObject("EM_BI_EquipmentFile"); // 档案表
|
||||
WQLObject planMstTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenancePlanMst"); // 设备保养计划主表
|
||||
WQLObject mainMstTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenanceMst"); // 设备保养单主表
|
||||
|
||||
// 1.查询 设备档案表 中状态为:正常10、闲置11、故障20、维修30、保养40状态的设备
|
||||
JSONArray fileArr = fileTab.query("status in (10,11,20,30,40)").getResultJSONArray(0);
|
||||
|
||||
// 2.根据查询出来的记录 查询 设备保养计划表 中启用状态 = 启用的记录
|
||||
for (int i = 0; i < fileArr.size(); i++) {
|
||||
JSONObject json = fileArr.getJSONObject(i);
|
||||
String devicerecord_id = json.getString("devicerecord_id");
|
||||
|
||||
JSONObject jsonPlanMst = planMstTab.query("devicerecord_id = '" + devicerecord_id + "' and is_active = '1'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(jsonPlanMst)) {
|
||||
// 2.1 判断保养计划表中:实际开始时间、实际结束时间 为空
|
||||
String real_start_date = jsonPlanMst.getString("real_start_date");
|
||||
String real_end_date = jsonPlanMst.getString("real_end_date");
|
||||
|
||||
// 2.2 根据源单号为保养计划id查询 保养单 --条件未删除、未审核
|
||||
JSONObject jsonMainMst = mainMstTab.query("source_bill_id = '" + jsonPlanMst.getString("maint_plan_id") + "' and is_delete = '0' and invstatus != '99'").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(real_start_date) && ObjectUtil.isEmpty(real_end_date)) {
|
||||
if (ObjectUtil.isEmpty(jsonMainMst)) {
|
||||
// 2.3 判断周期
|
||||
String maintenancecycle = jsonPlanMst.getString("maintenancecycle");
|
||||
String plan_start_date = jsonPlanMst.getString("plan_start_date").replace("-", "");
|
||||
String today = DateUtil.today().replace("-", "");
|
||||
// 准备参数
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("devicerecord_id",jsonPlanMst.getString("devicerecord_id"));
|
||||
param.put("maintenancecycle","01");
|
||||
param.put("plan_start_date",jsonPlanMst.getString("plan_start_date"));
|
||||
param.put("source_bill_id",jsonPlanMst.getString("maint_plan_id"));
|
||||
param.put("source_bill_code",jsonPlanMst.getString("maint_plan_code"));
|
||||
|
||||
// 计算 当前日期 - 保养计划日期 后的天数
|
||||
String num = String.valueOf(NumberUtil.sub(today, plan_start_date));
|
||||
|
||||
// 周期为年 :当前日期-保养计划日期 <= 15 天时,新增保养单
|
||||
if (StrUtil.equals(maintenancecycle,"01")) {
|
||||
if (Integer.parseInt(num) <= 15) {
|
||||
this.createMain(param);
|
||||
}
|
||||
// 周期为月 :当前日期-保养计划日期 <= 7 天时,新增保养单
|
||||
} else if (StrUtil.equals(maintenancecycle,"02")) {
|
||||
if (Integer.parseInt(num) <= 7) {
|
||||
this.createMain(param);
|
||||
}
|
||||
// 周期为周 :当前日期-保养计划日期 <= 3 天时,新增保养单
|
||||
} else if (StrUtil.equals(maintenancecycle,"03")) {
|
||||
if (Integer.parseInt(num) <= 3) {
|
||||
this.createMain(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 3 如果保养实际开始时间 和 保养实际结束时间不为空 并且查不到对应单据
|
||||
if (ObjectUtil.isEmpty(jsonMainMst)) {
|
||||
// 取保养实际结束日期:用当前日期 - 保养实际结束日期
|
||||
String maintenancecycle = jsonPlanMst.getString("maintenancecycle");
|
||||
String rep_real_end_date = jsonPlanMst.getString("real_end_date").replace("-", "");
|
||||
String today = DateUtil.today().replace("-", "");
|
||||
|
||||
// 准备参数
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("devicerecord_id",jsonPlanMst.getString("devicerecord_id"));
|
||||
param.put("maintenancecycle","01");
|
||||
param.put("plan_start_date",jsonPlanMst.getString("plan_start_date"));
|
||||
param.put("source_bill_id",jsonPlanMst.getString("maint_plan_id"));
|
||||
param.put("source_bill_code",jsonPlanMst.getString("maint_plan_code"));
|
||||
// 计算 当前日期 - 保养实际结束 后的天数
|
||||
String num = String.valueOf(NumberUtil.sub(today, rep_real_end_date));
|
||||
|
||||
// 周期为年 :当前日期-保养实际结束 <= 15 天时,新增保养单
|
||||
if (StrUtil.equals(maintenancecycle,"01")) {
|
||||
if (Integer.parseInt(num) <= 15) {
|
||||
this.createMain(param);
|
||||
}
|
||||
// 周期为月 :当前日期-保养实际结束 <= 7 天时,新增保养单
|
||||
} else if (StrUtil.equals(maintenancecycle,"02")) {
|
||||
if (Integer.parseInt(num) <= 7) {
|
||||
this.createMain(param);
|
||||
}
|
||||
// 周期为周 :当前日期-保养实际结束 <= 3 天时,新增保养单
|
||||
} else if (StrUtil.equals(maintenancecycle,"03")) {
|
||||
if (Integer.parseInt(num) <= 3) {
|
||||
this.createMain(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建保养单共用方法
|
||||
* json: {
|
||||
* 设备档案标识:devicerecord_id,
|
||||
* 单据类型:maintenancecycle,
|
||||
* 计划开始日期:plan_start_date,
|
||||
* 来源单据标识:source_bill_id,
|
||||
* 来源单据编码:source_bill_code,
|
||||
* }
|
||||
*/
|
||||
public void createMain(JSONObject json) {
|
||||
Long currentUserId = 1L;
|
||||
String nickName = "管理员";
|
||||
Long deptId = 1L;
|
||||
|
||||
WQLObject mainMstTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenanceMst"); // 设备保养单主表
|
||||
WQLObject mainDtlTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenanceDtl"); // 设备保养单主明细表
|
||||
WQLObject planDtlTab = WQLObject.getWQLObject("EM_BI_DeviceMaintenancePlanDtl"); // 设备保养计划明细表
|
||||
|
||||
JSONArray planDtlArr = planDtlTab.query("maint_plan_id = '" + json.getString("source_bill_id") + "'").getResultJSONArray(0);
|
||||
|
||||
// 保养单主表
|
||||
JSONObject jsonMainMst = new JSONObject();
|
||||
jsonMainMst.put("maint_id", IdUtil.getSnowflake(1,1).nextId());
|
||||
jsonMainMst.put("maint_code", CodeUtil.getNewCode("MAINT_CODE"));
|
||||
jsonMainMst.put("devicerecord_id",json.get("devicerecord_id"));
|
||||
jsonMainMst.put("maintenancecycle",json.getString("maintenancecycle"));
|
||||
jsonMainMst.put("invstatus","01");
|
||||
jsonMainMst.put("plan_start_date",json.getString("plan_start_date"));
|
||||
jsonMainMst.put("detail_count",planDtlArr.size());
|
||||
jsonMainMst.put("source_bill_id",json.get("source_bill_id"));
|
||||
jsonMainMst.put("source_bill_type","BYJH");
|
||||
jsonMainMst.put("source_bill_code",json.getString("source_bill_code"));
|
||||
jsonMainMst.put("input_optid",currentUserId);
|
||||
jsonMainMst.put("input_optname",nickName);
|
||||
jsonMainMst.put("input_time", DateUtil.now());
|
||||
jsonMainMst.put("sysdeptid", deptId);
|
||||
jsonMainMst.put("syscompanyid", deptId);
|
||||
mainMstTab.insert(jsonMainMst);
|
||||
|
||||
// 保养单明细表
|
||||
for (int i = 0; i < planDtlArr.size(); i++) {
|
||||
JSONObject jsonObject = planDtlArr.getJSONObject(i);
|
||||
JSONObject jsonMainDtl = new JSONObject();
|
||||
jsonMainDtl.put("maint_dtl_id", IdUtil.getSnowflake(1,1).nextId());
|
||||
jsonMainDtl.put("maint_id", jsonMainMst.get("maint_id"));
|
||||
jsonMainDtl.put("device_item_id", jsonObject.get("maint_item_id"));
|
||||
mainDtlTab.insert(jsonMainDtl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user