sunxianglong пре 4 месеци
родитељ
комит
f0808cb152

+ 13 - 0
src/main/java/com/jeesite/modules/erp/entity/MesProductOrder.java

@@ -2,6 +2,8 @@ package com.jeesite.modules.erp.entity;
 
 import javax.validation.constraints.Size;
 import java.util.Date;
+import java.util.List;
+
 import com.jeesite.common.mybatis.annotation.JoinTable;
 import com.jeesite.common.mybatis.annotation.JoinTable.Type;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -10,6 +12,7 @@ import com.jeesite.common.entity.DataEntity;
 import com.jeesite.common.mybatis.annotation.Column;
 import com.jeesite.common.mybatis.annotation.Table;
 import com.jeesite.common.mybatis.mapper.query.QueryType;
+import com.jeesite.modules.mes.entity.MesMaterialBl;
 
 /**
  * 生产订单Entity
@@ -43,6 +46,16 @@ public class MesProductOrder extends DataEntity<MesProductOrder> {
 	private String remark;		// 备注
 	private String state;		// 状态 0=草稿 1=下发 2=完成
 
+	private List<MesMaterialBl> list; //备料列表
+
+	public List<MesMaterialBl> getList() {
+		return list;
+	}
+
+	public void setList(List<MesMaterialBl> list) {
+		this.list = list;
+	}
+
 	public MesProductOrder() {
 		this(null);
 	}

+ 71 - 0
src/main/java/com/jeesite/modules/erp/service/MesProductOrderService.java

@@ -1,13 +1,22 @@
 package com.jeesite.modules.erp.service;
 
 import java.util.List;
+
+import com.jeesite.modules.mes.entity.MesMaterial;
+import com.jeesite.modules.mes.service.MesMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import com.jeesite.common.collect.ListUtils;
 import com.jeesite.common.entity.Page;
+import com.jeesite.common.lang.StringUtils;
 import com.jeesite.common.service.CrudService;
+import com.jeesite.common.service.ServiceException;
 import com.jeesite.modules.erp.entity.MesProductOrder;
 import com.jeesite.modules.erp.dao.MesProductOrderDao;
+import com.jeesite.modules.mes.entity.MesMaterialBl;
+import com.jeesite.modules.mes.service.MesMaterialBlService;
 
 /**
  * 生产订单Service
@@ -17,6 +26,11 @@ import com.jeesite.modules.erp.dao.MesProductOrderDao;
 @Service
 public class MesProductOrderService extends CrudService<MesProductOrderDao, MesProductOrder> {
 
+	@Autowired
+	private MesMaterialBlService mesMaterialBlService;
+	@Autowired
+	private MesMaterialService mesMaterialService;
+
 	/**
 	 * 获取单条数据
 	 * @param mesProductOrder
@@ -82,4 +96,61 @@ public class MesProductOrderService extends CrudService<MesProductOrderDao, MesP
 		return dao.findBySn(sn,state);
 	}
 
+	/**
+	 * 接收 ERP 下发生产订单及备料清单
+	 */
+	@Transactional
+	public void receiveOrder(MesProductOrder mesProductOrder) {
+		if (StringUtils.isBlank(mesProductOrder.getSn())) {
+			throw new ServiceException(text("订单编号不能为空!"));
+		}
+		if (StringUtils.isBlank(mesProductOrder.getLineSn())) {
+			throw new ServiceException(text("产线编号不能为空!"));
+		}
+		if (mesProductOrder.getNums() == null) {
+			throw new ServiceException(text("生产数量不能为空!"));
+		}
+		if (ListUtils.isEmpty(mesProductOrder.getList())) {
+			throw new ServiceException(text("备料清单不能为空!"));
+		}
+
+		MesProductOrder exist = dao.findBySn(mesProductOrder.getSn(), null);
+		if (exist != null) {
+			if ("2".equals(exist.getState())) {
+				throw new ServiceException(text("订单已完成,无法重复接收!"));
+			}
+			mesProductOrder.setId(exist.getId());
+			mesProductOrder.setIsNewRecord(false);
+			if (mesProductOrder.getNowNums() == null) {
+				mesProductOrder.setNowNums(exist.getNowNums() != null ? exist.getNowNums() : 0);
+			}
+		} else {
+			mesProductOrder.setIsNewRecord(true);
+			mesProductOrder.setNowNums(0);
+		}
+		if (StringUtils.isBlank(mesProductOrder.getState())) {
+			mesProductOrder.setState("1");
+		}
+		super.save(mesProductOrder);
+
+		List<MesMaterialBl> list =mesProductOrder.getList();
+		for (MesMaterialBl mesMaterialBl : list) {
+			if (StringUtils.isBlank(mesMaterialBl.getErpSn())) {
+				throw new ServiceException(text("erp编码不能为空!"));
+			}
+			mesMaterialBl.setOrderId(mesProductOrder.getSn());
+			MesMaterial mm=new MesMaterial();
+			mm.setErpSn(mesMaterialBl.getErpSn());
+			MesMaterial info = mesMaterialService.findInfo(mm);
+			if(info==null){
+				throw new ServiceException(text("erp编码参数错误!"));
+			}
+			mesMaterialBl.setTitle(info.getTitle());
+			mesMaterialBl.setSpec(info.getSpec());
+			mesMaterialBlService.save(mesMaterialBl);
+		}
+
+
+	}
+
 }

