diff --git a/src/main/java/com/huaheng/pc/config/material/controller/MaterialController.java b/src/main/java/com/huaheng/pc/config/material/controller/MaterialController.java index e094781..8f5e5b6 100644 --- a/src/main/java/com/huaheng/pc/config/material/controller/MaterialController.java +++ b/src/main/java/com/huaheng/pc/config/material/controller/MaterialController.java @@ -108,35 +108,7 @@ public class MaterialController extends BaseController { @ResponseBody public AjaxResult addSave(Material material) { - LambdaQueryWrapper<Material> lambda = Wrappers.lambdaQuery(); - lambda.eq(Material::getCode, material.getCode()) - .eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode()) - .eq(Material::getDeleted, false); - Map<String, Object> map = materialService.getMap(lambda); - if (map != null) { - return AjaxResult.error("物料已经存在"); - } - LambdaQueryWrapper<MaterialUnit> lambdaQueryWrapper = Wrappers.lambdaQuery(); - lambdaQueryWrapper.eq(MaterialUnit::getMaterialCode, material.getCode()) - .eq(MaterialUnit::getUnit, material.getUnit()); - if (materialUnitService.getOne(lambdaQueryWrapper) == null){ - MaterialUnit materialUnit = new MaterialUnit(); - materialUnit.setMaterialCode(material.getCode()); - materialUnit.setMaterialName(material.getName()); - materialUnit.setMaterialSpec(material.getSpec()); - materialUnit.setCompanyCode(material.getCompanyCode()); - materialUnit.setWarehouseCode(ShiroUtils.getWarehouseCode()); - materialUnit.setUnit(material.getUnit()); - materialUnit.setCreatedBy(ShiroUtils.getLoginName()); - materialUnit.setLastUpdatedBy(ShiroUtils.getLoginName()); - - materialUnitService.save(materialUnit); - } - - material.setWarehouseCode(ShiroUtils.getWarehouseCode()); - material.setCreatedBy(ShiroUtils.getLoginName()); - material.setLastUpdatedBy(ShiroUtils.getLoginName()); - return AjaxResult.toAjax(materialService.save(material)); + return materialService.addSave(material); } /** diff --git a/src/main/java/com/huaheng/pc/config/material/service/MaterialService.java b/src/main/java/com/huaheng/pc/config/material/service/MaterialService.java index d1ef5f7..0b689e3 100644 --- a/src/main/java/com/huaheng/pc/config/material/service/MaterialService.java +++ b/src/main/java/com/huaheng/pc/config/material/service/MaterialService.java @@ -13,5 +13,10 @@ public interface MaterialService extends IService<Material>{ String importMaterial(List<Material> materialList, Boolean updateSupport,String operName); - + /** + * 添加物料 + * @param material + * @return + */ + AjaxResult addSave(Material material); } diff --git a/src/main/java/com/huaheng/pc/config/material/service/MaterialServiceImpl.java b/src/main/java/com/huaheng/pc/config/material/service/MaterialServiceImpl.java index e26537b..faf608a 100644 --- a/src/main/java/com/huaheng/pc/config/material/service/MaterialServiceImpl.java +++ b/src/main/java/com/huaheng/pc/config/material/service/MaterialServiceImpl.java @@ -7,10 +7,15 @@ import com.huaheng.common.support.Convert; import com.huaheng.common.utils.StringUtils; import com.huaheng.common.utils.security.ShiroUtils; import com.huaheng.framework.web.domain.AjaxResult; +import com.huaheng.pc.config.materialType.domain.MaterialType; +import com.huaheng.pc.config.materialType.service.MaterialTypeService; +import com.huaheng.pc.config.materialUnit.domain.MaterialUnit; +import com.huaheng.pc.config.materialUnit.service.MaterialUnitService; import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail; import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.lang.ref.WeakReference; import java.util.List; import java.util.Map; @@ -23,6 +28,10 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i @Resource private ReceiptDetailService receiptDetailService; + @Resource + private MaterialUnitService materialUnitService; + @Resource + private MaterialTypeService materialTypeService; @Override public AjaxResult removeByIds(String ids) { @@ -94,4 +103,60 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i } return successMsg.toString(); } + + /** + * 添加物料 + * @param material + * @return + */ + @Override + public AjaxResult addSave(Material material) { + LambdaQueryWrapper<Material> lambda = Wrappers.lambdaQuery(); + //如果物料编码为空则生成物料编码 + if (material.getCode() == null) { + material.setCode(createCode(material.getType())); + } + lambda.eq(Material::getCode, material.getCode()) + .eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode()) + .eq(Material::getDeleted, false); + Map<String, Object> map = this.getMap(lambda); + if (map != null) { + return AjaxResult.error("物料已经存在"); + } + + LambdaQueryWrapper<MaterialUnit> lambdaQueryWrapper = Wrappers.lambdaQuery(); + lambdaQueryWrapper.eq(MaterialUnit::getMaterialCode, material.getCode()) + .eq(MaterialUnit::getUnit, material.getUnit()); + //如果不存在该物料的单位是新建物料单位 + if (materialUnitService.getOne(lambdaQueryWrapper) == null){ + MaterialUnit materialUnit = new MaterialUnit(); + materialUnit.setMaterialCode(material.getCode()); + materialUnit.setMaterialName(material.getName()); + materialUnit.setMaterialSpec(material.getSpec()); + materialUnit.setCompanyCode(material.getCompanyCode()); + materialUnit.setWarehouseCode(ShiroUtils.getWarehouseCode()); + materialUnit.setUnit(material.getUnit()); + materialUnit.setCreatedBy(ShiroUtils.getLoginName()); + materialUnit.setLastUpdatedBy(ShiroUtils.getLoginName()); + + materialUnitService.save(materialUnit); + } + material.setWarehouseCode(ShiroUtils.getWarehouseCode()); + material.setCreatedBy(ShiroUtils.getLoginName()); + material.setLastUpdatedBy(ShiroUtils.getLoginName()); + return null; + } + + /** + * 生成物料编码 + * @param code + * @return + */ + private String createCode(String code){ + LambdaQueryWrapper<MaterialType> lambda = Wrappers.lambdaQuery(); + lambda.eq(MaterialType::getCode, code); + MaterialType materialType = materialTypeService.getOne(lambda); + + return String.format(materialType.getAutoGenSerialNumFormat(), materialType.getTrackSerialNum()); + } } diff --git a/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailService.java b/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailService.java index 96af1bf..9d8f509 100644 --- a/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailService.java +++ b/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailService.java @@ -3,6 +3,7 @@ package com.huaheng.pc.inventory.inventoryDetail.service; import com.baomidou.mybatisplus.extension.service.IService; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail; +import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail; import java.util.List; @@ -11,7 +12,7 @@ public interface InventoryDetailService extends IService<InventoryDetail> { AjaxResult detailcreateCheckOutTask (Integer id); - List<InventoryDetail> selectBysql(String sql); + List<InventoryDetail> selectBysql(String sql, ShipmentDetail shipmentDetail); } diff --git a/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailServiceImpl.java b/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailServiceImpl.java index 457d060..24b68ef 100644 --- a/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailServiceImpl.java +++ b/src/main/java/com/huaheng/pc/inventory/inventoryDetail/service/InventoryDetailServiceImpl.java @@ -9,6 +9,7 @@ import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.pc.config.location.domain.Location; import com.huaheng.pc.config.location.service.LocationService; import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail; +import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail; import com.huaheng.pc.task.taskDetail.domain.TaskDetail; import com.huaheng.pc.task.taskDetail.service.TaskDetailService; import com.huaheng.pc.task.taskHeader.domain.TaskHeader; @@ -103,7 +104,11 @@ public class InventoryDetailServiceImpl extends ServiceImpl<InventoryDetailMappe } @Override - public List<InventoryDetail> selectBysql(String sql) { + public List<InventoryDetail> selectBysql(String sql, ShipmentDetail shipmentDetail) { + sql=sql+" \n" +"and warehouseCode='" + shipmentDetail.getWarehouseCode()+"' \n" + + "and companyCode='" + shipmentDetail.getCompanyCode()+"' \n" + + "and materialCode='" + shipmentDetail.getMaterialCode() +"' \n" + + "and inventorySts='" + shipmentDetail.getInventorySts() + "'"; return inventoryDetailMapper.selectBysql(sql); } diff --git a/src/main/java/com/huaheng/pc/receipt/receiptDetail/service/ReceiptDetailServiceImpl.java b/src/main/java/com/huaheng/pc/receipt/receiptDetail/service/ReceiptDetailServiceImpl.java index 7719f94..7ef8e72 100644 --- a/src/main/java/com/huaheng/pc/receipt/receiptDetail/service/ReceiptDetailServiceImpl.java +++ b/src/main/java/com/huaheng/pc/receipt/receiptDetail/service/ReceiptDetailServiceImpl.java @@ -156,7 +156,7 @@ public class ReceiptDetailServiceImpl extends ServiceImpl<ReceiptDetailMapper, R */ @Transactional public ReceiptDetail queryflow(ReceiptDetail receiptDetail){ - + //当单据状态为驳回或作废时不更新状态 if ("10".equals(receiptDetail.getProcessStamp()) || "20".equals(receiptDetail.getProcessStamp())){ return receiptDetail; } diff --git a/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java b/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java index 279cbed..4990101 100644 --- a/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java +++ b/src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java @@ -360,13 +360,13 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont continue; } // 根据 仓库编码、货主编码、存货编码,物料状态,项目号来查找可以出库的物料 - ShippingSearch search = new ShippingSearch(); - search.setWarehouseCode(ShiroUtils.getWarehouseCode()); - search.setCompanyCode(item.getCompanyCode()); - search.setMaterialCode(item.getMaterialCode()); - search.setInventorySts(item.getInventorySts()); //物料状态 +// ShippingSearch search = new ShippingSearch(); +// search.setWarehouseCode(ShiroUtils.getWarehouseCode()); +// search.setCompanyCode(item.getCompanyCode()); +// search.setMaterialCode(item.getMaterialCode()); +// search.setInventorySts(item.getInventorySts()); //物料状态 - List<InventoryDetail> inventoryList = shippingCombinationService.getInventorys(search); + List<InventoryDetail> inventoryList = shippingCombinationService.getInventorys(item); if (inventoryList.size() < 1) { num = num + 1; } else { diff --git a/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java b/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java index 67d1df9..47bc577 100644 --- a/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java +++ b/src/main/java/com/huaheng/pc/shipment/shippingCombination/controller/ShippingCombinationController.java @@ -42,8 +42,7 @@ public class ShippingCombinationController extends BaseController { private String prefix = "shipment/shippingCombination"; - @Autowired - MaterialServiceImpl materialService; + @Autowired ShipmentDetailServiceImpl shipmentDetailService; @Autowired @@ -54,14 +53,6 @@ public class ShippingCombinationController extends BaseController { ShipmentContainerDetailService shipmentContainerDetailService; @Autowired ShipmentHeaderService shipmentHeaderService; - @Autowired - InventoryDetailService inventoryDetailService; - @Autowired - ConfigValueService configValueService; - @Autowired - FilterConfigDetailService filterConfigDetailService; - @Autowired - ShipmentPreferenceService shipmentPreferenceService; /** @@ -152,72 +143,8 @@ public class ShippingCombinationController extends BaseController { throw new ServiceException("找不到子单"); } + List<InventoryDetail> list=shippingCombinationService.getInventorys(shipmentDetail); //查找分配规则 - List<InventoryDetail> list=new ArrayList<>(); - FilterConfigDetail filterConfigDetail=new FilterConfigDetail(); - LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambdaQueryWrapper=Wrappers.lambdaQuery(); - filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getWarehouseCode,shipmentDetail.getWarehouseCode()); - - //出库子单的分配规则有时,优先出库子单的分配规则 - if(StringUtils.isNotEmpty(shipmentDetail.getAllocationRule())){ - filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentDetail.getAllocationRule()); - filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); - if(filterConfigDetail==null){ - throw new ServiceException("出库子单出库规则配置不存在"); - } - - //根据sql查库存 - try { - list = inventoryDetailService.selectBysql(filterConfigDetail.getStatement()); - }catch (Exception e){ - throw new ServiceException("sql错误"); - } - return getDataTable(list); - } - - //出库子单的分配规则没有时,优先物料的分配规则 - LambdaQueryWrapper<Material> materialLambdaQueryWrapper=Wrappers.lambdaQuery(); - materialLambdaQueryWrapper.eq(Material::getCode,shipmentDetail.getMaterialCode()) - .eq(Material::getWarehouseCode,shipmentDetail.getWarehouseCode()); - Material material=materialService.getOne(materialLambdaQueryWrapper); - if(StringUtils.isNotEmpty(material.getAllocationRule())){ - filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,material.getAllocationRule()); - filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); - if(filterConfigDetail==null){ - throw new ServiceException("物料出库规则配置不存在"); - } - - //根据sql查库存 - list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement()); - return getDataTable(list); - } - - //都没有时,默认仓库的分配规则 - LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper=Wrappers.lambdaQuery(); - configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType,"shipment") - .eq(ConfigValue::getWarehouseCode,shipmentDetail.getWarehouseCode()); - ConfigValue configValue=configValueService.getOne(configValueLambdaQueryWrapper); - if(configValue==null){ - throw new ServiceException("仓库的出库配置不存在"); - } - - //查找出库首选项 - LambdaQueryWrapper<ShipmentPreference> slam=Wrappers.lambdaQuery(); - slam.eq(ShipmentPreference::getCode,configValue.getIdentifier()) - .eq(ShipmentPreference::getWarehouseCode,configValue.getWarehouseCode()); - ShipmentPreference shipmentPreference=shipmentPreferenceService.getOne(slam); - if(shipmentPreference==null){ - throw new ServiceException("仓库的出库配置中出库首选项不存在"); - } - //查找分配规则 - filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentPreference.getAllocationRule()); - filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); - if(filterConfigDetail==null){ - throw new ServiceException("出库首选项中出库规则配置不存在"); - } - - //根据sql查库存 - list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement()); return getDataTable(list); } diff --git a/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java b/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java index fba8f25..9c38262 100644 --- a/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java +++ b/src/main/java/com/huaheng/pc/shipment/shippingCombination/service/ShippingCombinationService.java @@ -1,12 +1,28 @@ package com.huaheng.pc.shipment.shippingCombination.service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.huaheng.common.exception.service.ServiceException; +import com.huaheng.common.utils.StringUtils; +import com.huaheng.pc.config.FilterConfigDetail.domain.FilterConfigDetail; +import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService; +import com.huaheng.pc.config.configValue.domain.ConfigValue; +import com.huaheng.pc.config.configValue.service.ConfigValueService; +import com.huaheng.pc.config.material.domain.Material; +import com.huaheng.pc.config.material.service.MaterialServiceImpl; +import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference; +import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService; import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail; +import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService; +import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail; import com.huaheng.pc.shipment.shippingCombination.domain.ShippingSearch; import com.huaheng.pc.shipment.shippingCombination.mapper.ShippingCombinationMapper; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; @@ -15,10 +31,86 @@ public class ShippingCombinationService { @Resource private ShippingCombinationMapper shippingCombinationMapper; + @Autowired + InventoryDetailService inventoryDetailService; + @Autowired + ConfigValueService configValueService; + @Autowired + FilterConfigDetailService filterConfigDetailService; + @Autowired + ShipmentPreferenceService shipmentPreferenceService; + @Autowired + MaterialServiceImpl materialService; - public List<InventoryDetail> getInventorys(ShippingSearch search) { - List<InventoryDetail> list = shippingCombinationMapper.getInventorys(search); + + //根据分配规则查找库存 + public List<InventoryDetail> getInventorys(ShipmentDetail shipmentDetail) { + List<InventoryDetail> list=new ArrayList<>(); + FilterConfigDetail filterConfigDetail=new FilterConfigDetail(); + LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambdaQueryWrapper= Wrappers.lambdaQuery(); + filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getWarehouseCode,shipmentDetail.getWarehouseCode()); + + //出库子单的分配规则有时,优先出库子单的分配规则 + if(StringUtils.isNotEmpty(shipmentDetail.getAllocationRule())){ + filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentDetail.getAllocationRule()); + filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); + if(filterConfigDetail==null){ + throw new ServiceException("出库子单出库规则配置不存在"); + } + + //根据sql查库存 + try { + list = inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail); + }catch (Exception e){ + throw new ServiceException("sql错误"); + } + return list; + } + + //出库子单的分配规则没有时,优先物料的分配规则 + LambdaQueryWrapper<Material> materialLambdaQueryWrapper=Wrappers.lambdaQuery(); + materialLambdaQueryWrapper.eq(Material::getCode,shipmentDetail.getMaterialCode()) + .eq(Material::getWarehouseCode,shipmentDetail.getWarehouseCode()); + Material material=materialService.getOne(materialLambdaQueryWrapper); + if(StringUtils.isNotEmpty(material.getAllocationRule())){ + filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,material.getAllocationRule()); + filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); + if(filterConfigDetail==null){ + throw new ServiceException("物料出库规则配置不存在"); + } + + //根据sql查库存 + list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail); + return list; + } + + //都没有时,默认仓库的分配规则 + LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper=Wrappers.lambdaQuery(); + configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType,"shipment") + .eq(ConfigValue::getWarehouseCode,shipmentDetail.getWarehouseCode()); + ConfigValue configValue=configValueService.getOne(configValueLambdaQueryWrapper); + if(configValue==null){ + throw new ServiceException("仓库的出库配置不存在"); + } + + //查找出库首选项 + LambdaQueryWrapper<ShipmentPreference> slam=Wrappers.lambdaQuery(); + slam.eq(ShipmentPreference::getCode,configValue.getIdentifier()) + .eq(ShipmentPreference::getWarehouseCode,configValue.getWarehouseCode()); + ShipmentPreference shipmentPreference=shipmentPreferenceService.getOne(slam); + if(shipmentPreference==null){ + throw new ServiceException("仓库的出库配置中出库首选项不存在"); + } + //查找分配规则 + filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentPreference.getAllocationRule()); + filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper); + if(filterConfigDetail==null){ + throw new ServiceException("出库首选项中出库规则配置不存在"); + } + + //根据sql查库存 + list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement(),shipmentDetail); return list; } diff --git a/src/main/resources/templates/shipment/shippingCombination/shippingCombination.html b/src/main/resources/templates/shipment/shippingCombination/shippingCombination.html index 396c5aa..cf6ddb3 100644 --- a/src/main/resources/templates/shipment/shippingCombination/shippingCombination.html +++ b/src/main/resources/templates/shipment/shippingCombination/shippingCombination.html @@ -135,7 +135,12 @@ id:row.id }, success:res=>{ - $("#bootstrap-table1").bootstrapTable('load',res.data) + if(res.code===200){ + $("#bootstrap-table1").bootstrapTable('load',res.data) + } + else{ + $.modal.alertError(res.msg) + } } }) },