SN编码功能

This commit is contained in:
DESKTOP-J7ED0MB\yinjinlu 2022-12-09 16:39:27 +08:00
parent cd01e39fd2
commit c439d98cef
7 changed files with 729 additions and 0 deletions

View File

@ -84,6 +84,7 @@ public class UserConstants
public static final String MACHINERY_TYPE_CODE="MACHINERY_TYPE_CODE";
public static final String TASK_CODE="TASK_CODE";
public static final String DEFECT_CODE = "DEFECT_CODE";
public static final String SN_CODE = "SN_CODE";
/**
* 单据的状态类型

View File

@ -0,0 +1,134 @@
package com.ktg.mes.wm.controller;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.date.DateUtil;
import com.ktg.common.constant.UserConstants;
import com.ktg.system.strategy.AutoCodeUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.mes.wm.domain.WmSn;
import com.ktg.mes.wm.service.IWmSnService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;
/**
* SN码Controller
*
* @author yinjinlu
* @date 2022-12-08
*/
@RestController
@RequestMapping("/mes/wm/sn")
public class WmSnController extends BaseController
{
@Autowired
private IWmSnService wmSnService;
@Autowired
private AutoCodeUtil autoCodeUtil;
/**
* 查询SN码列表
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:list')")
@GetMapping("/list")
public TableDataInfo list(WmSn wmSn)
{
startPage();
List<WmSn> list = wmSnService.selectWmSnList(wmSn);
return getDataTable(list);
}
/**
* 查询SN码列表
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:list')")
@GetMapping("/listSn")
public TableDataInfo listSn(WmSn wmSn)
{
startPage();
List<WmSn> list = wmSnService.selectSnList(wmSn);
return getDataTable(list);
}
/**
* 导出SN码列表
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:export')")
@Log(title = "SN码", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, WmSn wmSn)
{
List<WmSn> list = wmSnService.selectWmSnList(wmSn);
ExcelUtil<WmSn> util = new ExcelUtil<WmSn>(WmSn.class);
util.exportExcel(response, list, "SN码数据");
}
/**
* 获取SN码详细信息
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:query')")
@GetMapping(value = "/{snId}")
public AjaxResult getInfo(@PathVariable("snId") Long snId)
{
return AjaxResult.success(wmSnService.selectWmSnBySnId(snId));
}
/**
* 新增SN码
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:add')")
@Log(title = "SN码", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WmSn wmSn)
{
Date genDate = DateUtil.date();
wmSn.setGenDate(genDate);
String SNCode= null;
if(wmSn.getSnNum()>0){
for(int i=0;i<wmSn.getSnNum();i++){
SNCode = autoCodeUtil.genSerialCode(UserConstants.SN_CODE,wmSn.getItemCode());
wmSn.setSnCode(SNCode);
wmSnService.insertWmSn(wmSn);
}
}
return AjaxResult.success();
}
/**
* 修改SN码
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:edit')")
@Log(title = "SN码", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WmSn wmSn)
{
return toAjax(wmSnService.updateWmSn(wmSn));
}
/**
* 删除SN码
*/
@PreAuthorize("@ss.hasPermi('mes:wm:sn:remove')")
@Log(title = "SN码", businessType = BusinessType.DELETE)
@DeleteMapping("/{snIds}")
public AjaxResult remove(@PathVariable Long[] snIds)
{
return toAjax(wmSnService.deleteWmSnBySnIds(snIds));
}
}

View File

