唯一码逻辑修改

This commit is contained in:
2026-03-19 16:56:22 +08:00
parent 077e54d619
commit 9e41dbdc9f
9 changed files with 246 additions and 108 deletions

View File

@@ -111,7 +111,10 @@ public class SecurityConfig
.authorizeHttpRequests((requests) -> {
permitAllUrl.getUrls().forEach(url -> requests.antMatchers(url).permitAll());
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
requests.antMatchers("/login", "/register", "/captchaImage").permitAll()
requests.antMatchers("/login",
"/register",
"/unique/code/**",
"/captchaImage").permitAll()
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

View File

@@ -78,7 +78,7 @@ public class WornUniqueCodeController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('unique:code:add')")
@Log(title = "唯一码管理", businessType = BusinessType.INSERT)
@PostMapping
@PostMapping("/add")
public AjaxResult add(@RequestBody WornUniqueCode wornUniqueCode)
{
return toAjax(wornUniqueCodeService.insertWornUniqueCode(wornUniqueCode));
@@ -100,8 +100,8 @@ public class WornUniqueCodeController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('unique:code:remove')")
@Log(title = "唯一码管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
@PostMapping("/remove")
public AjaxResult remove(@RequestBody Long[] ids)
{
return toAjax(wornUniqueCodeService.deleteWornUniqueCodeByIds(ids));
}

View File

@@ -22,7 +22,7 @@ public class WornUniqueCode extends BaseEntity
/** 唯一码编号 */
@Excel(name = "唯一码编号")
private String code;
private Integer code;
/** 所属入库单据号 */
@Excel(name = "所属入库单据号")
@@ -32,8 +32,8 @@ public class WornUniqueCode extends BaseEntity
@Excel(name = "项目ID", readConverterExp = "用于数据隔离对应sys_dept.id")
private Long projectId;
/** 当前状态0已生成 1已打印 2已入库 3已出库 4已配送 */
@Excel(name = "当前状态", readConverterExp = "0=已生成,1=已打印,2=已入库,3=已出库,4=已配送")
/** 当前状态0初始化创建 1已打印 2已入库 3已出库 4已配送 */
@Excel(name = "当前状态", readConverterExp = "0=初始化创建,1=已打印,2=已入库,3=已出库,4=已配送")
private String status;
/** RFID编码 */
@@ -71,12 +71,12 @@ public class WornUniqueCode extends BaseEntity
this.id = id;
}
public String getCode()
public Integer getCode()
{
return code;
}
public void setCode(String code)
public void setCode(Integer code)
{
this.code = code;
}

View File

@@ -3,6 +3,7 @@ package com.shzg.project.unique.domain;
import java.math.BigDecimal;
import com.shzg.framework.web.domain.BaseEntity;
import com.shzg.project.worn.domain.WornMaterial;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.shzg.framework.aspectj.lang.annotation.Excel;
@@ -25,11 +26,11 @@ public class WornUniqueCodeMaterial extends BaseEntity
private Long uniqueCodeId;
/** 物料ID对应worn_material.id */
@Excel(name = "物料ID", readConverterExp = "=应worn_material.id")
@Excel(name = "物料ID", readConverterExp = "对应worn_material.id")
private Long materialId;
/** 单位ID对应worn_material_unit.id */
@Excel(name = "单位ID", readConverterExp = "=应worn_material_unit.id")
@Excel(name = "单位ID", readConverterExp = "对应worn_material_unit.id")
private Long unitId;
/** 数量 */
@@ -40,19 +41,21 @@ public class WornUniqueCodeMaterial extends BaseEntity
@Excel(name = "是否删除", readConverterExp = "0=正常,1=删除")
private String isDelete;
public void setId(Long id)
{
this.id = id;
}
/** ==================== 扩展字段(不落库) ==================== */
/** 物料详细信息(联表查询) */
private WornMaterial wornMaterial;
/** ==================== getter / setter ==================== */
public Long getId()
{
return id;
}
public void setUniqueCodeId(Long uniqueCodeId)
public void setId(Long id)
{
this.uniqueCodeId = uniqueCodeId;
this.id = id;
}
public Long getUniqueCodeId()
@@ -60,9 +63,9 @@ public class WornUniqueCodeMaterial extends BaseEntity
return uniqueCodeId;
}
public void setMaterialId(Long materialId)
public void setUniqueCodeId(Long uniqueCodeId)
{
this.materialId = materialId;
this.uniqueCodeId = uniqueCodeId;
}
public Long getMaterialId()
@@ -70,9 +73,9 @@ public class WornUniqueCodeMaterial extends BaseEntity
return materialId;
}
public void setUnitId(Long unitId)
public void setMaterialId(Long materialId)
{
this.unitId = unitId;
this.materialId = materialId;
}
public Long getUnitId()
@@ -80,9 +83,9 @@ public class WornUniqueCodeMaterial extends BaseEntity
return unitId;
}
public void setQuantity(BigDecimal quantity)
public void setUnitId(Long unitId)
{
this.quantity = quantity;
this.unitId = unitId;
}
public BigDecimal getQuantity()
@@ -90,9 +93,9 @@ public class WornUniqueCodeMaterial extends BaseEntity
return quantity;
}
public void setIsDelete(String isDelete)
public void setQuantity(BigDecimal quantity)
{
this.isDelete = isDelete;
this.quantity = quantity;
}
public String getIsDelete()
@@ -100,8 +103,24 @@ public class WornUniqueCodeMaterial extends BaseEntity
return isDelete;
}
public void setIsDelete(String isDelete)
{
this.isDelete = isDelete;
}
public WornMaterial getWornMaterial()
{
return wornMaterial;
}
public void setWornMaterial(WornMaterial wornMaterial)
{
this.wornMaterial = wornMaterial;
}
@Override
public String toString() {
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("uniqueCodeId", getUniqueCodeId())
@@ -114,6 +133,7 @@ public class WornUniqueCodeMaterial extends BaseEntity
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("isDelete", getIsDelete())
.append("wornMaterial", getWornMaterial())
.toString();
}
}

