Browse Source

修改库存查询算法

lwx_dev
erdanergou 3 years ago
parent
commit
269d0866b2
  1. 91
      src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java
  2. 18
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java
  3. 105
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml
  4. 13
      src/main/java/com/dreamchaser/depository_manage/service/MaterialService.java
  5. 85
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  6. 105
      target/classes/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml

91
src/main/java/com/dreamchaser/depository_manage/controller/MaterialController.java

@ -154,94 +154,28 @@ public class MaterialController {
UserByPort userToken = AuthenticationTokenPool.getUserToken(token);
List<InventoryP> list = new ArrayList<>();
Integer total = 0;
if (Integer.compare(userToken.getMaindeparment(), 361) != 0) {
Integer isadmin = userToken.getIsadmin();
if (isadmin == null) {
isadmin = 1;
}
if (isadmin != 4 && Integer.compare(userToken.getMaindeparment(), 361) != 0) {
// 查询当前用户管理的仓库
List<RoleAndDepository> depositoryAndRole = roleService.findDepositoryAndRole(userToken.getId());
// 查询当前用户部门拥有的仓库
List<Depository> depositoryByAdminorg = depositoryService.findDepositoryByAdminorg(userToken.getMaindeparment().toString());
// 定义仓库编号列表
List<Integer> didList = new ArrayList<>();
Integer size = 10, page = 1; // 定义每页展示数量
if (map.containsKey("size")) {
size = ObjectFormatUtil.toInteger(map.get("size"));
}
if (!(map.containsKey("depositoryId") || map.containsKey("mcode") || map.containsKey("mname") || map.containsKey("version"))) {
// 用于标识是一次就查询成功
boolean flag = true;
for (Depository depository : depositoryByAdminorg) {
Integer did = depository.getId();
didList.add(did);
map.put("depositoryId", did);
List<InventoryP> inventory = null;
if (!flag) {
// 如果不是一次成功
page = ObjectFormatUtil.toInteger(map.get("page"));
if (page == null) {
page = 1;
}
if (size - list.size() != size) {
// 如果当前不是崭新一页
map.put("begin", 0);
} else {
map.put("begin", (page - 1) * size - total);
for (RoleAndDepository andDepository : depositoryAndRole) {
didList.add(andDepository.getId());
}
map.put("size", size - list.size());
}
if (!map.containsKey("begin")) {
inventory = materialService.findInventory(map);
} else {
inventory = materialService.findInventoryByDepository(map);
for (Depository value : depositoryByAdminorg) {
didList.add(value.getId());
}
total += materialService.findInventoryCount(map);
map.put("depositoryIds", didList);
if (list.size() < size) {
list.addAll(inventory);
// 如果本次没有达到数目
if (list.size() < size) {
flag = false;
}
}
}
for (RoleAndDepository roleAndDepository : depositoryAndRole) {
Integer depositoryId = roleAndDepository.getDepositoryId();
if (didList.contains(depositoryId)) {
// 如果当前仓库编号存在
continue; // 跳过本次循环
}
map.put("depositoryId", depositoryId);
// 如果当前数目不足
if (map.containsKey("page")) {
// 当前页
page = ObjectFormatUtil.toInteger(map.get("page"));
}
// 计算所有页数
// 判断当前是在全新一页还是包含上述内容
if (size - list.size() != size) {
// 如果当前不是崭新一页
map.put("begin", 0);
} else {
map.put("begin", (page - 1) * size - total);
}
map.put("size", size - list.size());
if (list.size() < size) {
List<InventoryP> materialByDepository = materialService.findInventoryByDepository(map);
list.addAll(materialByDepository);
}
total += materialService.findMaterialByDepositoryCount(map);
}
} else {
List<InventoryP> inventory = materialService.findInventory(map);
list.addAll(inventory);
total += materialService.findInventoryCount(map);
}
for (InventoryP inventoryP : list
) {
inventoryP.setSplitInfoList(splitUnitService.findSplitInfoByMid(inventoryP.getMid()));
}
list = materialService.findInventoryByDids(map);
total = materialService.findInventoryCountByDids(map);
} else {
list = materialService.findInventory(map);
total = materialService.findInventoryCount(map);
@ -1691,6 +1625,7 @@ public class MaterialController {
/**
* 用于库存盘点时根据物料查询所处位置
*
* @param map
* @param request
* @return

18
src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java

@ -1,6 +1,7 @@
package com.dreamchaser.depository_manage.mapper;
import com.dreamchaser.depository_manage.entity.*;
import com.dreamchaser.depository_manage.pojo.InventoryP;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@ -144,6 +145,21 @@ public interface MaterialMapper {
*/
List<Inventory> findInventory(Map<String,Object> map);
/**
* 根据条件查询符合条件的库存
* @param map
* @return
*/
List<Inventory> findInventoryByDids(Map<String,Object> map);
/**
* 根据条件查询符合条件的库存数量
* @param map
* @return
*/
Integer findInventoryCountByDids(Map<String,Object> map);
/**
* 根据条件查询符合条件的库存
* @param map
@ -167,6 +183,8 @@ public interface MaterialMapper {
*/
List<Inventory> findInventoryByMidAndDids(Map<String,Object> map);
/**
* 根据id查询库存信息
* @param id 库存id

105
src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml

@ -352,6 +352,111 @@
</if>
</select>
<select id="findInventoryByDids" resultMap="InventoryMap" parameterType="map">
SELECT
<include refid="allColumnsAndTypeNameOnViewByInventory"/>
from findInventory
where 1 = 1
and depositoryId in
<foreach collection="depositoryIds" index="index" item="did" open="(" separator="," close=")">
#{did}
</foreach>
<if test="mid != null">
and mid = #{mid}
</if>
<if test="mname != null and mname != ''">
AND mname LIKE CONCAT('%', #{mname}, '%')
</if>
<if test="version != null">
and version = #{version}
</if>
<if test="quantity != null">
AND quantity = #{quantity}
</if>
<if test="price != null">
AND price = #{price}
</if>
<if test="materialTypeId != null">
AND mtid = #{materialTypeId}
</if>
<if test="state != null and state != ''">
And mstate = #{state}
</if>
<if test="mcode != null and mcode != '' ">
and mcode = #{mcode}
</if>
<if test="shelfLife != null">
and #{shelfLife} >= shelfLife
</if>
<if test="producedDate != null">
and producedDate >= #{producedDate}
</if>
<if test="productionPlace != null and productionPlace !=''">
and productionPlace = #{productionPlace}
</if>
<if test="brand != '' and brand != null">
and brand LIKE CONCAT('%', #{brand}, '%')
</if>
<if test="remark != '' and remark != null">
and remark LIKE CONCAT('%', #{remark}, '%')
</if>
<if test="begin != null and size != null">
LIMIT #{begin},#{size}
</if>
</select>
<select id="findInventoryCountByDids" resultType="int" parameterType="map">
SELECT
COUNT(*)
from findInventory
where 1 = 1
and depositoryId in
<foreach collection="depositoryIds" index="index" item="did" open="(" separator="," close=")">
#{did}
</foreach>
<if test="mid != null">
and mid = #{mid}
</if>
<if test="mname != null and mname != ''">
AND mname LIKE CONCAT('%', #{mname}, '%')
</if>
<if test="version != null">
and version = #{version}
</if>
<if test="quantity != null">
AND quantity = #{quantity}
</if>
<if test="price != null">
AND price = #{price}
</if>
<if test="materialTypeId != null">
AND mtid = #{materialTypeId}
</if>
<if test="state != null and state != ''">
And mstate = #{state}
</if>
<if test="mcode != null and mcode != '' ">
and mcode = #{mcode}
</if>
<if test="shelfLife != null">
and #{shelfLife} >= shelfLife
</if>
<if test="producedDate != null">
and producedDate >= #{producedDate}
</if>
<if test="productionPlace != null and productionPlace !=''">
and productionPlace = #{productionPlace}
</if>
<if test="brand != '' and brand != null">
and brand LIKE CONCAT('%', #{brand}, '%')
</if>
<if test="remark != '' and remark != null">
and remark LIKE CONCAT('%', #{remark}, '%')
</if>
</select>
<!--根据条件查询库存-->
<select id="findInventoryForImport" resultMap="InventoryMap" parameterType="map">
SELECT

13
src/main/java/com/dreamchaser/depository_manage/service/MaterialService.java

@ -74,6 +74,19 @@ public interface MaterialService {
*/
List<InventoryP> findInventory(Map<String,Object> map);
/**
* 根据条件查询符合条件的库存数量
* @param map
* @return
*/
Integer findInventoryCountByDids(Map<String,Object> map);
/**
* 根据条件查询符合条件的库存
* @param map
* @return
*/
List<InventoryP> findInventoryByDids(Map<String,Object> map);
/**
* 根据物料编码及所处仓库查询库存

85
src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java

@ -298,32 +298,42 @@ public class MaterialServiceImpl implements MaterialService {
}
map.put("state", state);
List<Inventory> list = materialMapper.findInventory(map);
for (Inventory inventory : list) {
if (inventory.getPrice() != null) {
inventory.setPrice(inventory.getPrice() / 100);
} else {
inventory.setPrice(0.0);
return pack(list);
}
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
// 获取当前物料所处仓库
Integer depositoryId = inventory.getDepositoryId();
// 获取当前物料所处库位
Integer mid = inventory.getId();
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(mid, depositoryId);
StringBuilder placeCode = new StringBuilder();
StringBuilder placeKingdeeCode = new StringBuilder();
for (PlaceP placeP : placeByMidAndDid) {
placeKingdeeCode.append(placeP.getKingdeecode()).append(" ");
placeCode.append(placeP.getCode()).append(" ");
/**
* 根据条件查询符合条件的库存数量
* @param map
* @return
*/
@Override
public Integer findInventoryCountByDids(Map<String, Object> map) {
return materialMapper.findInventoryCountByDids(map);
}
if (depositoryId != null) {
Depository depositoryRecordById = depositoryMapper.findDepositoryById(depositoryId);
String code = depositoryRecordById.getCode();
inventory.setDepositoryCode(code);
/**
* 根据条件查询符合条件的库存
*
* @param map
* @return
*/
@Override
public List<InventoryP> findInventoryByDids(Map<String, Object> map) {
Integer size = 10, page = 1;
if (map.containsKey("size")) {
size = ObjectFormatUtil.toInteger(map.get("size"));
map.put("size", size);
}
inventory.setPlaceCode(placeCode.toString());
inventory.setPlaceKingdeeCode(placeKingdeeCode.toString());
if (map.containsKey("page")) {
page = ObjectFormatUtil.toInteger(map.get("page"));
map.put("begin", (page - 1) * size);
}
Object state = 1;
if (map.containsKey("state")) {
state = map.get("state");
}
map.put("state", state);
List<Inventory> list = materialMapper.findInventoryByDids(map);
return pack(list);
}
@ -754,10 +764,34 @@ public class MaterialServiceImpl implements MaterialService {
*/
private List<InventoryP> pack(List<Inventory> list) {
List<InventoryP> result = new ArrayList<>(list.size());
for (Inventory inventory : list) {
if (inventory.getPrice() != null) {
inventory.setPrice(inventory.getPrice() / 100);
} else {
inventory.setPrice(0.0);
}
inventory.setAmounts(inventory.getPrice() * inventory.getQuantity());
// 获取当前物料所处仓库
Integer depositoryId = inventory.getDepositoryId();
// 获取当前物料所处库位
Integer mid = inventory.getId();
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(mid, depositoryId);
StringBuilder placeCode = new StringBuilder();
StringBuilder placeKingdeeCode = new StringBuilder();
for (PlaceP placeP : placeByMidAndDid) {
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);
}
inventory.setPlaceCode(placeCode.toString());
inventory.setPlaceKingdeeCode(placeKingdeeCode.toString());
InventoryP m = new InventoryP(inventory);
Integer warningCount = 0;
Integer depositoryId = inventory.getDepositoryId();
if (depositoryId != null) {
m.setDepositoryName(depositoryMapper.findDepositoryNameById(depositoryId));
m.setWarehouseManager(depositoryMapper.findUserNameByDepositoryId(depositoryId));
@ -807,10 +841,6 @@ public class MaterialServiceImpl implements MaterialService {
m.setTypeId(materialTypeByOldId.getOldId());
m.setWarningCount(warningCount);
// 查询当前物料在该仓库中的库位位置
List<PlaceP> placeByMidAndDid = placeService.findPlaceByMidAndDid(m.getId(), m.getDepositoryId());
Map<String, Double> splitInventoryForUnit = new HashMap<>();
splitInventoryForUnit.put(inventory.getUnit(), (double) inventory.getQuantity() / 100);
m.setBaseUnitQuantity((double) inventory.getQuantity() / 100);
@ -993,7 +1023,6 @@ public class MaterialServiceImpl implements MaterialService {
}
double quantity = Double.parseDouble(map.get("quantity").toString());
double quantity_residue = 0;
int splitInfoScaleQuantity = 0;

105
target/classes/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml

@ -352,6 +352,111 @@
</if>
</select>
<select id="findInventoryByDids" resultMap="InventoryMap" parameterType="map">
SELECT
<include refid="allColumnsAndTypeNameOnViewByInventory"/>
from findInventory
where 1 = 1
and depositoryId in
<foreach collection="depositoryIds" index="index" item="did" open="(" separator="," close=")">
#{did}
</foreach>
<if test="mid != null">
and mid = #{mid}
</if>
<if test="mname != null and mname != ''">
AND mname LIKE CONCAT('%', #{mname}, '%')
</if>
<if test="version != null">
and version = #{version}
</if>
<if test="quantity != null">
AND quantity = #{quantity}
</if>
<if test="price != null">
AND price = #{price}
</if>
<if test="materialTypeId != null">
AND mtid = #{materialTypeId}
</if>
<if test="state != null and state != ''">
And mstate = #{state}
</if>
<if test="mcode != null and mcode != '' ">
and mcode = #{mcode}
</if>
<if test="shelfLife != null">
and #{shelfLife} >= shelfLife
</if>
<if test="producedDate != null">
and producedDate >= #{producedDate}
</if>
<if test="productionPlace != null and productionPlace !=''">
and productionPlace = #{productionPlace}
</if>
<if test="brand != '' and brand != null">
and brand LIKE CONCAT('%', #{brand}, '%')
</if>
<if test="remark != '' and remark != null">
and remark LIKE CONCAT('%', #{remark}, '%')
</if>
<if test="begin != null and size != null">
LIMIT #{begin},#{size}
</if>
</select>
<select id="findInventoryCountByDids" resultType="int" parameterType="map">
SELECT
COUNT(*)
from findInventory
where 1 = 1
and depositoryId in
<foreach collection="depositoryIds" index="index" item="did" open="(" separator="," close=")">
#{did}
</foreach>
<if test="mid != null">
and mid = #{mid}
</if>
<if test="mname != null and mname != ''">
AND mname LIKE CONCAT('%', #{mname}, '%')
</if>
<if test="version != null">
and version = #{version}
</if>
<if test="quantity != null">
AND quantity = #{quantity}
</if>
<if test="price != null">
AND price = #{price}
</if>
<if test="materialTypeId != null">
AND mtid = #{materialTypeId}
</if>
<if test="state != null and state != ''">
And mstate = #{state}
</if>
<if test="mcode != null and mcode != '' ">
and mcode = #{mcode}
</if>
<if test="shelfLife != null">
and #{shelfLife} >= shelfLife
</if>
<if test="producedDate != null">
and producedDate >= #{producedDate}
</if>
<if test="productionPlace != null and productionPlace !=''">
and productionPlace = #{productionPlace}
</if>
<if test="brand != '' and brand != null">
and brand LIKE CONCAT('%', #{brand}, '%')
</if>
<if test="remark != '' and remark != null">
and remark LIKE CONCAT('%', #{remark}, '%')
</if>
</select>
<!--根据条件查询库存-->
<select id="findInventoryForImport" resultMap="InventoryMap" parameterType="map">
SELECT

Loading…
Cancel
Save