@ -0,0 +1,218 @@
package com.ktg.mes.wm.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ktg.common.annotation.Excel;
import com.ktg.common.core.domain.BaseEntity;
import java.util.Date;
/**
* SN码对象 wm_sn
*
* @author yinjinlu
* @date 2022-12-08
*/
public class WmSn extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** SN码ID */
private Long snId;
/** SN码 */
@Excel(name = "SN码")
private String snCode;
/** 产品物料ID */
@Excel(name = "产品物料ID")
private Long itemId;
/** 产品物料编码 */
@Excel(name = "产品物料编码")
private String itemCode;
/** 产品物料名称 */
@Excel(name = "产品物料名称")
private String itemName;
/** 规格型号 */
@Excel(name = "规格型号")
private String specification;
/** 单位 */
@Excel(name = "单位")
private String unitOfMeasure;
/** 批次号 */
@Excel(name = "批次号")
private String batchCode;
/**
* SN码的数量
*/
private Integer snNum;
/** 退货日期 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "生成时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date genDate;
/** 预留字段1 */
private String attr1;
/** 预留字段2 */
private String attr2;
/** 预留字段3 */
private Long attr3;
/** 预留字段4 */
private Long attr4;
public void setSnId(Long snId)
{
this.snId = snId;
}
public Long getSnId()
{
return snId;
}
public void setSnCode(String snCode)
{
this.snCode = snCode;
}
public String getSnCode()
{
return snCode;
}
public void setItemId(Long itemId)
{
this.itemId = itemId;
}
public Long getItemId()
{
return itemId;
}
public void setItemCode(String itemCode)
{
this.itemCode = itemCode;
}
public String getItemCode()
{
return itemCode;
}
public void setItemName(String itemName)
{
this.itemName = itemName;
}
public String getItemName()
{
return itemName;
}
public void setSpecification(String specification)
{
this.specification = specification;
}
public String getSpecification()
{
return specification;
}
public void setUnitOfMeasure(String unitOfMeasure)
{
this.unitOfMeasure = unitOfMeasure;
}
public String getUnitOfMeasure()
{
return unitOfMeasure;
}
public void setBatchCode(String batchCode)
{
this.batchCode = batchCode;
}
public String getBatchCode()
{
return batchCode;
}
public void setAttr1(String attr1)
{
this.attr1 = attr1;
}
public Integer getSnNum() {
return snNum;
}
public void setSnNum(Integer snNum) {
this.snNum = snNum;
}
public Date getGenDate() {
return genDate;
}
public void setGenDate(Date genDate) {
this.genDate = genDate;
}
public String getAttr1()
{
return attr1;
}
public void setAttr2(String attr2)
{
this.attr2 = attr2;
}
public String getAttr2()
{
return attr2;
}
public void setAttr3(Long attr3)
{
this.attr3 = attr3;
}
public Long getAttr3()
{
return attr3;
}
public void setAttr4(Long attr4)
{
this.attr4 = attr4;
}
public Long getAttr4()
{
return attr4;
}
@Override
public String toString() {
return "WmSn{" +
"snId=" + snId +
", snCode='" + snCode + '\'' +
", itemId=" + itemId +
", itemCode='" + itemCode + '\'' +
", itemName='" + itemName + '\'' +
", specification='" + specification + '\'' +
", unitOfMeasure='" + unitOfMeasure + '\'' +
", batchCode='" + batchCode + '\'' +
", snNum=" + snNum +
", genDate=" + genDate +
", attr1='" + attr1 + '\'' +
", attr2='" + attr2 + '\'' +
", attr3=" + attr3 +
", attr4=" + attr4 +
'}';
}
}

View File

@ -0,0 +1,68 @@
package com.ktg.mes.wm.mapper;
import java.util.List;
import com.ktg.mes.wm.domain.WmSn;
/**
* SN码Mapper接口
*
* @author yinjinlu
* @date 2022-12-08
*/
public interface WmSnMapper
{
/**
* 查询SN码
*
* @param snId SN码主键
* @return SN码
*/
public WmSn selectWmSnBySnId(Long snId);
/**
* 查询SN码列表
*
* @param wmSn SN码
* @return SN码集合
*/
public List<WmSn> selectWmSnList(WmSn wmSn);
/**
* 查询SN展示列表
* @param wmSn
* @return
*/
public List<WmSn> selectSnList(WmSn wmSn);
/**
* 新增SN码
*
* @param wmSn SN码
* @return 结果
*/
public int insertWmSn(WmSn wmSn);
/**
* 修改SN码
*
* @param wmSn SN码
* @return 结果
*/
public int updateWmSn(WmSn wmSn);
/**
* 删除SN码
*
* @param snId SN码主键
* @return 结果
*/
public int deleteWmSnBySnId(Long snId);
/**
* 批量删除SN码
*
* @param snIds 需要删除的数据主键集合
* @return 结果
*/
public int deleteWmSnBySnIds(Long[] snIds);
}

View File

