opt:优化ERP同步锁,单据推送暂停问题

This commit is contained in:
2025-03-12 13:09:31 +08:00
parent fa85da9eb3
commit de817ef511
10 changed files with 100 additions and 100 deletions

View File

@@ -27,6 +27,7 @@ public class DictConstantPool {
,"qty","申请数量"
,"plan_qty","计划数量"
,"assign_qty","已领数量"
,"actual_qty","实际数量"
,"bar_code","条码"
,"unit_id","单位"
,"pcsn","批次"

View File

@@ -30,7 +30,7 @@ import java.util.stream.Collectors;
public class ErpServiceUtils {
@Resource
ErpSec erpSec;
private final ReentrantLock lock = new ReentrantLock();
/**
@@ -50,48 +50,39 @@ public class ErpServiceUtils {
if (StringUtils.isBlank(query.getFormId())) {
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());
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("系统正在自动同步ERP单据正占用接口资源请稍后再试1");
}
return JSON.parseArray(JSON.toJSONString(result));
} catch (Exception ex) {
throw new BadRequestException(ex.getMessage());
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return JSON.parseArray(JSON.toJSONString(result));
}
/**
@@ -101,10 +92,8 @@ public class ErpServiceUtils {
if (StringUtils.isBlank(query.getFormId())) {
throw new BadRequestException("参数异常");
}
boolean islock = lock.tryLock();
List<JSONObject> result = new ArrayList<>();
try {
if (islock) {
String jsonString = JSON.toJSONString(query);
K3CloudApi cloudApi = getCloudApi();
List<List<Object>> lists = cloudApi.executeBillQuery(jsonString);
@@ -114,15 +103,8 @@ public class ErpServiceUtils {
jsonObject.put("erpCounts",list.get(1));
result.add(jsonObject);
}
} else {
throw new BadRequestException("系统正在自动同步ERP单据正占用接口资源请稍后再试2");
}
} catch (Exception ex) {
throw new BadRequestException(ex.getMessage());
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return result;
}

View File

@@ -115,7 +115,7 @@ public class BmFormStrucController {
@GetMapping("/getParentFormTypes")
public ResponseEntity<Object> getParentFormTypes(){
//参数判读,参数解析,调用参数入库
QueryWrapper<BmFormStruc> queryWrapper = new QueryWrapper<BmFormStruc>().select("form_type", "form_name").isNull("parent_id").groupBy("form_type");
QueryWrapper<BmFormStruc> queryWrapper = new QueryWrapper<BmFormStruc>().select("form_type", "form_name").isNull("parent_id").isNotNull("sort").groupBy("form_type").orderByAsc("sort");;
List<Map<String, Object>> select = iBmFormStrucService.listMaps(queryWrapper);
List<Map> list = new ArrayList<>();
for (Map<String, Object> map : select) {
@@ -128,7 +128,7 @@ public class BmFormStrucController {
//参数判读,参数解析,调用参数入库
QueryWrapper<BmFormStruc> queryWrapper = new QueryWrapper<BmFormStruc>().select("form_type", "form_name").isNull("parent_id").groupBy("form_type").orderByAsc("sort");
if (StringUtils.isNotEmpty(desc)){
queryWrapper.like("form_desc",desc);
queryWrapper.like("form_desc",desc).isNotNull("sort");
}
List<Map<String, Object>> select = iBmFormStrucService.listMaps(queryWrapper);
List<Map> list = new ArrayList<>();

View File

@@ -106,6 +106,11 @@ public class BmFormStruc implements Serializable {
*/
private String plan_qty;
/**
* 实际数量
*/
private String actual_qty;
/**
* 已领取数量
*/

View File

@@ -153,11 +153,14 @@ public class SchBaseTaskServiceImpl extends ServiceImpl<SchBaseTaskMapper, SchBa
handleFinishTask(param, task);
return;
}
MdPbVehicleMater vehicleMater = iMdPbVehicleMaterService.getOne(new QueryWrapper<MdPbVehicleMater>()
List<MdPbVehicleMater> vehicleMaterList = iMdPbVehicleMaterService.list(new QueryWrapper<MdPbVehicleMater>()
.eq("vehicle_code", task.getVehicle_code())
.eq("is_delete", false));
if (vehicleMater != null && !StringUtils.isEmpty(vehicleMater.getProc_inst_id())) {
FlowContinueEvent continueEvent = new FlowContinueEvent(vehicleMater.getProc_inst_id(), null, null);
if (ObjectUtils.isEmpty(vehicleMaterList)) {
throw new BadRequestException("当前任务未找到组盘信息");
}
if (StringUtils.isEmpty(vehicleMaterList.get(0).getProc_inst_id())) {
FlowContinueEvent continueEvent = new FlowContinueEvent(vehicleMaterList.get(0).getProc_inst_id(), null, null);
BussEventMulticaster.Publish(continueEvent);
} else {
handleFinishTask(param, task);

View File

@@ -83,6 +83,11 @@ public class PmFormData implements Serializable {
*/
private BigDecimal assign_qty;
/**
* 实际数量
*/
private BigDecimal actual_qty;
/**
* 单位
*/

View File

@@ -125,6 +125,10 @@ public class PmFormDataDto implements Serializable {
* 已分配数量
*/
private BigDecimal assign_qty;
/**
* 实际数量
*/
private BigDecimal actual_qty;
/**
* 单位

View File

@@ -353,6 +353,8 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
for (PmFormDataDto child : children) {
String childProductArea = child.getForm_data().getString("product_area");
child.setProduct_area(childProductArea);
BigDecimal total = child.getPlan_qty().subtract(child.getAssign_qty().add(child.getActual_qty() == null ? BigDecimal.ZERO : child.getActual_qty()));
child.setQty(total.compareTo(BigDecimal.ZERO) > 0 ? total : BigDecimal.ZERO);
}
}
dataDto.setChildren(children);
@@ -415,6 +417,8 @@ public class PmFormDataServiceImpl extends ServiceImpl<PmFormDataMapper, PmFormD
child.setSto_qty(BigDecimal.valueOf(maps.stream().mapToInt(a -> a.getSto_qty().intValue()).sum()));
child.setPcsn("");
}
BigDecimal total = child.getPlan_qty().subtract(child.getAssign_qty().add(child.getActual_qty() == null ? BigDecimal.ZERO : child.getActual_qty()));
child.setQty(total.compareTo(BigDecimal.ZERO) > 0 ? total : BigDecimal.ZERO);
}
pmFormDataDto.setChildren(childs);
return pmFormDataDto;

View File

@@ -180,11 +180,11 @@ public class SyncErpBillsScheduleService {
* 手动同步
*/
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());
@@ -211,15 +211,8 @@ public class SyncErpBillsScheduleService {
} else {
return "同步成功,共计" + result.size() + "";
}
}else {
throw new BadRequestException("3系统正在自动同步ERP单据正占用接口资源请稍后再试3");
}
} catch (Exception ex) {
throw new BadRequestException(ex.getMessage());
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
}
@@ -303,21 +296,18 @@ public class SyncErpBillsScheduleService {
//单据明细
if (StringUtils.isBlank(f.getCode())) {
PmFormData existDtlData = formDataService.getOne(new QueryWrapper<PmFormData>().eq("id", id).select("qty"));
//existDtlData.getQty().compareTo(BigDecimal.ZERO) > 0||f.getPlan_qty().compareTo(f.getAssign_qty()) > 0
if (existDtlData.getQty() != null) {
if (existDtlData.getQty().compareTo(BigDecimal.ZERO) > 0) {
formDataService.update(new LambdaUpdateWrapper<PmFormData>()
.set(PmFormData::getMaterial_id, f.getMaterial_id())
.set(PmFormData::getQty, f.getQty())
.set(PmFormData::getUnit_id, f.getUnit_id())
.set(PmFormData::getForm_data, JSON.toJSONString(f.getForm_data()))
.set(PmFormData::getPlan_qty, f.getPlan_qty())
.set(PmFormData::getTaxPrice, f.getActual_qty())
.set(PmFormData::getBar_code, f.getBar_code())
.set(PmFormData::getUpdate_name, DateUtil.now())
.set(PmFormData::getUpdate_name, SecurityUtils.getCurrentNickName())
.eq(PmFormData::getId, id));
}
}
}
} else {
//单据明细