+ 23 - 6
src/main/java/com/jeesite/modules/erp/web/MesProductOrderController.java

@@ -11,11 +11,13 @@ import org.springframework.ui.Model;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import com.jeesite.common.config.Global;
 import com.jeesite.common.entity.Page;
+import com.jeesite.common.service.ServiceException;
 import com.jeesite.common.web.BaseController;
 import com.jeesite.modules.erp.entity.MesProductOrder;
 import com.jeesite.modules.erp.service.MesProductOrderService;
@@ -31,7 +33,7 @@ public class MesProductOrderController extends BaseController {
 
 	@Autowired
 	private MesProductOrderService mesProductOrderService;
-	
+
 	/**
 	 * 获取数据
 	 */
@@ -39,7 +41,7 @@ public class MesProductOrderController extends BaseController {
 	public MesProductOrder get(String id, boolean isNewRecord) {
 		return mesProductOrderService.get(id, isNewRecord);
 	}
-	
+
 	/**
 	 * 查询列表
 	 */
@@ -49,7 +51,7 @@ public class MesProductOrderController extends BaseController {
 		model.addAttribute("mesProductOrder", mesProductOrder);
 		return "modules/erp/mesProductOrderList";
 	}
-	
+
 	/**
 	 * 查询列表数据
 	 */
@@ -82,7 +84,7 @@ public class MesProductOrderController extends BaseController {
 		mesProductOrderService.save(mesProductOrder);
 		return renderResult(Global.TRUE, text("保存生产订单成功!"));
 	}
-	
+
 	/**
 	 * 删除数据
 	 */
@@ -93,5 +95,20 @@ public class MesProductOrderController extends BaseController {
 		mesProductOrderService.delete(mesProductOrder);
 		return renderResult(Global.TRUE, text("删除生产订单成功!"));
 	}
-	
-}
+
+	/**
+	 * 接收erp生产订单
+	 */
+//	@RequiresPermissions("erp:mesProductOrder:edit")
+	@PostMapping(value = "receiveOrder")
+	@ResponseBody
+	public String receiveOrder(@RequestBody MesProductOrder mesProductOrder) {
+		try {
+			mesProductOrderService.receiveOrder(mesProductOrder);
+			return renderResult(Global.TRUE, text("接收生产订单成功!"));
+		} catch (ServiceException e) {
+			return renderResult(Global.FALSE, text(e.getMessage()));
+		}
+	}
+
+}

+ 4 - 0
src/main/java/com/jeesite/modules/mes/service/MesProductRecordService.java

@@ -320,6 +320,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 			Integer i = 1;
 			Long cdate = Long.valueOf(CommonUitl.Date2TimeStamp(new Date()));
 			List<MesProductRecord> records = new ArrayList<>();
+			boolean reachedOnlineOprno = false;
 			for (MesTemplateItems mesTemplateItems : lists){
 				MesProductRecord mpr1 = new MesProductRecord();
 				mpr1.setSn(mesProductRecord.getSn());
@@ -334,6 +335,7 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 				mpr1.setCdate(cdate);//排序字段
 				mpr1.setContent("UDF");
 				if(mesTemplateItems.getOprno().equals(oprno)){
+					reachedOnlineOprno = true;
 					if(mesProductRecord.getOprno().length()==5){
 						oprno += "A";
 						mpr1.setOprno(mesProductRecord.getOprno()+"A");
@@ -353,6 +355,8 @@ public class MesProductRecordService extends CrudService<MesProductRecordDao, Me
 							break;
 						}
 					}
+				} else if (!reachedOnlineOprno) {
+					mpr1.setContent("OK");
 				}
 
 				records.add(mpr1);

