Authored by caoyan

商品详情增加传图模块

package com.yoho.ufo.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.SizePoolDetail;
import com.yoho.ufo.dal.model.SizePoolImage;
/**
* Created by caoyan.
*/
public interface SizePoolImageMapper {
int batchInsert(@Param("list")List<SizePoolImage> list);
int deleteBySizePoolId(@Param("sizePoolId") Integer sizePoolId);
List<SizePoolImage> queryBySizePoolId(@Param("sizePoolId") Integer sizePoolId);
List<SizePoolImage> queryBySizePoolIds(@Param("sizePoolIdList") List<Integer> sizePoolIdList);
}
... ...
package com.yoho.ufo.dal.model;
import com.alibaba.fastjson.JSONObject;
public class SizePoolImage {
private Integer id;
private Integer sizePoolId;
private String imageUrl;
private Integer imageWidth;
private Integer imageHeight;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSizePoolId() {
return sizePoolId;
}
public void setSizePoolId(Integer sizePoolId) {
this.sizePoolId = sizePoolId;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public Integer getImageWidth() {
return imageWidth;
}
public void setImageWidth(Integer imageWidth) {
this.imageWidth = imageWidth;
}
public Integer getImageHeight() {
return imageHeight;
}
public void setImageHeight(Integer imageHeight) {
this.imageHeight = imageHeight;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.ufo.dal.SizePoolImageMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.SizePoolImage">
<result column="id" property="id" jdbcType="INTEGER" />
<result column="size_pool_id" property="sizePoolId" jdbcType="INTEGER" />
<result column="image_url" property="imageUrl" jdbcType="VARCHAR" />
<result column="image_width" property="imageWidth" jdbcType="INTEGER" />
<result column="image_height" property="imageHeight" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List">
id, size_pool_id, image_url, image_width, image_height
</sql>
<insert id="batchInsert" parameterType="java.util.List" >
insert into size_pool_image (size_pool_id, image_url, image_width, image_height) values
<foreach collection="list" item="item" index="index" separator="," >
( #{item.sizePoolId,jdbcType=INTEGER}, #{item.imageUrl,jdbcType=VARCHAR},
#{item.imageWidth,jdbcType=INTEGER}, #{item.imageHeight,jdbcType=INTEGER})
</foreach>
</insert>
<delete id="deleteBySizePoolId" parameterType="java.lang.Integer">
delete from size_pool_image
where size_pool_id = #{sizePoolId,jdbcType=INTEGER}
</delete>
<select id="queryBySizePoolId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from size_pool_image
where size_pool_id= #{sizePoolId, jdbcType=INTEGER}
</select>
<select id="queryBySizePoolIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from size_pool_image
where size_pool_id in
<foreach collection="sizePoolIdList" item="sizePoolId" open="(" close=")" separator=",">
#{sizePoolId}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -27,7 +27,7 @@ public class SizePoolController {
private ISizePoolService sizePoolService;
@RequestMapping(value = "/addSizePool")
public ApiResponse addSizePool(SizePoolRequest bo) {
public ApiResponse addSizePool(@RequestBody SizePoolRequest bo) {
LOGGER.info(" Method addSizePool in.");
try {
sizePoolService.addSizePool(bo);
... ...
... ... @@ -15,14 +15,17 @@ import org.springframework.stereotype.Service;
import com.google.common.collect.Lists;
import com.yoho.ufo.dal.BrandMapper;
import com.yoho.ufo.dal.SizePoolDetailMapper;
import com.yoho.ufo.dal.SizePoolImageMapper;
import com.yoho.ufo.dal.SizePoolMapper;
import com.yoho.ufo.dal.model.SizePool;
import com.yoho.ufo.dal.model.SizePoolDetail;
import com.yoho.ufo.dal.model.SizePoolImage;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.model.brand.Brand;
import com.yoho.ufo.service.ISizePoolService;
import com.yoho.ufo.service.model.PageResponseBO;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.request.size.SizePoolImageBo;
import com.yohobuy.ufo.model.request.size.SizePoolRequest;
import com.yohobuy.ufo.model.request.size.SizePoolResp;
... ... @@ -54,6 +57,9 @@ public class SizePoolService implements ISizePoolService{
@Autowired
private BrandMapper brandMapper;
@Autowired
private SizePoolImageMapper sizePoolImageMapper;
@Override
public int addSizePool(SizePoolRequest bo) throws PlatformException {
... ... @@ -68,9 +74,9 @@ public class SizePoolService implements ISizePoolService{
SizePool sizePool = new SizePool();
sizePool.setStatus(STATUS_OPEN);//默认开启
sizePool.setRangeType(bo.getRangeType());
sizePool.setImageUrl(bo.getImageUrl());
sizePool.setImageWidth(bo.getImageWidth());
sizePool.setImageHeight(bo.getImageHeight());
sizePool.setImageUrl(bo.getImageInfoList().get(0).getImageUrl());
sizePool.setImageWidth(bo.getImageInfoList().get(0).getImageWidth());
sizePool.setImageHeight(bo.getImageInfoList().get(0).getImageHeight());
sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds());
sizePool.setUpdateUid(new UserHelper().getUserId());
... ... @@ -79,10 +85,26 @@ public class SizePoolService implements ISizePoolService{
return result;
}
saveSizePoolImage(bo.getImageInfoList(), sizePool.getId());
return batchAddSizePoolDetail(sizePool.getId(), bo);
}
private void saveSizePoolImage(List<SizePoolImageBo> imageInfoList, Integer sizePoolId) {
List<SizePoolImage> list = Lists.newArrayList();
for(SizePoolImageBo item : imageInfoList) {
SizePoolImage image = new SizePoolImage();
image.setId(sizePoolId);
image.setImageUrl(item.getImageUrl());
image.setImageWidth(item.getImageWidth());
image.setImageHeight(item.getImageHeight());
list.add(image);
}
sizePoolImageMapper.batchInsert(list);
}
@Override
public int updateSizePool(SizePoolRequest bo) throws PlatformException {
Optional<SizePoolRequest> poolOptional = Optional.ofNullable(bo);
... ... @@ -95,9 +117,9 @@ public class SizePoolService implements ISizePoolService{
SizePool sizePool = new SizePool();
sizePool.setId(bo.getId());
sizePool.setImageUrl(bo.getImageUrl());
sizePool.setImageWidth(bo.getImageWidth());
sizePool.setImageHeight(bo.getImageHeight());
sizePool.setImageUrl(bo.getImageInfoList().get(0).getImageUrl());
sizePool.setImageWidth(bo.getImageInfoList().get(0).getImageWidth());
sizePool.setImageHeight(bo.getImageInfoList().get(0).getImageHeight());
sizePool.setUpdateTime(DateUtil.getCurrentTimeSeconds());
sizePool.setUpdateUid(new UserHelper().getUserId());
... ... @@ -125,14 +147,28 @@ public class SizePoolService implements ISizePoolService{
}
List<SizePoolDetail> list = sizePoolDetailMapper.queryBySizePoolId(sizePoolId);
List<SizePoolImage> imageList = sizePoolImageMapper.queryBySizePoolId(sizePoolId);
SizePoolResp resp = new SizePoolResp();
resp.setId(sizePoolId);
resp.setRangeType(sizePool.getRangeType());
resp.setImageUrl(sizePool.getImageUrl());
buildImageResp(resp, imageList);
buildResp(resp, list);
return resp;
}
private void buildImageResp(SizePoolResp resp, List<SizePoolImage> imageList) {
List<SizePoolImageBo> list = Lists.newArrayList();
for(SizePoolImage item : imageList) {
SizePoolImageBo image = new SizePoolImageBo();
image.setImageUrl(item.getImageUrl());
image.setImageWidth(item.getImageWidth());
image.setImageHeight(item.getImageHeight());
list.add(image);
}
resp.setImageInfoList(list);
}
@Override
public int deleteSizePool(Integer sizePoolId) throws PlatformException{
if(null == sizePoolId){
... ... @@ -147,6 +183,7 @@ public class SizePoolService implements ISizePoolService{
int result = sizePoolDetailMapper.deleteBySizePoolId(sizePoolId);
if(result > 0) {
sizePoolImageMapper.deleteBySizePoolId(sizePoolId);
return sizePoolMapper.deleteByPrimaryKey(sizePoolId);
}else {
return 0;
... ... @@ -166,6 +203,8 @@ public class SizePoolService implements ISizePoolService{
List<Integer> poolIdList = list.stream().map(SizePool::getId).collect(Collectors.toList());
List<SizePoolDetail> detailList = sizePoolDetailMapper.queryBySizePoolIds(poolIdList);
Map<Integer, List<SizePoolDetail>> poolIdMap = detailList.stream().collect(Collectors.groupingBy(SizePoolDetail::getSizePoolId));
List<SizePoolImage> imageList = sizePoolImageMapper.queryBySizePoolIds(poolIdList);
Map<Integer, List<SizePoolImage>> poolIdImageMap = imageList.stream().collect(Collectors.groupingBy(SizePoolImage::getSizePoolId));
List<SizePoolResp> respList = Lists.newArrayList();
for(SizePool pool : list) {
SizePoolResp resp = new SizePoolResp();
... ... @@ -173,7 +212,7 @@ public class SizePoolService implements ISizePoolService{
resp.setStatus(pool.getStatus());
resp.setStatusStr(getStatusStr(pool.getStatus()));
resp.setRangeTypeStr(getRangeTypeStr(pool.getRangeType()));
resp.setImageUrl(pool.getImageUrl());
buildImageResp(resp, poolIdImageMap.get(pool.getId()));
List<SizePoolDetail> itemList = poolIdMap.get(pool.getId());
if(CollectionUtils.isNotEmpty(itemList)) {
if(pool.getRangeType().equals(RANGE_TYPE_BRAND)) {
... ...
... ... @@ -18,6 +18,7 @@ datasources:
- com.yoho.ufo.dal.SizePoolDetailMapper
- com.yoho.product.model.ProductOperateRecord
- com.yoho.product.dal.ProductChainMapper
- com.yoho.ufo.dal.SizePoolImageMapper
ufo_order:
servers:
... ...
... ... @@ -19,6 +19,7 @@ datasources:
- com.yoho.ufo.dal.SizePoolDetailMapper
- com.yoho.product.model.ProductOperateRecord
- com.yoho.product.dal.ProductChainMapper
- com.yoho.ufo.dal.SizePoolImageMapper
ufo_order:
servers:
... ...