Browse Source

添加拆单功能

lwx_dev
erdanergou 3 years ago
parent
commit
1163b9a296
  1. 39
      src/main/java/com/dreamchaser/depository_manage/entity/SplitInfo.java
  2. 34
      src/main/java/com/dreamchaser/depository_manage/entity/SplitInventory.java
  3. 98
      src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.java
  4. 170
      src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml
  5. 27
      src/main/java/com/dreamchaser/depository_manage/service/SplitUnitService.java
  6. 136
      src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java
  7. 2
      src/main/java/com/dreamchaser/depository_manage/utils/ObjectFormatUtil.java
  8. 5
      src/test/java/com/dreamchaser/depository_manage/TestForOther.java

39
src/main/java/com/dreamchaser/depository_manage/entity/SplitInfo.java

@ -0,0 +1,39 @@
package com.dreamchaser.depository_manage.entity;
import lombok.Data;
/**
* 拆单基础信息
*/
@Data
public class SplitInfo {
/**
* 拆单id
*/
private Integer id;
/**
* 物料id
*/
private Integer mid;
/**
* 旧计量单位
*/
private String oldUnit;
/**
* 新计量单位
*/
private String newUnit;
/**
* 新旧单位映射数
*/
private Integer quantity;
/**
* 父级id
*/
private Integer parentId;
/**
* 状态1启用2禁用3删除
*/
private Integer state;
}

34
src/main/java/com/dreamchaser/depository_manage/entity/SplitInventory.java

@ -0,0 +1,34 @@
package com.dreamchaser.depository_manage.entity;
import lombok.Data;
/**
* 拆单后出入库记录
*/
@Data
public class SplitInventory {
/**
* 记录id
*/
private Integer id;
/**
* 对应库存id
*/
private Integer iid;
/**
* 对应拆单id
*/
private Integer sid;
/**
* 出库数量
*/
private Integer outQuantity;
/**
* 入库数量
*/
private Integer inQuantity;
/**
* 入库后剩余的数量
*/
private Integer saveQuantity;
}

98
src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.java

@ -0,0 +1,98 @@
package com.dreamchaser.depository_manage.mapper;
import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
@Mapper
@Repository
public interface SplitUnitMapper {
/**
* 用于添加一条拆单记录
* @param map 待添加数据
* @return
*/
Integer addSplitInfo(Map<String,Object> map);
/**
* 用于修改拆单记录数据
* @param map 待修改数据
* @return
*/
Integer updateSplitInfo(Map<String,Object> map);
/**
* 用于修改拆单记录数据
* @param splitInfo 待修改数据
* @return
*/
Integer updateSplitInfo(SplitInfo splitInfo);
/**
* 通过主键id删除一条拆单记录
* @param id 待删除主键id
* @return
*/
Integer delSplitInfoById(Integer id);
/**
* 通过主键id批量删除一条拆单记录
* @param ids 待删除主键id
* @return
*/
Integer delSplitInfoByIds(List<Integer> ids);
/**
* 用于添加一条拆单库存处理记录
* @param map 待添加数量
* @return
*/
Integer addSplitInventory(Map<String,Object> map);
/**
* 用于修改拆单库存处理记录
* @param map 待修改数据
* @return
*/
Integer updateSplitInventory(Map<String,Object> map);
/**
* 用于修改拆单库存处理记录
* @param splitInventory 待修改数据
* @return
*/
Integer updateSplitInventory(SplitInventory splitInventory);
/**
* 通过主键id删除一条拆单库存处理记录
* @param id 待删除主键id
* @return
*/
Integer delSplitInventoryById(Integer id);
/**
* 通过主键id批量删除一条拆单库存处理记录
* @param ids 待删除主键id
* @return
*/
Integer delSplitInventoryByIds(List<Integer> ids);
/**
* 通过物料id与拆单前的计量单位获取对应拆单记录
* @param map 查询条件
* @return
*/
SplitInfo findSplitInfoByMidAndUnit(Map<String,Object> map);
/**
* 通过物料库存id与拆单id获取拆单库存操作记录
* @param map 查询条件
* @return
*/
SplitInventory findSplitInventoryByIidAndSid(Map<String,Object> map);
}