+ 5 - 5
src/main/java/com/jeesite/modules/mes/web/MesMaterialCheckRecordController.java

@@ -82,7 +82,7 @@ public class MesMaterialCheckRecordController extends BaseController {
 	public MesMaterialCheckRecord get(String id, boolean isNewRecord) {
 		return mesMaterialCheckRecordService.get(id, isNewRecord);
 	}
-	
+
 	/**
 	 * 查询列表
 	 */
@@ -92,7 +92,7 @@ public class MesMaterialCheckRecordController extends BaseController {
 		model.addAttribute("mesMaterialCheckRecord", mesMaterialCheckRecord);
 		return "modules/mes/mesMaterialCheckRecordList";
 	}
-	
+
 	/**
 	 * 查询列表数据
 	 */
@@ -273,8 +273,8 @@ public class MesMaterialCheckRecordController extends BaseController {
 			resp.setMessage("参数错误");
 			return resp;
 		}
-		String[] result = sn.split("_");
-		if(result.length!=3){
+		String[] result = sn.split(",");
+		if(result.length!=7){
 			resp.setResult(Global.FALSE);
 			resp.setMessage("二维码格式错误");
 			return resp;
@@ -452,4 +452,4 @@ public class MesMaterialCheckRecordController extends BaseController {
 		}
 	}
 
-}
+}

+ 60 - 23
src/main/java/com/jeesite/modules/mes/web/MesMaterialController.java

@@ -4,7 +4,11 @@ import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONValidator;
+import com.jeesite.common.collect.ListUtils;
 import com.jeesite.common.codec.EncodeUtils;
 import com.jeesite.common.lang.DateUtils;
 import com.jeesite.common.utils.excel.ExcelExport;