@ -0,0 +1,68 @@
package com.ktg.mes.wm.service;
import java.util.List;
import com.ktg.mes.wm.domain.WmSn;
/**
* SN码Service接口
*
* @author yinjinlu
* @date 2022-12-08
*/
public interface IWmSnService
{
/**
* 查询SN码
*
* @param snId SN码主键
* @return SN码
*/
public WmSn selectWmSnBySnId(Long snId);
/**
* 查询SN码列表
*
* @param wmSn SN码
* @return SN码集合
*/
public List<WmSn> selectWmSnList(WmSn wmSn);
/**
* 查询SN展示列表
* @param wmSn
* @return
*/
public List<WmSn> selectSnList(WmSn wmSn);
/**
* 新增SN码
*
* @param wmSn SN码
* @return 结果
*/
public int insertWmSn(WmSn wmSn);
/**
* 修改SN码
*
* @param wmSn SN码
* @return 结果
*/
public int updateWmSn(WmSn wmSn);
/**
* 批量删除SN码
*
* @param snIds 需要删除的SN码主键集合
* @return 结果
*/
public int deleteWmSnBySnIds(Long[] snIds);
/**
* 删除SN码信息
*
* @param snId SN码主键
* @return 结果
*/
public int deleteWmSnBySnId(Long snId);
}

View File

@ -0,0 +1,101 @@
package com.ktg.mes.wm.service.impl;
import java.util.List;
import com.ktg.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktg.mes.wm.mapper.WmSnMapper;
import com.ktg.mes.wm.domain.WmSn;
import com.ktg.mes.wm.service.IWmSnService;
/**
* SN码Service业务层处理
*
* @author yinjinlu
* @date 2022-12-08
*/
@Service
public class WmSnServiceImpl implements IWmSnService
{
@Autowired
private WmSnMapper wmSnMapper;
/**
* 查询SN码
*
* @param snId SN码主键
* @return SN码
*/
@Override
public WmSn selectWmSnBySnId(Long snId)
{
return wmSnMapper.selectWmSnBySnId(snId);
}
/**
* 查询SN码列表
*
* @param wmSn SN码
* @return SN码
*/
@Override
public List<WmSn> selectWmSnList(WmSn wmSn)
{
return wmSnMapper.selectWmSnList(wmSn);
}
@Override
public List<WmSn> selectSnList(WmSn wmSn) {
return wmSnMapper.selectSnList(wmSn);
}
/**
* 新增SN码
*
* @param wmSn SN码
* @return 结果
*/
@Override
public int insertWmSn(WmSn wmSn)
{
wmSn.setCreateTime(DateUtils.getNowDate());
return wmSnMapper.insertWmSn(wmSn);
}
/**
* 修改SN码
*
* @param wmSn SN码
* @return 结果
*/
@Override
public int updateWmSn(WmSn wmSn)
{
wmSn.setUpdateTime(DateUtils.getNowDate());
return wmSnMapper.updateWmSn(wmSn);
}
/**
* 批量删除SN码
*
* @param snIds 需要删除的SN码主键
* @return 结果
*/
@Override
public int deleteWmSnBySnIds(Long[] snIds)
{
return wmSnMapper.deleteWmSnBySnIds(snIds);
}
/**
* 删除SN码信息
*
* @param snId SN码主键
* @return 结果
*/
@Override
public int deleteWmSnBySnId(Long snId)
{
return wmSnMapper.deleteWmSnBySnId(snId);
}
}

View File

