fix:删除金蝶依赖性
This commit is contained in:
@@ -200,20 +200,6 @@
|
|||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.20</version>
|
<version>8.0.20</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.gson</groupId>
|
|
||||||
<artifactId>gson-jar</artifactId>
|
|
||||||
<version>2.8.0</version>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>/Users/mima0000/Desktop/gson-2.8.0.jar</systemPath>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.kingdee.bos.webapi</groupId>
|
|
||||||
<artifactId>kingdee-jar</artifactId>
|
|
||||||
<version>8.0.6</version>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>/Users/mima0000/Desktop/k3cloud-webapi-sdk8.0.6.jar</systemPath>
|
|
||||||
</dependency>
|
|
||||||
<!-- druid数据源驱动 -->
|
<!-- druid数据源驱动 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
|||||||
@@ -1,16 +1,8 @@
|
|||||||
package org.nl.common.utils;
|
package org.nl.common.utils;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.github.javaparser.utils.Log;
|
|
||||||
import com.kingdee.bos.webapi.entity.*;
|
|
||||||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -27,125 +19,17 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class ErpServiceUtils {
|
public class ErpServiceUtils {
|
||||||
@Resource
|
|
||||||
ErpSec erpSec;
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建api
|
|
||||||
*/
|
|
||||||
public K3CloudApi getCloudApi() {
|
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
|
||||||
return new K3CloudApi(identifyInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param query 查询条件
|
* @param query 查询条件
|
||||||
*/
|
*/
|
||||||
public JSONArray queryBills(ErpQuery query) {
|
public JSONArray queryBills(Object query) {
|
||||||
if (StringUtils.isBlank(query.getFormId())) {
|
return null;
|
||||||
throw new BadRequestException("参数异常");
|
|
||||||
}
|
|
||||||
boolean islock = lock.tryLock();
|
|
||||||
List<Object> result = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
if (islock) {
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
K3CloudApi cloudApi = getCloudApi();
|
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
|
||||||
for (List<Object> list : lists) {
|
|
||||||
for (Object r : list) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
log.error("单据同步失败,没有找到FID");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
OperateParam param = new OperateParam();
|
|
||||||
param.setId(fid);
|
|
||||||
OperatorResult view = cloudApi.view(query.getFormId(), param);
|
|
||||||
RepoStatus status = view.getResult().getResponseStatus();
|
|
||||||
if (status.isIsSuccess()) {
|
|
||||||
new ArrayList<>();
|
|
||||||
result.add(view.getResult().getResult());
|
|
||||||
} else {
|
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
|
||||||
log.error("查询ID [{}] 时出现异常: {}", fid, errors.stream().map(RepoError::getMessage).collect(Collectors.joining(",")));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询ID [{}] 时出现异常: {}", fid, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new BadRequestException(ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JSON.parseArray(JSON.toJSONString(result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单据保存
|
|
||||||
*/
|
|
||||||
public JSONObject save(JSONObject from) {
|
|
||||||
String result;
|
|
||||||
try {
|
|
||||||
//要回传的json数据
|
|
||||||
String json = from.toJSONString();
|
|
||||||
result = getCloudApi().save(from.getString("formid"), json);
|
|
||||||
from.put("result", result);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.error(ex.getMessage());
|
|
||||||
from.put("result", ex.getMessage());
|
|
||||||
}
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单据审核
|
|
||||||
*/
|
|
||||||
public JSONObject audit(JSONObject from) {
|
|
||||||
String result;
|
|
||||||
//执行回传
|
|
||||||
try {
|
|
||||||
String json = from.toJSONString();
|
|
||||||
result = getCloudApi().audit(from.getString("formid"), json);
|
|
||||||
from.put("result", result);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.error(ex.getMessage());
|
|
||||||
from.put("result", ex.getMessage());
|
|
||||||
}
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单据下推
|
|
||||||
*/
|
|
||||||
public JSONObject push(JSONObject from) {
|
|
||||||
String result;
|
|
||||||
//执行回传
|
|
||||||
try {
|
|
||||||
//要回传的json数据
|
|
||||||
String json = from.toJSONString();
|
|
||||||
result = getCloudApi().push(from.getString("TargetFormId"), json);
|
|
||||||
from.put("result", result);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.error(ex.getMessage());
|
|
||||||
from.put("result", ex.getMessage());
|
|
||||||
}
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,160 +0,0 @@
|
|||||||
package org.nl.wms.external_system.erp;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
||||||
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
|
||||||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.nl.common.utils.ErpServiceUtils;
|
|
||||||
import org.nl.wms.base_manage.bsrealstorattr.service.impl.StIvtBsrealstorattrServiceImpl;
|
|
||||||
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
|
||||||
import org.nl.wms.base_manage.material.service.impl.MdMeMaterialbaseServiceImpl;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 表单同步配置表 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author generator
|
|
||||||
* @since 2024-04-11
|
|
||||||
* 表单同步规则:从erp拉取数据
|
|
||||||
* |
|
|
||||||
* 单据结构表获取单据需要的字段<---->单据配置的映射关系获取到需要字段的值
|
|
||||||
* |
|
|
||||||
* 结构表has_child:单据明细的单据结构表字段<---->单据配置的映射关系获取到需要字段的值
|
|
||||||
* |
|
|
||||||
* 保存明细跟主单据
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class SyncErpService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ErpSec erpSec;
|
|
||||||
@Resource
|
|
||||||
private ErpServiceUtils erpServiceUtils;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
MdMeMaterialbaseServiceImpl mdMeMaterialbaseServiceImpl;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StIvtBsrealstorattrServiceImpl stIvtBsrealstorattrServiceImpl;
|
|
||||||
|
|
||||||
|
|
||||||
public List<Object> syncMaterialData(SyncFormMapping syncFormMapping) {
|
|
||||||
List<MdMeMaterialbase> list = mdMeMaterialbaseServiceImpl.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_id, "0"));
|
|
||||||
list.forEach(r -> {
|
|
||||||
syncMaterial(r.getMaterial_code());
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Object> syncMaterial(String fNumber) {
|
|
||||||
List<Object> result = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
|
||||||
//String filterString = "FNumber ='" + fNumber + "'";
|
|
||||||
String filterString = "FUseOrgId='750572' AND FNumber ='" + fNumber + "'";
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId("BD_MATERIAL");
|
|
||||||
query.setFieldKeys("FMATERIALID,FNumber");
|
|
||||||
//query.setLimit(10);
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
|
||||||
log.info("同步ERP结果" + lists.size());
|
|
||||||
List<String> ids = new ArrayList<>();
|
|
||||||
if (ObjectUtils.isNotEmpty(lists)) {
|
|
||||||
List<Object> firstList = lists.get(0);
|
|
||||||
for (Object r : firstList) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
throw new RuntimeException("单据同步失败,没有找到FID");
|
|
||||||
}
|
|
||||||
ids.add(fid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ids.size() > 1) {
|
|
||||||
List<MdMeMaterialbase> sds = mdMeMaterialbaseServiceImpl.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_code, ids.get(1)));
|
|
||||||
if (ObjectUtils.isNotEmpty(sds)) {
|
|
||||||
if (StringUtils.isNotBlank(ids.get(0)) && StringUtils.isNotBlank(ids.get(1))) {
|
|
||||||
String id = ids.get(0);
|
|
||||||
String code = ids.get(1);
|
|
||||||
if (code.contains(".")) {
|
|
||||||
LambdaUpdateWrapper<MdMeMaterialbase> data = new LambdaUpdateWrapper<>();
|
|
||||||
data.eq(MdMeMaterialbase::getMaterial_code, code);
|
|
||||||
data.set(MdMeMaterialbase::getMaterial_id, id);
|
|
||||||
mdMeMaterialbaseServiceImpl.update(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
throw new RuntimeException("同步失败:" + ex.getMessage());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下推回传
|
|
||||||
*/
|
|
||||||
public JSONObject push(JSONObject from) {
|
|
||||||
return erpServiceUtils.push(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 合格证保存
|
|
||||||
*/
|
|
||||||
public JSONObject process(JSONObject from) {
|
|
||||||
return erpServiceUtils.save(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单据审核
|
|
||||||
*/
|
|
||||||
public JSONObject audit(JSONObject from) {
|
|
||||||
return erpServiceUtils.audit(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据同步
|
|
||||||
*/
|
|
||||||
public JSONArray syncData(SyncFormMapping syncFormMapping) {
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFormId(syncFormMapping.getForm_type());
|
|
||||||
query.setFieldKeys(syncFormMapping.getFieldKeys());
|
|
||||||
if (StringUtils.isNotBlank(syncFormMapping.getFilterString())) {
|
|
||||||
query.setFilterString(syncFormMapping.getFilterString());
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(syncFormMapping.getOrderString())) {
|
|
||||||
query.setOrderString(syncFormMapping.getOrderString());
|
|
||||||
}
|
|
||||||
query.setLimit(syncFormMapping.getLimit());
|
|
||||||
return erpServiceUtils.queryBills(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package org.nl.wms.external_system.erp.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import org.nl.common.TableDataInfo;
|
|
||||||
import org.nl.common.anno.Log;
|
|
||||||
import org.nl.common.domain.entity.PageQuery;
|
|
||||||
import org.nl.wms.dispatch_manage.task.service.ISchBaseTaskService;
|
|
||||||
import org.nl.wms.dispatch_manage.task.service.dao.SchBaseTask;
|
|
||||||
import org.nl.wms.dispatch_manage.task.service.dto.SchBaseTaskQuery;
|
|
||||||
import org.nl.wms.system_manage.service.quartz.task.SyncErpBillsScheduleService;
|
|
||||||
import org.nl.wms.system_manage.service.quartz.task.TaskScheduleService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 任务表 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author generator
|
|
||||||
* @since 2024-05-06
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("api/sycnErp")
|
|
||||||
public class SyncErpController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SyncErpBillsScheduleService syncErpBillsScheduleService;
|
|
||||||
|
|
||||||
@PostMapping("manualSync")
|
|
||||||
@Log("同步ERP")
|
|
||||||
public ResponseEntity<Object> manualSync(@RequestBody JSONObject param) {
|
|
||||||
//TODO:调用同步
|
|
||||||
String formType = param.getString("form_type");
|
|
||||||
String formCode = param.getString("form_code");
|
|
||||||
String startTime = null;
|
|
||||||
String endTime = null;
|
|
||||||
JSONArray datepick = param.getJSONArray("datepick");
|
|
||||||
if (datepick!=null && datepick.size()>0){
|
|
||||||
startTime = datepick.getString(0); //时间格式2024-12-12 12:00:00没选则为空
|
|
||||||
endTime = datepick.getString(1);
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(TableDataInfo.buildJson(syncErpBillsScheduleService.manualSync(formType,formCode,startTime,endTime)), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package org.nl.wms.external_system.erp.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class ErpQuery {
|
|
||||||
/**
|
|
||||||
* 业务对象表单Id(必录)
|
|
||||||
*/
|
|
||||||
private String FormId;
|
|
||||||
/**
|
|
||||||
* 需查询的字段key集合,字符串类型,格式:"key1,key2,..."(必录) 注(查询单据体内码,需加单据体Key和下划线,如:FEntryKey_FEntryId)
|
|
||||||
*/
|
|
||||||
private String FieldKeys = "FID";
|
|
||||||
/**
|
|
||||||
* 过滤条件,数组类型,如:[{"Left":"(","FieldName":"Field1","Compare":"67","Value":"111","Right":")","Logic":"0"},{"Left":"(","FieldName":"Field2","Compare":"67","Value":"222","Right":")","Logic":"0"}]
|
|
||||||
*/
|
|
||||||
private String FilterString;
|
|
||||||
/**
|
|
||||||
* 排序字段,字符串类型(非必录)
|
|
||||||
*/
|
|
||||||
private String OrderString;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* 返回总行数,整型(非必录)
|
|
||||||
*/
|
|
||||||
private Integer TopRowCount;
|
|
||||||
/**
|
|
||||||
* 开始行索引,整型(非必录)
|
|
||||||
*/
|
|
||||||
private Integer StartRow = 0;
|
|
||||||
/**
|
|
||||||
* 行数
|
|
||||||
*/
|
|
||||||
private Integer Limit = 100;
|
|
||||||
/**
|
|
||||||
* 表单所在的子系统内码,字符串类型(非必录)
|
|
||||||
*/
|
|
||||||
private Integer SubSystemId;
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package org.nl.wms.external_system.erp.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "kdapi")
|
|
||||||
@Data
|
|
||||||
public class ErpSec {
|
|
||||||
private String appId;
|
|
||||||
private String appSecret;
|
|
||||||
private String userName;
|
|
||||||
private String pwd;
|
|
||||||
private String serverUrl;
|
|
||||||
private String dCID;
|
|
||||||
}
|
|
||||||
@@ -7,8 +7,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.github.javaparser.utils.Log;
|
import com.github.javaparser.utils.Log;
|
||||||
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
|
||||||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
@@ -16,8 +15,6 @@ import org.nl.common.enums.StatusEnum;
|
|||||||
import org.nl.common.utils.ErpServiceUtils;
|
import org.nl.common.utils.ErpServiceUtils;
|
||||||
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
||||||
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
|
||||||
import org.nl.wms.flow_manage.flow.framework.process.nodeType.excess.impl.process.classprocess.ClassProcess;
|
import org.nl.wms.flow_manage.flow.framework.process.nodeType.excess.impl.process.classprocess.ClassProcess;
|
||||||
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
||||||
import org.nl.wms.pm_manage.form_data.service.dao.PmFormData;
|
import org.nl.wms.pm_manage.form_data.service.dao.PmFormData;
|
||||||
@@ -42,8 +39,6 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
|||||||
@Autowired
|
@Autowired
|
||||||
IPmFormDataService iPmFormDataService;
|
IPmFormDataService iPmFormDataService;
|
||||||
@Autowired
|
@Autowired
|
||||||
ErpSec erpSec;
|
|
||||||
@Autowired
|
|
||||||
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
||||||
@Resource
|
@Resource
|
||||||
private ErpServiceUtils erpServiceUtils;
|
private ErpServiceUtils erpServiceUtils;
|
||||||
@@ -53,137 +48,8 @@ public class SyncReceiptProcessHandler implements ClassProcess {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public JSONObject process(JSONObject from, JSONObject param) {
|
public JSONObject process(JSONObject from, JSONObject param) {
|
||||||
//执行回传单
|
|
||||||
String formType = from.getString("form_type");
|
|
||||||
String id = from.getString("id");
|
|
||||||
PmFormData pmFormData = iPmFormDataService.getById(id);
|
|
||||||
//要回传的json数据
|
|
||||||
JSONObject formData = pmFormData.getForm_data();
|
|
||||||
if (!formType.contains("RECEIPT")) {
|
|
||||||
throw new BadRequestException("回传失败:单据类型不是回传类型单据");
|
|
||||||
}
|
|
||||||
String formid = formData.getString("formid");
|
|
||||||
if (StringUtils.isEmpty(formid)) {
|
|
||||||
throw new BadRequestException("回传失败:回传数据form_data中数据格式不是formid,data类型");
|
|
||||||
}
|
|
||||||
handleBillEntity(pmFormData.getForm_type(), formData);
|
|
||||||
String json = formData.toJSONString();
|
|
||||||
try {
|
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
|
||||||
JSONObject res;
|
|
||||||
if (Integer.parseInt(StatusEnum.ERP_TYPE.code(formid)) > 22) {
|
|
||||||
String result = erpServiceUtils.audit(formData).getString("result");
|
|
||||||
res = JSONObject.parseObject(result);
|
|
||||||
} else {
|
|
||||||
String result = erpServiceUtils.save(formData).getString("result");
|
|
||||||
res = JSONObject.parseObject(result);
|
|
||||||
}
|
|
||||||
JSONObject responseStatus = res.getJSONObject("Result").getJSONObject("ResponseStatus");
|
|
||||||
boolean isSuccess = responseStatus.getBooleanValue("IsSuccess");
|
|
||||||
JSONArray errors = responseStatus.getJSONArray("Errors");
|
|
||||||
String errorMessages = "";
|
|
||||||
if (ObjectUtils.isNotEmpty(errors)) {
|
|
||||||
errorMessages = errors.stream()
|
|
||||||
.map(error -> ((JSONObject) error).getString("Message"))
|
|
||||||
.collect(Collectors.joining("; "));
|
|
||||||
}
|
|
||||||
LambdaUpdateWrapper<PmFormData> updateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
updateWrapper.eq(PmFormData::getId, pmFormData.getId());
|
|
||||||
updateWrapper.set(PmFormData::getUpdate_time, DateUtil.now());
|
|
||||||
if (isSuccess) {
|
|
||||||
updateWrapper.set(PmFormData::getStatus, StatusEnum.FORM_STATUS.code("完成"));
|
|
||||||
updateWrapper.set(PmFormData::getRemark, "回执单创建成功,回传Erp数据为:" + responseStatus.getJSONArray("SuccessEntitys").toJSONString());
|
|
||||||
} else {
|
|
||||||
updateWrapper.set(PmFormData::getStatus, StatusEnum.FORM_STATUS.code("暂停"));
|
|
||||||
updateWrapper.set(PmFormData::getRemark,"回执单创建失败,原因为:"+errorMessages + ",回传Erp数据为:" + json);
|
|
||||||
}
|
|
||||||
iPmFormDataService.update(updateWrapper);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LambdaUpdateWrapper<PmFormData> updateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
updateWrapper.eq(PmFormData::getId, pmFormData.getId());
|
|
||||||
updateWrapper.set(PmFormData::getRemark, "回执单创建失败,原因为:" + ex.getMessage() + ",回传Erp数据为:" + json);
|
|
||||||
iPmFormDataService.update(updateWrapper);
|
|
||||||
Log.error(ex.getMessage());
|
|
||||||
}
|
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleBillEntity(String formType, JSONObject formData) {
|
|
||||||
JSONObject model = formData.getJSONObject("Model");
|
|
||||||
if (model == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray fEntityArray = formData.getJSONObject("Model").getJSONArray("FEntity");
|
|
||||||
//判断生产入库的手工录入与MRP生成方式需回传不同的源单信息
|
|
||||||
if ("RECEIPT_PRD".equals(formType)) {
|
|
||||||
for (int i = 0; i < fEntityArray.size(); i++) {
|
|
||||||
JSONObject fEntity = fEntityArray.getJSONObject(i);
|
|
||||||
if ("0".equals(fEntity.getString("FSrcEntryId"))) {
|
|
||||||
//查询工序汇报单
|
|
||||||
ErpQuery reportQuery = new ErpQuery();
|
|
||||||
reportQuery.setFilterString("FMoNumber ='" + fEntity.getString("FMoBillNo") + "'");
|
|
||||||
reportQuery.setOrderString("FId desc");
|
|
||||||
reportQuery.setFormId("SFC_OperationReport");
|
|
||||||
JSONArray jsonArray = erpServiceUtils.queryBills(reportQuery);
|
|
||||||
JSONArray optRptEntry = jsonArray.getJSONObject(0).getJSONArray("OptRptEntry");
|
|
||||||
if (fEntity.containsKey("FSrcEntryId")) {
|
|
||||||
//增加源单分录id
|
|
||||||
fEntity.put("FSrcEntryId", optRptEntry.getJSONObject(0).getString("SrcEntryId"));
|
|
||||||
}
|
|
||||||
Map<String, Object> linkedMap = new LinkedHashMap<>();
|
|
||||||
for (String key : fEntity.keySet()) {
|
|
||||||
linkedMap.put(key, fEntity.get(key));
|
|
||||||
}
|
|
||||||
Map<String, Object> tempMap = new LinkedHashMap<>();
|
|
||||||
for (Map.Entry<String, Object> entry : linkedMap.entrySet()) {
|
|
||||||
tempMap.put(entry.getKey(), entry.getValue());
|
|
||||||
if ("FMoEntryId".equals(entry.getKey())) {
|
|
||||||
//源单编号为工序汇报单号
|
|
||||||
tempMap.put("FSrcBillNo", jsonArray.getJSONObject(0).getString("BillNo"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fEntity.clear();
|
|
||||||
fEntity.putAll(tempMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//判断生产领料单的批次与辅助单位
|
|
||||||
if ("RECEIPT_PickMtrl".equals(formType)) {
|
|
||||||
for (int i = 0; i < fEntityArray.size(); i++) {
|
|
||||||
JSONObject fEntity = fEntityArray.getJSONObject(i);
|
|
||||||
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_code,JSON.parseObject(fEntity.getString("FMaterialId")).getString("FNumber")));
|
|
||||||
MdMeMaterialbase materialInfo = materialList.get(0);
|
|
||||||
//没有启用批次号
|
|
||||||
if ("0".equals(materialInfo.getPrint_no())) {
|
|
||||||
if (fEntity.containsKey("FLot")) {
|
|
||||||
fEntity.remove("FLot");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//辅助单位
|
|
||||||
Map<String, Object> linkedMap = new LinkedHashMap<>();
|
|
||||||
for (String key : fEntity.keySet()) {
|
|
||||||
linkedMap.put(key, fEntity.get(key));
|
|
||||||
}
|
|
||||||
Map<String, Object> tempMap = new LinkedHashMap<>();
|
|
||||||
for (Map.Entry<String, Object> entry : linkedMap.entrySet()) {
|
|
||||||
tempMap.put(entry.getKey(), entry.getValue());
|
|
||||||
if (!"0".equals(materialInfo.getAssist_unit_id()) && "FUnitID".equals(entry.getKey())) {
|
|
||||||
JSONObject fUnit = new JSONObject();
|
|
||||||
fUnit.put("FNumber", materialInfo.getAssist_unit_id());
|
|
||||||
tempMap.put("FSecUnitId", fUnit);
|
|
||||||
}
|
|
||||||
if ("FStockId".equals(entry.getKey())) {
|
|
||||||
JSONObject fStockId = new JSONObject();
|
|
||||||
//tofix 目前都入料箱库
|
|
||||||
fStockId.put("FNumber", "25");
|
|
||||||
tempMap.put("FStockId", fStockId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fEntity.clear();
|
|
||||||
fEntity.putAll(tempMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class PdaInController {
|
|||||||
@GetMapping("/getCertificateInfo/{id}")
|
@GetMapping("/getCertificateInfo/{id}")
|
||||||
@Log("根据合格证查询物料信息")
|
@Log("根据合格证查询物料信息")
|
||||||
public ResponseEntity<Object> getCertificateInfo(@PathVariable String id) {
|
public ResponseEntity<Object> getCertificateInfo(@PathVariable String id) {
|
||||||
return new ResponseEntity<>(pdaIOService.getCertificateInfo(id), HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
@@ -21,8 +20,6 @@ import org.nl.wms.base_manage.measure.service.dao.BmMeasureUnit;
|
|||||||
import org.nl.wms.base_manage.measure.service.impl.BmMeasureUnitServiceImpl;
|
import org.nl.wms.base_manage.measure.service.impl.BmMeasureUnitServiceImpl;
|
||||||
import org.nl.wms.config_manage.form_struc.service.IBmFormStrucService;
|
import org.nl.wms.config_manage.form_struc.service.IBmFormStrucService;
|
||||||
import org.nl.wms.config_manage.form_struc.service.dao.BmFormStruc;
|
import org.nl.wms.config_manage.form_struc.service.dao.BmFormStruc;
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
|
||||||
import org.nl.wms.md_manage.vehicleMater.service.IMdPbVehicleMaterService;
|
import org.nl.wms.md_manage.vehicleMater.service.IMdPbVehicleMaterService;
|
||||||
import org.nl.wms.md_manage.vehicleMater.service.dao.MdPbVehicleMater;
|
import org.nl.wms.md_manage.vehicleMater.service.dao.MdPbVehicleMater;
|
||||||
import org.nl.wms.pda_manage.iostorage.server.dto.PdaFormOutDtl;
|
import org.nl.wms.pda_manage.iostorage.server.dto.PdaFormOutDtl;
|
||||||
@@ -42,7 +39,7 @@ import org.nl.wms.stor_manage.struct.service.dao.StructAssignQty;
|
|||||||
import org.nl.wms.stor_manage.struct.service.dto.StructattrVechielDto;
|
import org.nl.wms.stor_manage.struct.service.dto.StructattrVechielDto;
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.impl.SyncFormMappingServiceImpl;
|
import org.nl.wms.sync_manage.service.form_mapping.impl.SyncFormMappingServiceImpl;
|
||||||
import org.nl.wms.system_manage.service.quartz.task.SyncErpBillsScheduleService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -60,14 +57,11 @@ import java.util.stream.Collectors;
|
|||||||
@Service
|
@Service
|
||||||
public class PdaIOService {
|
public class PdaIOService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ErpSec erpSec;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ErpServiceUtils erpServiceUtils;
|
private ErpServiceUtils erpServiceUtils;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SyncErpBillsScheduleService syncErpBillsScheduleService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SyncFormMappingServiceImpl syncFormMappingServiceImpl;
|
private SyncFormMappingServiceImpl syncFormMappingServiceImpl;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -310,199 +304,4 @@ public class PdaIOService {
|
|||||||
private void pdaTaskOpen(StIvtIostorinv mst) {
|
private void pdaTaskOpen(StIvtIostorinv mst) {
|
||||||
iStIvtIostorinvService.taskOpen((JSONObject) JSONObject.toJSON(mst));
|
iStIvtIostorinvService.taskOpen((JSONObject) JSONObject.toJSON(mst));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PmFormData getCertificateInfo(String id) {
|
|
||||||
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
|
|
||||||
PmFormData result = new PmFormData();
|
|
||||||
try {
|
|
||||||
if (id.contains("OP") || id.contains("op")) {
|
|
||||||
//生产入库
|
|
||||||
getOpBills(id, result, k3CloudApi);
|
|
||||||
} else {
|
|
||||||
//采购入库
|
|
||||||
ReceiveBillData receiveBillData = pmFormDataMapper.queryReceiveBill(id);
|
|
||||||
if (receiveBillData != null) {
|
|
||||||
String pForm_data = receiveBillData.getPForm_data();
|
|
||||||
String dForm_data = receiveBillData.getDForm_data();
|
|
||||||
JSONObject pFormJson = JSONObject.parseObject(pForm_data);
|
|
||||||
JSONObject dFormJson = JSONObject.parseObject(dForm_data);
|
|
||||||
if (ObjectUtils.isNotEmpty(dFormJson) && ObjectUtils.isNotEmpty(pFormJson)) {
|
|
||||||
result.setBillNo(receiveBillData.getPCode());
|
|
||||||
result.setBusinessType(StringUtils.isBlank(pFormJson.getString("businessType")) ? "CG" : dFormJson.getString("businessType"));
|
|
||||||
result.setPrdOrgId(pFormJson.getString("DemandOrgId"));
|
|
||||||
result.setStockOrgId(pFormJson.getString("StockOrgId"));
|
|
||||||
result.setSupplierId(pFormJson.getString("SupplierId"));
|
|
||||||
result.setMaterial_id(receiveBillData.getMaterial_id());
|
|
||||||
result.setPcsn(StringUtils.isBlank(receiveBillData.getPcsn()) ? "001" : receiveBillData.getPcsn());
|
|
||||||
result.setPurchaserId(pFormJson.getString("PurchaserId"));
|
|
||||||
result.setUnit_id(receiveBillData.getUnit_id());
|
|
||||||
result.setQty(new BigDecimal(dFormJson.getString("ActReceiveQty")));
|
|
||||||
result.setTaxPrice(dFormJson.getString("taxPrice"));
|
|
||||||
result.setMoNumber(receiveBillData.getPCode());
|
|
||||||
result.setMoEntryId(receiveBillData.getDId().substring(0, receiveBillData.getDId().indexOf("$")));
|
|
||||||
//源单信息校验
|
|
||||||
if (StringUtils.isBlank(dFormJson.getString("OrderBillNo"))) {
|
|
||||||
result.setSrcBillNo(null);
|
|
||||||
} else {
|
|
||||||
if (dFormJson.getString("OrderBillNo").equals("0")) {
|
|
||||||
result.setSrcBillNo(null);
|
|
||||||
} else {
|
|
||||||
result.setSrcBillNo(dFormJson.getString("OrderBillNo"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("查询合格证关联的收料通知单信息异常!");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("未查询到该合格证信息!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new BadRequestException("未查询到该合格证信息!");
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(result.getUnit_id())) {
|
|
||||||
List<BmMeasureUnit> bmMeasureUnitList = bmMeasureUnitServiceImpl.list(new LambdaQueryWrapper<BmMeasureUnit>().eq(BmMeasureUnit::getUnit_id, result.getUnit_id()));
|
|
||||||
if (ObjectUtils.isNotEmpty(bmMeasureUnitList)) {
|
|
||||||
result.setUnit_name(bmMeasureUnitList.get(0).getUnit_name());
|
|
||||||
result.setUnit_code(bmMeasureUnitList.get(0).getUnit_code());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(result.getMaterial_id())) {
|
|
||||||
List<MdMeMaterialbase> materialbaseList = mdMeMaterialbaseServiceImpl.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_id, result.getMaterial_id()));
|
|
||||||
//本地存在改物料信息
|
|
||||||
if (ObjectUtils.isNotEmpty(materialbaseList)) {
|
|
||||||
result.setMaterial_code(materialbaseList.get(0).getMaterial_code());
|
|
||||||
result.setMaterial_spec(materialbaseList.get(0).getMaterial_spec());
|
|
||||||
result.setMaterial_name(materialbaseList.get(0).getMaterial_name());
|
|
||||||
} else {
|
|
||||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
|
||||||
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
|
||||||
syncErpBillsScheduleService.queryMaterialInfo(materialMappingString, "BD_MATERIAL", false, result.getMaterial_id(), k3CloudApi);
|
|
||||||
List<MdMeMaterialbase> materialList = mdMeMaterialbaseServiceImpl.list(new LambdaQueryWrapper<MdMeMaterialbase>().eq(MdMeMaterialbase::getMaterial_id, result.getMaterial_id()));
|
|
||||||
result.setMaterial_code(materialList.get(0).getMaterial_code());
|
|
||||||
result.setMaterial_spec(materialList.get(0).getMaterial_spec());
|
|
||||||
result.setMaterial_name(materialList.get(0).getMaterial_name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isNotBlank(result.getStockId())) {
|
|
||||||
List<StIvtBsrealstorattr> storattrList = stIvtBsrealstorattrServiceImpl.list(new LambdaQueryWrapper<StIvtBsrealstorattr>().eq(StIvtBsrealstorattr::getId, result.getStockId()));
|
|
||||||
if (ObjectUtils.isNotEmpty(storattrList)) {
|
|
||||||
result.setStockId(storattrList.get(0).getStor_code());
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
result.setStockId("0");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void getOpBills(String id, PmFormData result, K3CloudApi k3CloudApi) throws Exception {
|
|
||||||
String filterString = "FBillNo = '" + id + "'";
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId("SFC_OperationPlanning");
|
|
||||||
query.setFieldKeys("FBillNo,FProOrgId,FStockInOrgId,FProductId,FProductName,FProSpecification,FMOQty,FMOUnitId,FOwnerId,FLot,FProDepartmentId,FMONumber,FMOEntrySeq,FOwnerTypeId");
|
|
||||||
query.setLimit(1);
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
List<List<Object>> lists = k3CloudApi.executeBillQuery(jsonString);
|
|
||||||
if (ObjectUtils.isNotEmpty(lists)) {
|
|
||||||
List<Object> dataList = lists.get(0);
|
|
||||||
if (ObjectUtils.isNotEmpty(dataList)) {
|
|
||||||
String moNumber = dataList.get(11).toString();
|
|
||||||
String moSeq = dataList.get(12).toString();
|
|
||||||
String moEntryId;
|
|
||||||
String moId;
|
|
||||||
String prdOrgId;
|
|
||||||
String stockOrgId;
|
|
||||||
String ownerIdHead_Id;
|
|
||||||
String workShopId1;
|
|
||||||
BigDecimal qty;
|
|
||||||
String ownerId_Id;
|
|
||||||
String stockId;
|
|
||||||
String keeperId;
|
|
||||||
String srcBillNo;
|
|
||||||
JSONObject pFormJson;
|
|
||||||
JSONObject dFormJson;
|
|
||||||
//查询本地生产订单信息
|
|
||||||
ReceiveBillData prdMoBillData = pmFormDataMapper.queryOrderStockId(dataList.get(11).toString(), dataList.get(12).toString());
|
|
||||||
if (prdMoBillData != null) {
|
|
||||||
String pForm_data = prdMoBillData.getPForm_data();
|
|
||||||
String dForm_data = prdMoBillData.getDForm_data();
|
|
||||||
pFormJson = JSONObject.parseObject(pForm_data);
|
|
||||||
dFormJson = JSONObject.parseObject(dForm_data);
|
|
||||||
if (ObjectUtils.isEmpty(dFormJson) || ObjectUtils.isEmpty(pFormJson)) {
|
|
||||||
throw new BadRequestException("查询合格证关联的生产订单信息异常!");
|
|
||||||
}
|
|
||||||
moId = prdMoBillData.getPId().substring(0, prdMoBillData.getPId().indexOf("$"));
|
|
||||||
prdOrgId = pFormJson.getString("PrdOrgId");
|
|
||||||
moEntryId = prdMoBillData.getDId().substring(0, prdMoBillData.getDId().indexOf("$"));
|
|
||||||
stockOrgId = dFormJson.getString("StockOrgId");
|
|
||||||
ownerIdHead_Id = dFormJson.getString("InStockOwnerId");
|
|
||||||
workShopId1 = dFormJson.getString("product_code");
|
|
||||||
qty = prdMoBillData.getQty();
|
|
||||||
ownerId_Id = dFormJson.getString("InStockOwnerId");
|
|
||||||
//tofix 目前都入料箱库
|
|
||||||
stockId = "25";
|
|
||||||
keeperId = dFormJson.getString("StockOrgId");
|
|
||||||
srcBillNo = dFormJson.getString("saleOrderEntryId");
|
|
||||||
} else {
|
|
||||||
query.setFieldKeys("FID");
|
|
||||||
query.setFilterString("FBillNo ='" + moNumber + "'");
|
|
||||||
query.setFormId("PRD_MO");
|
|
||||||
JSONArray moBills = erpServiceUtils.queryBills(query);
|
|
||||||
JSONObject moBill = moBills.getJSONObject(0);
|
|
||||||
moId = moBill.getString("Id");
|
|
||||||
prdOrgId = JSON.parseObject(moBill.getString("PrdOrgId")).getString("FNumber");
|
|
||||||
JSONArray moTreeEntity = moBills.getJSONObject(0).getJSONArray("TreeEntity");
|
|
||||||
JSONObject entity = moTreeEntity.stream()
|
|
||||||
.map(r -> (JSONObject) r)
|
|
||||||
.filter(json -> moSeq.equals(json.getString("Seq")))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
if (entity != null) {
|
|
||||||
moEntryId = entity.getString("Id");
|
|
||||||
stockOrgId = JSON.parseObject(entity.getString("StockInOrgId")).getString("Number");
|
|
||||||
ownerIdHead_Id = JSON.parseObject(entity.getString("InStockOwnerId")).getString("Number");
|
|
||||||
workShopId1 = JSON.parseObject(entity.getString("WorkShopID")).getString("Number");
|
|
||||||
qty = new BigDecimal(entity.getString("Qty"));
|
|
||||||
ownerId_Id = JSON.parseObject(entity.getString("InStockOwnerId")).getString("Number");
|
|
||||||
keeperId = JSON.parseObject(entity.getString("InStockOwnerId")).getString("Number");
|
|
||||||
srcBillNo = entity.getString("SaleOrderEntryId");
|
|
||||||
//tofix 目前都入料箱库
|
|
||||||
stockId = "25";
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("查询合格证关联的生产订单明细信息异常!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.setBillNo(dataList.get(0).toString());
|
|
||||||
result.setPrdOrgId(prdOrgId);
|
|
||||||
result.setStockOrgId(stockOrgId);
|
|
||||||
result.setOwnerIdHead_Id(ownerIdHead_Id);
|
|
||||||
result.setMoNumber(moNumber);
|
|
||||||
result.setMoId(moId);
|
|
||||||
result.setMoEntryId(moEntryId);
|
|
||||||
result.setMaterial_id(dataList.get(3).toString());
|
|
||||||
result.setPcsn(dataList.get(11).toString());
|
|
||||||
result.setUnit_id(dataList.get(7).toString());
|
|
||||||
result.setWorkShopId1(workShopId1);
|
|
||||||
result.setQty(qty);
|
|
||||||
result.setMustQty(qty);
|
|
||||||
result.setInStockType("1");
|
|
||||||
result.setOwnerTypeId(StringUtils.isBlank(dataList.get(13).toString()) ? "BD_OwnerOrg" : dataList.get(13).toString());
|
|
||||||
result.setOwnerId_Id(ownerId_Id);
|
|
||||||
result.setStockStatusId("KCZT01_SYS");
|
|
||||||
result.setStockId(stockId);
|
|
||||||
result.setKeeperId(keeperId);
|
|
||||||
result.setKeeperTypeId("BD_KeeperOrg");
|
|
||||||
result.setSrcBillNo(srcBillNo);
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("查询合格证关联的生产订单信息异常!");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new BadRequestException("未查询到该合格证信息!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import org.nl.wms.stor_manage.struct.service.IStIvtStructattrService;
|
|||||||
import org.nl.wms.stor_manage.struct.service.dao.StructAssignQty;
|
import org.nl.wms.stor_manage.struct.service.dao.StructAssignQty;
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.ISyncFormMappingService;
|
import org.nl.wms.sync_manage.service.form_mapping.ISyncFormMappingService;
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
||||||
import org.nl.wms.system_manage.service.quartz.task.SyncErpBillsScheduleService;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
@@ -88,10 +87,6 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IStIvtStructattrService iStIvtStructattrService;
|
private IStIvtStructattrService iStIvtStructattrService;
|
||||||
|
|
||||||
@Lazy
|
|
||||||
@Autowired
|
|
||||||
private SyncErpBillsScheduleService syncErpBillsScheduleService;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer syncFormData(String form_type, String dataString) {
|
public Integer syncFormData(String form_type, String dataString) {
|
||||||
@@ -113,60 +108,7 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String syncFeedBack(JSONObject jsonData) {
|
public String syncFeedBack(JSONObject jsonData) {
|
||||||
//执行回传单
|
return "message";
|
||||||
PmFormData pmFormData = jsonData.toJavaObject(PmFormData.class);
|
|
||||||
if (Integer.parseInt(pmFormData.getStatus()) > 30) {
|
|
||||||
throw new BadRequestException("该单据状态为已完成,无需再次回传!");
|
|
||||||
}
|
|
||||||
JSONObject formData = pmFormData.getForm_data();
|
|
||||||
//要回传的json数据
|
|
||||||
String formid = formData.getString("formid");
|
|
||||||
if (StringUtils.isEmpty(formid)) {
|
|
||||||
throw new BadRequestException("回传失败:回传数据form_data中数据格式不是formid,data类型");
|
|
||||||
}
|
|
||||||
SyncReceiptProcessHandler.handleBillEntity(pmFormData.getForm_type(), formData);
|
|
||||||
String json = formData.toJSONString();
|
|
||||||
String message = "";
|
|
||||||
try {
|
|
||||||
JSONObject res;
|
|
||||||
if (Integer.parseInt(StatusEnum.ERP_TYPE.code(formid)) > 22) {
|
|
||||||
String result = erpServiceUtils.audit(formData).getString("result");
|
|
||||||
res = JSONObject.parseObject(result);
|
|
||||||
} else {
|
|
||||||
String result = erpServiceUtils.save(formData).getString("result");
|
|
||||||
;
|
|
||||||
res = JSONObject.parseObject(result);
|
|
||||||
}
|
|
||||||
JSONObject responseStatus = res.getJSONObject("Result").getJSONObject("ResponseStatus");
|
|
||||||
boolean isSuccess = responseStatus.getBooleanValue("IsSuccess");
|
|
||||||
JSONArray errors = responseStatus.getJSONArray("Errors");
|
|
||||||
if (ObjectUtils.isNotEmpty(errors)) {
|
|
||||||
message = errors.stream()
|
|
||||||
.map(error -> ((JSONObject) error).getString("Message"))
|
|
||||||
.collect(Collectors.joining("; "));
|
|
||||||
}
|
|
||||||
LambdaUpdateWrapper<PmFormData> updateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
updateWrapper.eq(PmFormData::getId, pmFormData.getId());
|
|
||||||
updateWrapper.set(PmFormData::getUpdate_time, DateUtil.now());
|
|
||||||
if (isSuccess) {
|
|
||||||
message = responseStatus.getJSONArray("SuccessEntitys").toJSONString();
|
|
||||||
message = "回执单创建成功,回传Erp数据为:" + message;
|
|
||||||
updateWrapper.set(PmFormData::getStatus, StatusEnum.FORM_STATUS.code("完成"));
|
|
||||||
updateWrapper.set(PmFormData::getRemark, message);
|
|
||||||
} else {
|
|
||||||
message = "回执单创建失败,原因为:" + message + ",回传Erp数据为:" + json;
|
|
||||||
updateWrapper.set(PmFormData::getStatus, StatusEnum.FORM_STATUS.code("暂停"));
|
|
||||||
updateWrapper.set(PmFormData::getRemark, message);
|
|
||||||
}
|
|
||||||
iPmFormDataService.update(updateWrapper);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LambdaUpdateWrapper<PmFormData> updateWrapper = new LambdaUpdateWrapper<>();
|
|
||||||
updateWrapper.eq(PmFormData::getId, pmFormData.getId());
|
|
||||||
updateWrapper.set(PmFormData::getRemark, "回执单创建失败,原因为:" + ex.getMessage() + ",回传Erp数据为:" + json);
|
|
||||||
iPmFormDataService.update(updateWrapper);
|
|
||||||
Log.error(ex.getMessage());
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -279,7 +221,6 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
|
|||||||
if (ObjectUtils.isNotEmpty(list)) {
|
if (ObjectUtils.isNotEmpty(list)) {
|
||||||
JSONArray mappingJson = list.get(0).getMapping_json();
|
JSONArray mappingJson = list.get(0).getMapping_json();
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
String mappingString = JSON.toJSONString(mappingJson);
|
||||||
syncErpBillsScheduleService.syncData(mappingString, list.get(0).getForm_type(), list.get(0).getDtl_split(), query.getCode());
|
|
||||||
List<PmFormDataDto> pmFormData = this.baseMapper.queryTree2(query);
|
List<PmFormDataDto> pmFormData = this.baseMapper.queryTree2(query);
|
||||||
if (!CollectionUtils.isEmpty(pmFormData)) {
|
if (!CollectionUtils.isEmpty(pmFormData)) {
|
||||||
handleFormDatas(pmFormData);
|
handleFormDatas(pmFormData);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.nl.common.anno.Log;
|
|||||||
import org.nl.common.domain.entity.PageQuery;
|
import org.nl.common.domain.entity.PageQuery;
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
import org.nl.common.domain.exception.BadRequestException;
|
||||||
import org.nl.common.utils.FileUtil;
|
import org.nl.common.utils.FileUtil;
|
||||||
import org.nl.wms.external_system.erp.SyncErpService;
|
import org.nl.common.utils.ListOf;
|
||||||
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
||||||
import org.nl.wms.pm_manage.form_data.service.dao.PmFormData;
|
import org.nl.wms.pm_manage.form_data.service.dao.PmFormData;
|
||||||
import org.nl.wms.sync_manage.service.field_mapping.dto.MappingQuery;
|
import org.nl.wms.sync_manage.service.field_mapping.dto.MappingQuery;
|
||||||
@@ -56,8 +56,7 @@ public class SyncFormMappingController {
|
|||||||
private ISyncFormMappingService iSyncFormMappingService;
|
private ISyncFormMappingService iSyncFormMappingService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IPmFormDataService formDataService;
|
private IPmFormDataService formDataService;
|
||||||
@Autowired
|
|
||||||
private SyncErpService syncErpService;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
@@ -118,10 +117,9 @@ public class SyncFormMappingController {
|
|||||||
public ResponseEntity<Object> syncData(@RequestBody JSONObject form){
|
public ResponseEntity<Object> syncData(@RequestBody JSONObject form){
|
||||||
//参数判读,参数解析,调用参数入库
|
//参数判读,参数解析,调用参数入库
|
||||||
SyncFormMapping syncFormMapping = form.toJavaObject(SyncFormMapping.class);
|
SyncFormMapping syncFormMapping = form.toJavaObject(SyncFormMapping.class);
|
||||||
List<Object> objects = syncErpService.syncData(syncFormMapping);
|
|
||||||
// List<PmFormData> pmFormDatas = formDataService.syncAnalyse(syncFormMapping, JSON.toJSONString(objects));
|
// List<PmFormData> pmFormDatas = formDataService.syncAnalyse(syncFormMapping, JSON.toJSONString(objects));
|
||||||
// formDataService.saveBatch(pmFormDatas);
|
// formDataService.saveBatch(pmFormDatas);
|
||||||
return new ResponseEntity<>(TableDataInfo.build(objects),HttpStatus.OK);
|
return new ResponseEntity<>(TableDataInfo.build(ListOf.of("1")),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,23 +127,20 @@ public class SyncFormMappingController {
|
|||||||
@Log("回传测试")
|
@Log("回传测试")
|
||||||
public ResponseEntity<Object> process(@RequestBody JSONObject form){
|
public ResponseEntity<Object> process(@RequestBody JSONObject form){
|
||||||
//参数判读,参数解析,调用参数入库
|
//参数判读,参数解析,调用参数入库
|
||||||
JSONObject result = syncErpService.process(form);
|
return new ResponseEntity<>(null,HttpStatus.OK);
|
||||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/audit")
|
@PostMapping("/audit")
|
||||||
@Log("单据审核")
|
@Log("单据审核")
|
||||||
public ResponseEntity<Object> audit(@RequestBody JSONObject form){
|
public ResponseEntity<Object> audit(@RequestBody JSONObject form){
|
||||||
JSONObject result = syncErpService.audit(form);
|
return new ResponseEntity<>(null,HttpStatus.OK);
|
||||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/push")
|
@PostMapping("/push")
|
||||||
@Log("下推测试")
|
@Log("下推测试")
|
||||||
public ResponseEntity<Object> push(@RequestBody JSONObject form){
|
public ResponseEntity<Object> push(@RequestBody JSONObject form){
|
||||||
//参数判读,参数解析,调用参数入库
|
//参数判读,参数解析,调用参数入库
|
||||||
JSONObject result = syncErpService.push(form);
|
return new ResponseEntity<>(null,HttpStatus.OK);
|
||||||
return new ResponseEntity<>(result,HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,464 +0,0 @@
|
|||||||
package org.nl.wms.system_manage.service.quartz.task;
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.kingdee.bos.webapi.entity.*;
|
|
||||||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.nl.common.domain.exception.BadRequestException;
|
|
||||||
import org.nl.common.utils.BaseCode;
|
|
||||||
import org.nl.common.utils.ErpServiceUtils;
|
|
||||||
import org.nl.common.utils.IdUtil;
|
|
||||||
import org.nl.common.utils.MapOf;
|
|
||||||
import org.nl.config.lucene.LuceneAppender;
|
|
||||||
import org.nl.wms.base_manage.material.service.IMdMeMaterialbaseService;
|
|
||||||
import org.nl.wms.base_manage.material.service.dao.MdMeMaterialbase;
|
|
||||||
import org.nl.wms.config_manage.form_struc.service.dao.BmFormStruc;
|
|
||||||
import org.nl.wms.config_manage.form_struc.service.impl.BmFormStrucServiceImpl;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpQuery;
|
|
||||||
import org.nl.wms.external_system.erp.dto.ErpSec;
|
|
||||||
import org.nl.wms.pm_manage.form_data.service.IPmFormDataService;
|
|
||||||
import org.nl.wms.pm_manage.form_data.service.dao.PmFormData;
|
|
||||||
import org.nl.wms.pm_manage.form_data.service.dao.mapper.PmFormDataMapper;
|
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.dao.SyncFormMapping;
|
|
||||||
import org.nl.wms.sync_manage.service.form_mapping.impl.SyncFormMappingServiceImpl;
|
|
||||||
import org.slf4j.MDC;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @author ZZQ
|
|
||||||
* @Date 2023/3/22 17:14
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class SyncErpBillsScheduleService {
|
|
||||||
|
|
||||||
private ReentrantLock lock = new ReentrantLock();
|
|
||||||
@Autowired
|
|
||||||
ErpSec erpSec;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SyncFormMappingServiceImpl syncFormMappingServiceImpl;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BmFormStrucServiceImpl bmFormStrucServiceImpl;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IMdMeMaterialbaseService iMdMeMaterialbaseService;
|
|
||||||
|
|
||||||
@Lazy
|
|
||||||
@Autowired
|
|
||||||
private IPmFormDataService formDataService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PmFormDataMapper pmFormDataMapper;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ErpServiceUtils erpServiceUtils;
|
|
||||||
|
|
||||||
|
|
||||||
//组织机构
|
|
||||||
private static final Map<String, String> BILL_ORG_MAPPING = MapOf.of(
|
|
||||||
"PRD_PPBOM", "FPrdOrgId",
|
|
||||||
"PRD_MO", "FPrdOrgId",
|
|
||||||
"SAL_SaleOrder", "FStockOrgId",
|
|
||||||
"PRD_PickMtrl", "FStockOrgId",
|
|
||||||
"PUR_ReceiveBill", "FStockOrgId",
|
|
||||||
"PUR_MRAPP", "FPURCHASEORGID",
|
|
||||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "F_PMSY_PrdOrgId",
|
|
||||||
"STK_TransferDirect", "FStockOrgId",
|
|
||||||
"SAL_RETURNSTOCK", "FStockOrgId",
|
|
||||||
"PUR_MRB", "FStockOrgId",
|
|
||||||
"STK_MisDelivery", "FStockOrgId");
|
|
||||||
//仓库信息
|
|
||||||
private static final Map<String, String> BILL_STOCK_ID_MAPPING = MapOf.of(
|
|
||||||
"PRD_PPBOM", "stock_Id",
|
|
||||||
"PRD_MO", "stockId",
|
|
||||||
"PRD_PickMtrl", "stockId",
|
|
||||||
"SAL_SaleOrder", "stockId",
|
|
||||||
"PUR_ReceiveBill", "StockID_Id",
|
|
||||||
"PUR_MRAPP", "FPURCHASEORGID",
|
|
||||||
"ka7c19edf9d4b4b39b8cc4a06802163b0", "stockId",
|
|
||||||
"STK_TransferDirect", "SrcStockId_Id",
|
|
||||||
"SAL_RETURNSTOCK", "stockId",
|
|
||||||
"PUR_MRB", "stockId",
|
|
||||||
"STK_MisDelivery", "stockId");
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
MDC.put("requestMethod", "TaskScheduleService#run");
|
|
||||||
MDC.put("requestIp", "127.0.0.1");
|
|
||||||
MDC.put("requestTime", DateUtil.now());
|
|
||||||
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
|
|
||||||
//List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
|
||||||
List<BmFormStruc> strucList = bmFormStrucServiceImpl.list(new LambdaQueryWrapper<BmFormStruc>().eq(BmFormStruc::getIs_sync, "1"));
|
|
||||||
Set<String> structSet = strucList.stream().map(BmFormStruc::getForm_type).collect(Collectors.toSet());
|
|
||||||
List<SyncFormMapping> list = syncFormMappingServiceImpl.list(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, structSet));
|
|
||||||
for (SyncFormMapping m : list) {
|
|
||||||
JSONArray mappingJson = m.getMapping_json();
|
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
|
||||||
syncData(mappingString, m.getForm_type(), m.getDtl_split(), "");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
LuceneAppender.traceIdTL.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动同步
|
|
||||||
*/
|
|
||||||
public void syncData(String mappingJson, String formType, Boolean dtlSplit, String billCode) {
|
|
||||||
boolean islock = lock.tryLock();
|
|
||||||
try {
|
|
||||||
if (islock) {
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
JSONArray result;
|
|
||||||
Map errorMsg = new HashMap<>();
|
|
||||||
// 获取当前日期
|
|
||||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
|
||||||
String sevenDaysAgo = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
||||||
String filterString;
|
|
||||||
if (StringUtils.isNotBlank(billCode)) {
|
|
||||||
filterString = "FBillNo = '" + billCode + "'";
|
|
||||||
} else {
|
|
||||||
filterString = getFilterString(formType, "", sevenDaysAgo, today);
|
|
||||||
}
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId(formType);
|
|
||||||
query.setFieldKeys("FID");
|
|
||||||
query.setLimit(0);
|
|
||||||
result = erpServiceUtils.queryBills(query);
|
|
||||||
if (ObjectUtils.isNotEmpty(result)) {
|
|
||||||
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
|
|
||||||
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手动同步
|
|
||||||
*/
|
|
||||||
public String manualSync(String formType, String code, String startTime, String endTime) {
|
|
||||||
if (StringUtils.isEmpty(formType)) {
|
|
||||||
throw new BadRequestException("单据类型不能为空");
|
|
||||||
}
|
|
||||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, formType));
|
|
||||||
JSONArray mappingJson = syncFormMapping.getMapping_json();
|
|
||||||
String mappingString = JSON.toJSONString(mappingJson);
|
|
||||||
return manualSyncData(mappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), code, startTime, endTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手动同步
|
|
||||||
*/
|
|
||||||
private String manualSyncData(String mappingJson, String formType, Boolean dtlSplit, String code, String start, String end) {
|
|
||||||
boolean islock = lock.tryLock();
|
|
||||||
Map errorMsg = new HashMap<>();
|
|
||||||
try {
|
|
||||||
if (islock) {
|
|
||||||
//单据同步总数
|
|
||||||
JSONArray result;
|
|
||||||
// 获取当前日期
|
|
||||||
String timeEnd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, -10);
|
|
||||||
String timeStart = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
|
|
||||||
if (StringUtils.isNotBlank(start) && StringUtils.isNotBlank(end)) {
|
|
||||||
timeStart = start;
|
|
||||||
timeEnd = end;
|
|
||||||
}
|
|
||||||
String filterString = getFilterString(formType, code, timeEnd, timeStart);
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId(formType);
|
|
||||||
query.setFieldKeys("FID");
|
|
||||||
query.setLimit(0);
|
|
||||||
result = erpServiceUtils.queryBills(query);
|
|
||||||
if (ObjectUtils.isNotEmpty(result)) {
|
|
||||||
K3CloudApi k3CloudApi = erpServiceUtils.getCloudApi();
|
|
||||||
handleBills(mappingJson, formType, dtlSplit, errorMsg, result, k3CloudApi);
|
|
||||||
}
|
|
||||||
if (!CollectionUtils.isEmpty(errorMsg)) {
|
|
||||||
throw new BadRequestException("同步成功" + (result.size() - errorMsg.size()) + "条,失败信息:" + errorMsg.toString());
|
|
||||||
} else {
|
|
||||||
return "同步成功,共计" + result.size() + "条";
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
throw new BadRequestException("当前同步操作正在执行,稍后再试");
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new BadRequestException(ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getFilterString(String formType, String code, String timeEnd, String timeStart) {
|
|
||||||
String filterString;
|
|
||||||
if (StringUtils.isNotBlank(code)) {
|
|
||||||
filterString = "FBillNo = '" + code + "'";
|
|
||||||
} else {
|
|
||||||
filterString = BILL_ORG_MAPPING.get(formType) + " = '750572' ";
|
|
||||||
if ("ka7c19edf9d4b4b39b8cc4a06802163b0".equals(formType)) {
|
|
||||||
filterString += "AND FDocumentStatus = 'C' AND F_PMSY_BillStatus = 'A' AND F_PMSY_CreateDate >= '" + timeStart + " 00:00:00' AND F_PMSY_CreateDate <= '" + timeEnd + " 23:59:59' ";
|
|
||||||
} else if ("SAL_SaleOrder".equals(formType)) {
|
|
||||||
filterString += " AND FDocumentStatus = 'C' AND FCloseStatus ='A' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
|
||||||
} else if ("STK_TransferDirect".equals(formType)||"STK_MisDelivery".equals(formType)||"PUR_MRB".equals(formType)||"SAL_RETURNSTOCK".equals(formType)) {
|
|
||||||
filterString += " AND FDocumentStatus ='B' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
|
||||||
} else {
|
|
||||||
filterString += " AND FDocumentStatus = 'C' AND FCreateDate >= '" + timeStart + " 00:00:00' and FCreateDate <= '" + timeEnd + " 23:59:59' ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filterString;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleBills(String mappingJson, String formType, Boolean dtlSplit, Map errorMsg, JSONArray result, K3CloudApi cloudApi) {
|
|
||||||
//物料同步
|
|
||||||
SyncFormMapping syncFormMapping = syncFormMappingServiceImpl.getOne(new LambdaQueryWrapper<SyncFormMapping>().in(SyncFormMapping::getForm_type, "BD_MATERIAL"));
|
|
||||||
String materialMappingString = JSON.toJSONString(syncFormMapping.getMapping_json());
|
|
||||||
Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
|
||||||
外部:
|
|
||||||
for (int i = 0; i < result.size(); i++) {
|
|
||||||
Object r = result.get(i);
|
|
||||||
try {
|
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
|
||||||
//主单据
|
|
||||||
List<PmFormData> mainBill = formDataList.stream().filter(rd -> StringUtils.isNotBlank(rd.getCode())).collect(Collectors.toList());
|
|
||||||
//主单据Id
|
|
||||||
final String mainId = mainBill.get(0).getId();
|
|
||||||
//仓库Key
|
|
||||||
final String stockId = BILL_STOCK_ID_MAPPING.get(formType);
|
|
||||||
//除了合格证相关单据,其他都过滤非立库仓库组织
|
|
||||||
// if (!"PRD_MO".equals(formType) && !"PUR_ReceiveBill".equals(formType)) {
|
|
||||||
if (false) {
|
|
||||||
//明细单据
|
|
||||||
List<PmFormData> detailBills = formDataList.stream()
|
|
||||||
.filter(rs -> StringUtils.isBlank(rs.getCode()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//仓库信息
|
|
||||||
List<PmFormData> detailWithStock = detailBills.stream()
|
|
||||||
.filter(rd -> StringUtils.isNotBlank(rd.getForm_data().getString(stockId)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//托盘1233925与料箱库1233926
|
|
||||||
List<PmFormData> filteredDetails = detailWithStock.stream()
|
|
||||||
.filter(rt -> new HashSet<>(Arrays.asList("1233925", "1233926")).contains(rt.getForm_data().getString(stockId)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (ObjectUtils.isNotEmpty(filteredDetails)) {
|
|
||||||
mainBill.addAll(filteredDetails);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mainBill = formDataList;
|
|
||||||
}
|
|
||||||
//检查物料信息,如果不存在则新增物料
|
|
||||||
Set<String> materials = mainBill.stream().filter(rd -> StringUtils.isBlank(rd.getCode())).map(PmFormData::getMaterial_id).collect(Collectors.toSet());
|
|
||||||
List<MdMeMaterialbase> materialList = iMdMeMaterialbaseService.list(new QueryWrapper<MdMeMaterialbase>().select("material_id").in("material_id", materials));
|
|
||||||
Set<String> materialHas = materialList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
|
||||||
for (String m : materials) {
|
|
||||||
if (!materialHas.contains(m)) {
|
|
||||||
Boolean materialSync = queryMaterialInfo(materialMappingString, syncFormMapping.getForm_type(), syncFormMapping.getDtl_split(), m, cloudApi);
|
|
||||||
if (!materialSync) {
|
|
||||||
continue 外部;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (PmFormData f : mainBill) {
|
|
||||||
if (exitFormDataList.contains(f.getId() + "$" + f.getForm_type())) {
|
|
||||||
continue 外部;
|
|
||||||
}
|
|
||||||
//单据明细
|
|
||||||
if (StringUtils.isBlank(f.getCode())) {
|
|
||||||
f.setParent_id(mainId + "$" + formType);
|
|
||||||
}
|
|
||||||
f.setId(f.getId() + "$" + f.getForm_type());
|
|
||||||
formDataService.save(f);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
errorMsg.put("result第"+i+1+"条解析异常:",e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询物料信息
|
|
||||||
*/
|
|
||||||
public Boolean queryMaterialInfo(String mappingJson, String formType, Boolean dtlSplit, String id, K3CloudApi cloudApi) {
|
|
||||||
try {
|
|
||||||
{
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
String filterString = "FUseOrgId='750572' AND FMATERIALID ='" + id + "'";
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId(formType);
|
|
||||||
query.setFieldKeys("FMATERIALID");
|
|
||||||
query.setLimit(0);
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
|
||||||
// Set<String> exitFormDataList = pmFormDataMapper.existFormDataList();
|
|
||||||
for (List<Object> list : lists) {
|
|
||||||
for (Object r : list) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
log.error("单据同步失败,没有找到FID");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
OperateParam param = new OperateParam();
|
|
||||||
param.setId(fid);
|
|
||||||
OperatorResult view = cloudApi.view(formType, param);
|
|
||||||
RepoStatus status = view.getResult().getResponseStatus();
|
|
||||||
if (status.isIsSuccess()) {
|
|
||||||
List<Object> result = new ArrayList<>();
|
|
||||||
result.add(view.getResult().getResult());
|
|
||||||
getData(mappingJson, formType, dtlSplit, result);
|
|
||||||
} else {
|
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("处理ID [{}] 时出现异常: {}", fid, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理物料信息
|
|
||||||
*/
|
|
||||||
private void getData(String mappingJson, String formType, Boolean dtlSplit, List<Object> result) {
|
|
||||||
外部:
|
|
||||||
for (Object r : result) {
|
|
||||||
try {
|
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(r));
|
|
||||||
if (formDataList != null) {
|
|
||||||
PmFormData mainFormData = formDataList.stream().filter(rs1 -> "BD_MATERIAL".equals(rs1.getForm_type())).collect(Collectors.toList()).get(0);
|
|
||||||
JSONObject object = mainFormData.getForm_data();
|
|
||||||
String m_code = object.getString("m_code");
|
|
||||||
String m_name = object.getString("m_name");
|
|
||||||
String m_spec = object.getString("m_spec");
|
|
||||||
String m_unit = mainFormData.getUnit_id();
|
|
||||||
PmFormData formData = formDataList.stream().filter(rs1 -> "BD_MATERIAL_1".equals(rs1.getForm_type())).collect(Collectors.toList()).get(0);
|
|
||||||
MdMeMaterialbase materialBase = new MdMeMaterialbase();
|
|
||||||
materialBase.setMaterial_id(mainFormData.getId());
|
|
||||||
materialBase.setMaterial_code(m_code);
|
|
||||||
materialBase.setMaterial_code(m_code);
|
|
||||||
materialBase.setMaterial_name(m_name);
|
|
||||||
materialBase.setMaterial_spec(m_spec);
|
|
||||||
materialBase.setQty_unit_id(m_unit);
|
|
||||||
materialBase.setAssist_unit_id(formData.getVehicle_code());
|
|
||||||
materialBase.setPrint_no(formData.getPcsn());
|
|
||||||
iMdMeMaterialbaseService.save(materialBase);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("解析数据 [{}] 时出现异常: {}", JSON.toJSONString(r), e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 物料信息同步
|
|
||||||
*/
|
|
||||||
public void syncMateralData(String mappingJson, String formType, Boolean dtlSplit) {
|
|
||||||
boolean islock = lock.tryLock();
|
|
||||||
try {
|
|
||||||
if (islock) {
|
|
||||||
IdentifyInfo identifyInfo = new IdentifyInfo();
|
|
||||||
BeanUtils.copyProperties(erpSec, identifyInfo);
|
|
||||||
K3CloudApi cloudApi = new K3CloudApi(identifyInfo);
|
|
||||||
String filterString = "FUseOrgId='750572'";
|
|
||||||
ErpQuery query = new ErpQuery();
|
|
||||||
query.setFilterString(filterString);
|
|
||||||
query.setFormId(formType);
|
|
||||||
query.setFieldKeys("FMATERIALID");
|
|
||||||
query.setLimit(0);
|
|
||||||
String jsonString = JSON.toJSONString(query);
|
|
||||||
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
|
|
||||||
//log.info("同步ERP结果" + lists.size());
|
|
||||||
Set<String> ids = new HashSet<>();
|
|
||||||
for (List<Object> list : lists) {
|
|
||||||
for (Object r : list) {
|
|
||||||
String fid = r.toString();
|
|
||||||
if (StringUtils.isEmpty(fid)) {
|
|
||||||
log.error("单据同步失败,没有找到FID");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ids.add(fid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OperateParam param = new OperateParam();
|
|
||||||
Map<String, String> error = new HashMap<>();
|
|
||||||
List<MdMeMaterialbase> formList = iMdMeMaterialbaseService.list();
|
|
||||||
Set<String> idSet1 = formList.stream().map(MdMeMaterialbase::getMaterial_id).collect(Collectors.toSet());
|
|
||||||
Set<String> differenceSet = new HashSet<>(ids);
|
|
||||||
differenceSet.removeAll(idSet1);
|
|
||||||
//数据库已存在的数据
|
|
||||||
// Set<String> existFormDataList = pmFormDataMapper.existFormDataList();
|
|
||||||
for (String id : differenceSet) {
|
|
||||||
param.setId(id);
|
|
||||||
OperatorResult view = cloudApi.view(formType, param);
|
|
||||||
RepoStatus status = view.getResult().getResponseStatus();
|
|
||||||
if (status.isIsSuccess()) {
|
|
||||||
JSONArray mappingJsonArray = JSONArray.parseArray(mappingJson);
|
|
||||||
List<PmFormData> formDataList = formDataService.syncAnalyse(mappingJsonArray, formType, dtlSplit, JSON.toJSONString(view.getResult().getResult()));
|
|
||||||
List<PmFormData> formData = formDataList.stream().filter(r -> StringUtils.isBlank(r.getCode())).collect(Collectors.toList());
|
|
||||||
if (!formData.isEmpty()) {
|
|
||||||
formDataService.saveBatch(formData);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ArrayList<RepoError> errors = status.getErrors();
|
|
||||||
String errorMsg = errors.stream().map(RepoError::getMessage).collect(Collectors.joining(","));
|
|
||||||
error.put(id, errorMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
log.error("同步数据时出现异常: {}", ex.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ spring:
|
|||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
# url: jdbc:mysql://${DB_HOST:192.168.8.218}:${DB_PORT:3306}/${DB_NAME:wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
# url: jdbc:mysql://${DB_HOST:192.168.8.218}:${DB_PORT:3306}/${DB_NAME:wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
||||||
url: jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
url: jdbc:mysql://${DB_HOST:192.168.81.251}:${DB_PORT:3306}/${DB_NAME:wms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true&useSSL=false
|
||||||
username: ${DB_USER:root}
|
username: ${DB_USER:root}
|
||||||
password: ${DB_PWD:123456}
|
password: ${DB_PWD:123456}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user