Browse Source

修改物料编码生产规则

lwx_dev
erdanergou 3 years ago
parent
commit
a3cb836de0
  1. 8
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.java
  2. 27
      src/main/java/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml
  3. 6
      src/main/java/com/dreamchaser/depository_manage/service/impl/MaterialServiceImpl.java
  4. 27
      target/classes/com/dreamchaser/depository_manage/mapper/MaterialMapper.xml

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

@ -321,6 +321,14 @@ public interface MaterialMapper {
List<Material> findMaterialByType(Long oldId); List<Material> findMaterialByType(Long oldId);
/**
* 查询当前类型下最大的物料编码
* @param oldId
* @return
*/
String findMaxMaterialCodeForMt(Long oldId);
/** /**
* 批量查询当前类型下的物料 * 批量查询当前类型下的物料
* @param list * @param list

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

@ -53,7 +53,6 @@
</resultMap> </resultMap>
<!-- 字段映射--> <!-- 字段映射-->
<resultMap id="materialAndTypeMap" type="com.dreamchaser.depository_manage.entity.Material"> <resultMap id="materialAndTypeMap" type="com.dreamchaser.depository_manage.entity.Material">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
@ -74,12 +73,14 @@
<result column="productionPlace" property="productionPlace" jdbcType="VARCHAR"/> <result column="productionPlace" property="productionPlace" jdbcType="VARCHAR"/>
<result column="brand" property="brand" jdbcType="VARCHAR"/> <result column="brand" property="brand" jdbcType="VARCHAR"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/> <result column="remark" property="remark" jdbcType="VARCHAR"/>
<association property="materialType" column="typeId" javaType="com.dreamchaser.depository_manage.entity.MaterialType"> <association property="materialType" column="typeId"
javaType="com.dreamchaser.depository_manage.entity.MaterialType">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
<result column="tname" property="tname" jdbcType="VARCHAR"/> <result column="tname" property="tname" jdbcType="VARCHAR"/>
<result column="introduce" property="introduce" jdbcType="VARCHAR"/> <result column="introduce" property="introduce" jdbcType="VARCHAR"/>
</association> </association>
<association property="depository" column="depositoryId" javaType="com.dreamchaser.depository_manage.entity.Depository"> <association property="depository" column="depositoryId"
javaType="com.dreamchaser.depository_manage.entity.Depository">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
<result column="dname" property="dname" jdbcType="VARCHAR"/> <result column="dname" property="dname" jdbcType="VARCHAR"/>
<result column="address" property="address" jdbcType="VARCHAR"/> <result column="address" property="address" jdbcType="VARCHAR"/>
@ -142,7 +143,6 @@
</sql> </sql>
<!-- 表查询字段,用于查询物料与条形码视图--> <!-- 表查询字段,用于查询物料与条形码视图-->
<sql id="materialAndBarCode"> <sql id="materialAndBarCode">
id,bmcode,mcode,mid,depositoryId,mname,mtid,version,texture,unit,tname,price,shelfLife id,bmcode,mcode,mid,depositoryId,mname,mtid,version,texture,unit,tname,price,shelfLife
@ -218,7 +218,6 @@
</select> </select>
<!-- 根据条件参数查询数据列表 --> <!-- 根据条件参数查询数据列表 -->
<select id="findMaterialByCondition" resultMap="materialMap" parameterType="map"> <select id="findMaterialByCondition" resultMap="materialMap" parameterType="map">
SELECT SELECT
@ -282,7 +281,8 @@
</select> </select>
<!-- 根据物料id与生产日期获取对应关系--> <!-- 根据物料id与生产日期获取对应关系-->
<select id="findMaterialAndProducedDateByMidAndProducedDate" resultMap="MaterialAndProducedDate" parameterType="map"> <select id="findMaterialAndProducedDateByMidAndProducedDate" resultMap="MaterialAndProducedDate"
parameterType="map">
select select
<include refid="allColumnsByMaterialAndProducedDate"/> <include refid="allColumnsByMaterialAndProducedDate"/>
from materialandproduceddate mp from materialandproduceddate mp
@ -625,7 +625,6 @@
</select> </select>
<!-- 根据仓库查询物料--> <!-- 根据仓库查询物料-->
<select id="findMaterialByDepository" resultMap="InventoryMap" parameterType="map"> <select id="findMaterialByDepository" resultMap="InventoryMap" parameterType="map">
SELECT SELECT
@ -701,6 +700,14 @@
</select> </select>
<select id="findMaxMaterialCodeForMt" resultType="string" parameterType="long">
select
max(code)
from material m
where m.type_id = #{oldId}
</select>
<!-- 根据主键查询数据 --> <!-- 根据主键查询数据 -->
<select id="findInventoryByIds" resultMap="InventoryMap" parameterType="list"> <select id="findInventoryByIds" resultMap="InventoryMap" parameterType="list">
SELECT SELECT
@ -741,7 +748,8 @@
<!-- 插入数据 --> <!-- 插入数据 -->
<insert id="insertMaterial" useGeneratedKeys="true" keyProperty="id"> <insert id="insertMaterial" useGeneratedKeys="true" keyProperty="id">
INSERT INTO material ( INSERT INTO material (
id, depository_id, mname, quantity, price, type_id,code,unit,version,texture,amounts,depositoryCode,producedDate,shelfLife,brand,productionPlace,remark id, depository_id, mname, quantity, price,
type_id,code,unit,version,texture,amounts,depositoryCode,producedDate,shelfLife,brand,productionPlace,remark
) VALUES ( ) VALUES (
#{id}, #{id},
<if test="depositoryId != null"> <if test="depositoryId != null">
@ -879,8 +887,6 @@
</delete> </delete>
<update id="updateMaterialAndProducedDate"> <update id="updateMaterialAndProducedDate">
update materialandproduceddate update materialandproduceddate
<set> <set>
@ -1027,7 +1033,6 @@
</update> </update>
<!-- 根据主键删除数据 --> <!-- 根据主键删除数据 -->
<delete id="deleteMaterialById" parameterType="int"> <delete id="deleteMaterialById" parameterType="int">
DELETE FROM material WHERE id = #{id} DELETE FROM material WHERE id = #{id}

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

@ -112,12 +112,12 @@ public class MaterialServiceImpl implements MaterialService {
Integer typeId = ObjectFormatUtil.toInteger(map.get("typeId").toString()); Integer typeId = ObjectFormatUtil.toInteger(map.get("typeId").toString());
MaterialType materialTypeById = materialTypeMapper.findMaterialTypeById(typeId); MaterialType materialTypeById = materialTypeMapper.findMaterialTypeById(typeId);
map.put("materialTypeId", materialTypeById.getOldId()); map.put("materialTypeId", materialTypeById.getOldId());
List<Material> materialByType = materialMapper.findMaterialByType(materialTypeById.getOldId()); String maxCode = materialMapper.findMaxMaterialCodeForMt(materialTypeById.getOldId());
String newCode = ""; String newCode = "";
if (materialByType == null) { if (maxCode == null) {
newCode = String.format("%04d", 1); newCode = String.format("%04d", 1);
} else { } else {
newCode = String.format("%04d",Integer.parseInt(materialByType.get(materialByType.size() - 1).getCode()) + 1); newCode = String.format("%04d",Integer.parseInt(maxCode) + 1);
} }
map.put("code",newCode); map.put("code",newCode);

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

@ -53,7 +53,6 @@
</resultMap> </resultMap>
<!-- 字段映射--> <!-- 字段映射-->
<resultMap id="materialAndTypeMap" type="com.dreamchaser.depository_manage.entity.Material"> <resultMap id="materialAndTypeMap" type="com.dreamchaser.depository_manage.entity.Material">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
@ -74,12 +73,14 @@
<result column="productionPlace" property="productionPlace" jdbcType="VARCHAR"/> <result column="productionPlace" property="productionPlace" jdbcType="VARCHAR"/>
<result column="brand" property="brand" jdbcType="VARCHAR"/> <result column="brand" property="brand" jdbcType="VARCHAR"/>
<result column="remark" property="remark" jdbcType="VARCHAR"/> <result column="remark" property="remark" jdbcType="VARCHAR"/>
<association property="materialType" column="typeId" javaType="com.dreamchaser.depository_manage.entity.MaterialType"> <association property="materialType" column="typeId"
javaType="com.dreamchaser.depository_manage.entity.MaterialType">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
<result column="tname" property="tname" jdbcType="VARCHAR"/> <result column="tname" property="tname" jdbcType="VARCHAR"/>
<result column="introduce" property="introduce" jdbcType="VARCHAR"/> <result column="introduce" property="introduce" jdbcType="VARCHAR"/>
</association> </association>
<association property="depository" column="depositoryId" javaType="com.dreamchaser.depository_manage.entity.Depository"> <association property="depository" column="depositoryId"
javaType="com.dreamchaser.depository_manage.entity.Depository">
<id column="id" property="id" jdbcType="INTEGER"/> <id column="id" property="id" jdbcType="INTEGER"/>
<result column="dname" property="dname" jdbcType="VARCHAR"/> <result column="dname" property="dname" jdbcType="VARCHAR"/>
<result column="address" property="address" jdbcType="VARCHAR"/> <result column="address" property="address" jdbcType="VARCHAR"/>
@ -142,7 +143,6 @@
</sql> </sql>
<!-- 表查询字段,用于查询物料与条形码视图--> <!-- 表查询字段,用于查询物料与条形码视图-->
<sql id="materialAndBarCode"> <sql id="materialAndBarCode">
id,bmcode,mcode,mid,depositoryId,mname,mtid,version,texture,unit,tname,price,shelfLife id,bmcode,mcode,mid,depositoryId,mname,mtid,version,texture,unit,tname,price,shelfLife
@ -218,7 +218,6 @@
</select> </select>
<!-- 根据条件参数查询数据列表 --> <!-- 根据条件参数查询数据列表 -->
<select id="findMaterialByCondition" resultMap="materialMap" parameterType="map"> <select id="findMaterialByCondition" resultMap="materialMap" parameterType="map">
SELECT SELECT
@ -282,7 +281,8 @@
</select> </select>
<!-- 根据物料id与生产日期获取对应关系--> <!-- 根据物料id与生产日期获取对应关系-->
<select id="findMaterialAndProducedDateByMidAndProducedDate" resultMap="MaterialAndProducedDate" parameterType="map"> <select id="findMaterialAndProducedDateByMidAndProducedDate" resultMap="MaterialAndProducedDate"
parameterType="map">
select select
<include refid="allColumnsByMaterialAndProducedDate"/> <include refid="allColumnsByMaterialAndProducedDate"/>
from materialandproduceddate mp from materialandproduceddate mp
@ -625,7 +625,6 @@
</select> </select>
<!-- 根据仓库查询物料--> <!-- 根据仓库查询物料-->
<select id="findMaterialByDepository" resultMap="InventoryMap" parameterType="map"> <select id="findMaterialByDepository" resultMap="InventoryMap" parameterType="map">
SELECT SELECT
@ -701,6 +700,14 @@
</select> </select>
<select id="findMaxMaterialCodeForMt" resultType="string" parameterType="long">
select
max(code)
from material m
where m.type_id = #{oldId}
</select>
<!-- 根据主键查询数据 --> <!-- 根据主键查询数据 -->
<select id="findInventoryByIds" resultMap="InventoryMap" parameterType="list"> <select id="findInventoryByIds" resultMap="InventoryMap" parameterType="list">
SELECT SELECT
@ -741,7 +748,8 @@
<!-- 插入数据 --> <!-- 插入数据 -->
<insert id="insertMaterial" useGeneratedKeys="true" keyProperty="id"> <insert id="insertMaterial" useGeneratedKeys="true" keyProperty="id">
INSERT INTO material ( INSERT INTO material (
id, depository_id, mname, quantity, price, type_id,code,unit,version,texture,amounts,depositoryCode,producedDate,shelfLife,brand,productionPlace,remark id, depository_id, mname, quantity, price,
type_id,code,unit,version,texture,amounts,depositoryCode,producedDate,shelfLife,brand,productionPlace,remark
) VALUES ( ) VALUES (
#{id}, #{id},
<if test="depositoryId != null"> <if test="depositoryId != null">
@ -879,8 +887,6 @@
</delete> </delete>
<update id="updateMaterialAndProducedDate"> <update id="updateMaterialAndProducedDate">
update materialandproduceddate update materialandproduceddate
<set> <set>
@ -1027,7 +1033,6 @@
</update> </update>
<!-- 根据主键删除数据 --> <!-- 根据主键删除数据 -->
<delete id="deleteMaterialById" parameterType="int"> <delete id="deleteMaterialById" parameterType="int">
DELETE FROM material WHERE id = #{id} DELETE FROM material WHERE id = #{id}

Loading…
Cancel
Save