@ -0,0 +1,139 @@
<?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">
<mapper namespace="com.ktg.mes.wm.mapper.WmSnMapper">
<resultMap type="WmSn" id="WmSnResult">
<result property="snId" column="sn_id" />
<result property="snCode" column="sn_code" />
<result property="itemId" column="item_id" />
<result property="itemCode" column="item_code" />
<result property="itemName" column="item_name" />
<result property="specification" column="specification" />
<result property="unitOfMeasure" column="unit_of_measure" />
<result property="batchCode" column="batch_code" />
<result property="snNum" column="snNum"></result>
<result property="remark" column="remark" />
<result property="attr1" column="attr1" />
<result property="attr2" column="attr2" />
<result property="attr3" column="attr3" />
<result property="attr4" column="attr4" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectWmSnVo">
select sn_id, sn_code, item_id, item_code, item_name, specification, unit_of_measure, batch_code, remark, attr1, attr2, attr3, attr4, create_by, create_time, update_by, update_time from wm_sn
</sql>
<select id="selectWmSnList" parameterType="WmSn" resultMap="WmSnResult">
<include refid="selectWmSnVo"/>
<where>
<if test="snCode != null and snCode != ''"> and sn_code = #{snCode}</if>
<if test="itemId != null "> and item_id = #{itemId}</if>
<if test="itemCode != null and itemCode != ''"> and item_code = #{itemCode}</if>
<if test="itemName != null and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
<if test="specification != null and specification != ''"> and specification = #{specification}</if>
<if test="unitOfMeasure != null and unitOfMeasure != ''"> and unit_of_measure = #{unitOfMeasure}</if>
<if test="batchCode != null and batchCode != ''"> and batch_code = #{batchCode}</if>
</where>
</select>
<select id="selectWmSnBySnId" parameterType="Long" resultMap="WmSnResult">
<include refid="selectWmSnVo"/>
where sn_id = #{snId}
</select>
<select id="selectSnList" parameterType="WmSn" resultMap="WmSnResult">
select item_id, item_code, item_name, specification, unit_of_measure, batch_code,gen_date , count(*) as snNum
from wm_sn
<where>
<if test="snCode != null and snCode != ''"> and sn_code = #{snCode}</if>
<if test="itemId != null "> and item_id = #{itemId}</if>
<if test="itemCode != null and itemCode != ''"> and item_code = #{itemCode}</if>
<if test="itemName != null and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
<if test="specification != null and specification != ''"> and specification = #{specification}</if>
<if test="unitOfMeasure != null and unitOfMeasure != ''"> and unit_of_measure = #{unitOfMeasure}</if>
<if test="batchCode != null and batchCode != ''"> and batch_code = #{batchCode}</if>
</where>
group by item_id, item_code, item_name, specification, unit_of_measure, batch_code, gen_date
order by item_id,batch_code desc
</select>
<insert id="insertWmSn" parameterType="WmSn" useGeneratedKeys="true" keyProperty="snId">
insert into wm_sn
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="snCode != null and snCode != ''">sn_code,</if>
<if test="itemId != null">item_id,</if>
<if test="itemCode != null">item_code,</if>
<if test="itemName != null">item_name,</if>
<if test="specification != null">specification,</if>
<if test="unitOfMeasure != null">unit_of_measure,</if>
<if test="batchCode != null">batch_code,</if>
<if test="remark != null">remark,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="attr4 != null">attr4,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="snCode != null and snCode != ''">#{snCode},</if>
<if test="itemId != null">#{itemId},</if>
<if test="itemCode != null">#{itemCode},</if>
<if test="itemName != null">#{itemName},</if>
<if test="specification != null">#{specification},</if>
<if test="unitOfMeasure != null">#{unitOfMeasure},</if>
<if test="batchCode != null">#{batchCode},</if>
<if test="remark != null">#{remark},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="attr4 != null">#{attr4},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateWmSn" parameterType="WmSn">
update wm_sn
<trim prefix="SET" suffixOverrides=",">
<if test="snCode != null and snCode != ''">sn_code = #{snCode},</if>
<if test="itemId != null">item_id = #{itemId},</if>
<if test="itemCode != null">item_code = #{itemCode},</if>
<if test="itemName != null">item_name = #{itemName},</if>
<if test="specification != null">specification = #{specification},</if>
<if test="unitOfMeasure != null">unit_of_measure = #{unitOfMeasure},</if>
<if test="batchCode != null">batch_code = #{batchCode},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>
<if test="attr2 != null">attr2 = #{attr2},</if>
<if test="attr3 != null">attr3 = #{attr3},</if>
<if test="attr4 != null">attr4 = #{attr4},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where sn_id = #{snId}
</update>
<delete id="deleteWmSnBySnId" parameterType="Long">
delete from wm_sn where sn_id = #{snId}
</delete>
<delete id="deleteWmSnBySnIds" parameterType="String">
delete from wm_sn where sn_id in
<foreach item="snId" collection="array" open="(" separator="," close=")">
#{snId}
</foreach>
</delete>
</mapper>