导入修改

This commit is contained in:
秦鸿展
2026-04-15 17:10:44 +08:00
parent ac51afdb7e
commit be323e975a
4 changed files with 145 additions and 21 deletions
@@ -1835,6 +1835,21 @@ public class StockInOrderApplicationService {
stockInOrderDO.setWarehouseName(warehouseFeignPO.getWarehouseName());
}
/**
* 导入入库单:解析出的货主用户是否属于当前登录用户同一组织(organizationId)。
* 仅当登录用户带有 organizationId 时启用过滤;否则保持与旧行为一致。
*/
private boolean shipperMatchesImporterOrganization(UserPo userPo, Long loginOrganizationId) {
if (loginOrganizationId == null) {
return true;
}
if (userPo == null) {
return false;
}
Long oid = userPo.getOrganizationId();
return oid != null && loginOrganizationId.equals(oid);
}
/**
* @description 根据货主名称或编号获取货主ID(用于导入时提前获取货主ID)
* @param shipperName 货主名称
@@ -1845,6 +1860,12 @@ public class StockInOrderApplicationService {
if (StringUtils.isBlank(shipperName) && StringUtils.isBlank(shipperCode)) {
return null;
}
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
Long shipperId = null;
@@ -1855,29 +1876,37 @@ public class StockInOrderApplicationService {
AjaxResult ajaxResult = userServiceFeign.getInfo(possibleId);
if ("200".equals(String.valueOf(ajaxResult.get("code"))) && ajaxResult.get("data") != null) {
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (userPo != null) {
if (userPo != null && shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
shipperId = userPo.getUserId();
log.info("根据货主名称(实际为ID)找到货主ID:{}", shipperId);
log.info("根据货主名称(实际为ID)找到货主ID:{}organizationId={}", shipperId, loginOrganizationId);
return shipperId;
}
if (userPo != null) {
log.info("按ID查到用户但与当前登录组织不一致,忽略。userId={},货主organizationId={},当前登录organizationId={}",
userPo.getUserId(), userPo.getOrganizationId(), loginOrganizationId);
}
}
} catch (Exception e) {
log.debug("尝试将货主名称作为ID查询失败,货主名称:{},错误:{}", shipperName, e.getMessage());
}
}
// 如果仍未找到,尝试根据名称查询
// 如果仍未找到,尝试根据名称查询(用户中心 user_name 等值匹配)
if (shipperId == null && StringUtils.isNotEmpty(shipperName) && !shipperName.matches("\\d+")) {
try {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(shipperName);
String code = String.valueOf(ajaxResult.get("code"));
if ("200".equals(code) && ajaxResult.get("data") != null) {
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (userPo != null) {
if (userPo != null && shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
shipperId = userPo.getUserId();
log.info("根据货主名称找到货主ID,货主名称:{},货主ID:{}", shipperName, shipperId);
log.info("根据货主名称找到货主ID,货主名称:{},货主ID:{}organizationId={}", shipperName, shipperId, loginOrganizationId);
return shipperId;
}
if (userPo != null) {
log.info("按名称查到用户但与当前登录组织不一致,继续从货主列表匹配。userId={},货主organizationId={},当前登录organizationId={}",
userPo.getUserId(), userPo.getOrganizationId(), loginOrganizationId);
}
}
} catch (Exception e) {
log.debug("根据货主名称查询失败,货主名称:{},错误:{}", shipperName, e.getMessage());
@@ -1947,10 +1976,23 @@ public class StockInOrderApplicationService {
}
if (matched && userId != null) {
shipperId = Long.valueOf(String.valueOf(userId));
log.info("从货主列表中找到货主ID,货主名称:{},货主编号:{},货主ID:{}",
shipperName, shipperCode, shipperId);
return shipperId;
Long candidateId = Long.valueOf(String.valueOf(userId));
try {
AjaxResult infoRes = userServiceFeign.getInfo(candidateId);
if ("200".equals(String.valueOf(infoRes.get("code"))) && infoRes.get("data") != null) {
UserPo up = JSON.parseObject(JSONObject.toJSONString(infoRes.get("data")), UserPo.class);
if (shipperMatchesImporterOrganization(up, loginOrganizationId)) {
shipperId = candidateId;
log.info("从货主列表中找到货主ID,货主名称:{},货主编号:{},货主ID{}organizationId={}",
shipperName, shipperCode, shipperId, loginOrganizationId);
return shipperId;
}
log.info("货主列表匹配到用户但与当前登录组织不一致,跳过。userId={},货主organizationId={},当前登录organizationId={}",
candidateId, up != null ? up.getOrganizationId() : null, loginOrganizationId);
}
} catch (Exception ex) {
log.debug("校验货主组织时查询用户信息失败,userId={},{}", candidateId, ex.getMessage());
}
}
}
}
@@ -1143,6 +1143,21 @@ public class StockOutOrderApplicationService {
stockOutOrderDO.setWarehouseName(warehouseFeignPO.getWarehouseName());
}
/**
* 出库单按名称/ID解析货主解析出的用户是否属于当前登录用户同一组织organizationId
* 仅当登录用户带有 organizationId 时启用过滤否则保持与旧行为一致
*/
private boolean shipperMatchesImporterOrganization(UserPo userPo, Long loginOrganizationId) {
if (loginOrganizationId == null) {
return true;
}
if (userPo == null) {
return false;
}
Long oid = userPo.getOrganizationId();
return oid != null && loginOrganizationId.equals(oid);
}
/**
* @description 封装货主信息
* @author ZhouGY
@@ -1151,12 +1166,23 @@ public class StockOutOrderApplicationService {
*/
private void shipperParam(StockOutOrderDO stockOutOrderDO){
String customerName = stockOutOrderDO.getCustomerName();
if (customerName == null || !customerName.matches("\\d+")) {
if (StringUtils.isEmpty(customerName)) {
return;
}
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
if (!customerName.matches("\\d+")) {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(customerName);
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该货主信息或客户名称与组织不匹配");
}
stockOutOrderDO.setShipperId(userPo.getUserId());
stockOutOrderDO.setShipperCode(userPo.getUserMemberCode());
stockOutOrderDO.setShipperName(userPo.getUserName());
@@ -1166,6 +1192,9 @@ public class StockOutOrderApplicationService {
throw new ServiceException("获取货主信息失败");
}
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该货主信息或客户名称与组织不匹配");
}
stockOutOrderDO.setShipperId(userPo.getUserId());
stockOutOrderDO.setShipperCode(userPo.getUserMemberCode());
stockOutOrderDO.setShipperName(userPo.getUserName());
@@ -1180,12 +1209,23 @@ public class StockOutOrderApplicationService {
*/
private void customerParam(StockOutOrderDO stockOutOrderDO){
String customerName = stockOutOrderDO.getCustomerName();
if (customerName == null || !customerName.matches("\\d+")) {
if (StringUtils.isEmpty(customerName)) {
return;
}
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
if (!customerName.matches("\\d+")) {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(customerName);
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该客户信息或客户名称与组织不匹配");
}
stockOutOrderDO.setCustomerId(userPo.getUserId());
stockOutOrderDO.setCustomerCode(userPo.getUserMemberCode());
stockOutOrderDO.setCustomerName(userPo.getUserName());
@@ -1195,6 +1235,9 @@ public class StockOutOrderApplicationService {
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该客户信息或客户名称与组织不匹配");
}
stockOutOrderDO.setCustomerId(userPo.getUserId());
stockOutOrderDO.setCustomerCode(userPo.getUserMemberCode());
stockOutOrderDO.setCustomerName(userPo.getUserName());
@@ -648,19 +648,15 @@ public class PickingOrderDomainService {
outOrderAbnormalService.genOutOrderAbnormal(outOrderAbnormalBaseDO, 1);
//更新出库单状态
updateStockOutOrder(pickingOrderPO);
// 点击完成拣货时不管数量多少强制将出库单状态推进到拣货完成7或已出库9
// 点击完成拣货时不管实拣数量多少强制将出库单置为拣货完成7
if (1 == pickingOrderPO.getType()) {
StockOutOrder forceUpdate = new StockOutOrder();
forceUpdate.setOutOrderNumber(pickingOrderPO.getOrderNumber());
int forceStatus = (pickingOrderPO.getReview() != null && pickingOrderPO.getReview() == 2) ? 9 : 7;
forceUpdate.setStatus(forceStatus);
forceUpdate.setStatus(7);
forceUpdate.setUpdateBy(loginUser.getUserid());
forceUpdate.setUpdateByName(loginUser.getUsername());
forceUpdate.setUpdateTime(new Date());
stockOutOrderService.update(forceUpdate, new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<StockOutOrder>().lambda().eq(StockOutOrder::getOutOrderNumber, pickingOrderPO.getOrderNumber()));
if (pickingOrderPO.getReview() != null && pickingOrderPO.getReview() == 2) {
genHandoverTaskOrder(pickingOrderPO);
}
}
//同步BMS结算系统生成业务单据
//这里只有不需要复核的时候才推送需要复核的在复核流程推送
@@ -177,12 +177,20 @@ public class ExcelParseService {
private void shipperParam(StockOutOrderDO stockOutOrderDO){
String customerName = stockOutOrderDO.getCustomerName();
if (StringUtils.isEmpty(customerName)) return;
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
if (!customerName.matches("\\d+")) {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(customerName);
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该货主信息或客户名称与组织不匹配");
}
stockOutOrderDO.setShipperId(userPo.getUserId());
stockOutOrderDO.setShipperCode(userPo.getUserMemberCode());
stockOutOrderDO.setShipperName(userPo.getUserName());
@@ -192,6 +200,9 @@ public class ExcelParseService {
throw new ServiceException("获取货主信息失败");
}
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该货主信息或客户名称与组织不匹配");
}
stockOutOrderDO.setShipperId(userPo.getUserId());
stockOutOrderDO.setShipperCode(userPo.getUserMemberCode());
stockOutOrderDO.setShipperName(userPo.getUserName());
@@ -207,12 +218,20 @@ public class ExcelParseService {
private void customerParam(StockOutOrderDO stockOutOrderDO){
String customerName = stockOutOrderDO.getCustomerName();
if (StringUtils.isEmpty(customerName)) return;
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
if (!customerName.matches("\\d+")) {
AjaxResult ajaxResult = userServiceFeign.getInfoByName(customerName);
if(!"200".equals(String.valueOf(ajaxResult.get("code")))){
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该客户信息或客户名称与组织不匹配");
}
stockOutOrderDO.setCustomerId(userPo.getUserId());
stockOutOrderDO.setCustomerCode(userPo.getUserMemberCode());
stockOutOrderDO.setCustomerName(userPo.getUserName());
@@ -222,6 +241,9 @@ public class ExcelParseService {
throw new ServiceException("获取客户信息失败");
}
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (!shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
throw new ServiceException("当前登录用户组织下不存在该客户信息或客户名称与组织不匹配");
}
stockOutOrderDO.setCustomerId(userPo.getUserId());
stockOutOrderDO.setCustomerCode(userPo.getUserMemberCode());
stockOutOrderDO.setCustomerName(userPo.getUserName());
@@ -307,18 +329,39 @@ public class ExcelParseService {
* @param customerName 客户名称在出库单中客户名称就是货主名称
* @return 货主ID如果找不到则返回null
*/
/**
* 导入出库单解析出的货主用户是否属于当前登录用户同一组织organizationId
* 仅当登录用户带有 organizationId 时启用过滤否则保持与旧行为一致
*/
private boolean shipperMatchesImporterOrganization(UserPo userPo, Long loginOrganizationId) {
if (loginOrganizationId == null) {
return true;
}
if (userPo == null) {
return false;
}
Long oid = userPo.getOrganizationId();
return oid != null && loginOrganizationId.equals(oid);
}
private Long getShipperIdByCustomerName(String customerName) {
if (StringUtils.isEmpty(customerName)) {
return null;
}
Long loginOrganizationId = null;
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
loginOrganizationId = loginUser.getUserPo().getOrganizationId();
}
try {
if (!customerName.matches("\\d+")) {
// 按名称查询
AjaxResult ajaxResult = userServiceFeign.getInfoByName(customerName);
if ("200".equals(String.valueOf(ajaxResult.get("code")))) {
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (userPo != null) {
if (userPo != null && shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
return userPo.getUserId();
}
}
@@ -327,7 +370,7 @@ public class ExcelParseService {
AjaxResult ajaxResult = userServiceFeign.getInfo(Long.valueOf(customerName));
if ("200".equals(String.valueOf(ajaxResult.get("code")))) {
UserPo userPo = JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), UserPo.class);
if (userPo != null) {
if (userPo != null && shipperMatchesImporterOrganization(userPo, loginOrganizationId)) {
return userPo.getUserId();
}
}
@@ -335,7 +378,7 @@ public class ExcelParseService {
} catch (Exception e) {
// 如果查询失败返回null后续在shipperParam方法中会再次尝试
}
return null;
}