Commit 726ccbe4e1dcff534ef25227cacc9fa4d39178c8
1 parent
7ca0016e
category 字段优化
Showing
8 changed files
with
66 additions
and
36 deletions
src/main/java/com/diligrp/xtrade/product/controllor/CategoryController.java
... | ... | @@ -51,13 +51,8 @@ public class CategoryController { |
51 | 51 | * @throws |
52 | 52 | */ |
53 | 53 | @RequestMapping("save") |
54 | - public Message<?> save(@RequestBody CategoryDto categoryDTO,@RequestParam(value = "file",required = false) MultipartFile file) { | |
55 | - checkImageFile(file); | |
56 | - try { | |
57 | - categoryDTO.setImage(file.getBytes()); | |
58 | - } catch (IOException e) { | |
59 | - throw new ProductException(ExceptionEnum.FILE_UP_ERROR); | |
60 | - } | |
54 | + public Message<?> save(CategoryDto categoryDTO) { | |
55 | + checkImageFile(categoryDTO.getImage()); | |
61 | 56 | categoryService.insert(categoryDTO); |
62 | 57 | return Message.success(); |
63 | 58 | } |
... | ... | @@ -128,15 +123,15 @@ public class CategoryController { |
128 | 123 | private void checkImageFile(MultipartFile file) { |
129 | 124 | try { |
130 | 125 | if (!ImageUtil.isImage(file.getInputStream())) { |
131 | - throw new ProductException(ExceptionEnum.NOT_IMAGE); | |
132 | - } | |
133 | - if (!ImageUtil.checkImageSize(file.getInputStream(), MAX_WIDTH, MAX_HEIGHT, MIN_WIDTH, MIN_HEIGHT)) { | |
134 | - | |
135 | - throw new ProductException(200005,"上传图片长宽超过限制,请保证图片大小范围为" + MIN_WIDTH + "*" + MIN_HEIGHT + "到" + MAX_WIDTH + "*" | |
136 | - + MAX_HEIGHT); | |
126 | + throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"只能上传图片"); | |
137 | 127 | } |
128 | +// if (!ImageUtil.checkImageSize(file.getInputStream(), MAX_WIDTH, MAX_HEIGHT, MIN_WIDTH, MIN_HEIGHT)) { | |
129 | +// | |
130 | +// throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片长宽超过限制,请保证图片大小范围为" + MIN_WIDTH + "*" + MIN_HEIGHT + "到" + MAX_WIDTH + "*" | |
131 | +// + MAX_HEIGHT); | |
132 | +// } | |
138 | 133 | if (file.getBytes().length > MAX_FILE_SIZE) { |
139 | - new ProductException(200005,"上传图片大小超过限制,请保证图片不超过256K"); | |
134 | + throw new ProductException(ExceptionEnum.FILE_UP_ERROR.getCode(),"上传图片大小超过限制,请保证图片不超过256K"); | |
140 | 135 | } |
141 | 136 | } catch (IOException e) { |
142 | 137 | throw new ProductException(ExceptionEnum.FILE_UP_ERROR); | ... | ... |
src/main/java/com/diligrp/xtrade/product/dao/CategoryDao.java
... | ... | @@ -29,11 +29,11 @@ public interface CategoryDao { |
29 | 29 | * |
30 | 30 | * @Title selectList |
31 | 31 | * @Description 品类条件查询 |
32 | - * @param categoryQueryDto | |
32 | + * @param category | |
33 | 33 | * @return |
34 | 34 | * @throws |
35 | 35 | */ |
36 | - List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto); | |
36 | + List<CategoryDo> selectList(CategoryDo category); | |
37 | 37 | /** |
38 | 38 | * |
39 | 39 | * @Title selectCateChild | ... | ... |
src/main/java/com/diligrp/xtrade/product/domain/dto/CategoryDto.java
1 | 1 | package com.diligrp.xtrade.product.domain.dto; |
2 | 2 | |
3 | +import javax.validation.constraints.NotBlank; | |
4 | + | |
5 | +import org.springframework.web.multipart.MultipartFile; | |
3 | 6 | |
4 | 7 | /** |
5 | 8 | * @ClassName: CategoryDto |
... | ... | @@ -17,10 +20,12 @@ public class CategoryDto{ |
17 | 20 | /** |
18 | 21 | * 品类名称 |
19 | 22 | */ |
23 | + @NotBlank(message = "品类名称不能为空") | |
20 | 24 | private String cname; |
21 | 25 | /** |
22 | 26 | * 拼音缩写 |
23 | 27 | */ |
28 | + @NotBlank(message = "品类拼音简写不能为空") | |
24 | 29 | private String shortName; |
25 | 30 | /** |
26 | 31 | * 品类状态 |
... | ... | @@ -37,7 +42,7 @@ public class CategoryDto{ |
37 | 42 | /** |
38 | 43 | * 图片 |
39 | 44 | */ |
40 | - private byte[] image; | |
45 | + private MultipartFile image; | |
41 | 46 | /** |
42 | 47 | * 品类有效期 |
43 | 48 | */ |
... | ... | @@ -45,7 +50,7 @@ public class CategoryDto{ |
45 | 50 | /** |
46 | 51 | * 类型 |
47 | 52 | */ |
48 | - private Long type; | |
53 | + private Integer type; | |
49 | 54 | /** |
50 | 55 | * 品类等级 |
51 | 56 | */ |
... | ... | @@ -53,6 +58,7 @@ public class CategoryDto{ |
53 | 58 | /** |
54 | 59 | * 市场id |
55 | 60 | */ |
61 | + @NotBlank(message = "市场id不能为空") | |
56 | 62 | private Integer marketId; |
57 | 63 | public String getParentId() { |
58 | 64 | return parentId; |
... | ... | @@ -97,10 +103,10 @@ public class CategoryDto{ |
97 | 103 | this.icon = icon; |
98 | 104 | } |
99 | 105 | |
100 | - public byte[] getImage() { | |
106 | + public MultipartFile getImage() { | |
101 | 107 | return image; |
102 | 108 | } |
103 | - public void setImage(byte[] image) { | |
109 | + public void setImage(MultipartFile image) { | |
104 | 110 | this.image = image; |
105 | 111 | } |
106 | 112 | public Integer getValidDay() { |
... | ... | @@ -109,10 +115,11 @@ public class CategoryDto{ |
109 | 115 | public void setValidDay(Integer validDay) { |
110 | 116 | this.validDay = validDay; |
111 | 117 | } |
112 | - public Long getType() { | |
118 | + | |
119 | + public Integer getType() { | |
113 | 120 | return type; |
114 | 121 | } |
115 | - public void setType(Long type) { | |
122 | + public void setType(Integer type) { | |
116 | 123 | this.type = type; |
117 | 124 | } |
118 | 125 | public Integer getLevel() { | ... | ... |
src/main/java/com/diligrp/xtrade/product/domain/dto/ShopQueryDto.java
... | ... | @@ -13,6 +13,7 @@ public class ShopQueryDto { |
13 | 13 | private String shopName; |
14 | 14 | private Long merId; |
15 | 15 | private LocalDateTime createdTime; |
16 | + private String address; | |
16 | 17 | public String getShopName() { |
17 | 18 | return shopName; |
18 | 19 | } |
... | ... | @@ -31,5 +32,11 @@ public class ShopQueryDto { |
31 | 32 | public void setCreatedTime(LocalDateTime createdTime) { |
32 | 33 | this.createdTime = createdTime; |
33 | 34 | } |
35 | + public String getAddress() { | |
36 | + return address; | |
37 | + } | |
38 | + public void setAddress(String address) { | |
39 | + this.address = address; | |
40 | + } | |
34 | 41 | |
35 | 42 | } | ... | ... |
src/main/java/com/diligrp/xtrade/product/domain/entity/CategoryDo.java
... | ... | @@ -44,7 +44,7 @@ public class CategoryDo extends BaseDo{ |
44 | 44 | /** |
45 | 45 | * 类型 |
46 | 46 | */ |
47 | - private Long type; | |
47 | + private Integer type; | |
48 | 48 | /** |
49 | 49 | * 品类等级 |
50 | 50 | */ |
... | ... | @@ -103,10 +103,11 @@ public class CategoryDo extends BaseDo{ |
103 | 103 | public void setValidDay(Integer validDay) { |
104 | 104 | this.validDay = validDay; |
105 | 105 | } |
106 | - public Long getType() { | |
106 | + | |
107 | + public Integer getType() { | |
107 | 108 | return type; |
108 | 109 | } |
109 | - public void setType(Long type) { | |
110 | + public void setType(Integer type) { | |
110 | 111 | this.type = type; |
111 | 112 | } |
112 | 113 | public Integer getLevel() { | ... | ... |
src/main/java/com/diligrp/xtrade/product/exception/ExceptionEnum.java
src/main/java/com/diligrp/xtrade/product/service/impl/CategoryServiceImpl.java
1 | 1 | package com.diligrp.xtrade.product.service.impl; |
2 | 2 | |
3 | +import java.io.IOException; | |
3 | 4 | import java.util.List; |
4 | 5 | |
5 | 6 | import org.apache.commons.lang3.StringUtils; |
... | ... | @@ -50,7 +51,14 @@ public class CategoryServiceImpl implements CategoryService { |
50 | 51 | cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id); |
51 | 52 | } |
52 | 53 | categoryDo.setCateCode(cateCode); |
53 | - category.setIcon(ICON_PREFIX + ImageUtil.getMd5(categoryDo.getImage()) + id); | |
54 | + try { | |
55 | + categoryDo.setImage(category.getImage().getBytes()); | |
56 | + } catch (IOException e) { | |
57 | + throw new ProductException(ExceptionEnum.FILE_UP_ERROR); | |
58 | + } | |
59 | + categoryDo.setIcon(ICON_PREFIX + ImageUtil.getMd5(categoryDo.getImage()) + id); | |
60 | + categoryDo.setStatus(1); | |
61 | + categoryDo.setId(id); | |
54 | 62 | categoryDao.insert(categoryDo); |
55 | 63 | } |
56 | 64 | |
... | ... | @@ -77,7 +85,9 @@ public class CategoryServiceImpl implements CategoryService { |
77 | 85 | |
78 | 86 | @Override |
79 | 87 | public List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto) { |
80 | - return categoryDao.selectList(categoryQueryDto); | |
88 | + CategoryDo categoryDo = new CategoryDo(); | |
89 | + BeanUtils.copyProperties(categoryQueryDto, categoryDo); | |
90 | + return categoryDao.selectList(categoryDo); | |
81 | 91 | } |
82 | 92 | |
83 | 93 | @Override |
... | ... | @@ -94,11 +104,11 @@ public class CategoryServiceImpl implements CategoryService { |
94 | 104 | * @throws |
95 | 105 | */ |
96 | 106 | private boolean categoryIsExit(CategoryDto category) { |
97 | - CategoryQueryDto categoryQueryDto = new CategoryQueryDto(); | |
98 | - categoryQueryDto.setCname(category.getCname()); | |
99 | - categoryQueryDto.setLevel(category.getLevel()); | |
100 | - categoryQueryDto.setMarketId(category.getMarketId()); | |
101 | - List<CategoryDo> categorys = categoryDao.selectList(categoryQueryDto); | |
107 | + CategoryDo categoryDo = new CategoryDo(); | |
108 | + categoryDo.setCname(category.getCname()); | |
109 | + categoryDo.setLevel(category.getLevel()); | |
110 | + categoryDo.setMarketId(category.getMarketId()); | |
111 | + List<CategoryDo> categorys = categoryDao.selectList(categoryDo); | |
102 | 112 | if(categorys != null && categorys.size() > 0) { |
103 | 113 | return true; |
104 | 114 | } | ... | ... |
src/main/resources/mapping/com/diligrp/xtrade/product/CategoryDao.xml
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | <if test="hasChild != null"><![CDATA[has_child = #{hasChild},]]></if> |
16 | 16 | <if test="shortName != null"><![CDATA[short_name = #{shortName},]]></if> |
17 | 17 | <if test="icon != null"><![CDATA[icon = #{icon},]]></if> |
18 | - <if test="cateLevel != null"><![CDATA[cate_level = #{cateLevel},]]></if> | |
18 | + <if test="level != null"><![CDATA[level = #{level},]]></if> | |
19 | 19 | <if test="image != null"><![CDATA[image = #{image},]]></if> |
20 | 20 | <if test="validDay != null"><![CDATA[valid_day = #{validDay},]]></if> |
21 | 21 | </set> |
... | ... | @@ -24,15 +24,16 @@ |
24 | 24 | <where> |
25 | 25 | <if test="cname != null and cname != ''"><![CDATA[AND cname = #{cname}]]></if> |
26 | 26 | <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if> |
27 | - <if test="cateLevel != null "><![CDATA[AND cate_level = #{cateLevel}]]></if> | |
27 | + <if test="level != null "><![CDATA[AND level = #{level}]]></if> | |
28 | 28 | <if test="shortName != null and shortName != ''"><![CDATA[AND short_name = #{shortName}]]></if> |
29 | 29 | <if test="cateCode != null and cateCode != ''"><![CDATA[AND cate_code = #{cateCode}]]></if> |
30 | + <if test="marketId != null and marketId != ''"><![CDATA[AND market_id = #{marketId}]]></if> | |
30 | 31 | </where> |
31 | 32 | </sql> |
32 | 33 | <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.CategoryDo"> |
33 | 34 | <![CDATA[ |
34 | 35 | INSERT INTO `category`(`id`, `cate_code`, `cname`, `short_name`, `status`, `level`, `type`, `icon`, `image`, `valid_day`, `created_time`, `modified_time`, `market_id`) VALUES |
35 | - (#{id}, #{cate_code}, #{sname}, #{shortName}, #{status}, #{level}, #{type}, #{icon}, #{image}, #{validDay}, now(), now(), #{marketId}); | |
36 | + (#{id}, #{cateCode}, #{cname}, #{shortName}, #{status}, #{level}, #{type}, #{icon}, #{image}, #{validDay}, now(), now(), #{marketId}); | |
36 | 37 | ]]> |
37 | 38 | </insert> |
38 | 39 | <select id="selectEntityById" parameterType="java.lang.Long" resultType="com.diligrp.xtrade.product.domain.entity.CategoryDo"> |
... | ... | @@ -68,4 +69,14 @@ |
68 | 69 | FROM `category` WHERE cate_code LIKE CONCAT(#{cateCode},'%'); |
69 | 70 | ]]> |
70 | 71 | </select> |
72 | + <select id="selectList" resultType="com.diligrp.xtrade.product.domain.entity.CategoryDo" parameterType="com.diligrp.xtrade.product.domain.entity.CategoryDo" > | |
73 | + <![CDATA[ | |
74 | + SELECT | |
75 | + ]]> | |
76 | + <include refid="QUERY_COLUMN_LIST"/> | |
77 | + <![CDATA[ | |
78 | + FROM `category` | |
79 | + ]]> | |
80 | + <include refid="QUERY_WHERE_CLAUSE"/> | |
81 | + </select> | |
71 | 82 | </mapper> | ... | ... |