170
src/main/java/com/dreamchaser/depository_manage/mapper/SplitUnitMapper.xml

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- user -->
<mapper namespace="com.dreamchaser.depository_manage.mapper.SplitUnitMapper">
<!-- 字段映射(权限) -->
<!-- 权限映射-->
<resultMap id="splitInfoMap" type="com.dreamchaser.depository_manage.entity.SplitInfo">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="mid" property="mid" jdbcType="INTEGER" />
<result column="quantity" property="quantity" jdbcType="INTEGER" />
<result column="parentId" property="parentId" jdbcType="INTEGER" />
<result column="state" property="state" jdbcType="INTEGER" />
<result column="oldUnit" property="oldUnit" jdbcType="VARCHAR" />
<result column="newUnit" property="newUnit" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="splitInventoryMap" type="com.dreamchaser.depository_manage.entity.SplitInventory">
<id column="id" property="id" jdbcType="INTEGER" />
<result column="iid" property="iid" jdbcType="INTEGER"/>
<result column="sid" property="sid" jdbcType="INTEGER"/>
<result column="outQuantity" property="outQuantity" jdbcType="INTEGER"/>
<result column="inQuantity" property="inQuantity" jdbcType="INTEGER"/>
<result column="saveQuantity" property="saveQuantity" jdbcType="INTEGER"/>
</resultMap>
<sql id="splitInfoAllColumns">
s.id,s.mid,s.oldUnit,s.newUnit,s.quantity,s.parentId,s.state
</sql>
<sql id="splitInventoryAllColumns">
si.id,si.iid,si.sid.si.outQuantity,si.inQuantity,si.saveQuantity
</sql>
<select id="findSplitInfoByMidAndUnit" parameterType="map" resultMap="splitInfoMap">
select
<include refid="splitInfoAllColumns"/>
from `split` s
where 1 = 1
<if test="mid != null and mid != ''">
and s.mid = #{mid}
</if>
<if test="oldUnit != null and oldUnit != ''">
and s.oldUnit = #{oldUnit}
</if>
<if test="newUnit != null and newUnit != ''">
and s.newUnit = #{newUnit}
</if>
</select>
<select id="findSplitInventoryByIidAndSid" parameterType="map" resultMap="splitInventoryMap">
select
<include refid="splitInventoryAllColumns"/>
from `split_inventory` si
where 1 = 1
<if test="iid != null and iid != ''">
and si.iid = #{iid},
</if>
<if test="sid != null and sid != ''">
and si.sid = #{sid}
</if>
</select>
<update id="updateSplitInfo">
update `split`
<set>
<if test="mid != null and mid != ''">
mid = #{mid},
</if>
<if test="oldUnit != null and oldUnit != ''">
oldUnit = #{oldUnit},
</if>
<if test="newUnit != null and newUnit != ''">
newUnit = #{newUnit},
</if>
<if test="quantity != null and quantity != ''">
quantity = #{quantity},
</if>
<if test="parentId != null and parentId != ''">
parentId = #{parentId},
</if>
<if test="state != null and state != ''">
state = #{state}
</if>
</set>
where id = #{id}
</update>
<update id="updateSplitInventory">
update `split_inventory`
<set>
<if test="iid != null and iid != ''">
iid = #{iid},
</if>
<if test="sid != null and sid != ''">
sid = #{sid},
</if>
<if test="outQuantity != null and outQuantity != ''">
outQuantity = #{outQuantity},
</if>
<if test="inQuantity != null and inQuantity != ''">
inQuantity = #{inQuantity},
</if>
<if test="saveQuantity != null and saveQuantity != ''">
saveQuantity = #{saveQuantity},
</if>
</set>
where id = #{id}
</update>
<insert id="addSplitInfo" parameterType="map" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `split` (
id, mid, oldUnit,newUnit,quantity,parentId,state
) VALUES (
#{id},
#{mid},
#{oldUnit},
#{newUnit},
#{quantity},
#{parentId},
#{state}
)
</insert>
<insert id="addSplitInventory" parameterType="map" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `split_inventory` (
id, iid, sid,outQuantity,inQuantity,saveQuantity
) VALUES (
#{id},
#{iid},
#{sid},
#{outQuantity},
#{inQuantity},
#{saveQuantity}
)
</insert>
<delete id="delSplitInfoById" parameterType="int">
delete from `split` WHERE id = #{id}
</delete>
<delete id="delSplitInfoByIds" parameterType="int">
delete from `split`
where id in
<foreach collection="list" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="delSplitInventoryById" parameterType="int">
delete from `split_inventory` WHERE id = #{id}
</delete>
<delete id="delSplitInventoryByIds" parameterType="int">
delete from `split_inventory`
where id in
<foreach collection="list" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

27
src/main/java/com/dreamchaser/depository_manage/service/SplitUnitService.java

@ -0,0 +1,27 @@
package com.dreamchaser.depository_manage.service;
import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory;
import java.util.List;
import java.util.Map;
/**
* 用于进行拆单操作的service
*/
public interface SplitUnitService {
/**
* 用于添加一条拆单记录
* @param map 待添加数据
* @return
*/
Integer addSplitInfo(Map<String,Object> map);
/**
* 用于添加一条拆单库存处理记录
* @param map 待添加数据
* @return
*/
Integer addSplitInventory(Map<String,Object> map);
}

136
src/main/java/com/dreamchaser/depository_manage/service/impl/SplitUnitServiceImpl.java

