物料同步修改 工单同步添加 工单完成反馈
This commit is contained in:
@@ -186,6 +186,7 @@ public class MaterialbaseServiceImpl implements MaterialbaseService {
|
||||
return MaterOptTypeEnum.getObj(materOpt_code);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void synchronize(JSONObject param) {
|
||||
// 获取 mes 地址,拼接请求地址
|
||||
|
||||
@@ -3,12 +3,15 @@ package org.nl.wms.ext.acs.service.impl;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.RedisUtils;
|
||||
import org.nl.modules.system.service.ParamService;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.nl.wms.basedata.service.MaterialbaseService;
|
||||
@@ -37,6 +40,7 @@ import org.nl.wms.st.structivt.service.dto.StructivtDto;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -56,6 +60,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
private final DeviceService deviceService;
|
||||
private final WorkordeService workordeService;
|
||||
private final RedisUtils redisUtils;
|
||||
private final ParamService paramService;
|
||||
|
||||
/**
|
||||
* task_id:任务标识
|
||||
@@ -132,6 +137,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public Map<String, Object> feedbackOrderStatus(String string) {
|
||||
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
|
||||
@@ -161,9 +167,22 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
wo.update(jsonObject1);
|
||||
status = "200";
|
||||
message = "操作成功!";
|
||||
|
||||
// 操作成功后向 MES 反馈
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("material_code", materialbaseService.findById(jsonObject1.getLong("material_id")).getMaterial_code());
|
||||
param.put("workorder_code", jsonObject1.getString("workorder_code"));
|
||||
param.put("workorder_qty", jsonObject1.getString("plan_qty"));
|
||||
param.put("device_code", deviceService.findByCode(jsonObject1.getString("device_code")).getExtend_code());
|
||||
String workorder_uri = paramService.findByCode("mes_url").getValue() + "api/mes/materialIvt";
|
||||
HttpRequest
|
||||
.post(workorder_uri)
|
||||
.body(param.toJSONString())
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
status = "400";
|
||||
message = "操作失败!";
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
}
|
||||
}
|
||||
resp.put("status", status);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.nl.wms.pdm.rest;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.wms.pdm.service.WorkordeService;
|
||||
import org.nl.wms.pdm.service.dto.WorkorderDto;
|
||||
@@ -142,4 +144,19 @@ public class WorkorderController {
|
||||
return new ResponseEntity<>(workordeService.getDtl(param),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/synchronize")
|
||||
@Log("从 MES 同步工单")
|
||||
@ApiOperation("从 MES 同步工单")
|
||||
public ResponseEntity<Object> synchronize(@RequestBody JSONObject param) {
|
||||
String start_time = param.getString("start_time");
|
||||
if (StrUtil.isEmpty(start_time)) {
|
||||
throw new BadRequestException("开始日期不能为空");
|
||||
}
|
||||
String end_time = param.getString("end_time");
|
||||
if (StrUtil.isEmpty(end_time)) {
|
||||
throw new BadRequestException("结束日期不能为空");
|
||||
}
|
||||
workordeService.synchronize(param);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,4 +121,6 @@ public interface WorkordeService {
|
||||
* @return
|
||||
*/
|
||||
JSONArray getDtl(JSONObject param);
|
||||
|
||||
void synchronize(JSONObject param);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -16,6 +18,7 @@ import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
|
||||
import org.nl.modules.common.utils.dto.CurrentUser;
|
||||
import org.nl.modules.system.service.ParamService;
|
||||
import org.nl.modules.system.util.CodeUtil;
|
||||
|
||||
import org.nl.modules.wql.WQL;
|
||||
@@ -32,8 +35,10 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author qinx
|
||||
@@ -47,6 +52,7 @@ public class WorkorderServiceImpl implements WorkordeService {
|
||||
|
||||
private final WmsToAcsService wmsToAcsService;
|
||||
private final MaterialbaseService materialbaseService;
|
||||
private final ParamService paramService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
|
||||
@@ -127,9 +133,9 @@ public class WorkorderServiceImpl implements WorkordeService {
|
||||
String now = DateUtil.now();
|
||||
CurrentUser currentUser = SecurityUtils.getCurrentUser();
|
||||
Long deptId = currentUser.getUser().getDeptId();
|
||||
String newCode = CodeUtil.getNewCode("PDM_SHIFTORDER");
|
||||
// String newCode = CodeUtil.getNewCode("PDM_SHIFTORDER");
|
||||
dto.setWorkorder_id(IdUtil.getSnowflake(1, 1).nextId());
|
||||
dto.setWorkorder_code(newCode);
|
||||
// dto.setWorkorder_code(newCode);
|
||||
dto.setCreate_id(currentUserId);
|
||||
dto.setCreate_time(now);
|
||||
dto.setCreate_name(nickName);
|
||||
@@ -458,4 +464,83 @@ public class WorkorderServiceImpl implements WorkordeService {
|
||||
return resultJSONArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchronize(JSONObject param) {
|
||||
// 获取 mes 地址,拼接请求地址
|
||||
String workorder_uri = paramService.findByCode("mes_url").getValue() + "api/mes/workorder";
|
||||
HttpResponse response = HttpRequest
|
||||
.post(workorder_uri)
|
||||
.body(param.toJSONString())
|
||||
.execute();
|
||||
if (response.getStatus() != 200) {
|
||||
throw new BadRequestException("与 MES 通信错误");
|
||||
}
|
||||
|
||||
JSONObject response_body = JSON.parseObject(response.body());
|
||||
if (ObjectUtil.isEmpty(response_body)) {
|
||||
throw new BadRequestException("MES 响应为空");
|
||||
}
|
||||
if (!response_body.getString("status").equals("200")) {
|
||||
throw new BadRequestException(response_body.getString("message"));
|
||||
}
|
||||
|
||||
// 解析数据添加工单
|
||||
JSONArray data = response_body.getJSONArray("data");
|
||||
WQLObject workorder_table = WQLObject.getWQLObject("pdm_bd_workorder");
|
||||
List<String> workorder_codes = workorder_table
|
||||
.query("is_delete = '0'")
|
||||
.getResultJSONArray(0)
|
||||
.stream()
|
||||
.map(o -> ((JSONObject) o).getString("workorder_code"))
|
||||
.collect(Collectors.toList());
|
||||
WQLObject material_table = WQLObject.getWQLObject("md_me_materialbase");
|
||||
List<String> material_codes = material_table
|
||||
.query("is_delete = '0'")
|
||||
.getResultJSONArray(0)
|
||||
.stream()
|
||||
.map(o -> ((JSONObject) o).getString("material_code"))
|
||||
.collect(Collectors.toList());
|
||||
WQLObject device_table = WQLObject.getWQLObject("pdm_bi_device");
|
||||
for (Object o : data) {
|
||||
JSONObject mes_workorder = (JSONObject) o;
|
||||
|
||||
// 判断工单是否存在,已存在则不处理
|
||||
String workorder_code = mes_workorder.getString("workorder_code");
|
||||
if (!workorder_codes.contains(workorder_code)) {
|
||||
// 判断物料是否存在,如果不存在则报错,让用户先去同步物料
|
||||
String material_code = mes_workorder.getString("material_code");
|
||||
if (!material_codes.contains(material_code)) {
|
||||
throw new BadRequestException("工单号[" + workorder_code + "]需要生产的物料不存在,请先同步物料");
|
||||
}
|
||||
|
||||
// 处理物料id
|
||||
Long material_id = material_table
|
||||
.query("is_delete = '0' AND material_code = '" + material_code + "'")
|
||||
.uniqueResult(0)
|
||||
.getLong("material_id");
|
||||
|
||||
// 处理工单数量
|
||||
int plan_qty = Integer.parseInt(mes_workorder.getString("workorder_qty")) / 1500;
|
||||
|
||||
// 处理设备
|
||||
JSONObject device = device_table
|
||||
.query("is_delete = '0' AND extend_code = '" + mes_workorder.getString("device_code") + "'")
|
||||
.uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(device)) {
|
||||
throw new BadRequestException("工单号[" + workorder_code + "]的生产设备不存在");
|
||||
}
|
||||
|
||||
//添加工单
|
||||
WorkorderDto workorder = new WorkorderDto();
|
||||
workorder.setWorkorder_code(workorder_code);
|
||||
workorder.setMaterial_id(material_id);
|
||||
workorder.setPlan_qty(BigDecimal.valueOf(plan_qty));
|
||||
workorder.setDevice_id(device.getLong("device_id"));
|
||||
workorder.setDevice_code(device.getString("device_code"));
|
||||
workorder.setOrder_status("1");
|
||||
this.create(workorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
ShiftOrder.produce_date <= 输入.end_time
|
||||
ENDOPTION
|
||||
OPTION 输入.produceorder_code <> ""
|
||||
ShiftOrder.produceorder_code like 输入.produceorder_code
|
||||
ShiftOrder.workorder_code like 输入.produceorder_code
|
||||
ENDOPTION
|
||||
OPTION 输入.material <> ""
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user