diff --git a/ktg-mes/pom.xml b/ktg-mes/pom.xml
index 86a794b..da186fc 100644
--- a/ktg-mes/pom.xml
+++ b/ktg-mes/pom.xml
@@ -53,6 +53,11 @@
swagger-models
1.6.2
+
+ jcifs
+ jcifs
+ 1.3.17
+
com.ktg
ktg-generator
diff --git a/ktg-mes/src/main/java/com/ktg/mes/cal/utils/CalendarUtil.java b/ktg-mes/src/main/java/com/ktg/mes/cal/utils/CalendarUtil.java
index f872822..2718bb3 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/cal/utils/CalendarUtil.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/cal/utils/CalendarUtil.java
@@ -91,6 +91,15 @@ public class CalendarUtil {
return format(new Date(), DATETIME_PATTERN);
}
+ /**
+ * 获取当前日期和时间字符串.
+ *
+ * @return String 日期时间字符串,例如 2015/08/11
+ */
+ public static String getDateTimeStrForFile() {
+ return format(new Date(), DATE_PATTERN_WITH_SLASH);
+ }
+
/**
* 时间戳转换为日期时间字符串
*
diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java b/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java
index 1956d28..5546b64 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/md/controller/BaseKnifeController.java
@@ -544,6 +544,12 @@ public class BaseKnifeController extends BaseController {
mdItem = mdItemService.selectMdItemByCode(techBom.getKnifeCode());
count = techBom.getKnifeCount() - countMap.get(techBom.getKnifeCode());
+ // 更新countMap
+ if (techBom.getKnifeCount() >= countMap.get(techBom.getKnifeCode()))
+ countMap.put(techBom.getKnifeCode(), 0);
+ else
+ countMap.put(techBom.getKnifeCode(), countMap.get(techBom.getKnifeCode()) + techBom.getKnifeCount());
+
// 先从台账表找
baseKnifeWrapper.setMbbBdMrlId(mdItem.getItemId());
baseKnifeWrapper.setIsLocked(0);
@@ -568,17 +574,29 @@ public class BaseKnifeController extends BaseController {
return AjaxResult.error("Bom头查询错误", techBom.getKnifeCode());
}
- // 生成组装任务
- WmsZdTask wmsZdTask = new WmsZdTask();
- wmsZdTask.setmProductId(mdItem.getItemId());
- wmsZdTask.setPlanSheet(productionArrangements.getPlanSheet());
- wmsZdTask.setCode(generateTaskCode(techBom.getProcessCode()));
- wmsZdTask.setName(techBom.getProcessName());
- wmsZdTask.setProductIdQty(count);
- wmsZdTask.setBomId(bomRouteList.get(0).getBomRouteId());
- wmsZdTask.setCreateTime(DateUtils.getNowDate());
- zdTaskService.insertWmsZdTask(wmsZdTask);
- msg = "生产准备验证成功!缺少物料已生成组装任务!";
+ // 判断是否存在组装任务
+ WmsZdTask wmsZdTaskWrapper = new WmsZdTask();
+ wmsZdTaskWrapper.setPlanSheet(productionArrangements.getPlanSheet());
+ wmsZdTaskWrapper.setmProductId(mdItem.getItemId());
+ List wmsZdTaskList = zdTaskService.selectWmsZdTaskList(wmsZdTaskWrapper);
+ if (wmsZdTaskList.isEmpty()){
+ // 生成组装任务
+ WmsZdTask wmsZdTask = new WmsZdTask();
+ wmsZdTask.setmProductId(mdItem.getItemId());
+ wmsZdTask.setPlanSheet(productionArrangements.getPlanSheet());
+ wmsZdTask.setCode(generateTaskCode(techBom.getProcessCode()));
+ wmsZdTask.setName(techBom.getProcessName());
+ wmsZdTask.setProductIdQty(count);
+ wmsZdTask.setBomId(bomRouteList.get(0).getBomRouteId());
+ wmsZdTask.setCreateTime(DateUtils.getNowDate());
+ zdTaskService.insertWmsZdTask(wmsZdTask);
+ msg = "生产准备验证成功!缺少物料已生成组装任务!";
+ } else {
+ WmsZdTask wmsZdTask = wmsZdTaskList.get(0);
+ wmsZdTask.setProductIdQty(wmsZdTask.getProductIdQty() + count);
+ wmsZdTask.setCreateTime(DateUtils.getNowDate());
+ msg = "生产准备验证成功!缺少物料已生成组装任务!";
+ }
} else {
baseKnifeOriginList.forEach(baseKnife -> baseKnifeService.updateBaseKnife(baseKnife));
operLog.setJsonResult("缺少BOM项:" + techBom.getKnifeCode());
diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutTaskController.java b/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutTaskController.java
index 09caedf..9ff5ca3 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutTaskController.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutTaskController.java
@@ -70,7 +70,7 @@ public class WmsOutTaskController extends BaseController {
/**
* 开放 查询出库任务列表
*/
- @GetMapping("/open/incomplete/{planSheet}")
+ @GetMapping("/open/incompleteList/{planSheet}")
public TableDataInfo openList(@PathVariable String planSheet) {
startPage();
List list = wmsOutTaskService.selectWmsOutTaskIncompleteList(planSheet);
diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/domain/MyConfig.java b/ktg-mes/src/main/java/com/ktg/mes/md/domain/MyConfig.java
index e8f2b64..dae89b8 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/md/domain/MyConfig.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/md/domain/MyConfig.java
@@ -6,9 +6,21 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class MyConfig {
- @Value("${toolSettingXml.path}")
+ @Value("${globalConfig.toolSettingXml.localPath}")
private String toolSettingXmlPath;
+ @Value("${globalConfig.toolSettingXml.remoteUrl}")
+ private String remoteUrl;
+
+ @Value("${globalConfig.toolSettingXml.remoteUser}")
+ private String remoteUser;
+
+ @Value("${globalConfig.toolSettingXml.remotePass}")
+ private String remotePass;
+
+ @Value("${globalConfig.productionControl.path}")
+ private String productionControlPath;
+
public String getToolSettingXmlPath() {
return toolSettingXmlPath;
}
@@ -16,4 +28,36 @@ public class MyConfig {
public void setToolSettingXmlPath(String toolSettingXmlPath) {
this.toolSettingXmlPath = toolSettingXmlPath;
}
+
+ public String getProductionControlPath() {
+ return productionControlPath;
+ }
+
+ public void setProductionControlPath(String productionControlPath) {
+ this.productionControlPath = productionControlPath;
+ }
+
+ public String getRemoteUrl() {
+ return remoteUrl;
+ }
+
+ public void setRemoteUrl(String remoteUrl) {
+ this.remoteUrl = remoteUrl;
+ }
+
+ public String getRemoteUser() {
+ return remoteUser;
+ }
+
+ public void setRemoteUser(String remoteUser) {
+ this.remoteUser = remoteUser;
+ }
+
+ public String getRemotePass() {
+ return remotePass;
+ }
+
+ public void setRemotePass(String remotePass) {
+ this.remotePass = remotePass;
+ }
}
diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java
index 19db822..da980e3 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/md/service/impl/BaseKnifeServiceImpl.java
@@ -2,12 +2,16 @@ package com.ktg.mes.md.service.impl;
import com.alibaba.fastjson.JSON;
import com.ktg.common.utils.DateUtils;
+import com.ktg.mes.cal.utils.CalendarUtil;
import com.ktg.mes.md.domain.*;
import com.ktg.mes.md.mapper.*;
import com.ktg.mes.md.service.IBaseKnifeService;
import com.ktg.mes.wm.domain.WmsInPlanDetailEntity;
import com.ktg.mes.wm.mapper.WmsInPlanDetailEntityMapper;
import com.ktg.mes.wm.service.impl.WmsInPlanDetailEntityServiceImpl;
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.smb.SmbFile;
+import jcifs.smb.SmbFileInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -21,7 +25,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.File;
+import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -120,14 +124,16 @@ public class BaseKnifeServiceImpl implements IBaseKnifeService {
hashMap.put("wmStorageAreaCode", wmsOutPlanDetail.getWmStorageAreaCode()); // 库位编码
hashMap.put("wmStorageAreaName", wmsOutPlanDetail.getWmStorageAreaName()); // 库位名称
hashMap.put("detailStatus", wmsOutPlanDetail.getDetailState()); // 明细状态
- hashMap.put("isToolSetting", 0); // 是否对刀
+ hashMap.put("isToolSetting", 0); // 是否对刀
// 读取xml配置文件
if ("PRODUCT".equals(nowWmsOutPlanDetailEntity.getItemOrProduct())) {
try {
-// File xmlFile = new File(myConfig.getToolSettingXmlPath() + nowBaseKnife.getRfid() + ".xml");
- File xmlFile = new File("\\\\DBJGJG24\\ddy\\aaa.xml");
-// File xmlFile = new File(myConfig.getToolSettingXmlPath() + "DDYDATA0" + (new Random().nextInt(5) + 1) + ".xml");
+ // 抓取远程文件
+ this.getRemoteFile();
+
+ // 读取本地文件
+ File xmlFile = new File(myConfig.getToolSettingXmlPath() + CalendarUtil.getDateTimeStrForFile() + "/TSP1203.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Tools.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Tools paramXml = (Tools) unmarshaller.unmarshal(xmlFile);
@@ -135,7 +141,8 @@ public class BaseKnifeServiceImpl implements IBaseKnifeService {
hashMap.put("isToolSetting", 1); // 是否对刀
hashMap.put("toolSettingParam", JSON.toJSONString(paramXml)); // 对刀参数
- } catch (JAXBException e) {
+ } catch (Exception e) {
+ System.out.println("系统找不到指定文件!");
// throw new RuntimeException(e);
}
}
@@ -168,6 +175,74 @@ public class BaseKnifeServiceImpl implements IBaseKnifeService {
return baseKnifeList;
}
+ /**
+ * 获取远程文件
+ */
+ public void getRemoteFile() throws IOException {
+ try {
+ // 创建认证用户
+ NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", myConfig.getRemoteUser(), myConfig.getRemotePass());
+
+ // 构建远程文件对象
+ SmbFile remoteFile = new SmbFile(myConfig.getRemoteUrl(), auth);
+ // 尝试链接
+ remoteFile.connect();
+ if(remoteFile.exists()){
+ // 获取共享文件夹中文件列表
+ SmbFile[] smbFiles = remoteFile.listFiles();
+ for (SmbFile smbFile : smbFiles){
+ createFile(smbFile);
+ }
+ } else {
+ System.out.println("==============START=================");
+ System.out.println("远程文件不存在");
+ System.out.println("===============END==================");
+ }
+ } catch (Exception e){
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * 创建本地文件
+ */
+ public void createFile(SmbFile remoteFile) {
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ // 创建本地文件
+// File localFile = new File("E:/xml_wjj/" + CalendarUtil.getDateTimeStrForFile() + "/" + remoteFile.getName());
+ File localFile = new File(myConfig.getToolSettingXmlPath() + CalendarUtil.getDateTimeStrForFile() + "/" + remoteFile.getName());
+ if (!localFile.getParentFile().exists()) localFile.getParentFile().mkdirs();
+ if (!localFile.exists()) localFile.createNewFile();
+ else {
+ localFile.delete();
+ localFile.createNewFile();
+ }
+ in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
+ // 获取远程输出流
+ out = new BufferedOutputStream(new FileOutputStream(localFile));
+ byte[] buffer = new byte[4096];
+ int len = 0;
+ // 写入
+ while ((len = in.read(buffer, 0, buffer.length)) != -1) {
+ out.write(buffer, 0, len);
+ }
+ out.flush(); // 刷新缓冲
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ try {
+ if (out != null) out.close();
+ if (in != null) in.close();
+ } catch (Exception e){
+ System.out.println("==============START=================");
+ System.out.println("关闭资源发生错误!");
+ System.out.println("===============END==================");
+ }
+ }
+ }
+
/**
* 新增工具台账
*
diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java
index ce3fa03..41b861d 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/wm/controller/WmsInTaskController.java
@@ -96,7 +96,7 @@ public class WmsInTaskController extends BaseController {
@GetMapping("/open/list")
public TableDataInfo openList(WmsInTask wmsInTask) {
startPage();
- List list = wmsInTaskService.selectWmsInTaskList(wmsInTask);
+ List list = wmsInTaskService.selectWmsInTaskListOpen(wmsInTask);
return getDataTable(list);
}
diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsInTaskService.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsInTaskService.java
index 990a27c..c9785a0 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsInTaskService.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/IWmsInTaskService.java
@@ -27,6 +27,14 @@ public interface IWmsInTaskService
*/
public List selectWmsInTaskList(WmsInTask wmsInTask);
+ /**
+ * 查询入库任务列表 开放
+ *
+ * @param wmsInTask 入库任务
+ * @return 入库任务集合
+ */
+ public List selectWmsInTaskListOpen(WmsInTask wmsInTask);
+
/**
* 新增入库任务
*
diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java
index 183de07..15228d2 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsInTaskServiceImpl.java
@@ -75,6 +75,17 @@ public class WmsInTaskServiceImpl implements IWmsInTaskService {
return wmsInTaskList;
}
+ /**
+ * 查询入库任务列表 开放
+ *
+ * @param wmsInTask 入库任务
+ * @return 入库任务
+ */
+ @Override
+ public List selectWmsInTaskListOpen(WmsInTask wmsInTask) {
+ return wmsInTaskMapper.selectWmsInTaskList(wmsInTask);
+ }
+
/**
* 新增入库任务
*
diff --git a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java
index 8fe0439..c3d1045 100644
--- a/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java
+++ b/ktg-mes/src/main/java/com/ktg/mes/wm/service/impl/WmsZdTaskServiceImpl.java
@@ -1,12 +1,15 @@
package com.ktg.mes.wm.service.impl;
+import java.io.IOException;
import java.util.*;
+import com.alibaba.fastjson.JSON;
import com.ktg.common.constant.UserConstants;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.utils.DateUtils;
import com.ktg.common.utils.StringUtils;
import com.ktg.generator.util.MultiModuleCodeGenerator;
+import com.ktg.mes.cal.utils.CalendarUtil;
import com.ktg.mes.md.domain.*;
import com.ktg.mes.md.mapper.*;
import com.ktg.mes.md.service.IBaseKnifeService;
@@ -20,6 +23,7 @@ import com.ktg.mes.wm.service.IWmsInPlanService;
import com.ktg.mes.wm.service.IWmsInTaskService;
import com.ktg.system.mapper.SysOperLogMapper;
import com.ktg.system.service.ISysOperLogService;
+import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.wm.service.IWmsZdTaskService;
@@ -74,6 +78,9 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
@Autowired
private ProductionArrangementsMapper productionArrangementsMapper;
+ @Autowired
+ private MyConfig myConfig;
+
/**
* 查询组装任务
*
@@ -388,7 +395,8 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
wmsInPlanTemp.setCellCode(wmStorageArea.getAreaCode());
wmsInPlanTemp.setPlanCode(zdTask.getPlanSheet() != null ? zdTask.getPlanSheet() : zdTask.getCode());
wmsInPlanTemp.setRelBillCode("组装单据");
- wmsInPlanTemp.setPlanTypeId(13L);
+ wmsInPlanTemp.setPlanTypeId(9L);
+ wmsInPlanTemp.setPlanTypeCode("ZDHK");
wmsInPlanTemp.setCreateBy(getUsername());
wmsInPlanTemp.setCreateTime(DateUtils.getNowDate());
@@ -487,12 +495,14 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
List baseTechnologyBomList = baseTechnologyBomMapper.selectBaseTechnologyBomList(baseTechnologyBomWrapper);
// 判断订单锁定的物料是否足够
+ Map coutMap = new HashMap<>();
for (BaseTechnologyBom technologyBom : baseTechnologyBomList) {
+ coutMap.merge(technologyBom.getKnifeCode(), technologyBom.getKnifeCount(), Integer::sum);
BaseKnife baseKnifeWrapper = new BaseKnife();
baseKnifeWrapper.setPlanSheet(planSheet);
baseKnifeWrapper.setKnifeCode(technologyBom.getKnifeCode());
List baseKnifePlanSheetList = baseKnifeMapper.selectBaseKnifeList(baseKnifeWrapper);
- if (baseKnifePlanSheetList.size() < technologyBom.getKnifeCount()) return false;
+ if (baseKnifePlanSheetList.size() < coutMap.get(technologyBom.getKnifeCode())) return false;
}
return true;
@@ -500,7 +510,7 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
// 检查订单完成状态
@Transactional
- public void createOutTask(String planSheet){
+ public void createOutTask(String planSheet) throws IOException {
// 构建出库计划
WmsOutPlan outPlan = new WmsOutPlan();
outPlan.setPlanCode(planSheet);
@@ -521,12 +531,16 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
List baseTechnologyBomList = baseTechnologyBomMapper.selectBaseTechnologyBomList(baseTechnologyBomWrapper);
// 判断订单锁定的物料是否足够
- for (BaseTechnologyBom technologyBom : baseTechnologyBomList) {
- BaseKnife baseKnifeWrapper = new BaseKnife();
+ Map coutMap = new HashMap<>();
+ for (BaseTechnologyBom technologyBom : baseTechnologyBomList)
+ coutMap.merge(technologyBom.getKnifeCode(), technologyBom.getKnifeCount(), Integer::sum);
+
+ for (Map.Entry item : coutMap.entrySet()) {
+ BaseKnife baseKnifeWrapper = new BaseKnife();
baseKnifeWrapper.setPlanSheet(planSheet);
- baseKnifeWrapper.setKnifeCode(technologyBom.getKnifeCode());
+ baseKnifeWrapper.setKnifeCode(item.getKey());
List baseKnifeLockedList = baseKnifeMapper.selectBaseKnifeList(baseKnifeWrapper);
- if (baseKnifeLockedList.size() == technologyBom.getKnifeCount()) baseKnifeResultList.addAll(baseKnifeLockedList);
+ if (baseKnifeLockedList.size() == item.getValue()) baseKnifeResultList.addAll(baseKnifeLockedList);
}
String batchNum = "SCZBPC01";
@@ -619,5 +633,69 @@ public class WmsZdTaskServiceImpl implements IWmsZdTaskService
productionArrangements.setStatus(1);
productionArrangementsMapper.updateProductionArrangements(productionArrangements);
+
+ // 给产线控制系统发指令
+ productionArrangementsIsOk(productionArrangements);
+ }
+
+ // 调用生产准备完成接口
+ public void productionArrangementsIsOk(ProductionArrangements productionArrangements) throws IOException {
+ // 产线控制系统生产准备完成接口
+ String url = myConfig.getProductionControlPath() + "/cutterapi/cutComplete";
+
+ // 请求客户端
+ OkHttpClient client = new OkHttpClient();
+
+ // 构建请求数据
+ Map requestMap = new HashMap<>();
+ requestMap.put("prodordercode", productionArrangements.getPlanSheet());
+ requestMap.put("result", "0");
+ requestMap.put("completetime", CalendarUtil.getDateTimeStr());
+
+ // 获取工艺信息
+ BaseTechnologyBom technologyBomWrapper = new BaseTechnologyBom();
+ technologyBomWrapper.setTechnologyCode(productionArrangements.getTechnologyCode());
+ List technologyBomList = baseTechnologyBomMapper.selectBaseTechnologyBomList(technologyBomWrapper);
+
+ BaseKnife baseKnifeWrapper = new BaseKnife();
+ baseKnifeWrapper.setPlanSheet(productionArrangements.getPlanSheet());
+
+ // 获取刀具信息
+ List