package com.vincent.rsf.server.api.controller.mes; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.vincent.rsf.framework.common.R; import com.vincent.rsf.server.common.annotation.OperationLog; import com.vincent.rsf.server.manager.entity.Loc; import com.vincent.rsf.server.manager.entity.LocItem; import com.vincent.rsf.server.manager.service.LocItemService; import com.vincent.rsf.server.manager.service.LocService; import com.vincent.rsf.server.manager.service.AsnOrderService; import com.vincent.rsf.server.manager.entity.WkOrder; import com.vincent.rsf.server.manager.controller.params.AsnOrderAndItemsParams; import com.vincent.rsf.server.manager.enums.OrderType; import com.vincent.rsf.server.manager.enums.OrderWorkType; import com.vincent.rsf.server.system.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Date; import org.springframework.web.bind.annotation.RequestBody; @RestController @RequestMapping("/mes") @Api(tags = "MES") public class MesController extends BaseController { @Resource private LocService locService; @Resource private LocItemService locItemService; @Resource private AsnOrderService asnOrderService; /** * @author Ryan * @date 2025/8/19 * @description: 物料分类列表查询 * @version 1.0 */ @ApiOperation(value = "模拟备料") @OperationLog("模拟备料") @PostMapping("/callMaterial") public R callMaterial(@RequestBody JSONObject params) { try { WkOrder order = new WkOrder(); String orderNo = params.getString("orderNo"); order.setCode(orderNo).setPoCode(orderNo).setType(OrderType.ORDER_OUT.type) // .setWkType(OrderWorkType.ORDER_WORK_TYPE_MATERIAL_PREPARATION.type) .setCreateBy(getLoginUserId()) .setUpdateBy(getLoginUserId()); if (params.getInteger("prepareType") == 1) { order.setWkType(OrderWorkType.ORDER_WORK_TYPE_NORMAL_MATERIAL_PREPARATION.type); } else { order.setWkType(OrderWorkType.ORDER_WORK_TYPE_FEED_IN_MATERIAL_PREPARATION.type); } JSONArray jsonArray = params.getJSONArray("orderItems"); List> items = new java.util.ArrayList<>(); for (int i = 0; i < jsonArray.size(); i++) { JSONObject item = jsonArray.getJSONObject(i); Map map = new java.util.HashMap<>(); String matnrCode = item.getString("matNr"); if (matnrCode == null) { matnrCode = item.getString("matNr"); } map.put("matnrCode", matnrCode); Double qty = item.getDouble("anfme"); if (qty == null) { qty = item.getDouble("anfme"); } map.put("anfme", qty); // map.put("unit", item.getString("unit")); // map.put("splrCode", item.getString("splrCode")); // map.put("splrName", item.getString("splrName")); // map.put("splrBatch", item.getString("splrBatch")); // map.put("platItemId", item.getString("platItemId")); items.add(map); } AsnOrderAndItemsParams dto = new AsnOrderAndItemsParams(); dto.setOrders(order); dto.setItems(items); R result = asnOrderService.saveOrderAndItems(dto, getLoginUserId()); if (!result.get("code").equals(200)) { return result; } Loc loc = locService.getOne(new LambdaQueryWrapper().eq(Loc::getUseStatus, "O").eq(Loc::getAreaId, 22).last("limit 1")); if (loc == null) { return R.error("没有可用库位"); } String palletId = "AA" + String.format("%06d", (int) (Math.random() * 1000000)); for (int i = 0; i < jsonArray.size(); i++) { JSONObject item = jsonArray.getJSONObject(i); loc.setBarcode(palletId); loc.setUseStatus("F"); locService.updateById(loc); LocItem locItem = new LocItem(); String matnrCode = item.getString("matNr"); if (matnrCode == null) { matnrCode = item.getString("matNr"); } Double qty = item.getDouble("anfme"); if (qty == null) { qty = item.getDouble("anfme"); } locItem.setLocId(loc.getId()) .setLocCode(loc.getCode()) .setOrderId(order.getId()) .setType(OrderType.ORDER_OUT.type) // .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_MATERIAL_PREPARATION.type)) // .setMatnrId(item.getLong("matnrId")) .setMatnrCode(matnrCode) // .setMaktx(item.getString("maktx")) .setQty(qty) .setAnfme(qty) // .setUnit(item.getString("unit")) .setBarcode(palletId) .setStatus(1) .setDeleted(0) .setCreateTime(new Date()); if (params.getInteger("prepareType") == 1) { locItem.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_NORMAL_MATERIAL_PREPARATION.type)); } else { locItem.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_FEED_IN_MATERIAL_PREPARATION.type)); } locItemService.save(locItem); } return R.ok().add(order.getId()); } catch (Exception e) { return R.error("备料处理异常: " + e.getMessage()); } } }