Authored by caoyan

商品详情增加传图模块

  1 +package com.yoho.ufo.dal;
  2 +
  3 +import java.util.List;
  4 +
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import com.yoho.ufo.dal.model.SizePoolDetail;
  8 +import com.yoho.ufo.dal.model.SizePoolImage;
  9 +
  10 +/**
  11 + * Created by caoyan.
  12 + */
  13 +public interface SizePoolImageMapper {
  14 +
  15 + int batchInsert(@Param("list")List<SizePoolImage> list);
  16 +
  17 + int deleteBySizePoolId(@Param("sizePoolId") Integer sizePoolId);
  18 +
  19 + List<SizePoolImage> queryBySizePoolId(@Param("sizePoolId") Integer sizePoolId);
  20 +
  21 + List<SizePoolImage> queryBySizePoolIds(@Param("sizePoolIdList") List<Integer> sizePoolIdList);
  22 +
  23 +}
  1 +package com.yoho.ufo.dal.model;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +
  5 +public class SizePoolImage {
  6 +
  7 + private Integer id;
  8 +
  9 + private Integer sizePoolId;
  10 +
  11 + private String imageUrl;
  12 +
  13 + private Integer imageWidth;
  14 +
  15 + private Integer imageHeight;
  16 +
  17 + public Integer getId() {
  18 + return id;
  19 + }
  20 +
  21 + public void setId(Integer id) {
  22 + this.id = id;
  23 + }
  24 +
  25 + public Integer getSizePoolId() {
  26 + return sizePoolId;
  27 + }
  28 +
  29 + public void setSizePoolId(Integer sizePoolId) {
  30 + this.sizePoolId = sizePoolId;
  31 + }
  32 +
  33 + public String getImageUrl() {
  34 + return imageUrl;
  35 + }
  36 +
  37 + public void setImageUrl(String imageUrl) {
  38 + this.imageUrl = imageUrl;
  39 + }
  40 +
  41 + public Integer getImageWidth() {
  42 + return imageWidth;
  43 + }
  44 +
  45 + public void setImageWidth(Integer imageWidth) {
  46 + this.imageWidth = imageWidth;
  47 + }
  48 +
  49 + public Integer getImageHeight() {
  50 + return imageHeight;
  51 + }
  52 +
  53 + public void setImageHeight(Integer imageHeight) {
  54 + this.imageHeight = imageHeight;
  55 + }
  56 +
  57 + @Override
  58 + public String toString() {
  59 + return JSONObject.toJSONString(this);
  60 + }
  61 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.ufo.dal.SizePoolImageMapper">
  4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.SizePoolImage">
  5 + <result column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="size_pool_id" property="sizePoolId" jdbcType="INTEGER" />
  7 + <result column="image_url" property="imageUrl" jdbcType="VARCHAR" />
  8 + <result column="image_width" property="imageWidth" jdbcType="INTEGER" />
  9 + <result column="image_height" property="imageHeight" jdbcType="INTEGER" />
  10 + </resultMap>
  11 +
  12 + <sql id="Base_Column_List">
  13 + id, size_pool_id, image_url, image_width, image_height
  14 + </sql>
  15 +
  16 + <insert id="batchInsert" parameterType="java.util.List" >
  17 + insert into size_pool_image (size_pool_id, image_url, image_width, image_height) values
  18 + <foreach collection="list" item="item" index="index" separator="," >
  19 + ( #{item.sizePoolId,jdbcType=INTEGER}, #{item.imageUrl,jdbcType=VARCHAR},
  20 + #{item.imageWidth,jdbcType=INTEGER}, #{item.imageHeight,jdbcType=INTEGER})
  21 + </foreach>
  22 + </insert>
  23 +
  24 + <delete id="deleteBySizePoolId" parameterType="java.lang.Integer">
  25 + delete from size_pool_image
  26 + where size_pool_id = #{sizePoolId,jdbcType=INTEGER}
  27 + </delete>
  28 +
  29 + <select id="queryBySizePoolId" resultMap="BaseResultMap">
  30 + select
  31 + <include refid="Base_Column_List" />
  32 + from size_pool_image
  33 + where size_pool_id= #{sizePoolId, jdbcType=INTEGER}
  34 + </select>
  35 +
  36 + <select id="queryBySizePoolIds" resultMap="BaseResultMap">
  37 + select
  38 + <include refid="Base_Column_List" />
  39 + from size_pool_image
  40 + where size_pool_id in
  41 + <foreach collection="sizePoolIdList" item="sizePoolId" open="(" close=")" separator=",">
  42 + #{sizePoolId}
  43 + </foreach>
  44 + </select>
  45 +</mapper>
@@ -27,7 +27,7 @@ public class SizePoolController { @@ -27,7 +27,7 @@ public class SizePoolController {
27 private ISizePoolService sizePoolService; 27 private ISizePoolService sizePoolService;
28 28
29 @RequestMapping(value = "/addSizePool") 29 @RequestMapping(value = "/addSizePool")
30 - public ApiResponse addSizePool(SizePoolRequest bo) { 30 + public ApiResponse addSizePool(@RequestBody SizePoolRequest bo) {
31 LOGGER.info(" Method addSizePool in."); 31 LOGGER.info(" Method addSizePool in.");
32 try { 32 try {
33 sizePoolService.addSizePool(bo); 33 sizePoolService.addSizePool(bo);
@@ -15,14 +15,17 @@ import org.springframework.stereotype.Service; @@ -15,14 +15,17 @@ import org.springframework.stereotype.Service;
15 import com.google.common.collect.Lists; 15 import com.google.common.collect.Lists;
16 import com.yoho.ufo.dal.BrandMapper; 16 import com.yoho.ufo.dal.BrandMapper;
17 import com.yoho.ufo.dal.SizePoolDetailMapper; 17 import com.yoho.ufo.dal.SizePoolDetailMapper;
  18 +import com.yoho.ufo.dal.SizePoolImageMapper;
18 import com.yoho.ufo.dal.SizePoolMapper; 19 import com.yoho.ufo.dal.SizePoolMapper;
19 import com.yoho.ufo.dal.model.SizePool; 20 import com.yoho.ufo.dal.model.SizePool;
20 import com.yoho.ufo.dal.model.SizePoolDetail; 21 import com.yoho.ufo.dal.model.SizePoolDetail;
  22 +import com.yoho.ufo.dal.model.SizePoolImage;
21 import com.yoho.ufo.exception.PlatformException; 23 import com.yoho.ufo.exception.PlatformException;
22 import com.yoho.ufo.model.brand.Brand; 24 import com.yoho.ufo.model.brand.Brand;
23 import com.yoho.ufo.service.ISizePoolService; 25 import com.yoho.ufo.service.ISizePoolService;
24 import com.yoho.ufo.service.model.PageResponseBO; 26 import com.yoho.ufo.service.model.PageResponseBO;
25 import com.yoho.ufo.util.DateUtil; 27 import com.yoho.ufo.util.DateUtil;
  28 +import com.yohobuy.ufo.model.request.size.SizePoolImageBo;
26 import com.yohobuy.ufo.model.request.size.SizePoolRequest; 29 import com.yohobuy.ufo.model.request.size.SizePoolRequest;
27 import com.yohobuy.ufo.model.request.size.SizePoolResp; 30 import com.yohobuy.ufo.model.request.size.SizePoolResp;
28 31
@@ -54,6 +57,9 @@ public class SizePoolService implements ISizePoolService{ @@ -54,6 +57,9 @@ public class SizePoolService implements ISizePoolService{
54 57
55 @Autowired 58 @Autowired
56 private BrandMapper brandMapper; 59 private BrandMapper brandMapper;
  60 +
  61 + @Autowired
  62 + private SizePoolImageMapper sizePoolImageMapper;
57 63
58 @Override 64 @Override
59 public int addSizePool(SizePoolRequest bo) throws PlatformException { 65 public int addSizePool(SizePoolRequest bo) throws PlatformException {
@@ -68,9 +74,9 @@ public class SizePoolService implements ISizePoolService{ @@ -68,9 +74,9 @@ public class SizePoolService implements ISizePoolService{
68 SizePool sizePool = new SizePool(); 74 SizePool sizePool = new SizePool();
69 sizePool.setStatus(STATUS_OPEN);//默认开启 75 sizePool.setStatus(STATUS_OPEN);//默认开启
70 sizePool.setRangeType(bo.getRangeType()); 76 sizePool.setRangeType(bo.getRangeType());
71 - sizePool.setImageUrl(bo.getImageUrl());  
72 - sizePool.setImageWidth(bo.getImageWidth());  
73 - sizePool.setImageHeight(bo.getImageHeight()); 77 + sizePool.setImageUrl(bo.getImageInfoList().get(0).getImageUrl());
  78 + sizePool.setImageWidth(bo.getImageInfoList().get(0).getImageWidth());
  79 + sizePool.setImageHeight(bo.getImageInfoList().get(0).getImageHeight());
74 sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds()); 80 sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds());
75 sizePool.setUpdateUid(new UserHelper().getUserId()); 81 sizePool.setUpdateUid(new UserHelper().getUserId());
76 82
@@ -79,10 +85,26 @@ public class SizePoolService implements ISizePoolService{ @@ -79,10 +85,26 @@ public class SizePoolService implements ISizePoolService{
79 return result; 85 return result;
80 } 86 }
81 87
  88 + saveSizePoolImage(bo.getImageInfoList(), sizePool.getId());
  89 +
82 return batchAddSizePoolDetail(sizePool.getId(), bo); 90 return batchAddSizePoolDetail(sizePool.getId(), bo);
83 91
84 } 92 }
85 93
  94 + private void saveSizePoolImage(List<SizePoolImageBo> imageInfoList, Integer sizePoolId) {
  95 + List<SizePoolImage> list = Lists.newArrayList();
  96 + for(SizePoolImageBo item : imageInfoList) {
  97 + SizePoolImage image = new SizePoolImage();
  98 + image.setId(sizePoolId);
  99 + image.setImageUrl(item.getImageUrl());
  100 + image.setImageWidth(item.getImageWidth());
  101 + image.setImageHeight(item.getImageHeight());
  102 + list.add(image);
  103 + }
  104 +
  105 + sizePoolImageMapper.batchInsert(list);
  106 + }
  107 +
86 @Override 108 @Override
87 public int updateSizePool(SizePoolRequest bo) throws PlatformException { 109 public int updateSizePool(SizePoolRequest bo) throws PlatformException {
88 Optional<SizePoolRequest> poolOptional = Optional.ofNullable(bo); 110 Optional<SizePoolRequest> poolOptional = Optional.ofNullable(bo);
@@ -95,9 +117,9 @@ public class SizePoolService implements ISizePoolService{ @@ -95,9 +117,9 @@ public class SizePoolService implements ISizePoolService{
95 117
96 SizePool sizePool = new SizePool(); 118 SizePool sizePool = new SizePool();
97 sizePool.setId(bo.getId()); 119 sizePool.setId(bo.getId());
98 - sizePool.setImageUrl(bo.getImageUrl());  
99 - sizePool.setImageWidth(bo.getImageWidth());  
100 - sizePool.setImageHeight(bo.getImageHeight()); 120 + sizePool.setImageUrl(bo.getImageInfoList().get(0).getImageUrl());
  121 + sizePool.setImageWidth(bo.getImageInfoList().get(0).getImageWidth());
  122 + sizePool.setImageHeight(bo.getImageInfoList().get(0).getImageHeight());
101 sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds()); 123 sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds());
102 sizePool.setUpdateUid(new UserHelper().getUserId()); 124 sizePool.setUpdateUid(new UserHelper().getUserId());
103 125
@@ -125,14 +147,28 @@ public class SizePoolService implements ISizePoolService{ @@ -125,14 +147,28 @@ public class SizePoolService implements ISizePoolService{
125 } 147 }
126 148
127 List<SizePoolDetail> list = sizePoolDetailMapper.queryBySizePoolId(sizePoolId); 149 List<SizePoolDetail> list = sizePoolDetailMapper.queryBySizePoolId(sizePoolId);
  150 + List<SizePoolImage> imageList = sizePoolImageMapper.queryBySizePoolId(sizePoolId);
128 SizePoolResp resp = new SizePoolResp(); 151 SizePoolResp resp = new SizePoolResp();
129 resp.setId(sizePoolId); 152 resp.setId(sizePoolId);
130 resp.setRangeType(sizePool.getRangeType()); 153 resp.setRangeType(sizePool.getRangeType());
131 - resp.setImageUrl(sizePool.getImageUrl()); 154 + buildImageResp(resp, imageList);
132 buildResp(resp, list); 155 buildResp(resp, list);
133 return resp; 156 return resp;
134 } 157 }
135 158
  159 + private void buildImageResp(SizePoolResp resp, List<SizePoolImage> imageList) {
  160 + List<SizePoolImageBo> list = Lists.newArrayList();
  161 + for(SizePoolImage item : imageList) {
  162 + SizePoolImageBo image = new SizePoolImageBo();
  163 + image.setImageUrl(item.getImageUrl());
  164 + image.setImageWidth(item.getImageWidth());
  165 + image.setImageHeight(item.getImageHeight());
  166 + list.add(image);
  167 + }
  168 +
  169 + resp.setImageInfoList(list);
  170 + }
  171 +
136 @Override 172 @Override
137 public int deleteSizePool(Integer sizePoolId) throws PlatformException{ 173 public int deleteSizePool(Integer sizePoolId) throws PlatformException{
138 if(null == sizePoolId){ 174 if(null == sizePoolId){
@@ -147,6 +183,7 @@ public class SizePoolService implements ISizePoolService{ @@ -147,6 +183,7 @@ public class SizePoolService implements ISizePoolService{
147 183
148 int result = sizePoolDetailMapper.deleteBySizePoolId(sizePoolId); 184 int result = sizePoolDetailMapper.deleteBySizePoolId(sizePoolId);
149 if(result > 0) { 185 if(result > 0) {
  186 + sizePoolImageMapper.deleteBySizePoolId(sizePoolId);
150 return sizePoolMapper.deleteByPrimaryKey(sizePoolId); 187 return sizePoolMapper.deleteByPrimaryKey(sizePoolId);
151 }else { 188 }else {
152 return 0; 189 return 0;
@@ -166,6 +203,8 @@ public class SizePoolService implements ISizePoolService{ @@ -166,6 +203,8 @@ public class SizePoolService implements ISizePoolService{
166 List<Integer> poolIdList = list.stream().map(SizePool::getId).collect(Collectors.toList()); 203 List<Integer> poolIdList = list.stream().map(SizePool::getId).collect(Collectors.toList());
167 List<SizePoolDetail> detailList = sizePoolDetailMapper.queryBySizePoolIds(poolIdList); 204 List<SizePoolDetail> detailList = sizePoolDetailMapper.queryBySizePoolIds(poolIdList);
168 Map<Integer, List<SizePoolDetail>> poolIdMap = detailList.stream().collect(Collectors.groupingBy(SizePoolDetail::getSizePoolId)); 205 Map<Integer, List<SizePoolDetail>> poolIdMap = detailList.stream().collect(Collectors.groupingBy(SizePoolDetail::getSizePoolId));
  206 + List<SizePoolImage> imageList = sizePoolImageMapper.queryBySizePoolIds(poolIdList);
  207 + Map<Integer, List<SizePoolImage>> poolIdImageMap = imageList.stream().collect(Collectors.groupingBy(SizePoolImage::getSizePoolId));
169 List<SizePoolResp> respList = Lists.newArrayList(); 208 List<SizePoolResp> respList = Lists.newArrayList();
170 for(SizePool pool : list) { 209 for(SizePool pool : list) {
171 SizePoolResp resp = new SizePoolResp(); 210 SizePoolResp resp = new SizePoolResp();
@@ -173,7 +212,7 @@ public class SizePoolService implements ISizePoolService{ @@ -173,7 +212,7 @@ public class SizePoolService implements ISizePoolService{
173 resp.setStatus(pool.getStatus()); 212 resp.setStatus(pool.getStatus());
174 resp.setStatusStr(getStatusStr(pool.getStatus())); 213 resp.setStatusStr(getStatusStr(pool.getStatus()));
175 resp.setRangeTypeStr(getRangeTypeStr(pool.getRangeType())); 214 resp.setRangeTypeStr(getRangeTypeStr(pool.getRangeType()));
176 - resp.setImageUrl(pool.getImageUrl()); 215 + buildImageResp(resp, poolIdImageMap.get(pool.getId()));
177 List<SizePoolDetail> itemList = poolIdMap.get(pool.getId()); 216 List<SizePoolDetail> itemList = poolIdMap.get(pool.getId());
178 if(CollectionUtils.isNotEmpty(itemList)) { 217 if(CollectionUtils.isNotEmpty(itemList)) {
179 if(pool.getRangeType().equals(RANGE_TYPE_BRAND)) { 218 if(pool.getRangeType().equals(RANGE_TYPE_BRAND)) {
@@ -18,6 +18,7 @@ datasources: @@ -18,6 +18,7 @@ datasources:
18 - com.yoho.ufo.dal.SizePoolDetailMapper 18 - com.yoho.ufo.dal.SizePoolDetailMapper
19 - com.yoho.product.model.ProductOperateRecord 19 - com.yoho.product.model.ProductOperateRecord
20 - com.yoho.product.dal.ProductChainMapper 20 - com.yoho.product.dal.ProductChainMapper
  21 + - com.yoho.ufo.dal.SizePoolImageMapper
21 22
22 ufo_order: 23 ufo_order:
23 servers: 24 servers:
@@ -19,6 +19,7 @@ datasources: @@ -19,6 +19,7 @@ datasources:
19 - com.yoho.ufo.dal.SizePoolDetailMapper 19 - com.yoho.ufo.dal.SizePoolDetailMapper
20 - com.yoho.product.model.ProductOperateRecord 20 - com.yoho.product.model.ProductOperateRecord
21 - com.yoho.product.dal.ProductChainMapper 21 - com.yoho.product.dal.ProductChainMapper
  22 + - com.yoho.ufo.dal.SizePoolImageMapper
22 23
23 ufo_order: 24 ufo_order:
24 servers: 25 servers: