|
@@ -1,52 +1,208 @@
|
|
|
package org.jeecg.modules.openApi.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.jeecg.modules.openApi.entity.SubcontractingOrder;
|
|
|
+import org.jeecg.modules.openApi.mapper.PurchaseWarehousingMapper;
|
|
|
import org.jeecg.modules.openApi.mapper.SubcontractingOrderMapper;
|
|
|
import org.jeecg.modules.openApi.service.SubcontractingOrderService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import static org.apache.commons.lang3.RegExUtils.replaceFirst;
|
|
|
|
|
|
@Service
|
|
|
public class SubcontractingOrderImpl extends ServiceImpl<SubcontractingOrderMapper, SubcontractingOrder> implements SubcontractingOrderService {
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private PurchaseWarehousingMapper purchaseWarehousingMapper;
|
|
|
@Autowired
|
|
|
private SubcontractingOrderMapper subcontractingOrderMapper;
|
|
|
|
|
|
+ /**
|
|
|
+ * 调用存储过程 获取下一个编码
|
|
|
+ * @param StuNo 单据类型 24:入库单
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
@DS("multi-one")
|
|
|
- public List<SubcontractingOrder> selectOrderByCode(String code,String MoDetailsID){
|
|
|
- return subcontractingOrderMapper.selectOrderByCode(code,MoDetailsID);
|
|
|
+ public String callGetMaxCode(String StuNo) {
|
|
|
+ int num = subcontractingOrderMapper.callGetMaxCode(StuNo);
|
|
|
+ if(num == 0){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if(num < 1000000000){
|
|
|
+ num = num + 1000000000;
|
|
|
+ }else{
|
|
|
+ return String.valueOf(num);
|
|
|
+ }
|
|
|
+ String code = String.valueOf(num);
|
|
|
+ code = replaceFirst(code, "1", "0");
|
|
|
+
|
|
|
+ return code;
|
|
|
}
|
|
|
|
|
|
- public String saveWarehousing(JSONArray json){
|
|
|
|
|
|
- for(int i=0;i<json.size();i++){
|
|
|
- JSONObject jsonObject=json.getJSONObject(i);
|
|
|
- //获取账套
|
|
|
- if(jsonObject.get("cAccId") != null){
|
|
|
- String cAccId=jsonObject.get("cAccId").toString();
|
|
|
+ /**
|
|
|
+ * 调用存储过程 获取下一个主键(包含主子表)
|
|
|
+ * @param StuNo rd:入库单
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
|
|
|
+ @DS("multi-one")
|
|
|
+ public Map<String,Integer> callGetUAMaxPK(String StuNo) {
|
|
|
+ Map<String,Integer> map = subcontractingOrderMapper.callGetUAMaxPK(StuNo);
|
|
|
+ Map<String,Integer> map1 = new HashMap<>();
|
|
|
+
|
|
|
+ if(map.get("iFatherId") != null){//主表主键
|
|
|
+ if(map.get("iFatherId") >= 1000000000){
|
|
|
+ map1.put("iFatherId",map.get("iFatherId"));
|
|
|
}else{
|
|
|
- throw new RuntimeException("cAccId不能为空,或不合法");
|
|
|
+ map1.put("iFatherId",map.get("iFatherId")+1000000000);
|
|
|
}
|
|
|
- if(jsonObject.get("cAccId") != null){
|
|
|
- String bredvouch=jsonObject.get("bredvouch").toString();//红蓝标识 采购入库
|
|
|
+ }
|
|
|
+ if(map.get("iChildId") != null){ //子表主键
|
|
|
+ if(map.get("iChildId") >= 1000000000){
|
|
|
+ map1.put("iChildId",map.get("iChildId"));
|
|
|
+ }else{
|
|
|
+ map1.put("iChildId",map.get("iChildId")+1000000000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @DS("multi-one")
|
|
|
+ public List<SubcontractingOrder> selectOrderByCodeOne(String code,String MoDetailsID){
|
|
|
+ return subcontractingOrderMapper.selectOrderByCode(code,MoDetailsID);
|
|
|
+ }
|
|
|
+ @DS("multi-two")
|
|
|
+ public List<SubcontractingOrder> selectOrderByCodeTwo(String code,String MoDetailsID){
|
|
|
+ return subcontractingOrderMapper.selectOrderByCode(code,MoDetailsID);
|
|
|
+ }
|
|
|
+ @DS("multi-three")
|
|
|
+ public List<SubcontractingOrder> selectOrderByCodeThree(String code,String MoDetailsID){
|
|
|
+ return subcontractingOrderMapper.selectOrderByCode(code,MoDetailsID);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DS("multi-one")
|
|
|
+ @Override
|
|
|
+ public String saveWarehousing(List<Map<String,Object>> mapList){
|
|
|
+
|
|
|
+ for(Map<String,Object> map:mapList){
|
|
|
+ //获取新的主表主键
|
|
|
+ Map<String,Integer> pkMap = this.callGetUAMaxPK("rd");
|
|
|
+ map.put("ID",pkMap.get("iFatherId"));
|
|
|
+ //获取新code
|
|
|
+ String cCode = this.callGetMaxCode("24");
|
|
|
+ if(cCode!=null){
|
|
|
+ map.put("cCode",cCode);
|
|
|
}else{
|
|
|
- throw new RuntimeException("bredvouch不能为空,或不合法");
|
|
|
+ throw new RuntimeException("获取入库单号失败");
|
|
|
}
|
|
|
|
|
|
+ //红蓝标识
|
|
|
+ if(map.get("cVouchType").toString().equals("0")){
|
|
|
+ map.put("cVouchType",0);//采购入库
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("cVouchType:只能进行采购入库(0)");
|
|
|
+ }
|
|
|
+ //入库类别、采购类型
|
|
|
+ if(map.get("cRdCode").toString().equals("委外入库")){
|
|
|
+ //委外入库
|
|
|
+ map.put("cRdCode",12);//入库类别
|
|
|
+ map.put("cPTCode",02);//采购类型
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("入库类别:只能进行委外入库");
|
|
|
+ }
|
|
|
+ map.put("dDate",new Date());//入库日期
|
|
|
+ if(map.get("cWhCode") == null){
|
|
|
+ throw new RuntimeException("cWhCode为空");
|
|
|
+ }
|
|
|
+ if(map.get("cOrderCode") == null){
|
|
|
+ throw new RuntimeException("委外订单号为空");
|
|
|
+ }
|
|
|
+ if(map.get("cBusType") == null){
|
|
|
+ map.put("cBusType","委外加工");//业务类型-根据订单号获取或者默认
|
|
|
+ }
|
|
|
|
|
|
+// map.put("cVenCode","");//供货单位 委外订单供应商-根据订单号获取
|
|
|
+// map.put("cDepCode","");//部门-根据订单号获取
|
|
|
+// map.put("cPersonCode","");//业务员-根据订单号获取
|
|
|
+//
|
|
|
+// map.put("cMemo","");//订单备注
|
|
|
|
|
|
+ //插入主表
|
|
|
+ subcontractingOrderMapper.saveRdRecord01One(map);
|
|
|
+ //子表
|
|
|
+ if(map.get("item") != null && !map.get("item").equals("")){
|
|
|
+ List<Map<String,Object>> itemList=(List<Map<String,Object>>)map.get("item");
|
|
|
+ Integer rowId=0;
|
|
|
+ for(Map<String,Object> itemMap:itemList){
|
|
|
+ rowId++;
|
|
|
+ //获取子表最大id
|
|
|
+ Map<String,Integer> pkMapChild = this.callGetUAMaxPK("rd");
|
|
|
+ itemMap.put("AutoID",pkMapChild.get("iChildId"));
|
|
|
+ //主表id
|
|
|
+ itemMap.put("ID",map.get("ID"));
|
|
|
+ //行号
|
|
|
+ itemMap.put("irowno",rowId);
|
|
|
|
|
|
+ //itemMap.put("cDefine22",rowId);//款号
|
|
|
+ //itemMap.put("cDefine28",rowId);//小PO 空
|
|
|
+ //itemMap.put("cInvCode",rowId);//存货编码 必填
|
|
|
+ if(itemMap.get("cInvCode") == null){
|
|
|
+ throw new RuntimeException("cInvCode为空");
|
|
|
+ }
|
|
|
+ //itemMap.put("iQuantity",rowId);//数量 必填
|
|
|
+ if(itemMap.get("iQuantity") == null){
|
|
|
+ throw new RuntimeException("iQuantity为空");
|
|
|
+ }
|
|
|
+ //itemMap.put("unit",rowId);//单位 必填
|
|
|
+ if(itemMap.get("unit") == null){
|
|
|
+ throw new RuntimeException("unit为空");
|
|
|
+ }
|
|
|
+ //itemMap.put("cBatch",rowId);//批号 必填
|
|
|
+ if(itemMap.get("cBatch") == null){
|
|
|
+ throw new RuntimeException("cBatch为空");
|
|
|
+ }
|
|
|
+ //itemMap.put("color",rowId);//颜色 必填
|
|
|
+ if(itemMap.get("color") == null){
|
|
|
+ throw new RuntimeException("color为空");
|
|
|
+ }
|
|
|
+ //itemMap.put("polishedBlank",rowId);/光坯毛门幅CM 验布机 要求门幅
|
|
|
+ //itemMap.put("gramWeight",rowId);/克重/工艺 验布机 克重
|
|
|
+ //itemMap.put("cDefine30",rowId);/染厂色号 验布机 色号
|
|
|
+ itemMap.put("iordercode",map.get("cOrderCode"));//委外订单号 必填
|
|
|
+ //itemMap.put("num",rowId);/件数 总卷数 必填
|
|
|
+ //itemMap.put("cbMemo",rowId);/备注
|
|
|
+ if(itemMap.get("num") == null){
|
|
|
+ throw new RuntimeException("num为空");
|
|
|
+ }
|
|
|
+ subcontractingOrderMapper.saveRdRecord01One(itemMap);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("item为空");
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
return "true";
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// public Integer getMaxId(String id, String tableName) {
|
|
|
+// Integer maxId=purchaseWarehousingMapper.getMaxId(id,tableName);
|
|
|
+// if(maxId!=null){
|
|
|
+// maxId=maxId+1;
|
|
|
+// }else{
|
|
|
+// maxId=0;
|
|
|
+// }
|
|
|
+// return maxId;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
}
|