From 9e41dbdc9f223d4e3ad6a250b837b20717e58bb0 Mon Sep 17 00:00:00 2001 From: wenshijun Date: Thu, 19 Mar 2026 16:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=94=AF=E4=B8=80=E7=A0=81=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shzg/framework/config/SecurityConfig.java | 5 +- .../controller/WornUniqueCodeController.java | 6 +- .../project/unique/domain/WornUniqueCode.java | 10 +- .../unique/domain/WornUniqueCodeMaterial.java | 98 +++++++------ .../mapper/WornUniqueCodeMaterialMapper.java | 3 +- .../impl/WornUniqueCodeServiceImpl.java | 85 ++++++++--- src/main/resources/application.yml | 2 +- .../mybatis/unique/WornUniqueCodeMapper.xml | 13 +- .../unique/WornUniqueCodeMaterialMapper.xml | 132 ++++++++++++++---- 9 files changed, 246 insertions(+), 108 deletions(-) diff --git a/src/main/java/com/shzg/framework/config/SecurityConfig.java b/src/main/java/com/shzg/framework/config/SecurityConfig.java index f3d81bf..013c2ef 100644 --- a/src/main/java/com/shzg/framework/config/SecurityConfig.java +++ b/src/main/java/com/shzg/framework/config/SecurityConfig.java @@ -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() diff --git a/src/main/java/com/shzg/project/unique/controller/WornUniqueCodeController.java b/src/main/java/com/shzg/project/unique/controller/WornUniqueCodeController.java index be01a8a..a47428e 100644 --- a/src/main/java/com/shzg/project/unique/controller/WornUniqueCodeController.java +++ b/src/main/java/com/shzg/project/unique/controller/WornUniqueCodeController.java @@ -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)); } diff --git a/src/main/java/com/shzg/project/unique/domain/WornUniqueCode.java b/src/main/java/com/shzg/project/unique/domain/WornUniqueCode.java index 8afe875..3039b8c 100644 --- a/src/main/java/com/shzg/project/unique/domain/WornUniqueCode.java +++ b/src/main/java/com/shzg/project/unique/domain/WornUniqueCode.java @@ -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; } diff --git a/src/main/java/com/shzg/project/unique/domain/WornUniqueCodeMaterial.java b/src/main/java/com/shzg/project/unique/domain/WornUniqueCodeMaterial.java index 9065b6c..a363d2a 100644 --- a/src/main/java/com/shzg/project/unique/domain/WornUniqueCodeMaterial.java +++ b/src/main/java/com/shzg/project/unique/domain/WornUniqueCodeMaterial.java @@ -3,13 +3,14 @@ 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; /** * 唯一码物料信息对象 worn_unique_code_material - * + * * @author shzg * @date 2026-03-17 */ @@ -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,80 +41,99 @@ public class WornUniqueCodeMaterial extends BaseEntity @Excel(name = "是否删除", readConverterExp = "0=正常,1=删除") private String isDelete; - public void setId(Long id) - { - this.id = id; - } + /** ==================== 扩展字段(不落库) ==================== */ - public Long getId() + /** 物料详细信息(联表查询) */ + 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() + public Long getUniqueCodeId() { return uniqueCodeId; } - public void setMaterialId(Long materialId) + public void setUniqueCodeId(Long uniqueCodeId) { - this.materialId = materialId; + this.uniqueCodeId = uniqueCodeId; } - public Long getMaterialId() + public Long getMaterialId() { return materialId; } - public void setUnitId(Long unitId) + public void setMaterialId(Long materialId) { - this.unitId = unitId; + this.materialId = materialId; } - public Long getUnitId() + public Long getUnitId() { return unitId; } - public void setQuantity(BigDecimal quantity) + public void setUnitId(Long unitId) { - this.quantity = quantity; + this.unitId = unitId; } - public BigDecimal getQuantity() + public BigDecimal getQuantity() { return quantity; } - public void setIsDelete(String isDelete) + public void setQuantity(BigDecimal quantity) { - this.isDelete = isDelete; + this.quantity = quantity; } - public String getIsDelete() + public String getIsDelete() { return isDelete; } - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("uniqueCodeId", getUniqueCodeId()) - .append("materialId", getMaterialId()) - .append("unitId", getUnitId()) - .append("quantity", getQuantity()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .append("isDelete", getIsDelete()) - .toString(); + 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() + { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("uniqueCodeId", getUniqueCodeId()) + .append("materialId", getMaterialId()) + .append("unitId", getUnitId()) + .append("quantity", getQuantity()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("isDelete", getIsDelete()) + .append("wornMaterial", getWornMaterial()) + .toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/shzg/project/unique/mapper/WornUniqueCodeMaterialMapper.java b/src/main/java/com/shzg/project/unique/mapper/WornUniqueCodeMaterialMapper.java index 96b13eb..bd9f86d 100644 --- a/src/main/java/com/shzg/project/unique/mapper/WornUniqueCodeMaterialMapper.java +++ b/src/main/java/com/shzg/project/unique/mapper/WornUniqueCodeMaterialMapper.java @@ -59,10 +59,11 @@ public interface WornUniqueCodeMaterialMapper */ public int deleteWornUniqueCodeMaterialByIds(Long[] ids); + /** * 根据唯一码id查询唯一码物料信息 * @param id * @return */ - WornUniqueCodeMaterial selectByUniqueCodeId(Long id); + WornUniqueCodeMaterial selectWithMaterialByUniqueCodeId(Long id); } diff --git a/src/main/java/com/shzg/project/unique/service/impl/WornUniqueCodeServiceImpl.java b/src/main/java/com/shzg/project/unique/service/impl/WornUniqueCodeServiceImpl.java index 460e934..5b2adee 100644 --- a/src/main/java/com/shzg/project/unique/service/impl/WornUniqueCodeServiceImpl.java +++ b/src/main/java/com/shzg/project/unique/service/impl/WornUniqueCodeServiceImpl.java @@ -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 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) { - wornUniqueCode.setUpdateTime(DateUtils.getNowDate()); - return wornUniqueCodeMapper.updateWornUniqueCode(wornUniqueCode); - } + Long userId = SecurityUtils.getLoginUser().getUser().getUserId(); + wornUniqueCode.setUpdateTime(DateUtils.getNowDate()); + 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; + } /** * 批量删除唯一码管理 * diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2932ab1..342029c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -167,7 +167,7 @@ mqtt: # MQTT 客户端 ID(在 EMQX 中唯一) # 建议:系统名 + 模块名,避免重复 - clientId: zg-wms-backend + clientId: zg-wms-wsj # MQTT 账号(EMQX Dashboard 中配置) username: test diff --git a/src/main/resources/mybatis/unique/WornUniqueCodeMapper.xml b/src/main/resources/mybatis/unique/WornUniqueCodeMapper.xml index f00b535..5359992 100644 --- a/src/main/resources/mybatis/unique/WornUniqueCodeMapper.xml +++ b/src/main/resources/mybatis/unique/WornUniqueCodeMapper.xml @@ -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 - and t.code = #{code} + and t.code = #{code} and t.bill_no = #{billNo} and t.project_id = #{projectId} and t.status = #{status} @@ -45,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into worn_unique_code - code, + code, bill_no, project_id, status, @@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" is_delete, - #{code}, + #{code}, #{billNo}, #{projectId}, #{status}, @@ -77,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update worn_unique_code - code = #{code}, + code = #{code}, bill_no = #{billNo}, project_id = #{projectId}, status = #{status}, @@ -93,9 +93,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} - - - delete from worn_unique_code where id in + + delete from worn_unique_code where id in #{id} diff --git a/src/main/resources/mybatis/unique/WornUniqueCodeMaterialMapper.xml b/src/main/resources/mybatis/unique/WornUniqueCodeMaterialMapper.xml index e580d5d..23d48de 100644 --- a/src/main/resources/mybatis/unique/WornUniqueCodeMaterialMapper.xml +++ b/src/main/resources/mybatis/unique/WornUniqueCodeMaterialMapper.xml @@ -1,21 +1,56 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -24,19 +59,61 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + + + + insert into worn_unique_code_material @@ -50,7 +127,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_time, remark, is_delete, - + #{uniqueCodeId}, #{materialId}, @@ -62,7 +139,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{updateTime}, #{remark}, #{isDelete}, - + @@ -86,16 +163,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from worn_unique_code_material where id = #{id} - - delete from worn_unique_code_material where id in + + delete from worn_unique_code_material where id in #{id} - \ No newline at end of file