Showing
10 changed files
with
95 additions
and
0 deletions
| ... | ... | @@ -2614,6 +2614,7 @@ ALTER TABLE procurement_weighing_ticket |
| 2614 | 2614 | CREATE TABLE IF NOT EXISTS `procurement_assay_apply` |
| 2615 | 2615 | ( |
| 2616 | 2616 | `id` varchar(32) NOT NULL COMMENT 'ID', |
| 2617 | + `code` varchar(50) DEFAULT NULL COMMENT '编号(SY+年月日+6位流水)', | |
| 2617 | 2618 | `weighing_ticket_id` varchar(32) NOT NULL COMMENT '过磅码单ID(单选,须为审核通过且已上传签字凭证的码单)', |
| 2618 | 2619 | `weighing_ticket_code` varchar(50) DEFAULT NULL COMMENT '码单编号(冗余展示)', |
| 2619 | 2620 | `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID(取自过磅码单,按分厂划分)', |
| ... | ... | @@ -2632,6 +2633,7 @@ CREATE TABLE IF NOT EXISTS `procurement_assay_apply` |
| 2632 | 2633 | `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| 2633 | 2634 | `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', |
| 2634 | 2635 | PRIMARY KEY (`id`), |
| 2636 | + UNIQUE KEY `uk_paa_code` (`code`), | |
| 2635 | 2637 | KEY `idx_paa_weighing_ticket_id` (`weighing_ticket_id`), |
| 2636 | 2638 | KEY `idx_paa_procurement_plan_id` (`procurement_plan_id`), |
| 2637 | 2639 | KEY `idx_paa_product_id` (`product_id`), | ... | ... |
| ... | ... | @@ -15,6 +15,9 @@ public class GetProcurementAssayApplyBo extends BaseBo<ProcurementAssayApply> { |
| 15 | 15 | @ApiModelProperty("ID") |
| 16 | 16 | private String id; |
| 17 | 17 | |
| 18 | + @ApiModelProperty("编号") | |
| 19 | + private String code; | |
| 20 | + | |
| 18 | 21 | @ApiModelProperty("过磅码单ID") |
| 19 | 22 | private String weighingTicketId; |
| 20 | 23 | ... | ... |
| ... | ... | @@ -100,6 +100,12 @@ public class ProcurementAssayApplyController extends DefaultBaseController { |
| 100 | 100 | return InvokeResultBuilder.success(procurementAssayApplyService.getBreedOptions(ticketId, planId)); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | + @ApiOperation("获取化验送样单编号(SY+年月日+6位流水,新增页预取)") | |
| 104 | + @GetMapping("/generateCode") | |
| 105 | + public InvokeResult<String> generateCode() { | |
| 106 | + return InvokeResultBuilder.success(procurementAssayApplyService.generateCode()); | |
| 107 | + } | |
| 108 | + | |
| 103 | 109 | @ApiOperation("新增化验送样单(草稿,取样员)") |
| 104 | 110 | @HasPermission({"warehouse-manage:sample-submission:add"}) |
| 105 | 111 | @PostMapping("") | ... | ... |
| ... | ... | @@ -24,6 +24,11 @@ public class ProcurementAssayApply extends BaseEntity implements BaseDto { |
| 24 | 24 | private String id; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | + * 编号(SY+年月日+6位流水) | |
| 28 | + */ | |
| 29 | + private String code; | |
| 30 | + | |
| 31 | + /** | |
| 27 | 32 | * 过磅码单ID(单选,须为审核通过且已上传签字凭证的码单) |
| 28 | 33 | */ |
| 29 | 34 | private String weighingTicketId; | ... | ... |
| ... | ... | @@ -38,6 +38,8 @@ import com.lframework.xingyun.sc.procurement.vo.weighing.CreateProcurementAssayA |
| 38 | 38 | import com.lframework.xingyun.sc.procurement.vo.weighing.QueryAssaySelectableTicketVo; |
| 39 | 39 | import com.lframework.xingyun.sc.procurement.vo.weighing.QueryProcurementAssayApplyVo; |
| 40 | 40 | import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateProcurementAssayApplyVo; |
| 41 | +import java.time.LocalDate; | |
| 42 | +import java.time.format.DateTimeFormatter; | |
| 41 | 43 | import java.util.ArrayList; |
| 42 | 44 | import java.util.Collections; |
| 43 | 45 | import java.util.HashSet; |
| ... | ... | @@ -76,6 +78,10 @@ public class ProcurementAssayApplyServiceImpl |
| 76 | 78 | private static final String DEPT_METROLOGY = "METROLOGY"; |
| 77 | 79 | /** 流程编号(需与流程设计器中的流程编号一致:测试室审核 -> 化验室审核) */ |
| 78 | 80 | private static final String BPM_FLAG = "ASSAY_APPLY"; |
| 81 | + /** 编号前缀 */ | |
| 82 | + private static final String CODE_PREFIX = "SY"; | |
| 83 | + /** 编号日期部分格式 */ | |
| 84 | + private static final DateTimeFormatter DATE_CODE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd"); | |
| 79 | 85 | |
| 80 | 86 | @Resource |
| 81 | 87 | private ProcurementAssayApplyMapper assayApplyMapper; |
| ... | ... | @@ -199,6 +205,16 @@ public class ProcurementAssayApplyServiceImpl |
| 199 | 205 | public String create(CreateProcurementAssayApplyVo vo) { |
| 200 | 206 | ProcurementAssayApply entity = new ProcurementAssayApply(); |
| 201 | 207 | entity.setId(IdUtil.getId()); |
| 208 | + | |
| 209 | + // 编号由前端预取传入,保存时校验唯一(预取接口不落库,极端并发下可能重号,唯一键+此处校验兜底) | |
| 210 | + Assert.notBlank(vo.getCode(), "编号不能为空!"); | |
| 211 | + long codeExists = this.count(Wrappers.lambdaQuery(ProcurementAssayApply.class) | |
| 212 | + .eq(ProcurementAssayApply::getCode, vo.getCode())); | |
| 213 | + if (codeExists > 0) { | |
| 214 | + throw new DefaultClientException("编号已存在,请重新获取!"); | |
| 215 | + } | |
| 216 | + entity.setCode(vo.getCode()); | |
| 217 | + | |
| 202 | 218 | applyFields(entity, vo); |
| 203 | 219 | |
| 204 | 220 | entity.setApprovalStatus(STATUS_DRAFT); |
| ... | ... | @@ -375,6 +391,34 @@ public class ProcurementAssayApplyServiceImpl |
| 375 | 391 | .eq(ProcurementAssayApply::getId, id)); |
| 376 | 392 | } |
| 377 | 393 | |
| 394 | + @Override | |
| 395 | + public String generateCode() { | |
| 396 | + String prefix = CODE_PREFIX + LocalDate.now().format(DATE_CODE_FORMATTER); | |
| 397 | + | |
| 398 | + // 当日已有最大编号,取其后六位流水作为起始 | |
| 399 | + int seq = 0; | |
| 400 | + String maxCode = assayApplyMapper.findMaxCodeByPrefix(prefix); | |
| 401 | + if (StringUtil.isNotBlank(maxCode) && maxCode.length() > prefix.length()) { | |
| 402 | + try { | |
| 403 | + seq = Integer.parseInt(maxCode.substring(prefix.length())); | |
| 404 | + } catch (NumberFormatException e) { | |
| 405 | + log.warn("化验送样单编号流水解析失败,maxCode={}", maxCode); | |
| 406 | + } | |
| 407 | + } | |
| 408 | + | |
| 409 | + // 并发下流水可能已被占用,逐个顺延并校验唯一 | |
| 410 | + for (int i = 1; i <= 1000; i++) { | |
| 411 | + String code = prefix + String.format("%06d", seq + i); | |
| 412 | + long exists = this.count(Wrappers.lambdaQuery(ProcurementAssayApply.class) | |
| 413 | + .eq(ProcurementAssayApply::getCode, code)); | |
| 414 | + if (exists <= 0) { | |
| 415 | + return code; | |
| 416 | + } | |
| 417 | + } | |
| 418 | + | |
| 419 | + throw new DefaultClientException("化验送样单编号生成失败,请重试!"); | |
| 420 | + } | |
| 421 | + | |
| 378 | 422 | /** |
| 379 | 423 | * 组装单据字段(新增/修改共用):校验码单、计划、品种合法后回填冗余字段 |
| 380 | 424 | */ | ... | ... |
| ... | ... | @@ -21,6 +21,11 @@ public interface ProcurementAssayApplyMapper extends BaseMapper<ProcurementAssay |
| 21 | 21 | ProcurementAssayApply findById(@Param("id") String id); |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | + * 查询以指定前缀开头的最大编号(用于生成当日流水号),不过滤 deleted 避免与作废单据编号重复 | |
| 25 | + */ | |
| 26 | + String findMaxCodeByPrefix(@Param("prefix") String prefix); | |
| 27 | + | |
| 28 | + /** | |
| 24 | 29 | * 分页查询可送样化验的过磅码单(审核通过且已上传签字凭证,选择码单弹窗) |
| 25 | 30 | */ |
| 26 | 31 | List<GetAssaySelectableTicketBo> querySelectableTickets( | ... | ... |
| ... | ... | @@ -47,6 +47,11 @@ public interface ProcurementAssayApplyService extends BaseMpService<ProcurementA |
| 47 | 47 | List<GetAssayTicketDataBo.BreedOption> getBreedOptions(String ticketId, String planId); |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | + * 生成编号(SY+年月日+6位流水,前端新增页预取,保存时以传入编号为准并校验唯一) | |
| 51 | + */ | |
| 52 | + String generateCode(); | |
| 53 | + | |
| 54 | + /** | |
| 50 | 55 | * 新增化验送样单(草稿):一单关联一个过磅码单并化验其中一个过磅品种 |
| 51 | 56 | */ |
| 52 | 57 | String create(CreateProcurementAssayApplyVo vo); | ... | ... |
| ... | ... | @@ -7,6 +7,10 @@ import lombok.Data; |
| 7 | 7 | @Data |
| 8 | 8 | public class CreateProcurementAssayApplyVo { |
| 9 | 9 | |
| 10 | + @ApiModelProperty(value = "编号(前端先调用获取编号接口预取,保存时校验唯一)", required = true) | |
| 11 | + @NotBlank(message = "编号不能为空!") | |
| 12 | + private String code; | |
| 13 | + | |
| 10 | 14 | @ApiModelProperty(value = "过磅码单ID(单选,须为审核通过且已上传签字凭证的码单)", required = true) |
| 11 | 15 | @NotBlank(message = "过磅码单不能为空!") |
| 12 | 16 | private String weighingTicketId; | ... | ... |
| ... | ... | @@ -17,6 +17,9 @@ public class QueryProcurementAssayApplyVo extends SortPageVo implements Serializ |
| 17 | 17 | |
| 18 | 18 | private static final long serialVersionUID = 1L; |
| 19 | 19 | |
| 20 | + @ApiModelProperty("编号(模糊匹配)") | |
| 21 | + private String code; | |
| 22 | + | |
| 20 | 23 | @ApiModelProperty("码单编号(模糊匹配)") |
| 21 | 24 | private String weighingTicketCode; |
| 22 | 25 | |
| ... | ... | @@ -26,6 +29,9 @@ public class QueryProcurementAssayApplyVo extends SortPageVo implements Serializ |
| 26 | 29 | @ApiModelProperty("计划编号(模糊匹配)") |
| 27 | 30 | private String planCode; |
| 28 | 31 | |
| 32 | + @ApiModelProperty("分厂ID") | |
| 33 | + private String workshopId; | |
| 34 | + | |
| 29 | 35 | @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL") |
| 30 | 36 | private String approvalStatus; |
| 31 | 37 | ... | ... |
| ... | ... | @@ -4,6 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | <resultMap id="ProcurementAssayApplyResult" type="com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayApply"> |
| 6 | 6 | <id column="id" property="id"/> |
| 7 | + <result column="code" property="code"/> | |
| 7 | 8 | <result column="weighing_ticket_id" property="weighingTicketId"/> |
| 8 | 9 | <result column="weighing_ticket_code" property="weighingTicketCode"/> |
| 9 | 10 | <result column="workshop_id" property="workshopId"/> |
| ... | ... | @@ -27,6 +28,7 @@ |
| 27 | 28 | <sql id="PAA_sql"> |
| 28 | 29 | SELECT |
| 29 | 30 | tb.id, |
| 31 | + tb.code, | |
| 30 | 32 | tb.weighing_ticket_id, |
| 31 | 33 | tb.weighing_ticket_code, |
| 32 | 34 | tb.workshop_id, |
| ... | ... | @@ -60,6 +62,9 @@ |
| 60 | 62 | AND tb.deleted = 0 |
| 61 | 63 | </otherwise> |
| 62 | 64 | </choose> |
| 65 | + <if test="vo.code != null and vo.code != ''"> | |
| 66 | + AND tb.code LIKE CONCAT('%', #{vo.code}, '%') | |
| 67 | + </if> | |
| 63 | 68 | <if test="vo.weighingTicketCode != null and vo.weighingTicketCode != ''"> |
| 64 | 69 | AND tb.weighing_ticket_code LIKE CONCAT('%', #{vo.weighingTicketCode}, '%') |
| 65 | 70 | </if> |
| ... | ... | @@ -69,6 +74,9 @@ |
| 69 | 74 | <if test="vo.planCode != null and vo.planCode != ''"> |
| 70 | 75 | AND tb.plan_code LIKE CONCAT('%', #{vo.planCode}, '%') |
| 71 | 76 | </if> |
| 77 | + <if test="vo.workshopId != null and vo.workshopId != ''"> | |
| 78 | + AND tb.workshop_id = #{vo.workshopId} | |
| 79 | + </if> | |
| 72 | 80 | <if test="vo.approvalStatus != null and vo.approvalStatus != ''"> |
| 73 | 81 | AND tb.approval_status = #{vo.approvalStatus} |
| 74 | 82 | </if> |
| ... | ... | @@ -96,6 +104,13 @@ |
| 96 | 104 | WHERE tb.id = #{id} |
| 97 | 105 | </select> |
| 98 | 106 | |
| 107 | + <!-- 查询以指定前缀开头的最大编号(用于生成当日流水号),不过滤 deleted 避免与作废单据编号重复 --> | |
| 108 | + <select id="findMaxCodeByPrefix" resultType="java.lang.String"> | |
| 109 | + SELECT MAX(tb.code) | |
| 110 | + FROM procurement_assay_apply tb | |
| 111 | + WHERE tb.code LIKE CONCAT(#{prefix}, '%') | |
| 112 | + </select> | |
| 113 | + | |
| 99 | 114 | <resultMap id="AssaySelectableTicketResult" type="com.lframework.xingyun.sc.bo.procurement.GetAssaySelectableTicketBo"> |
| 100 | 115 | <id column="id" property="id"/> |
| 101 | 116 | <result column="code" property="code"/> | ... | ... |