@ -0,0 +1,136 @@
package com.dreamchaser.depository_manage.service.impl;
import com.dreamchaser.depository_manage.entity.Inventory;
import com.dreamchaser.depository_manage.entity.SplitInfo;
import com.dreamchaser.depository_manage.entity.SplitInventory;
import com.dreamchaser.depository_manage.mapper.DepositoryMapper;
import com.dreamchaser.depository_manage.mapper.MaterialMapper;
import com.dreamchaser.depository_manage.mapper.PlaceMapper;
import com.dreamchaser.depository_manage.mapper.SplitUnitMapper;
import com.dreamchaser.depository_manage.service.DepositoryRecordService;
import com.dreamchaser.depository_manage.service.MaterialService;
import com.dreamchaser.depository_manage.service.SplitUnitService;
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
@Service
public class SplitUnitServiceImpl implements SplitUnitService {
@Autowired
SplitUnitMapper splitUnitMapper;
@Autowired
MaterialMapper materialMapper;
@Autowired
PlaceMapper placeMapper;
@Autowired
DepositoryMapper depositoryMapper;
@Autowired
DepositoryRecordService depositoryRecordService;
/**
* 用于添加一条拆单记录
* @param map 待添加数据
* @return
*/
@Override
public Integer addSplitInfo(Map<String, Object> map) {
// 查询该物料拆单前是否存在该计量单位
Map<String,Object> paramForUnit = new HashMap<>();
// 获取物料id
paramForUnit.put("mid",map.get("mid"));
// 获取拆单前的计量单位
paramForUnit.put("oldUnit",map.get("oldUnit"));
// 查询当前要拆单的记录是否已经是拆单过的
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForUnit);
if(splitInfoForUnit != null){
// 如果是拆单过
map.put("parentId",splitInfoForUnit.getId());
}else{
// 如果没有
map.put("parentId",null);
}
// 插入
return splitUnitMapper.addSplitInfo(map);
}
/**
* 用于添加一条拆单库存处理记录
* @param map 待添加数据
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Integer addSplitInventory(Map<String, Object> map) {
Map<String,Object> paramForUnit = new HashMap<>();
paramForUnit.put("newUnit",map.get("unit"));
paramForUnit.put("mid",map.get("mid"));
// 查询当前拆单是否存在
SplitInfo splitInfoForUnit = splitUnitMapper.findSplitInfoByMidAndUnit(paramForUnit);
// 用于存储最终计算结果
Integer result = 0;
if(splitInfoForUnit != null) {
// 获取当前处理的类型
String type = (String) map.get("type");
// 获取当前操作的库存id
Integer iid = ObjectFormatUtil.toInteger(map.get("iid"));
// 用于存储拆单库存处理操作的数据
Map<String,Object> paramForInsertSplitInventory = new HashMap<>();
paramForInsertSplitInventory.put("iid",iid);
paramForInsertSplitInventory.put("sid",splitInfoForUnit.getId());
// 查询当前库存是否有该拆单的处理记录
SplitInventory splitInventory = splitUnitMapper.findSplitInventoryByIidAndSid(paramForInsertSplitInventory);
// 获取要操作的数量
Double quantity = ObjectFormatUtil.toDouble(map.get("quantity"));
if ("in".equals(type)) {
// 如果是入库操作
// 计算处理数量(下取整)
Integer disposeQuantity = ObjectFormatUtil.toInteger(Math.floor(quantity / splitInfoForUnit.getQuantity()));
// 最终存储到拆单处理的数量
double saveQuantity = quantity - disposeQuantity;
if(splitInventory != null){
// 如果有过记录
// 设置当前计量单位的库存
splitInventory.setSaveQuantity(ObjectFormatUtil.toInteger(saveQuantity) + splitInventory.getSaveQuantity());
// 设置当前计量单位的入库数目
splitInventory.setInQuantity(ObjectFormatUtil.toInteger(splitInventory.getInQuantity() + quantity));
splitUnitMapper.updateSplitInventory(splitInventory);
}else{
// 如果没有记录
paramForInsertSplitInventory.put("inQuantity",quantity);
paramForInsertSplitInventory.put("saveQuantity",saveQuantity);
splitUnitMapper.addSplitInventory(paramForInsertSplitInventory);
}
map.put("quantity",disposeQuantity);
result += depositoryRecordService.applicationInPlace(map);
} else if ("out".equals(type)) {
// 如果是出库操作
// 设置出库标志位
paramForInsertSplitInventory.put("outFlag",1);
}
}
return result;
}
}

2
src/main/java/com/dreamchaser/depository_manage/utils/ObjectFormatUtil.java

@ -25,4 +25,6 @@ public class ObjectFormatUtil {
return (o==null)?null:Boolean.getBoolean(o.toString());
}
public static Double toDouble(Object o){return (o == null)?null:Double.parseDouble(o.toString());}
}

5
src/test/java/com/dreamchaser/depository_manage/TestForOther.java

@ -23,8 +23,9 @@ public class TestForOther {
@Test
public void Test() throws IOException {
Double a = 12.5;
Integer b = 10;
System.out.println(a - b);
}
}

Loading…
Cancel
Save