diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/basedata/service/impl/MaterialbaseServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/basedata/service/impl/MaterialbaseServiceImpl.java index d1f4ea1..dd1ee47 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/basedata/service/impl/MaterialbaseServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/basedata/service/impl/MaterialbaseServiceImpl.java @@ -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 地址,拼接请求地址 diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java index 30a73b2..08e0822 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/service/impl/AcsToWmsServiceImpl.java @@ -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 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); diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/rest/WorkorderController.java b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/rest/WorkorderController.java index 8c10da8..4bc8b94 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/rest/WorkorderController.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/rest/WorkorderController.java @@ -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 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); + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/WorkordeService.java b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/WorkordeService.java index 3cb23e1..c93e140 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/WorkordeService.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/WorkordeService.java @@ -121,4 +121,6 @@ public interface WorkordeService { * @return */ JSONArray getDtl(JSONObject param); + + void synchronize(JSONObject param); } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/impl/WorkorderServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/impl/WorkorderServiceImpl.java index a748336..5bead7e 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/impl/WorkorderServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/service/impl/WorkorderServiceImpl.java @@ -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 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 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 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); + } + } + } } diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/wql/MPS_PRODUCEDURE001.wql b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/wql/MPS_PRODUCEDURE001.wql index 634533b..0e83cab 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/pdm/wql/MPS_PRODUCEDURE001.wql +++ b/lms/nladmin-system/src/main/java/org/nl/wms/pdm/wql/MPS_PRODUCEDURE001.wql @@ -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 <> "" ( diff --git a/lms/nladmin-ui/src/api/wms/pdm/workorder.js b/lms/nladmin-ui/src/api/wms/pdm/workorder.js index 4d4f364..1589446 100644 --- a/lms/nladmin-ui/src/api/wms/pdm/workorder.js +++ b/lms/nladmin-ui/src/api/wms/pdm/workorder.js @@ -96,4 +96,12 @@ export function getDtl(data) { }) } -export default { add, edit, del, submits, getDevice, getTable, openStart, saveReport, finish, getReportWork, forceFinish, getDtl } +export function synchronize(data) { + return request({ + url: 'api/workorder/synchronize', + method: 'post', + data + }) +} + +export default { add, edit, del, submits, getDevice, getTable, openStart, saveReport, finish, getReportWork, forceFinish, getDtl, synchronize } diff --git a/lms/nladmin-ui/src/views/wms/basedata/material/index.vue b/lms/nladmin-ui/src/views/wms/basedata/material/index.vue index 81f1c28..828da28 100644 --- a/lms/nladmin-ui/src/views/wms/basedata/material/index.vue +++ b/lms/nladmin-ui/src/views/wms/basedata/material/index.vue @@ -218,6 +218,8 @@ value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" + :default-value="default_date_show" + :picker-options="disabled_time" /> @@ -305,6 +307,12 @@ export default { permission: {}, show_sync_dialog: false, sync_time: '', + default_date_show: '', + disabled_time: { + disabledDate(time) { + return time.getTime() > Date.now() // 可选历史天、可选当前天、不可选未来天 + } + }, rules: { material_id: [ { required: true, message: '不能为空', trigger: 'blur' } @@ -331,6 +339,8 @@ export default { } }, created() { + this.default_date_show = new Date() + this.default_date_show.setMonth(new Date().getMonth() - 1) this.initClass1() this.initClass2() this.initClass3() @@ -408,7 +418,6 @@ export default { }).catch(() => { this.show_sync_dialog = false }) - console.log(this.sync_time) }, queryClassId() { const param = { diff --git a/lms/nladmin-ui/src/views/wms/pdm/device/index.vue b/lms/nladmin-ui/src/views/wms/pdm/device/index.vue index f192457..0209e6e 100644 --- a/lms/nladmin-ui/src/views/wms/pdm/device/index.vue +++ b/lms/nladmin-ui/src/views/wms/pdm/device/index.vue @@ -40,7 +40,7 @@ diff --git a/lms/nladmin-ui/src/views/wms/pdm/workerorder/index.vue b/lms/nladmin-ui/src/views/wms/pdm/workerorder/index.vue index d0ecb59..b1c2bbc 100644 --- a/lms/nladmin-ui/src/views/wms/pdm/workerorder/index.vue +++ b/lms/nladmin-ui/src/views/wms/pdm/workerorder/index.vue @@ -53,7 +53,7 @@ /> - + - + 强制完成 + + 同步 + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - + - + - + - + {{ scope.row.produceorder_code }}--> + + + + - - - + + - - - - - - - - - + + + + + + - + - - + +