@@ -17,6 +21,7 @@ import org.springframework.ui.Model;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -95,37 +100,69 @@ public class MesMaterialController extends BaseController {
 	 */
 	@PostMapping(value = "saveMaterial")
 	@ResponseBody
-	public String saveMaterial(@Validated MesMaterial mesMaterial) {
-//		if (StringUtils.isBlank(mesMaterial.getTitle())) {
-//			return renderResult(Global.FALSE, text("部件名称不能为空!"));
-//		}
-//		if (StringUtils.isBlank(mesMaterial.getSpec())) {
-//			return renderResult(Global.FALSE, text("部件规格不能为空!"));
-//		}
-		if (StringUtils.isBlank(mesMaterial.getErpSn())) {
+	public String saveMaterial(@RequestBody String body) {
+		if (StringUtils.isBlank(body)) {
+			return renderResult(Global.FALSE, text("参数错误!"));
+		}
+		List<JSONObject> items = parseMaterialList(body.trim());
+		if (items.isEmpty()) {
+			return renderResult(Global.FALSE, text("参数错误!"));
+		}
+		for (JSONObject obj : items) {
+			String err = doSaveOneMaterial(obj);
+			if (err != null) {
+				return err;
+			}
+		}
+		return renderResult(Global.TRUE, text("保存物料表成功!"));
+	}
+
+	private List<JSONObject> parseMaterialList(String jsonStr) {
+		List<JSONObject> list = ListUtils.newArrayList();
+		if (jsonStr.startsWith("{")) {
+			list.add(JSON.parseObject(jsonStr));
+			return list;
+		}
+		JSONArray arr = JSON.parseArray(jsonStr);
+		for (int i = 0; i < arr.size(); i++) {
+			Object item = arr.get(i);
+			if (item instanceof JSONArray) {
+				JSONArray inner = (JSONArray) item;
+				for (int j = 0; j < inner.size(); j++) {
+					list.add(inner.getJSONObject(j));
+				}
+			} else if (item instanceof JSONObject) {
+				list.add((JSONObject) item);
+			}
+		}
+		return list;
+	}
+
+	private String doSaveOneMaterial(JSONObject obj) {
+		String erpSn = obj.getString("erpSn");
+		if (StringUtils.isBlank(erpSn)) {
 			return renderResult(Global.FALSE, text("ERP编码不能为空!"));
 		}
-//		if (StringUtils.isBlank(mesMaterial.getUnit())) {
-//			return renderResult(Global.FALSE, text("单位不能为空!"));
-//		}
-//		if (StringUtils.isBlank(mesMaterial.getHouse())) {
-//			return renderResult(Global.FALSE, text("仓库不能为空!"));
-//		}
-//		if (StringUtils.isBlank(mesMaterial.getLocation())) {
-//			return renderResult(Global.FALSE, text("库位不能为空!"));
-//		}
-		MesMaterial oldmm=new MesMaterial();
-		oldmm.setErpSn(mesMaterial.getErpSn());
+		MesMaterial mesMaterial = new MesMaterial();
+		mesMaterial.setErpSn(erpSn);
+		mesMaterial.setTitle(obj.getString("title"));
+		mesMaterial.setSpec(obj.getString("spec"));
+		mesMaterial.setUnit(obj.getString("unit"));
+		mesMaterial.setHouse(obj.getString("house"));
+		mesMaterial.setLocation(obj.getString("location"));
+
+		MesMaterial oldmm = new MesMaterial();
+		oldmm.setErpSn(erpSn);
 		List<MesMaterial> list = mesMaterialService.findList(oldmm);
-		if(!list.isEmpty()){
-			MesMaterial mm=list.get(0);
+		if (!list.isEmpty()) {
+			MesMaterial mm = list.get(0);
 			mm.setHouse(mesMaterial.getHouse());
 			mm.setLocation(mesMaterial.getLocation());
 			mesMaterialService.update(mm);
-			return renderResult(Global.TRUE, text("保存物料表成功!"));
+			return null;
 		}
 		mesMaterialService.save(mesMaterial);
-		return renderResult(Global.TRUE, text("保存物料表成功!"));
+		return null;
 	}
 
 	/**

+ 5 - 3
src/main/java/com/jeesite/modules/mes/web/MesMaterialRkController.java

@@ -228,9 +228,11 @@ public class MesMaterialRkController extends BaseController {
 	@RequestMapping(value = "mesToErp")
 	@ResponseBody
 	public String mesToErp(MesMaterialRk mesMaterialRk) {
-		mesMaterialRkService.save(mesMaterialRk);
-		if (StringUtils.isNotBlank(mesMaterialRk.getId())) {
-			mesMaterialRk = mesMaterialRkService.get(mesMaterialRk);
+		MesMaterialRk erpCode=null;
+		erpCode.setLotCode(mesMaterialRk.getLotCode());
+		List<MesMaterialRk> list = mesMaterialRkService.findList(erpCode);
+		if (list.isEmpty()){
+			mesMaterialRkService.save(mesMaterialRk);
 		}
 		if (mesMaterialRk == null) {
 			return renderResult(Global.FALSE, text("采购入库单不存在!"));

+ 2 - 1
src/main/java/com/jeesite/modules/mes/web/MesRepairQualityController.java

@@ -171,6 +171,7 @@ public class MesRepairQualityController extends BaseController {
 		}
 		MesProduct mesProduct = new MesProduct();
 		mesProduct.setSn(sn);
+		mesProduct.setCate("ZHXT");
 		MesProduct pd = mesProductService.findInfo(mesProduct);
 		if(com.jeesite.common.lang.ObjectUtils.isEmpty(pd)){
 			resp.setMessage("产品信息不存在");
@@ -321,4 +322,4 @@ public class MesRepairQualityController extends BaseController {
 		resp.setResult(Global.TRUE);
 		return resp;
 	}
-}
+}

+ 2 - 1
src/main/resources/views/modules/erp/mesProductOrderList.html

@@ -88,8 +88,9 @@ $('#dataGrid').dataGrid({
 		// {header:'${text("状态")}', name:'status', index:'a.status', width:150, align:"center", formatter: function(val, obj, row, act){
 		// 	return js.getDictLabel(${@DictUtils.getDictListJson('sys_search_status')}, val, '${text("未知")}', true);
 		// }},
-		{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
+		{header:'${text("操作")}', name:'actions', width:150, formatter: function(val, obj, row, act){
 			var actions = [];
+			actions.push('<a href="${ctx}/mes/mesMaterialBl/list?orderId='+row.sn+'" class="btnList" title="${text("备料表")}"><i class="fa fa-list-alt"></i></a>&nbsp;');
 			//<% if(hasPermi('erp:mesProductOrder:edit')){ %>
 				actions.push('<a href="${ctx}/erp/mesProductOrder/form?id='+row.id+'" class="btnList" title="${text("编辑生产订单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
 				actions.push('<a href="${ctx}/erp/mesProductOrder/delete?id='+row.id+'" class="btnList" title="${text("删除生产订单")}" data-confirm="${text("确认要删除该生产订单吗?")}"><i class="fa fa-trash-o"></i></a>&nbsp;');