Commit e3ec743311d672ebfdcaabc7a47415cc5f3a9563

Authored by 房远帅
1 parent db7ac74a

报价:基础表单问题修改

... ... @@ -1630,10 +1630,10 @@ CREATE TABLE `base_data_breed_relationship`
1630 1630 (
1631 1631 `id` varchar(32) NOT NULL COMMENT 'ID',
1632 1632 `product_name` varchar(200) NOT NULL COMMENT '品名',
1633   - `code` varchar(200) NOT NULL COMMENT '代号',
1634   - `type` varchar(200) NOT NULL COMMENT '类型',
1635   - `attrition_rate` decimal(18, 10) NOT NULL COMMENT '损耗率',
1636   - `miscellaneous_tax_rate` decimal(18, 10) NOT NULL COMMENT '杂率',
  1633 + `code` varchar(200) DEFAULT NULL COMMENT '代号',
  1634 + `type` varchar(200) DEFAULT NULL COMMENT '类型',
  1635 + `attrition_rate` decimal(18, 10) DEFAULT NULL COMMENT '损耗率',
  1636 + `miscellaneous_tax_rate` decimal(18, 10) DEFAULT NULL COMMENT '杂率',
1637 1637 `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
1638 1638 `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
1639 1639 `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
... ...
... ... @@ -93,6 +93,18 @@ public class QueryBreedRelationshipBo extends BaseBo<BreedRelationship> {
93 93 @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
94 94 private LocalDateTime updateTime;
95 95
  96 + /**
  97 + * 是否可编辑
  98 + */
  99 + @ApiModelProperty("是否可编辑")
  100 + private Boolean canEdit = true;
  101 +
  102 + /**
  103 + * 是否可删除
  104 + */
  105 + @ApiModelProperty("是否可删除")
  106 + private Boolean canDelete = true;
  107 +
96 108 public QueryBreedRelationshipBo() {
97 109
98 110 }
... ...
... ... @@ -76,6 +76,18 @@ public class QueryPriceBo extends BaseBo<Price> {
76 76 @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
77 77 private LocalDateTime updateTime;
78 78
  79 + /**
  80 + * 是否可编辑
  81 + */
  82 + @ApiModelProperty("是否可编辑")
  83 + private Boolean canEdit = true;
  84 +
  85 + /**
  86 + * 是否可删除
  87 + */
  88 + @ApiModelProperty("是否可删除")
  89 + private Boolean canDelete = true;
  90 +
79 91
80 92 public QueryPriceBo() {
81 93
... ...
1 1 package com.lframework.xingyun.basedata.controller;
2 2
  3 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
3 4 import com.lframework.starter.web.core.annotations.security.HasPermission;
4 5 import com.lframework.starter.web.core.controller.DefaultBaseController;
5 6 import com.lframework.starter.web.core.utils.PageResultUtil;
... ... @@ -8,7 +9,9 @@ import com.lframework.starter.web.core.components.resp.InvokeResult;
8 9 import javax.validation.constraints.NotBlank;
9 10 import com.lframework.xingyun.basedata.bo.breed.QueryBreedRelationshipBo;
10 11 import com.lframework.xingyun.basedata.entity.BreedRelationship;
  12 +import com.lframework.xingyun.basedata.entity.PriceSubTable;
11 13 import com.lframework.xingyun.basedata.service.breed.BreedRelationshipService;
  14 +import com.lframework.xingyun.basedata.service.price.PriceSubTableService;
12 15 import com.lframework.xingyun.basedata.vo.breed.CreateBreedRelationshipVo;
13 16 import com.lframework.xingyun.basedata.vo.breed.QueryBreedRelationshipVo;
14 17 import com.lframework.xingyun.basedata.vo.breed.UpdateBreedRelationshipVo;
... ... @@ -23,7 +26,10 @@ import org.springframework.beans.factory.annotation.Autowired;
23 26 import org.springframework.validation.annotation.Validated;
24 27 import org.springframework.web.bind.annotation.*;
25 28 import javax.validation.Valid;
  29 +import java.util.Collections;
  30 +import java.util.HashSet;
26 31 import java.util.List;
  32 +import java.util.Set;
27 33 import java.util.stream.Collectors;
28 34
29 35 /**
... ... @@ -39,6 +45,9 @@ public class BreedRelationshipController extends DefaultBaseController {
39 45 @Autowired
40 46 private BreedRelationshipService breedRelationshipService;
41 47
  48 + @Autowired
  49 + private PriceSubTableService priceSubTableService;
  50 +
42 51 /**
43 52 * 查询列表
44 53 */
... ... @@ -54,6 +63,7 @@ public class BreedRelationshipController extends DefaultBaseController {
54 63
55 64 if (!CollectionUtil.isEmpty(datas)) {
56 65 results = datas.stream().map(QueryBreedRelationshipBo::new).collect(Collectors.toList());
  66 + fillCanOperate(results);
57 67 }
58 68
59 69 return InvokeResultBuilder.success(PageResultUtil.rebuild(pageResult, results));
... ... @@ -74,6 +84,7 @@ public class BreedRelationshipController extends DefaultBaseController {
74 84 }
75 85
76 86 QueryBreedRelationshipBo result = new QueryBreedRelationshipBo(data);
  87 + fillCanOperate(Collections.singletonList(result));
77 88
78 89 return InvokeResultBuilder.success(result);
79 90 }
... ... @@ -117,4 +128,24 @@ public class BreedRelationshipController extends DefaultBaseController {
117 128
118 129 return InvokeResultBuilder.success();
119 130 }
  131 +
  132 + private void fillCanOperate(List<QueryBreedRelationshipBo> results) {
  133 + if (CollectionUtil.isEmpty(results)) {
  134 + return;
  135 + }
  136 +
  137 + List<String> ids = results.stream().map(QueryBreedRelationshipBo::getId).collect(Collectors.toList());
  138 + Set<String> referencedIds = priceSubTableService.list(Wrappers.lambdaQuery(PriceSubTable.class)
  139 + .select(PriceSubTable::getProductId)
  140 + .in(PriceSubTable::getProductId, ids))
  141 + .stream()
  142 + .map(PriceSubTable::getProductId)
  143 + .collect(Collectors.toCollection(HashSet::new));
  144 +
  145 + results.forEach(item -> {
  146 + boolean referenced = referencedIds.contains(item.getId());
  147 + item.setCanEdit(!referenced);
  148 + item.setCanDelete(!referenced);
  149 + });
  150 + }
120 151 }
... ...
... ... @@ -29,7 +29,9 @@ import org.springframework.transaction.annotation.Transactional;
29 29 import javax.annotation.Resource;
30 30 import java.io.Serializable;
31 31 import java.util.ArrayList;
  32 +import java.util.HashSet;
32 33 import java.util.List;
  34 +import java.util.Set;
33 35 import java.util.stream.Collectors;
34 36
35 37 @Service
... ... @@ -72,6 +74,7 @@ public class PriceServiceImpl extends BaseMpServiceImpl<PriceMapper, Price> impl
72 74 @Override
73 75 public String create(CreatePriceVo vo) {
74 76 checkCodeUnique(vo.getCode(), null);
  77 + checkPriceSubTableDuplicateCreate(vo.getPriceSubTableList());
75 78
76 79 Price data = new Price();
77 80 data.setId(IdUtil.getId());
... ... @@ -104,6 +107,7 @@ public class PriceServiceImpl extends BaseMpServiceImpl<PriceMapper, Price> impl
104 107 throw new DefaultClientException("价格表不存在!");
105 108 }
106 109 checkCodeUnique(vo.getCode(), vo.getId());
  110 + checkPriceSubTableDuplicateUpdate(vo.getPriceSubTableList());
107 111
108 112 LambdaUpdateWrapper<Price> updateWrapper = Wrappers.lambdaUpdate(Price.class)
109 113 .set(Price::getCode, vo.getCode())
... ... @@ -193,6 +197,32 @@ public class PriceServiceImpl extends BaseMpServiceImpl<PriceMapper, Price> impl
193 197 }
194 198 }
195 199
  200 + private void checkPriceSubTableDuplicateCreate(List<CreatePriceSubTableVo> priceSubTableList) {
  201 + if (CollectionUtils.isEmpty(priceSubTableList)) {
  202 + return;
  203 + }
  204 +
  205 + Set<String> productIds = new HashSet<>(priceSubTableList.size());
  206 + for (CreatePriceSubTableVo priceSubTableVo : priceSubTableList) {
  207 + if (!productIds.add(priceSubTableVo.getProductId())) {
  208 + throw new DefaultClientException("不允许重复选择同一个品种!");
  209 + }
  210 + }
  211 + }
  212 +
  213 + private void checkPriceSubTableDuplicateUpdate(List<UpdatePriceSubTableVo> priceSubTableList) {
  214 + if (CollectionUtils.isEmpty(priceSubTableList)) {
  215 + return;
  216 + }
  217 +
  218 + Set<String> productIds = new HashSet<>(priceSubTableList.size());
  219 + for (UpdatePriceSubTableVo priceSubTableVo : priceSubTableList) {
  220 + if (!productIds.add(priceSubTableVo.getProductId())) {
  221 + throw new DefaultClientException("不允许重复选择同一个品种!");
  222 + }
  223 + }
  224 + }
  225 +
196 226 @Override
197 227 public void cleanCacheByKey(Serializable key) {
198 228
... ...
... ... @@ -27,24 +27,21 @@ public class CreateBreedRelationshipVo implements BaseVo, Serializable {
27 27 /**
28 28 * 代号
29 29 */
30   - @ApiModelProperty(value = "代号", required = true)
31   - @NotBlank(message = "请输入代号!")
  30 + @ApiModelProperty("代号")
32 31 @Length(message = "代号最多允许200个字符!")
33 32 private String code;
34 33
35 34 /**
36 35 * 类型
37 36 */
38   - @ApiModelProperty(value = "类型", required = true)
39   - @NotBlank(message = "请输入类型!")
  37 + @ApiModelProperty("类型")
40 38 @Length(message = "类型最多允许200个字符!")
41 39 private String type;
42 40
43 41 /**
44 42 * 损耗率
45 43 */
46   - @ApiModelProperty(value = "损耗率", required = true)
47   - @NotNull(message = "请输入损耗率!")
  44 + @ApiModelProperty("损耗率")
48 45 @TypeMismatch(message = "损耗率格式有误!")
49 46 @IsNumberPrecision(message = "损耗率最多允许10位小数!", value = 10)
50 47 private BigDecimal attritionRate;
... ... @@ -52,8 +49,7 @@ public class CreateBreedRelationshipVo implements BaseVo, Serializable {
52 49 /**
53 50 * 杂率
54 51 */
55   - @ApiModelProperty(value = "杂率", required = true)
56   - @NotNull(message = "请输入杂率!")
  52 + @ApiModelProperty("杂率")
57 53 @TypeMismatch(message = "杂率格式有误!")
58 54 @IsNumberPrecision(message = "杂率最多允许10位小数!", value = 10)
59 55 private BigDecimal miscellaneousTaxRate;
... ...
... ... @@ -34,34 +34,30 @@ public class UpdateBreedRelationshipVo implements BaseVo, Serializable {
34 34 /**
35 35 * 代号
36 36 */
37   - @ApiModelProperty(value = "代号", required = true)
38   - @NotBlank(message = "请输入代号!")
  37 + @ApiModelProperty("代号")
39 38 @Length(message = "代号最多允许200个字符!")
40 39 private String code;
41 40
42 41 /**
43 42 * 类型
44 43 */
45   - @ApiModelProperty(value = "类型", required = true)
46   - @NotBlank(message = "请输入类型!")
  44 + @ApiModelProperty("类型")
47 45 @Length(message = "类型最多允许200个字符!")
48 46 private String type;
49 47
50 48 /**
51 49 * 损耗率
52 50 */
53   - @ApiModelProperty(value = "损耗率", required = true)
  51 + @ApiModelProperty("损耗率")
54 52 @TypeMismatch(message = "损耗率格式有误!")
55   - @NotNull(message = "请输入损耗率!")
56 53 @IsNumberPrecision(message = "损耗率最多允许10位小数!", value = 10)
57 54 private BigDecimal attritionRate;
58 55
59 56 /**
60 57 * 杂率
61 58 */
62   - @ApiModelProperty(value = "杂率", required = true)
  59 + @ApiModelProperty("杂率")
63 60 @TypeMismatch(message = "杂率格式有误!")
64   - @NotNull(message = "请输入杂率!")
65 61 @IsNumberPrecision(message = "杂率最多允许10位小数!", value = 10)
66 62 private BigDecimal miscellaneousTaxRate;
67 63
... ...
... ... @@ -2,7 +2,7 @@
2 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3 <mapper namespace="com.lframework.xingyun.basedata.mappers.PriceMapper">
4 4
5   - <resultMap id="PriceSubTable" type="com.lframework.xingyun.basedata.entity.Price">
  5 + <resultMap id="Price" type="com.lframework.xingyun.basedata.entity.Price">
6 6 <id column="id" property="id"/>
7 7 <result column="code" property="code"/>
8 8 <result column="create_by_id" property="createById"/>
... ... @@ -13,7 +13,7 @@
13 13 <result column="update_time" property="updateTime"/>
14 14 </resultMap>
15 15
16   - <sql id="PriceSubTable_sql">
  16 + <sql id="Price_sql">
17 17 SELECT
18 18 tb.id,
19 19 tb.code,
... ... @@ -23,14 +23,14 @@
23 23 tb.update_by,
24 24 tb.create_time,
25 25 tb.update_time
26   - FROM base_data_price_sub_table AS tb
  26 + FROM base_data_price AS tb
27 27 </sql>
28 28
29   - <select id="query" resultMap="PriceSubTable">
30   - <include refid="PriceSubTable_sql"/>
  29 + <select id="query" resultMap="Price">
  30 + <include refid="Price_sql"/>
31 31 <where>
32 32 <if test="vo.code != null and vo.code != ''">
33   - AND tb.code =LIKE CONCAT('%', #{vo.code},'%')
  33 + AND tb.code LIKE CONCAT('%', #{vo.code},'%')
34 34 </if>
35 35 <if test="vo.createBy != null and vo.createBy != ''">
36 36 AND tb.create_by LIKE CONCAT('%', #{vo.createBy},'%')
... ...