|
|
|
@ -14,6 +14,7 @@ import com.dreamchaser.depository_manage.security.pool.RedisPool; |
|
|
|
import com.dreamchaser.depository_manage.service.*; |
|
|
|
import com.dreamchaser.depository_manage.utils.DateUtil; |
|
|
|
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -26,6 +27,7 @@ import java.util.concurrent.*; |
|
|
|
/** |
|
|
|
* @author Dreamchaser |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class MaterialServiceImpl implements MaterialService { |
|
|
|
@Autowired |
|
|
|
@ -301,7 +303,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
} |
|
|
|
map.put("state", state); |
|
|
|
List<Inventory> list = materialMapper.findInventory(map); |
|
|
|
return pack(list); |
|
|
|
return pack(list, map.get("placeId")); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -752,9 +754,20 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
* @param list DepositoryRecord集合 |
|
|
|
* @return 包装好的集合 |
|
|
|
*/ |
|
|
|
private List<InventoryP> pack(List<Inventory> list) { |
|
|
|
private List<InventoryP> pack(List<Inventory> list, Object pid) { |
|
|
|
List<InventoryP> result = new ArrayList<>(list.size()); |
|
|
|
|
|
|
|
boolean flagForByPlace = false; |
|
|
|
int placeId = -1; |
|
|
|
if (pid != null) { |
|
|
|
try { |
|
|
|
placeId = ObjectFormatUtil.toInteger(pid); |
|
|
|
if (placeId != 0) { |
|
|
|
flagForByPlace = true; |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("查看库存时,库位转换失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
for (Inventory inventory : list) { |
|
|
|
if (inventory.getPrice() != null) { |
|
|
|
inventory.setPrice(inventory.getPrice() / 100); |
|
|
|
@ -764,23 +777,91 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity()); |
|
|
|
// 获取当前物料所处仓库
|
|
|
|
Integer depositoryId = inventory.getDepositoryId(); |
|
|
|
|
|
|
|
List<PlaceP> placePList = new ArrayList<>(); |
|
|
|
if (flagForByPlace) { |
|
|
|
// 如果是根据库位查询
|
|
|
|
placePList.add(new PlaceP(placeService.findPlaceById(placeId))); |
|
|
|
|
|
|
|
} else { |
|
|
|
// 如果不是
|
|
|
|
|
|
|
|
// 获取当前物料所处库位
|
|
|
|
Integer mid = inventory.getId(); |
|
|
|
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(mid, depositoryId); |
|
|
|
placePList = placeService.findPlaceByMidAndDid(mid, depositoryId); |
|
|
|
} |
|
|
|
|
|
|
|
InventoryP m = new InventoryP(inventory); |
|
|
|
|
|
|
|
Map<String, Double> splitInventoryForUnit = new HashMap<>(); |
|
|
|
splitInventoryForUnit.put(inventory.getUnit(), (double) inventory.getQuantity() / 100); |
|
|
|
m.setBaseUnitQuantity((double) inventory.getQuantity() / 100); |
|
|
|
|
|
|
|
// 定义最后展示单位及数目
|
|
|
|
String unit = inventory.getUnit(); |
|
|
|
|
|
|
|
//定义总额
|
|
|
|
double amounts = 0.0; |
|
|
|
|
|
|
|
boolean flagForInventoryAndPlace = true; |
|
|
|
for (PlaceP place : |
|
|
|
placePList) { |
|
|
|
// 获取当前具体数据
|
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialByMidAndPid(place.getId(), m.getId()); |
|
|
|
if (placeAndMaterialByMidAndPid == null) { |
|
|
|
flagForInventoryAndPlace = false; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
flagForInventoryAndPlace = true; |
|
|
|
} |
|
|
|
// 获取当前是否存在拆单处理记录
|
|
|
|
|
|
|
|
// 获取当前物料对应的所有拆单数目
|
|
|
|
List<SplitInfo> splitInfoByMid = splitUnitMapper.findSplitInfoByMid(inventory.getMid()); |
|
|
|
for (SplitInfo splitInfo : splitInfoByMid |
|
|
|
) { |
|
|
|
// 获取当前拆单单位的总数
|
|
|
|
double saveQuantity = splitUnitService.findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, splitInfo.getId(), 0, true); |
|
|
|
|
|
|
|
if (splitInventoryForUnit.containsKey(splitInfo.getNewUnit())) { |
|
|
|
// 如果当前存在该拆单类型的记录
|
|
|
|
|
|
|
|
// 更新当前类型数据
|
|
|
|
splitInventoryForUnit.put(splitInfo.getNewUnit(), splitInventoryForUnit.get(splitInfo.getNewUnit()) + saveQuantity); |
|
|
|
} else { |
|
|
|
// 如果不存在,则新增
|
|
|
|
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity); |
|
|
|
|
|
|
|
} |
|
|
|
if (inventory.getPrice() == null) { |
|
|
|
inventory.setPrice(0.0); |
|
|
|
} |
|
|
|
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / scale); |
|
|
|
double split_price = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
amounts = ObjectFormatUtil.sum(amounts, split_price * saveQuantity); |
|
|
|
unit = splitInfo.getNewUnit(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!flagForInventoryAndPlace) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
StringBuilder placeCode = new StringBuilder(); |
|
|
|
StringBuilder placeKingdeeCode = new StringBuilder(); |
|
|
|
for (PlaceP placeP : placeByMidAndDid) { |
|
|
|
for (PlaceP placeP : placePList) { |
|
|
|
placeKingdeeCode.append(placeP.getKingdeecode()).append(" "); |
|
|
|
placeCode.append(placeP.getCode()).append(" "); |
|
|
|
} |
|
|
|
if (depositoryId != null) { |
|
|
|
Depository depositoryRecordById = depositoryMapper.findDepositoryById(depositoryId); |
|
|
|
String code = depositoryRecordById.getCode(); |
|
|
|
inventory.setDepositoryCode(code); |
|
|
|
m.setDepositoryCode(code); |
|
|
|
} |
|
|
|
inventory.setPlaceCode(placeCode.toString()); |
|
|
|
inventory.setPlaceKingdeeCode(placeKingdeeCode.toString()); |
|
|
|
InventoryP m = new InventoryP(inventory); |
|
|
|
m.setPlaceCode(placeCode.toString()); |
|
|
|
m.setPlaceKingdeeCode(placeKingdeeCode.toString()); |
|
|
|
|
|
|
|
Integer warningCount = 0; |
|
|
|
if (depositoryId != null) { |
|
|
|
m.setDepositoryName(depositoryMapper.findDepositoryNameById(depositoryId)); |
|
|
|
@ -831,49 +912,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
m.setTypeId(materialTypeByOldId.getOldId()); |
|
|
|
m.setWarningCount(warningCount); |
|
|
|
|
|
|
|
Map<String, Double> splitInventoryForUnit = new HashMap<>(); |
|
|
|
splitInventoryForUnit.put(inventory.getUnit(), (double) inventory.getQuantity() / 100); |
|
|
|
m.setBaseUnitQuantity((double) inventory.getQuantity() / 100); |
|
|
|
|
|
|
|
// 定义最后展示单位及数目
|
|
|
|
String unit = inventory.getUnit(); |
|
|
|
|
|
|
|
//定义总额
|
|
|
|
double amounts = 0.0; |
|
|
|
|
|
|
|
for (PlaceP place : |
|
|
|
placeByMidAndDid) { |
|
|
|
// 获取当前具体数据
|
|
|
|
MaterialAndPlace placeAndMaterialByMidAndPid = placeService.findPlaceAndMaterialByMidAndPid(place.getId(), m.getId()); |
|
|
|
// 获取当前是否存在拆单处理记录
|
|
|
|
// 获取当前物料对应的所有拆单数目
|
|
|
|
List<SplitInfo> splitInfoByMid = splitUnitMapper.findSplitInfoByMid(inventory.getMid()); |
|
|
|
for (SplitInfo splitInfo : splitInfoByMid |
|
|
|
) { |
|
|
|
// 获取当前拆单单位的总数
|
|
|
|
double saveQuantity = splitUnitService.findAllInventoryForSplitInfo(-1, placeAndMaterialByMidAndPid, splitInfo.getId(), 0, true); |
|
|
|
|
|
|
|
if (splitInventoryForUnit.containsKey(splitInfo.getNewUnit())) { |
|
|
|
// 如果当前存在该拆单类型的记录
|
|
|
|
|
|
|
|
// 更新当前类型数据
|
|
|
|
splitInventoryForUnit.put(splitInfo.getNewUnit(), splitInventoryForUnit.get(splitInfo.getNewUnit()) + saveQuantity); |
|
|
|
} else { |
|
|
|
// 如果不存在,则新增
|
|
|
|
splitInventoryForUnit.put(splitInfo.getNewUnit(), saveQuantity); |
|
|
|
|
|
|
|
} |
|
|
|
if (inventory.getPrice() == null) { |
|
|
|
inventory.setPrice(0.0); |
|
|
|
} |
|
|
|
int scale = splitUnitService.findSplitInfoScaleQuantity(splitInfo, -1); |
|
|
|
BigDecimal bigDecimal = BigDecimal.valueOf(inventory.getPrice() / scale); |
|
|
|
double split_price = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); |
|
|
|
amounts = ObjectFormatUtil.sum(amounts, split_price * saveQuantity); |
|
|
|
unit = splitInfo.getNewUnit(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 设置新总额
|
|
|
|
m.setAmounts(m.getAmounts() + amounts); |
|
|
|
// 设置当前各拆单信息对应的库存
|
|
|
|
@ -976,7 +1015,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity()); |
|
|
|
} |
|
|
|
|
|
|
|
return pack(materialByDepository); |
|
|
|
return pack(materialByDepository, null); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -1074,8 +1113,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
// 如果要导入的不是默认库位
|
|
|
|
Map<String, Object> param = new HashMap<>(); |
|
|
|
param.put("depositoryId", material.getDepositoryId()); |
|
|
|
@ -1119,8 +1157,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
} |
|
|
|
} |
|
|
|
return materialMapper.updateInventory(material); |
|
|
|
} |
|
|
|
else { |
|
|
|
} else { |
|
|
|
// 用于标志是新插入的物料
|
|
|
|
map.put("isNew", true); |
|
|
|
Double quantity = ObjectFormatUtil.toDouble(map.get("quantity")); |
|
|
|
@ -1573,7 +1610,7 @@ public class MaterialServiceImpl implements MaterialService { |
|
|
|
// 新增对应关系
|
|
|
|
Map<String, Object> insertAfter = new HashMap<>(); |
|
|
|
insertAfter.put("mid", id); |
|
|
|
insertAfter.put("quantity", quantity); |
|
|
|
insertAfter.put("quantity", (int)(quantity * 100)); |
|
|
|
insertAfter.put("pid", toPlaceId); |
|
|
|
// 添加对应关系
|
|
|
|
placeService.addMaterialOnPlace(insertAfter); |
|
|
|
|