Commit 726ccbe4e1dcff534ef25227cacc9fa4d39178c8

Authored by yangfan
1 parent 7ca0016e

category 字段优化

src/main/java/com/diligrp/xtrade/product/controllor/CategoryController.java
@@ -51,13 +51,8 @@ public class CategoryController { @@ -51,13 +51,8 @@ public class CategoryController {
51 * @throws 51 * @throws
52 */ 52 */
53 @RequestMapping("save") 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 categoryService.insert(categoryDTO); 56 categoryService.insert(categoryDTO);
62 return Message.success(); 57 return Message.success();
63 } 58 }
@@ -128,15 +123,15 @@ public class CategoryController { @@ -128,15 +123,15 @@ public class CategoryController {
128 private void checkImageFile(MultipartFile file) { 123 private void checkImageFile(MultipartFile file) {
129 try { 124 try {
130 if (!ImageUtil.isImage(file.getInputStream())) { 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 if (file.getBytes().length > MAX_FILE_SIZE) { 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 } catch (IOException e) { 136 } catch (IOException e) {
142 throw new ProductException(ExceptionEnum.FILE_UP_ERROR); 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,11 +29,11 @@ public interface CategoryDao {
29 * 29 *
30 * @Title selectList 30 * @Title selectList
31 * @Description 品类条件查询 31 * @Description 品类条件查询
32 - * @param categoryQueryDto 32 + * @param category
33 * @return 33 * @return
34 * @throws 34 * @throws
35 */ 35 */
36 - List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto); 36 + List<CategoryDo> selectList(CategoryDo category);
37 /** 37 /**
38 * 38 *
39 * @Title selectCateChild 39 * @Title selectCateChild
src/main/java/com/diligrp/xtrade/product/domain/dto/CategoryDto.java
1 package com.diligrp.xtrade.product.domain.dto; 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 * @ClassName: CategoryDto 8 * @ClassName: CategoryDto
@@ -17,10 +20,12 @@ public class CategoryDto{ @@ -17,10 +20,12 @@ public class CategoryDto{
17 /** 20 /**
18 * 品类名称 21 * 品类名称
19 */ 22 */
  23 + @NotBlank(message = "品类名称不能为空")
20 private String cname; 24 private String cname;
21 /** 25 /**
22 * 拼音缩写 26 * 拼音缩写
23 */ 27 */
  28 + @NotBlank(message = "品类拼音简写不能为空")
24 private String shortName; 29 private String shortName;
25 /** 30 /**
26 * 品类状态 31 * 品类状态
@@ -37,7 +42,7 @@ public class CategoryDto{ @@ -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,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,6 +58,7 @@ public class CategoryDto{
53 /** 58 /**
54 * 市场id 59 * 市场id
55 */ 60 */
  61 + @NotBlank(message = "市场id不能为空")
56 private Integer marketId; 62 private Integer marketId;
57 public String getParentId() { 63 public String getParentId() {
58 return parentId; 64 return parentId;
@@ -97,10 +103,10 @@ public class CategoryDto{ @@ -97,10 +103,10 @@ public class CategoryDto{
97 this.icon = icon; 103 this.icon = icon;
98 } 104 }
99 105
100 - public byte[] getImage() { 106 + public MultipartFile getImage() {
101 return image; 107 return image;
102 } 108 }
103 - public void setImage(byte[] image) { 109 + public void setImage(MultipartFile image) {
104 this.image = image; 110 this.image = image;
105 } 111 }
106 public Integer getValidDay() { 112 public Integer getValidDay() {
@@ -109,10 +115,11 @@ public class CategoryDto{ @@ -109,10 +115,11 @@ public class CategoryDto{
109 public void setValidDay(Integer validDay) { 115 public void setValidDay(Integer validDay) {
110 this.validDay = validDay; 116 this.validDay = validDay;
111 } 117 }
112 - public Long getType() { 118 +
  119 + public Integer getType() {
113 return type; 120 return type;
114 } 121 }
115 - public void setType(Long type) { 122 + public void setType(Integer type) {
116 this.type = type; 123 this.type = type;
117 } 124 }
118 public Integer getLevel() { 125 public Integer getLevel() {
src/main/java/com/diligrp/xtrade/product/domain/dto/ShopQueryDto.java
@@ -13,6 +13,7 @@ public class ShopQueryDto { @@ -13,6 +13,7 @@ public class ShopQueryDto {
13 private String shopName; 13 private String shopName;
14 private Long merId; 14 private Long merId;
15 private LocalDateTime createdTime; 15 private LocalDateTime createdTime;
  16 + private String address;
16 public String getShopName() { 17 public String getShopName() {
17 return shopName; 18 return shopName;
18 } 19 }
@@ -31,5 +32,11 @@ public class ShopQueryDto { @@ -31,5 +32,11 @@ public class ShopQueryDto {
31 public void setCreatedTime(LocalDateTime createdTime) { 32 public void setCreatedTime(LocalDateTime createdTime) {
32 this.createdTime = createdTime; 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,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,10 +103,11 @@ public class CategoryDo extends BaseDo{
103 public void setValidDay(Integer validDay) { 103 public void setValidDay(Integer validDay) {
104 this.validDay = validDay; 104 this.validDay = validDay;
105 } 105 }
106 - public Long getType() { 106 +
  107 + public Integer getType() {
107 return type; 108 return type;
108 } 109 }
109 - public void setType(Long type) { 110 + public void setType(Integer type) {
110 this.type = type; 111 this.type = type;
111 } 112 }
112 public Integer getLevel() { 113 public Integer getLevel() {
src/main/java/com/diligrp/xtrade/product/exception/ExceptionEnum.java
@@ -16,7 +16,6 @@ public enum ExceptionEnum implements IEnumType { @@ -16,7 +16,6 @@ public enum ExceptionEnum implements IEnumType {
16 CARD_MERCHANT_CREATED(200003,"该卡已创建商户,请使用用户名密码登录"), 16 CARD_MERCHANT_CREATED(200003,"该卡已创建商户,请使用用户名密码登录"),
17 CATE_EXISTENCE(200004,"品类已存在"), 17 CATE_EXISTENCE(200004,"品类已存在"),
18 FILE_UP_ERROR(200005,"文件上传失败"), 18 FILE_UP_ERROR(200005,"文件上传失败"),
19 - NOT_IMAGE(200006,"只能上传图片")  
20 ; 19 ;
21 20
22 private int code; 21 private int code;
src/main/java/com/diligrp/xtrade/product/service/impl/CategoryServiceImpl.java
1 package com.diligrp.xtrade.product.service.impl; 1 package com.diligrp.xtrade.product.service.impl;
2 2
  3 +import java.io.IOException;
3 import java.util.List; 4 import java.util.List;
4 5
5 import org.apache.commons.lang3.StringUtils; 6 import org.apache.commons.lang3.StringUtils;
@@ -50,7 +51,14 @@ public class CategoryServiceImpl implements CategoryService { @@ -50,7 +51,14 @@ public class CategoryServiceImpl implements CategoryService {
50 cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id); 51 cateCode = String.format("%s_%d", pCategoryDo.getCateCode(),id);
51 } 52 }
52 categoryDo.setCateCode(cateCode); 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 categoryDao.insert(categoryDo); 62 categoryDao.insert(categoryDo);
55 } 63 }
56 64
@@ -77,7 +85,9 @@ public class CategoryServiceImpl implements CategoryService { @@ -77,7 +85,9 @@ public class CategoryServiceImpl implements CategoryService {
77 85
78 @Override 86 @Override
79 public List<CategoryDo> selectList(CategoryQueryDto categoryQueryDto) { 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 @Override 93 @Override
@@ -94,11 +104,11 @@ public class CategoryServiceImpl implements CategoryService { @@ -94,11 +104,11 @@ public class CategoryServiceImpl implements CategoryService {
94 * @throws 104 * @throws
95 */ 105 */
96 private boolean categoryIsExit(CategoryDto category) { 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 if(categorys != null && categorys.size() > 0) { 112 if(categorys != null && categorys.size() > 0) {
103 return true; 113 return true;
104 } 114 }
src/main/resources/mapping/com/diligrp/xtrade/product/CategoryDao.xml
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 <if test="hasChild != null"><![CDATA[has_child = #{hasChild},]]></if> 15 <if test="hasChild != null"><![CDATA[has_child = #{hasChild},]]></if>
16 <if test="shortName != null"><![CDATA[short_name = #{shortName},]]></if> 16 <if test="shortName != null"><![CDATA[short_name = #{shortName},]]></if>
17 <if test="icon != null"><![CDATA[icon = #{icon},]]></if> 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 <if test="image != null"><![CDATA[image = #{image},]]></if> 19 <if test="image != null"><![CDATA[image = #{image},]]></if>
20 <if test="validDay != null"><![CDATA[valid_day = #{validDay},]]></if> 20 <if test="validDay != null"><![CDATA[valid_day = #{validDay},]]></if>
21 </set> 21 </set>
@@ -24,15 +24,16 @@ @@ -24,15 +24,16 @@
24 <where> 24 <where>
25 <if test="cname != null and cname != ''"><![CDATA[AND cname = #{cname}]]></if> 25 <if test="cname != null and cname != ''"><![CDATA[AND cname = #{cname}]]></if>
26 <if test="status != null and status != ''"><![CDATA[AND status = #{status}]]></if> 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 <if test="shortName != null and shortName != ''"><![CDATA[AND short_name = #{shortName}]]></if> 28 <if test="shortName != null and shortName != ''"><![CDATA[AND short_name = #{shortName}]]></if>
29 <if test="cateCode != null and cateCode != ''"><![CDATA[AND cate_code = #{cateCode}]]></if> 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 </where> 31 </where>
31 </sql> 32 </sql>
32 <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.CategoryDo"> 33 <insert id="insert" parameterType="com.diligrp.xtrade.product.domain.entity.CategoryDo">
33 <![CDATA[ 34 <![CDATA[
34 INSERT INTO `category`(`id`, `cate_code`, `cname`, `short_name`, `status`, `level`, `type`, `icon`, `image`, `valid_day`, `created_time`, `modified_time`, `market_id`) VALUES 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 </insert> 38 </insert>
38 <select id="selectEntityById" parameterType="java.lang.Long" resultType="com.diligrp.xtrade.product.domain.entity.CategoryDo"> 39 <select id="selectEntityById" parameterType="java.lang.Long" resultType="com.diligrp.xtrade.product.domain.entity.CategoryDo">
@@ -68,4 +69,14 @@ @@ -68,4 +69,14 @@
68 FROM `category` WHERE cate_code LIKE CONCAT(#{cateCode},'%'); 69 FROM `category` WHERE cate_code LIKE CONCAT(#{cateCode},'%');
69 ]]> 70 ]]>
70 </select> 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 </mapper> 82 </mapper>