View File

@@ -59,10 +59,11 @@ public interface WornUniqueCodeMaterialMapper
*/
public int deleteWornUniqueCodeMaterialByIds(Long[] ids);
/**
* 根据唯一码id查询唯一码物料信息
* @param id
* @return
*/
WornUniqueCodeMaterial selectByUniqueCodeId(Long id);
WornUniqueCodeMaterial selectWithMaterialByUniqueCodeId(Long id);
}

View File

@@ -45,7 +45,7 @@ public class WornUniqueCodeServiceImpl implements IWornUniqueCodeService
@Override
public WornUniqueCode selectWornUniqueCodeById(Long id)
{
/* 1 主表 */
/* 主表 */
WornUniqueCode code = wornUniqueCodeMapper.selectWornUniqueCodeById(id);
if (code == null)
@@ -53,33 +53,31 @@ public class WornUniqueCodeServiceImpl implements IWornUniqueCodeService
throw new ServiceException("唯一码不存在");
}
/* 2 数据隔离校验(必须加) */
/* 数据隔离校验 */
Long deptId = SecurityUtils.getDeptId();
if (!SecurityUtils.isAdmin() && !deptId.equals(code.getProjectId()))
{
throw new ServiceException("无权限查看该数据");
}
/* 3⃣ 查询物料1条 */
/* ================== 查询物料================== */
WornUniqueCodeMaterial material =
materialMapper.selectByUniqueCodeId(id);
materialMapper.selectWithMaterialByUniqueCodeId(id);
code.setMaterial(material);
/* 4⃣ 查询事件(多条) */
/* ================== 查询事件 ================== */
List<WornUniqueCodeEvent> eventList =
eventMapper.selectByUniqueCodeId(id);
code.setEventList(eventList);
/* 5⃣ 生成二维码 */
String qrBase64 = QrCodeUtils.generateBase64(code.getCode());
/* ================== 生成二维码 ================== */
String qrBase64 = QrCodeUtils.generateBase64(String.valueOf(code.getCode()));
code.setQrCode(qrBase64);
return code;
}
/**
* 查询唯一码管理列表
*
@@ -103,46 +101,74 @@ public class WornUniqueCodeServiceImpl implements IWornUniqueCodeService
@Transactional(rollbackFor = Exception.class)
public int insertWornUniqueCode(WornUniqueCode wornUniqueCode)
{
/* ================== 0⃣ 参数校验 ================== */
WornUniqueCodeMaterial material = wornUniqueCode.getMaterial();
if (material == null)
{
throw new RuntimeException("物料信息不能为空");
}
Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
/* ================== 1⃣ 获取当前用户 ================== */
// Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
// Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId();
Long userId = 111L;
Long deptId = 222L;
wornUniqueCode.setProjectId(deptId);
/* ================== 1️⃣ 主表 ================== */
/* ================== 2️⃣ 主表 ================== */
wornUniqueCode.setCreateTime(DateUtils.getNowDate());
wornUniqueCode.setCreateBy(String.valueOf(userId));
wornUniqueCode.setStatus("0");
wornUniqueCode.setIsDelete("0");
wornUniqueCode.setCode(0);
wornUniqueCodeMapper.insertWornUniqueCode(wornUniqueCode);
Long id = wornUniqueCode.getId();
if (id == null)
{
throw new RuntimeException("新增唯一码失败主键ID未回填");
}
/* ================== 2️⃣ 生成code ================== */
String code = String.valueOf(600000 + id);
wornUniqueCode.setCode(code);
wornUniqueCodeMapper.updateWornUniqueCode(wornUniqueCode);
/* ================== 3️⃣ 生成 code ================== */
Integer code = 600000 + id.intValue();
/* ================== 3⃣ 插入物料 ================== */
WornUniqueCode update = new WornUniqueCode();
update.setId(id);
update.setCode(code);
update.setUpdateTime(DateUtils.getNowDate());
update.setUpdateBy(String.valueOf(userId));
wornUniqueCodeMapper.updateWornUniqueCode(update);
/* ================== 4⃣ 插入物料 ================== */
material.setUniqueCodeId(id);
material.setCreateTime(DateUtils.getNowDate());
material.setCreateBy(String.valueOf(userId));
material.setIsDelete("0");
materialMapper.insertWornUniqueCodeMaterial(material);
/* ================== 4️⃣ 插入事件 ================== */
/* ================== 5️⃣ 插入事件 ================== */
WornUniqueCodeEvent event = new WornUniqueCodeEvent();
event.setUniqueCodeId(id);
event.setEventType("0");
event.setEventStatus("0");
event.setEventDesc("唯一码生成");
event.setOperatorId(userId);
event.setCreateTime(DateUtils.getNowDate());
event.setCreateBy(String.valueOf(userId));
event.setIsDelete("0");
eventMapper.insertWornUniqueCodeEvent(event);
return 1;
}
/**
* 修改唯一码管理
*
@@ -150,12 +176,29 @@ public class WornUniqueCodeServiceImpl implements IWornUniqueCodeService
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int updateWornUniqueCode(WornUniqueCode wornUniqueCode)
{
Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
wornUniqueCode.setUpdateTime(DateUtils.getNowDate());
return wornUniqueCodeMapper.updateWornUniqueCode(wornUniqueCode);
wornUniqueCode.setUpdateBy(String.valueOf(userId));
// 1⃣ 更新主表
wornUniqueCodeMapper.updateWornUniqueCode(wornUniqueCode);
// 2⃣ 更新物料
if (wornUniqueCode.getMaterial() != null)
{
WornUniqueCodeMaterial material = wornUniqueCode.getMaterial();
material.setUpdateTime(DateUtils.getNowDate());
material.setUpdateBy(String.valueOf(userId));
materialMapper.updateWornUniqueCodeMaterial(material);
}
return 1;
}
/**
* 批量删除唯一码管理
*

View File

@@ -167,7 +167,7 @@ mqtt:
# MQTT 客户端 ID在 EMQX 中唯一)
# 建议:系统名 + 模块名,避免重复
clientId: zg-wms-backend
clientId: zg-wms-wsj
# MQTT 账号EMQX Dashboard 中配置)
username: test

View File

@@ -29,7 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM worn_unique_code t
LEFT JOIN sys_dept d ON t.project_id = d.dept_id
<where>
<if test="code != null and code != ''"> and t.code = #{code}</if>
<if test="code != null"> and t.code = #{code}</if>
<if test="billNo != null and billNo != ''"> and t.bill_no = #{billNo}</if>
<if test="projectId != null "> and t.project_id = #{projectId}</if>
<if test="status != null and status != ''"> and t.status = #{status}</if>
@@ -45,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertWornUniqueCode" parameterType="WornUniqueCode" useGeneratedKeys="true" keyProperty="id">
insert into worn_unique_code
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="code != null and code != ''">code,</if>
<if test="code != null">code,</if>
<if test="billNo != null">bill_no,</if>
<if test="projectId != null">project_id,</if>
<if test="status != null">status,</if>
@@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isDelete != null">is_delete,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="code != null and code != ''">#{code},</if>
<if test="code != null">#{code},</if>
<if test="billNo != null">#{billNo},</if>
<if test="projectId != null">#{projectId},</if>
<if test="status != null">#{status},</if>
@@ -77,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateWornUniqueCode" parameterType="WornUniqueCode">
update worn_unique_code
<trim prefix="SET" suffixOverrides=",">
<if test="code != null and code != ''">code = #{code},</if>
<if test="code != null">code = #{code},</if>
<if test="billNo != null">bill_no = #{billNo},</if>
<if test="projectId != null">project_id = #{projectId},</if>
<if test="status != null">status = #{status},</if>
@@ -93,8 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<delete id="deleteWornUniqueCodeByIds" parameterType="String">
<delete id="deleteWornUniqueCodeByIds" parameterType="Long">
delete from worn_unique_code where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}

View File

@@ -4,6 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.shzg.project.unique.mapper.WornUniqueCodeMaterialMapper">
<!-- ================= 原有 resultMap ================= -->
<resultMap type="WornUniqueCodeMaterial" id="WornUniqueCodeMaterialResult">
<result property="id" column="id"/>
<result property="uniqueCodeId" column="unique_code_id"/>
@@ -18,6 +19,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="isDelete" column="is_delete"/>
</resultMap>
<!-- ================= 联表 resultMap ================= -->
<resultMap id="materialWithWornMaterial" type="com.shzg.project.unique.domain.WornUniqueCodeMaterial">
<id property="id" column="id"/>
<result property="uniqueCodeId" column="unique_code_id"/>
<result property="materialId" column="material_id"/>
<result property="unitId" column="unit_id"/>
<result property="quantity" column="quantity"/>
<result property="remark" column="remark"/>
<result property="isDelete" column="is_delete"/>
<!-- 嵌套物料 -->
<association property="wornMaterial" javaType="com.shzg.project.worn.domain.WornMaterial">
<id property="id" column="wm_id"/>
<result property="materialName" column="material_name"/>
<result property="materialShortName" column="material_short_name"/>
<result property="materialCode" column="material_code"/>
<result property="typeId" column="type_id"/>
<result property="unitId" column="unit_id"/>
<result property="materialCategory" column="material_category"/>
<result property="kgFactor" column="kg_factor"/>
<result property="specification" column="specification"/>
<result property="model" column="model"/>
<result property="barcode" column="barcode"/>
<result property="weight" column="weight"/>
<result property="description" column="description"/>
<!-- 扩展字段 -->
<result property="typeName" column="type_name"/>
<result property="typeAncestors" column="type_ancestors"/>
<result property="typeParentNames" column="type_parent_names"/>
<result property="unitName" column="unit_name"/>
</association>
</resultMap>
<sql id="selectWornUniqueCodeMaterialVo">
select id, unique_code_id, material_id, unit_id, quantity, create_by, create_time, update_by, update_time, remark, is_delete from worn_unique_code_material
</sql>
@@ -37,6 +72,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectWornUniqueCodeMaterialVo"/>
where id = #{id}
</select>
<!-- ================= 核心:联表查询 ================= -->
<select id="selectWithMaterialByUniqueCodeId"
parameterType="java.lang.Long"
resultMap="materialWithWornMaterial">
SELECT
m.*,
wm.id AS wm_id,
wm.material_name,
wm.material_short_name,
wm.material_code,
wm.type_id,
wm.unit_id,
wm.material_category,
wm.kg_factor,
wm.specification,
wm.model,
wm.barcode,
wm.weight,
wm.description,
wt.type_name,
wt.ancestors AS type_ancestors,
wu.unit_name,
GROUP_CONCAT(wt_parent.type_name ORDER BY wt_parent.id SEPARATOR '/') AS type_parent_names
FROM worn_unique_code_material m
LEFT JOIN worn_material wm ON m.material_id = wm.id
LEFT JOIN worn_material_type wt ON wm.type_id = wt.id
LEFT JOIN worn_material_type wt_parent ON FIND_IN_SET(wt_parent.id, wt.ancestors)
LEFT JOIN worn_material_unit wu ON wm.unit_id = wu.id
WHERE m.unique_code_id = #{uniqueCodeId}
GROUP BY m.id
</select>
<insert id="insertWornUniqueCodeMaterial" parameterType="WornUniqueCodeMaterial" useGeneratedKeys="true" keyProperty="id">
insert into worn_unique_code_material
<trim prefix="(" suffix=")" suffixOverrides=",">
@@ -86,16 +163,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from worn_unique_code_material where id = #{id}
</delete>
<delete id="deleteWornUniqueCodeMaterialByIds" parameterType="String">
<delete id="deleteWornUniqueCodeMaterialByIds" parameterType="Long">
delete from worn_unique_code_material where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectByUniqueCodeId" resultType="com.shzg.project.unique.domain.WornUniqueCodeMaterial">
SELECT *
FROM worn_unique_code_material
WHERE unique_code_id = #{uniqueCodeId}
</select>
</mapper>