Authored by Lixiaodi

导入bo提交

@@ -122,6 +122,30 @@ public class BatchService { @@ -122,6 +122,30 @@ public class BatchService {
122 } 122 }
123 return retStr; 123 return retStr;
124 } 124 }
  125 +
  126 + public <T> List<T> parseData(MultipartFile file, String partOfFileName, Class<T> cls) throws Exception {
  127 + // 先保存到临时目录
  128 + File localFile = createLocalFile(partOfFileName);
  129 + try {
  130 + file.transferTo(localFile);
  131 + logger.info("batch import {} to local: {}", file.getOriginalFilename(), localFile.getAbsolutePath());
  132 +
  133 + // 将Xlsx数据解析为指定类
  134 + List<T> dataList = XlsxUtils.parse(localFile, cls);
  135 + return dataList;
  136 + } catch (POIXMLException e){
  137 + if (e.getMessage() != null && e.getMessage().contains("Package should contain a content type part [M1.13]")) {
  138 + throw new PlatformException("解析出错,请上传 Excel 2007 以上版本", e, 400);
  139 + }
  140 + logger.warn("batchImport find wrong." ,e);
  141 + // 处理完成后,删除本地临时文件
  142 + localFile.delete();
  143 + throw e;
  144 + } catch(Exception e) {
  145 + logger.warn("batchImport find wrong." ,e);
  146 + throw new PlatformException(e.getMessage(), e, 500);
  147 + }
  148 + }
125 149
126 /** 150 /**
127 * 将批量数据导出为Excel文件 151 * 将批量数据导出为Excel文件
  1 +package com.yoho.ufo.dal;
  2 +
  3 +import com.yoho.ufo.dal.model.ProductImportTranItem;
  4 +
  5 +public interface ProductImportTranItemMapper {
  6 + int deleteByPrimaryKey(Integer id);
  7 +
  8 + int insert(ProductImportTranItem record);
  9 +
  10 + int insertSelective(ProductImportTranItem record);
  11 +
  12 + ProductImportTranItem selectByPrimaryKey(Integer id);
  13 +
  14 + int updateByPrimaryKeySelective(ProductImportTranItem record);
  15 +
  16 + int updateByPrimaryKey(ProductImportTranItem record);
  17 +
  18 + ProductImportTranItem selectTranInfoByTranId(Integer tranId);
  19 +
  20 +}
  1 +package com.yoho.ufo.dal;
  2 +
  3 +import com.yoho.ufo.dal.model.ProductImportTran;
  4 +
  5 +public interface ProductImportTranMapper {
  6 + int deleteByPrimaryKey(Integer id);
  7 +
  8 + int insert(ProductImportTran record);
  9 +
  10 + int insertSelective(ProductImportTran record);
  11 +
  12 + ProductImportTran selectByPrimaryKey(Integer id);
  13 +
  14 + ProductImportTran selectUserProcessing(Integer editUid);
  15 +
  16 + int updateByPrimaryKeySelective(ProductImportTran record);
  17 +
  18 + int updateByPrimaryKey(ProductImportTran record);
  19 +}
@@ -67,6 +67,9 @@ public interface ProductMapper { @@ -67,6 +67,9 @@ public interface ProductMapper {
67 67
68 // 根据Id列表查询商品列表 68 // 根据Id列表查询商品列表
69 List<Product> selectProductListByIds(@Param("productIdList")List<Integer> productIdList); 69 List<Product> selectProductListByIds(@Param("productIdList")List<Integer> productIdList);
  70 +
  71 + List<Product> selectProductListByProductCodes(@Param("productCodeList")List<String> productCodeList);
  72 +
70 73
71 74
72 int updateStatusByPrimaryKey(@Param("id") Integer id, 75 int updateStatusByPrimaryKey(@Param("id") Integer id,
@@ -32,4 +32,6 @@ public interface StorageMapper { @@ -32,4 +32,6 @@ public interface StorageMapper {
32 @Param("suggestHighPrice") BigDecimal suggestHighPrice); 32 @Param("suggestHighPrice") BigDecimal suggestHighPrice);
33 33
34 int updateBatchSuggestPrice(@Param("storageList") List<Storage> storageList); 34 int updateBatchSuggestPrice(@Param("storageList") List<Storage> storageList);
  35 +
  36 + List<Storage> selectByCondition(@Param("conditionSql") String conditionSql);
35 } 37 }
@@ -104,4 +104,6 @@ public interface UfoSizeMapper { @@ -104,4 +104,6 @@ public interface UfoSizeMapper {
104 * @return 104 * @return
105 */ 105 */
106 List<Size> selectBySizeName(@Param("sizeName") String sizeName); 106 List<Size> selectBySizeName(@Param("sizeName") String sizeName);
  107 +
  108 + List<Size> selectBySizeNameList(@Param("sizeNameList")List<String> sizeNameList);
107 } 109 }
  1 +package com.yoho.ufo.dal.model;
  2 +
  3 +public class ProductImportTran {
  4 + private Integer id;
  5 +
  6 + private Integer editUid;
  7 +
  8 + private Integer uid;
  9 +
  10 + private Integer status;
  11 +
  12 + private Integer createTime;
  13 +
  14 + private Integer updateTime;
  15 +
  16 + public Integer getId() {
  17 + return id;
  18 + }
  19 +
  20 + public void setId(Integer id) {
  21 + this.id = id;
  22 + }
  23 +
  24 + public Integer getEditUid() {
  25 + return editUid;
  26 + }
  27 +
  28 + public void setEditUid(Integer editUid) {
  29 + this.editUid = editUid;
  30 + }
  31 +
  32 + public Integer getUid() {
  33 + return uid;
  34 + }
  35 +
  36 + public void setUid(Integer uid) {
  37 + this.uid = uid;
  38 + }
  39 +
  40 + public Integer getStatus() {
  41 + return status;
  42 + }
  43 +
  44 + public void setStatus(Integer status) {
  45 + this.status = status;
  46 + }
  47 +
  48 + public Integer getCreateTime() {
  49 + return createTime;
  50 + }
  51 +
  52 + public void setCreateTime(Integer createTime) {
  53 + this.createTime = createTime;
  54 + }
  55 +
  56 + public Integer getUpdateTime() {
  57 + return updateTime;
  58 + }
  59 +
  60 + public void setUpdateTime(Integer updateTime) {
  61 + this.updateTime = updateTime;
  62 + }
  63 +}
  1 +package com.yoho.ufo.dal.model;
  2 +
  3 +import java.math.BigDecimal;
  4 +
  5 +import com.yoho.ufo.annotation.BatchImportField;
  6 +
  7 +import lombok.Data;
  8 +
  9 +@Data
  10 +public class ProductImportTranItem {
  11 +
  12 + private Integer id;
  13 +
  14 + private Integer tranId;
  15 +
  16 + @BatchImportField(index = 0)
  17 + private Integer uid;
  18 +
  19 + @BatchImportField(index = 1)
  20 + private String productCode;
  21 +
  22 + @BatchImportField(index = 2)
  23 + private String sizeName;
  24 +
  25 + @BatchImportField(index = 3)
  26 + private BigDecimal price;
  27 +
  28 + @BatchImportField(index = 4)
  29 + private Integer num;
  30 +
  31 + private Integer storageId;
  32 +
  33 + private Integer successdNum;
  34 +
  35 + private Integer status;
  36 +
  37 + private Integer createTime;
  38 +
  39 + private Integer updateTime;
  40 +
  41 + private Integer productId;
  42 + private Integer sizeId;
  43 +
  44 + private Integer itemCount;
  45 + private Integer maxStatus;
  46 +
  47 +}
  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.ProductImportTranItemMapper" >
  4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.ProductImportTranItem" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="tran_id" property="tranId" jdbcType="INTEGER" />
  7 + <result column="uid" property="uid" jdbcType="INTEGER" />
  8 + <result column="product_code" property="productCode" jdbcType="VARCHAR" />
  9 + <result column="size_name" property="sizeName" jdbcType="VARCHAR" />
  10 + <result column="price" property="price" jdbcType="DECIMAL" />
  11 + <result column="num" property="num" jdbcType="INTEGER" />
  12 + <result column="storage_id" property="storageId" jdbcType="INTEGER" />
  13 + <result column="successd_num" property="successdNum" jdbcType="INTEGER" />
  14 + <result column="status" property="status" jdbcType="TINYINT" />
  15 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  16 + <result column="update_time" property="updateTime" jdbcType="INTEGER" />
  17 + </resultMap>
  18 + <sql id="Base_Column_List" >
  19 + id, tran_id, uid, product_code, size_name, price, num, storage_id, successd_num,
  20 + status, create_time, update_time
  21 + </sql>
  22 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  23 + select
  24 + <include refid="Base_Column_List" />
  25 + from product_import_tran_item
  26 + where id = #{id,jdbcType=INTEGER}
  27 + </select>
  28 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  29 + delete from product_import_tran_item
  30 + where id = #{id,jdbcType=INTEGER}
  31 + </delete>
  32 + <insert id="insert" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
  33 + insert into product_import_tran_item (id, tran_id, uid,
  34 + product_code, size_name, price,
  35 + num, storage_id, successd_num,
  36 + status, create_time, update_time
  37 + )
  38 + values (#{id,jdbcType=INTEGER}, #{tranId,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
  39 + #{productCode,jdbcType=VARCHAR}, #{sizeName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
  40 + #{num,jdbcType=INTEGER}, #{storageId,jdbcType=INTEGER}, #{successdNum,jdbcType=INTEGER},
  41 + #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}
  42 + )
  43 + </insert>
  44 + <insert id="insertSelective" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
  45 + insert into product_import_tran_item
  46 + <trim prefix="(" suffix=")" suffixOverrides="," >
  47 + <if test="id != null" >
  48 + id,
  49 + </if>
  50 + <if test="tranId != null" >
  51 + tran_id,
  52 + </if>
  53 + <if test="uid != null" >
  54 + uid,
  55 + </if>
  56 + <if test="productCode != null" >
  57 + product_code,
  58 + </if>
  59 + <if test="sizeName != null" >
  60 + size_name,
  61 + </if>
  62 + <if test="price != null" >
  63 + price,
  64 + </if>
  65 + <if test="num != null" >
  66 + num,
  67 + </if>
  68 + <if test="storageId != null" >
  69 + storage_id,
  70 + </if>
  71 + <if test="successdNum != null" >
  72 + successd_num,
  73 + </if>
  74 + <if test="status != null" >
  75 + status,
  76 + </if>
  77 + <if test="createTime != null" >
  78 + create_time,
  79 + </if>
  80 + <if test="updateTime != null" >
  81 + update_time,
  82 + </if>
  83 + </trim>
  84 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  85 + <if test="id != null" >
  86 + #{id,jdbcType=INTEGER},
  87 + </if>
  88 + <if test="tranId != null" >
  89 + #{tranId,jdbcType=INTEGER},
  90 + </if>
  91 + <if test="uid != null" >
  92 + #{uid,jdbcType=INTEGER},
  93 + </if>
  94 + <if test="productCode != null" >
  95 + #{productCode,jdbcType=VARCHAR},
  96 + </if>
  97 + <if test="sizeName != null" >
  98 + #{sizeName,jdbcType=VARCHAR},
  99 + </if>
  100 + <if test="price != null" >
  101 + #{price,jdbcType=DECIMAL},
  102 + </if>
  103 + <if test="num != null" >
  104 + #{num,jdbcType=INTEGER},
  105 + </if>
  106 + <if test="storageId != null" >
  107 + #{storageId,jdbcType=INTEGER},
  108 + </if>
  109 + <if test="successdNum != null" >
  110 + #{successdNum,jdbcType=INTEGER},
  111 + </if>
  112 + <if test="status != null" >
  113 + #{status,jdbcType=TINYINT},
  114 + </if>
  115 + <if test="createTime != null" >
  116 + #{createTime,jdbcType=INTEGER},
  117 + </if>
  118 + <if test="updateTime != null" >
  119 + #{updateTime,jdbcType=INTEGER},
  120 + </if>
  121 + </trim>
  122 + </insert>
  123 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
  124 + update product_import_tran_item
  125 + <set >
  126 + <if test="tranId != null" >
  127 + tran_id = #{tranId,jdbcType=INTEGER},
  128 + </if>
  129 + <if test="uid != null" >
  130 + uid = #{uid,jdbcType=INTEGER},
  131 + </if>
  132 + <if test="productCode != null" >
  133 + product_code = #{productCode,jdbcType=VARCHAR},
  134 + </if>
  135 + <if test="sizeName != null" >
  136 + size_name = #{sizeName,jdbcType=VARCHAR},
  137 + </if>
  138 + <if test="price != null" >
  139 + price = #{price,jdbcType=DECIMAL},
  140 + </if>
  141 + <if test="num != null" >
  142 + num = #{num,jdbcType=INTEGER},
  143 + </if>
  144 + <if test="storageId != null" >
  145 + storage_id = #{storageId,jdbcType=INTEGER},
  146 + </if>
  147 + <if test="successdNum != null" >
  148 + successd_num = #{successdNum,jdbcType=INTEGER},
  149 + </if>
  150 + <if test="status != null" >
  151 + status = #{status,jdbcType=TINYINT},
  152 + </if>
  153 + <if test="createTime != null" >
  154 + create_time = #{createTime,jdbcType=INTEGER},
  155 + </if>
  156 + <if test="updateTime != null" >
  157 + update_time = #{updateTime,jdbcType=INTEGER},
  158 + </if>
  159 + </set>
  160 + where id = #{id,jdbcType=INTEGER}
  161 + </update>
  162 + <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
  163 + update product_import_tran_item
  164 + set tran_id = #{tranId,jdbcType=INTEGER},
  165 + uid = #{uid,jdbcType=INTEGER},
  166 + product_code = #{productCode,jdbcType=VARCHAR},
  167 + size_name = #{sizeName,jdbcType=VARCHAR},
  168 + price = #{price,jdbcType=DECIMAL},
  169 + num = #{num,jdbcType=INTEGER},
  170 + storage_id = #{storageId,jdbcType=INTEGER},
  171 + successd_num = #{successdNum,jdbcType=INTEGER},
  172 + status = #{status,jdbcType=TINYINT},
  173 + create_time = #{createTime,jdbcType=INTEGER},
  174 + update_time = #{updateTime,jdbcType=INTEGER}
  175 + where id = #{id,jdbcType=INTEGER}
  176 + </update>
  177 + <select id="selectTranInfoByTranId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  178 + select count(*) as itemCount, sum(num) as num, sum(successd_num) as successdNum, min(status) as status,max(status) as maxStatus
  179 + from product_import_tran_item
  180 + where tran_id = #{tranId,jdbcType=INTEGER}
  181 + </select>
  182 +
  183 +</mapper>
  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.ProductImportTranMapper" >
  4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.ProductImportTran" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="edit_uid" property="editUid" jdbcType="INTEGER" />
  7 + <result column="uid" property="uid" jdbcType="INTEGER" />
  8 + <result column="status" property="status" jdbcType="TINYINT" />
  9 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  10 + <result column="update_time" property="updateTime" jdbcType="INTEGER" />
  11 + </resultMap>
  12 + <sql id="Base_Column_List" >
  13 + id, edit_uid, uid, status, create_time, update_time
  14 + </sql>
  15 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  16 + select
  17 + <include refid="Base_Column_List" />
  18 + from product_import_tran
  19 + where id = #{id,jdbcType=INTEGER}
  20 + </select>
  21 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  22 + delete from product_import_tran
  23 + where id = #{id,jdbcType=INTEGER}
  24 + </delete>
  25 + <insert id="insert" parameterType="com.yoho.ufo.dal.model.ProductImportTran" useGeneratedKeys="true" keyProperty="id" >
  26 + insert into product_import_tran (id, edit_uid, uid,
  27 + status, create_time, update_time
  28 + )
  29 + values (#{id,jdbcType=INTEGER}, #{editUid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
  30 + #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}
  31 + )
  32 + </insert>
  33 + <insert id="insertSelective" parameterType="com.yoho.ufo.dal.model.ProductImportTran" useGeneratedKeys="true" keyProperty="id" >
  34 + insert into product_import_tran
  35 + <trim prefix="(" suffix=")" suffixOverrides="," >
  36 + <if test="id != null" >
  37 + id,
  38 + </if>
  39 + <if test="editUid != null" >
  40 + edit_uid,
  41 + </if>
  42 + <if test="uid != null" >
  43 + uid,
  44 + </if>
  45 + <if test="status != null" >
  46 + status,
  47 + </if>
  48 + <if test="createTime != null" >
  49 + create_time,
  50 + </if>
  51 + <if test="updateTime != null" >
  52 + update_time,
  53 + </if>
  54 + </trim>
  55 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  56 + <if test="id != null" >
  57 + #{id,jdbcType=INTEGER},
  58 + </if>
  59 + <if test="editUid != null" >
  60 + #{editUid,jdbcType=INTEGER},
  61 + </if>
  62 + <if test="uid != null" >
  63 + #{uid,jdbcType=INTEGER},
  64 + </if>
  65 + <if test="status != null" >
  66 + #{status,jdbcType=TINYINT},
  67 + </if>
  68 + <if test="createTime != null" >
  69 + #{createTime,jdbcType=INTEGER},
  70 + </if>
  71 + <if test="updateTime != null" >
  72 + #{updateTime,jdbcType=INTEGER},
  73 + </if>
  74 + </trim>
  75 + </insert>
  76 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.ProductImportTran" >
  77 + update product_import_tran
  78 + <set >
  79 + <if test="editUid != null" >
  80 + edit_uid = #{editUid,jdbcType=INTEGER},
  81 + </if>
  82 + <if test="uid != null" >
  83 + uid = #{uid,jdbcType=INTEGER},
  84 + </if>
  85 + <if test="status != null" >
  86 + status = #{status,jdbcType=TINYINT},
  87 + </if>
  88 + <if test="createTime != null" >
  89 + create_time = #{createTime,jdbcType=INTEGER},
  90 + </if>
  91 + <if test="updateTime != null" >
  92 + update_time = #{updateTime,jdbcType=INTEGER},
  93 + </if>
  94 + </set>
  95 + where id = #{id,jdbcType=INTEGER}
  96 + </update>
  97 + <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.ProductImportTran" >
  98 + update product_import_tran
  99 + set edit_uid = #{editUid,jdbcType=INTEGER},
  100 + uid = #{uid,jdbcType=INTEGER},
  101 + status = #{status,jdbcType=TINYINT},
  102 + create_time = #{createTime,jdbcType=INTEGER},
  103 + update_time = #{updateTime,jdbcType=INTEGER}
  104 + where id = #{id,jdbcType=INTEGER}
  105 + </update>
  106 + <select id="selectUserProcessing" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  107 + select
  108 + <include refid="Base_Column_List" />
  109 + from product_import_tran
  110 + where edit_uid = #{editUid,jdbcType=INTEGER} and status=0 order by id desc limit 1
  111 + </select>
  112 +
  113 +</mapper>
@@ -234,4 +234,13 @@ @@ -234,4 +234,13 @@
234 <select id="selectByProductName" resultMap="BaseResultMap"> 234 <select id="selectByProductName" resultMap="BaseResultMap">
235 select id, product_name from product where product_name like "%"#{productName}"%" 235 select id, product_name from product where product_name like "%"#{productName}"%"
236 </select> 236 </select>
  237 + <select id="selectProductListByProductCodes" resultMap="BaseResultMap">
  238 + select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
  239 + gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
  240 + shelve_status, storage, key_words, del_status, age_level
  241 + from product where shelve_status = 1 and product_code in
  242 + <foreach item="item" index="index" collection="productCodeList" open="(" separator="," close=")">
  243 + #{item}
  244 + </foreach>
  245 + </select>
237 </mapper> 246 </mapper>
@@ -100,4 +100,8 @@ @@ -100,4 +100,8 @@
100 </foreach> 100 </foreach>
101 101
102 </update> 102 </update>
  103 + <select id="selectByCondition" resultMap="BaseResultMap">
  104 + select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price
  105 + from storage where ${conditionSql}
  106 + </select>
103 </mapper> 107 </mapper>
@@ -195,4 +195,13 @@ @@ -195,4 +195,13 @@
195 <select id="selectBySizeName" resultMap="sizeMap"> 195 <select id="selectBySizeName" resultMap="sizeMap">
196 select id, size_name from size where size_name = #{sizeName} 196 select id, size_name from size where size_name = #{sizeName}
197 </select> 197 </select>
  198 +
  199 + <select id="selectBySizeNameList" resultMap="sizeMap">
  200 + select id, size_name
  201 + from size where size_name in
  202 + <foreach item="item" index="index" collection="sizeNameList" open="(" separator="," close=")">
  203 + #{item}
  204 + </foreach>
  205 + </select>
  206 +
198 </mapper> 207 </mapper>
@@ -7,12 +7,19 @@ import org.slf4j.Logger; @@ -7,12 +7,19 @@ import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 7 import org.slf4j.LoggerFactory;
8 import org.springframework.web.bind.annotation.RequestBody; 8 import org.springframework.web.bind.annotation.RequestBody;
9 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RequestMethod;
  11 +import org.springframework.web.bind.annotation.RequestParam;
10 import org.springframework.web.bind.annotation.RestController; 12 import org.springframework.web.bind.annotation.RestController;
  13 +import org.springframework.web.multipart.MultipartFile;
11 14
  15 +import com.yoho.ufo.dal.model.ProductImportTranItem;
  16 +import com.yoho.ufo.exception.PlatformException;
12 import com.yoho.ufo.service.IProductService; 17 import com.yoho.ufo.service.IProductService;
  18 +import com.yoho.ufo.service.impl.UserHelper;
13 import com.yohobuy.ufo.model.common.ApiResponse; 19 import com.yohobuy.ufo.model.common.ApiResponse;
14 import com.yohobuy.ufo.model.common.PageResponseBO; 20 import com.yohobuy.ufo.model.common.PageResponseBO;
15 import com.yohobuy.ufo.model.request.product.ProductRequestBo; 21 import com.yohobuy.ufo.model.request.product.ProductRequestBo;
  22 +import com.yohobuy.ufo.model.request.productpool.ProductPoolRequestBo;
16 import com.yohobuy.ufo.model.resp.product.ProductEditResponceBo; 23 import com.yohobuy.ufo.model.resp.product.ProductEditResponceBo;
17 import com.yohobuy.ufo.model.resp.product.ProductResponceBo; 24 import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
18 25
@@ -76,4 +83,36 @@ public class ProductController { @@ -76,4 +83,36 @@ public class ProductController {
76 LOGGER.info("product.addOrUpdate param = {}", bo); 83 LOGGER.info("product.addOrUpdate param = {}", bo);
77 return productService.importProduct(bo); 84 return productService.importProduct(bo);
78 } 85 }
  86 +
  87 + @RequestMapping(value = "/batchImportFromXls", method = RequestMethod.POST)
  88 + public ApiResponse<Void> batchImportFromXls(@RequestParam("file") MultipartFile file) {
  89 + Integer uid = new UserHelper().getUserId();
  90 + if (uid == null || uid < 1) {
  91 + return new ApiResponse<>(400, "请先登录!", null);
  92 + }
  93 + LOGGER.info("batchImportFromXls uid={},file = {}", uid, file);
  94 + if (file == null || file.getSize() == 0) {
  95 + return new ApiResponse<>(201, "请选择需要上传的问题件!", null);
  96 + }
  97 + try {
  98 + productService.batchImportFromXls(file, uid);
  99 + } catch (PlatformException px) {
  100 + LOGGER.warn("batchImportFromXls PlatformException. errorMsg = {}", px.getMessage());
  101 + return new ApiResponse<>(px.getCode(), px.getMessage(), null);
  102 + } catch (Exception e) {
  103 + LOGGER.error("batchImportFromXls error.", e);
  104 + return new ApiResponse<>(201, "系统异常", null);
  105 + }
  106 + return new ApiResponse<>();
  107 + }
  108 +
  109 + @RequestMapping(value = "/getBatchImportResult")
  110 + public ApiResponse<ProductImportTranItem> batchImportFromXls(@RequestParam("tranId") Integer tranId) {
  111 + try {
  112 + return productService.getBatchImportResult(tranId);
  113 + } catch (PlatformException e) {
  114 + return new ApiResponse<>(e.getCode(), e.getMessage(), null);
  115 + }
  116 + }
  117 +
79 } 118 }
  1 +package com.yoho.ufo.convert;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.yohobuy.ufo.model.order.vo.AddressInfo;
  5 +
  6 +import java.util.Objects;
  7 +
  8 +/**
  9 + * Created by chenchao on 2018/9/21.
  10 + */
  11 +public class AddressInfoConvertor {
  12 +
  13 + /**
  14 + * is_update = N 四级地址
  15 + is_update = Y 三级地址
  16 +
  17 + * {
  18 + "area": "内蒙古自治区 呼和浩特市 回民区 新华西路办事处",
  19 + "address": "ghjkkl",
  20 + "tag_code": "",
  21 + "consignee": "uuuii",
  22 + "is_support": "Y",
  23 + "area_code": "150103001",
  24 + "mobile": "13512503760",
  25 + "address_id": "2395852",
  26 + "is_default": "Y",
  27 + "is_delivery": "Y",
  28 + "zip_code": "",
  29 + "uid": "500030962",
  30 + "is_cash_delivery": "Y",
  31 + "phone": "",
  32 + "is_update": "N",
  33 + "email": ""
  34 + }
  35 + * @param resp
  36 + * @return
  37 + */
  38 + public static AddressInfo userAddressRsp2AddressInfo(JSONObject resp){
  39 + if (Objects.isNull(resp)){
  40 + return null;
  41 + }
  42 + AddressInfo addressInfo = new AddressInfo();
  43 + addressInfo.setAddress_id(resp.getInteger("address_id"));
  44 + addressInfo.setAreaCode(resp.getString("area_code"));
  45 + addressInfo.setArea(resp.getString("area"));
  46 + addressInfo.setAddress(resp.getString("address"));
  47 + addressInfo.setConsignee(resp.getString("consignee"));
  48 + addressInfo.setPhone(resp.getString("phone"));
  49 + addressInfo.setMobile(resp.getString("mobile"));
  50 + addressInfo.setZipCode(resp.getString("zip_code"));
  51 + addressInfo.setIsUpdate(resp.getString("is_update"));
  52 + return addressInfo;
  53 + }
  54 +}
1 package com.yoho.ufo.service; 1 package com.yoho.ufo.service;
2 2
  3 +import org.springframework.web.multipart.MultipartFile;
  4 +
3 import com.yoho.core.dal.datasource.annotation.Database; 5 import com.yoho.core.dal.datasource.annotation.Database;
  6 +import com.yoho.ufo.dal.model.ProductImportTranItem;
  7 +import com.yoho.ufo.exception.PlatformException;
4 import com.yohobuy.ufo.model.common.ApiResponse; 8 import com.yohobuy.ufo.model.common.ApiResponse;
5 import com.yohobuy.ufo.model.common.PageResponseBO; 9 import com.yohobuy.ufo.model.common.PageResponseBO;
6 import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo; 10 import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo;
@@ -26,4 +30,8 @@ public interface IProductService { @@ -26,4 +30,8 @@ public interface IProductService {
26 ApiResponse<Void> changeProductStatus(ProductRequestBo bo); 30 ApiResponse<Void> changeProductStatus(ProductRequestBo bo);
27 31
28 ApiResponse<Void> importProduct(ProductRequestBatchBo bo); 32 ApiResponse<Void> importProduct(ProductRequestBatchBo bo);
  33 +
  34 + void batchImportFromXls(MultipartFile file, Integer editUid) throws Exception;
  35 +
  36 + ApiResponse<ProductImportTranItem> getBatchImportResult(Integer tranId) throws PlatformException;
29 } 37 }
  1 +package com.yoho.ufo.service;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.google.common.collect.Maps;
  6 +import com.yoho.core.rest.client.ServiceCaller;
  7 +import com.yoho.error.ServiceError;
  8 +import com.yoho.error.exception.ServiceException;
  9 +import com.yoho.service.model.request.UserAddressReqBO;
  10 +import com.yoho.ufo.convert.AddressInfoConvertor;
  11 +import com.yohobuy.ufo.model.common.ApiResponse;
  12 +import com.yohobuy.ufo.model.order.vo.AddressInfo;
  13 +import org.apache.commons.lang3.StringUtils;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.beans.factory.annotation.Value;
  18 +import org.springframework.stereotype.Service;
  19 +
  20 +import java.util.Map;
  21 +import java.util.Objects;
  22 +import java.util.concurrent.TimeUnit;
  23 +
  24 +/**
  25 + * Created by chenchao on 2018/9/18.
  26 + */
  27 +@Service
  28 +public class UserProxyService {
  29 +
  30 +
  31 + private Logger logger = LoggerFactory.getLogger(getClass());
  32 +
  33 + @Autowired
  34 + ServiceCaller serviceCaller;
  35 +
  36 + @Value("${erp-gateway.url}")
  37 + private String erpGatewayUrl;
  38 +
  39 + @Value("${uic.url:http://uic.yohoops.org/uic}")
  40 + private String uicUrl;
  41 +
  42 + /**
  43 + * 获取用户信息
  44 + * @param uid
  45 + * @param addressId
  46 + * @return
  47 + */
  48 + public AddressInfo getHiddenAddressInfo(int uid) {
  49 + String url = erpGatewayUrl + "/erp/passport/gethiddenAddress";
  50 + return getAddressInfoWithUrl(url,uid);
  51 + }
  52 +
  53 + /**
  54 + * 获取用户信息
  55 + * 地址不隐藏星号
  56 + * @param uid
  57 + * @param addressId
  58 + * @return
  59 + */
  60 + public AddressInfo getAddressInfoNotHidden(int uid) {
  61 + String url = erpGatewayUrl + "/erp/passport/getInnerAddress";
  62 + return getAddressInfoWithUrl(url,uid);
  63 + }
  64 +
  65 + private AddressInfo getAddressInfoWithUrl(String url ,int uid) {
  66 + // 收货地址信息, 入口参数:uid, address_id
  67 + UserAddressReqBO userAddressReqBO = new UserAddressReqBO();
  68 + userAddressReqBO.setUid(uid);
  69 +
  70 + //超时,使用默认地址,后续需要手动补充地址
  71 + ApiResponse defaultResponse = new ApiResponse();
  72 +
  73 +
  74 + Map<String,Object> params = Maps.newHashMap();
  75 + params.put("uid", uid);
  76 + params.put("debug", "XYZ");
  77 +
  78 + AddressInfo addressInfo ;
  79 + ApiResponse userAddressBO ;
  80 + try {
  81 + userAddressBO = serviceCaller.get("users.getAddress", url, params,
  82 + ApiResponse.class, defaultResponse).get(500, TimeUnit.MILLISECONDS);
  83 +
  84 + }catch (Exception ex){
  85 + logger.warn("in getAddressInfo fail, uid {}", uid, ex);
  86 + throw new ServiceException(ServiceError.ADDRESS_NULL);
  87 + }
  88 + JSONArray addressArray ;
  89 + if (userAddressBO == null || (addressArray = (JSONArray)userAddressBO.getData()) == null){
  90 + logger.warn("in getAddressInfo fail, uid {}", uid);
  91 + throw new ServiceException(ServiceError.ADDRESS_NULL);
  92 + }
  93 + JSONObject addressJsonObj = (JSONObject) addressArray.parallelStream().filter(addressJson -> {
  94 + Integer address_id = ((JSONObject)addressJson).getInteger("address_id");
  95 + String isDefault = ((JSONObject)addressJson).getString("is_default");
  96 + return Objects.nonNull(address_id) && StringUtils.equals(isDefault, "Y");
  97 + }).findFirst().orElse(null);
  98 + if (addressJsonObj == null){
  99 + logger.warn("in getAddressInfo fail, uid {}, addressArray {}", uid, addressArray);
  100 + throw new ServiceException(ServiceError.ADDRESS_NULL);
  101 + }
  102 + addressInfo = AddressInfoConvertor.userAddressRsp2AddressInfo(addressJsonObj);
  103 + return addressInfo;
  104 + }
  105 +
  106 + /**
  107 + * http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
  108 + * //profile/getProfile?uid=600032978
  109 + * @param uid
  110 + * @return
  111 + */
  112 + public static final String PRFILE_API = "/profile/getProfile";
  113 + public String getMobile(int uid){
  114 + String url = uicUrl + PRFILE_API;
  115 + Map<String,Object> params = Maps.newHashMap();
  116 + params.put("uid", uid);
  117 +
  118 + ApiResponse userInfo ;
  119 + try {
  120 + userInfo = serviceCaller.get("users.getAddress", url, params,
  121 + ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
  122 +
  123 + }catch (Exception ex){
  124 + logger.warn("in getMobile fail, uid {}", uid, ex);
  125 + throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
  126 + }
  127 +
  128 + JSONObject jsonObject;
  129 + String mobile;
  130 + if (userInfo == null || (jsonObject = (JSONObject)userInfo.getData()) == null
  131 + || StringUtils.isBlank(mobile = jsonObject.getString("mobile_phone"))){
  132 + logger.warn("in getMobile fail, uid {}, userInfo {}", uid, userInfo);
  133 + throw new ServiceException(ServiceError.PROFILE_IS_NULL);
  134 + }
  135 + return mobile;
  136 + }
  137 +
  138 +}
@@ -4,10 +4,12 @@ import java.math.BigDecimal; @@ -4,10 +4,12 @@ import java.math.BigDecimal;
4 import java.text.ParseException; 4 import java.text.ParseException;
5 import java.text.SimpleDateFormat; 5 import java.text.SimpleDateFormat;
6 import java.util.*; 6 import java.util.*;
  7 +import java.util.concurrent.TimeUnit;
7 8
8 import com.alibaba.fastjson.JSONObject; 9 import com.alibaba.fastjson.JSONObject;
9 import com.yoho.core.dal.datasource.annotation.Database; 10 import com.yoho.core.dal.datasource.annotation.Database;
10 import com.yoho.core.rest.client.ServiceCaller; 11 import com.yoho.core.rest.client.ServiceCaller;
  12 +import com.yoho.service.model.order.request.OrderRequest;
11 import com.yoho.ufo.dal.*; 13 import com.yoho.ufo.dal.*;
12 import com.yoho.ufo.event.model.StorageNumEvent; 14 import com.yoho.ufo.event.model.StorageNumEvent;
13 import com.yoho.ufo.model.brand.BrandSeries; 15 import com.yoho.ufo.model.brand.BrandSeries;
@@ -15,6 +17,9 @@ import com.yoho.ufo.model.commoditybasicrole.color.ProductColor; @@ -15,6 +17,9 @@ import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
15 import com.yoho.ufo.util.ImagesConstant; 17 import com.yoho.ufo.util.ImagesConstant;
16 import com.yoho.ufo.util.ImagesHelper; 18 import com.yoho.ufo.util.ImagesHelper;
17 import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum; 19 import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
  20 +import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
  21 +import com.yohobuy.ufo.model.order.req.SellerReq;
  22 +import com.yohobuy.ufo.model.order.vo.AddressInfo;
18 import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo; 23 import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo;
19 import org.apache.commons.collections.CollectionUtils; 24 import org.apache.commons.collections.CollectionUtils;
20 import org.apache.commons.lang3.StringUtils; 25 import org.apache.commons.lang3.StringUtils;
@@ -27,18 +32,23 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -27,18 +32,23 @@ import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.context.ApplicationContext; 32 import org.springframework.context.ApplicationContext;
28 import org.springframework.context.ApplicationContextAware; 33 import org.springframework.context.ApplicationContextAware;
29 import org.springframework.stereotype.Service; 34 import org.springframework.stereotype.Service;
  35 +import org.springframework.web.multipart.MultipartFile;
30 36
31 import com.alibaba.fastjson.JSON; 37 import com.alibaba.fastjson.JSON;
32 import com.yoho.ufo.dal.model.Goods; 38 import com.yoho.ufo.dal.model.Goods;
33 import com.yoho.ufo.dal.model.GoodsImages; 39 import com.yoho.ufo.dal.model.GoodsImages;
34 import com.yoho.ufo.dal.model.Product; 40 import com.yoho.ufo.dal.model.Product;
  41 +import com.yoho.ufo.dal.model.ProductImportTran;
  42 +import com.yoho.ufo.dal.model.ProductImportTranItem;
35 import com.yoho.ufo.dal.model.Storage; 43 import com.yoho.ufo.dal.model.Storage;
36 import com.yoho.ufo.dal.model.StoragePrice; 44 import com.yoho.ufo.dal.model.StoragePrice;
37 import com.yoho.ufo.exception.CommonException; 45 import com.yoho.ufo.exception.CommonException;
  46 +import com.yoho.ufo.exception.PlatformException;
38 import com.yoho.ufo.model.brand.Brand; 47 import com.yoho.ufo.model.brand.Brand;
39 import com.yoho.ufo.model.commoditybasicrole.category.ProductSort; 48 import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
40 import com.yoho.ufo.model.commoditybasicrole.size.Size; 49 import com.yoho.ufo.model.commoditybasicrole.size.Size;
41 import com.yoho.ufo.service.IProductService; 50 import com.yoho.ufo.service.IProductService;
  51 +import com.yoho.ufo.service.UserProxyService;
42 import com.yoho.ufo.util.CollectionUtil; 52 import com.yoho.ufo.util.CollectionUtil;
43 import com.yohobuy.ufo.model.common.ApiResponse; 53 import com.yohobuy.ufo.model.common.ApiResponse;
44 import com.yohobuy.ufo.model.common.PageResponseBO; 54 import com.yohobuy.ufo.model.common.PageResponseBO;
@@ -69,6 +79,10 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw @@ -69,6 +79,10 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
69 private StoragePriceMapper storagePriceMapper; 79 private StoragePriceMapper storagePriceMapper;
70 @Autowired 80 @Autowired
71 private UfoSizeMapper sizeMapper; 81 private UfoSizeMapper sizeMapper;
  82 + @Autowired
  83 + private ProductImportTranMapper productImportTranMapper;
  84 + @Autowired
  85 + private ProductImportTranItemMapper productImportTranItemMapper;
72 /*@Autowired 86 /*@Autowired
73 private InboxService inboxService;*/ 87 private InboxService inboxService;*/
74 88
@@ -80,6 +94,13 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw @@ -80,6 +94,13 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
80 private UfoBrandSeriesMapper brandSeriesMapper; 94 private UfoBrandSeriesMapper brandSeriesMapper;
81 @Autowired 95 @Autowired
82 private ProductIntroService productIntroService; 96 private ProductIntroService productIntroService;
  97 +
  98 + @Autowired
  99 + private UserProxyService userProxyService;
  100 +
  101 + @Autowired
  102 + private BatchService batchService;
  103 +
83 @Override 104 @Override
84 public ApiResponse<Void> addOrUpdate(ProductRequestBo bo, boolean isCheckUrl) { 105 public ApiResponse<Void> addOrUpdate(ProductRequestBo bo, boolean isCheckUrl) {
85 checkProductInfo(bo, isCheckUrl); 106 checkProductInfo(bo, isCheckUrl);
@@ -712,4 +733,220 @@ public static void main(String[] args) { @@ -712,4 +733,220 @@ public static void main(String[] args) {
712 733
713 return new ApiResponse<>(200, "操作成功!"); 734 return new ApiResponse<>(200, "操作成功!");
714 } 735 }
  736 +
  737 + @Override
  738 + public ApiResponse<ProductImportTranItem> getBatchImportResult(Integer tranId) throws PlatformException {
  739 + ProductImportTran exist = productImportTranMapper.selectByPrimaryKey(tranId);
  740 + if (exist == null) {
  741 + throw new PlatformException("任务不存在!", 400);
  742 + }
  743 + ProductImportTranItem item = productImportTranItemMapper.selectTranInfoByTranId(tranId);
  744 + if (item == null || item.getItemCount() == null || item.getItemCount() == 0) {
  745 + item = new ProductImportTranItem();
  746 + item.setStatus(0);
  747 + } else if (item.getStatus() != null && item.getStatus() > 0) {
  748 + ProductImportTran update = new ProductImportTran();
  749 + update.setId(tranId);
  750 + update.setStatus(item.getMaxStatus());
  751 + productImportTranMapper.updateByPrimaryKeySelective(update);
  752 + }
  753 + return new ApiResponse<>(200, "查询成功", item);
  754 + }
  755 +
  756 + @Override
  757 + public void batchImportFromXls(MultipartFile file, Integer editUid) throws Exception {
  758 + LOGGER.info("用户{}开始导入商品数据!", editUid);
  759 + // 查看是否有正在执行
  760 + int now = (int) (System.currentTimeMillis() / 1000);
  761 + ProductImportTran exist;
  762 + if ((exist = productImportTranMapper.selectUserProcessing(editUid)) != null
  763 + && (now - exist.getCreateTime()) < 300) {
  764 + LOGGER.warn("用户{}正在导入中,结束", editUid);
  765 + throw new PlatformException("有导入操作正在进行中!", 400);
  766 + }
  767 +
  768 + List<ProductImportTranItem> items = batchService.parseData(file, "batchImportStoragePrice", ProductImportTranItem.class);
  769 + if (CollectionUtils.isEmpty(items)) {
  770 + LOGGER.info("用户{}导入的excel为空,结束", editUid);
  771 + throw new PlatformException("导入的excel数据为空!", 400);
  772 + }
  773 + LOGGER.info("Excel解析成功一共{}行", items.size());
  774 +
  775 + Integer count = 0, uid = null;
  776 + Set<String> uniqSet = new HashSet<>();
  777 + for (int i = 0; i < items.size(); i++) {
  778 + ProductImportTranItem item = items.get(i);
  779 + if (StringUtils.isAnyBlank(item.getProductCode(), item.getSizeName())) {
  780 + LOGGER.info("第{}行数据:商品编码或尺码为空!", i + 1);
  781 + throw new PlatformException("第" + (i + 1) + "行数据:商品编码或尺码为空!", 400);
  782 + }
  783 + if (item.getUid() == null || item.getUid() < 1) {
  784 + LOGGER.info("第{}行数据:uid不合法!", i + 1);
  785 + throw new PlatformException("第" + (i + 1) + "行数据:uid:" + item.getUid() + "不合法!", 400);
  786 + }
  787 + if (uid == null) {
  788 + uid = item.getUid();
  789 + } else if (item.getUid() != uid) {
  790 + LOGGER.info("excel中存在多个uid!");
  791 + throw new PlatformException("excel中存在多个uid!", 400);
  792 + }
  793 + if (item.getNum() == null || item.getNum() < 1) {
  794 + LOGGER.info("第{}行数据:数量不合法!", i + 1);
  795 + throw new PlatformException("第" + (i + 1) + "行数据:数量" + item.getNum() + "不合法!", 400);
  796 + }
  797 + count += item.getNum();
  798 + if (count > 200) {
  799 + LOGGER.info("总数量大于200!");
  800 + throw new PlatformException("总数量不能大于200!", 400);
  801 + }
  802 + BigDecimal price = item.getPrice();
  803 + if (price == null || price.compareTo(BigDecimal.ZERO) <= 0
  804 + || price.divideAndRemainder(BigDecimal.TEN)[1].compareTo(new BigDecimal("9")) != 0) {
  805 + LOGGER.info("第{}行数据:金额不合法!", i + 1);
  806 + throw new PlatformException("第" + (i + 1) + "行数据:金额" + price + "不合法!", 400);
  807 + }
  808 +
  809 + String key = item.getProductCode() + " *SPLIT* " + item.getSizeName();
  810 + if (uniqSet.contains(key)) {
  811 + LOGGER.info("第{}行数据:货号{}+尺码{}有重复行!", i + 1, item.getProductCode(), item.getSizeName());
  812 + throw new PlatformException(
  813 + "第" + (i + 1) + "行数据:货号+尺码有重复行:" + item.getProductCode() + "," + item.getSizeName(), 400);
  814 + }
  815 + uniqSet.add(key);
  816 + }
  817 +
  818 + List<String> productCodeList = CollectionUtil.distinct(items, ProductImportTranItem::getProductCode);
  819 + List<Product> productList = productMapper.selectProductListByProductCodes(productCodeList);
  820 + Map<String, Product> codeProductMap = CollectionUtil.extractMap(productList, Product::getProductCode);
  821 + for (int i = 0; i < items.size(); i++) {
  822 + ProductImportTranItem item = items.get(i);
  823 + Product p = codeProductMap.get(item.getProductCode());
  824 + if (p == null) {
  825 + LOGGER.info("第{}行数据:商品编码{}不存在!", i + 1, item.getProductCode());
  826 + throw new PlatformException("第" + (i + 1) + "行数据:商品编码" + item.getProductCode() + "不存在!", 400);
  827 + }
  828 + if (item.getPrice().compareTo(p.getMaxPrice()) > 0 || item.getPrice().compareTo(p.getMinPrice()) < 0) {
  829 + LOGGER.info("第{}行数据:价格{}超出规定范围!", i + 1, item.getPrice());
  830 + throw new PlatformException("第" + (i + 1) + "行数据:价格" + item.getPrice() + "超出规定范围!", 400);
  831 + }
  832 + item.setProductId(p.getId());
  833 + }
  834 +
  835 + List<String> sizeNameList = CollectionUtil.distinct(items, ProductImportTranItem::getSizeName);
  836 + List<Size> sizeList = sizeMapper.selectBySizeNameList(sizeNameList);
  837 + Map<String, Size> sizeNameMap = CollectionUtil.extractMap(sizeList, Size::getSizeName);
  838 + for (int i = 0; i < items.size(); i++) {
  839 + ProductImportTranItem item = items.get(i);
  840 + Size s = sizeNameMap.get(item.getSizeName());
  841 + if (s == null) {
  842 + LOGGER.info("第{}行数据:尺码{}不存在!", i + 1, item.getSizeName());
  843 + throw new PlatformException("第" + (i + 1) + "行数据:尺码" + item.getSizeName() + "不存在!", 400);
  844 + }
  845 + item.setSizeId(s.getId());
  846 + }
  847 +
  848 + StringBuilder sql = new StringBuilder();
  849 + Map<Integer, Set<Integer>> productIdSizeMap = new HashMap<>();
  850 + for (int i = 0; i < items.size(); i++) {
  851 + ProductImportTranItem item = items.get(i);
  852 + Size s = sizeNameMap.get(item.getSizeName());
  853 + Set<Integer> sizeIds = productIdSizeMap.get(item.getProductId());
  854 + if (sizeIds == null) {
  855 + sizeIds = new HashSet<>();
  856 + productIdSizeMap.put(item.getProductId(), sizeIds);
  857 + }
  858 + sizeIds.add(s.getId());
  859 + }
  860 + productIdSizeMap.forEach((k, v) -> {
  861 + sql.append("or (product_id=" + k + " and size_id in(" + StringUtils.join(v, ",") + ")) ");
  862 + });
  863 + List<Storage> storageList = storageMapper.selectByCondition(sql.substring(3));
  864 +
  865 + Map<String, Storage> storageMap = CollectionUtil.extractMap(storageList,
  866 + s -> s.getProductId() + "_" + s.getSizeId());
  867 + for (int i = 0; i < items.size(); i++) {
  868 + ProductImportTranItem item = items.get(i);
  869 + Storage s = storageMap.get(item.getProductId() + "_" + item.getSizeId());
  870 + if (s == null) {
  871 + LOGGER.info("第{}行数据:商品{}无该尺码{}!", i + 1, item.getProductCode(), item.getSizeName());
  872 + throw new PlatformException(
  873 + "第" + (i + 1) + "行数据:该商品" + item.getProductCode() + "下的这个尺码" + item.getSizeName() + "不存在!",
  874 + 400);
  875 + }
  876 + item.setStorageId(s.getId());
  877 + }
  878 +
  879 + // 检查用户身份
  880 + try {
  881 + LOGGER.info("get user account info");
  882 + SellerReq req = new SellerReq();
  883 + req.setUid(uid);
  884 + Boolean userResp = serviceCaller.call("ufo-gateway.isNormalSuper", req, Boolean.class, 10);
  885 + LOGGER.info("get user account info result is {}", userResp);
  886 +
  887 + if (userResp == null || !userResp) {
  888 + throw new PlatformException("uid:" + uid + "账号不是超级卖家或者余额不足!", 400);
  889 + }
  890 + } catch (Exception e) {
  891 + LOGGER.error("get user account info error", e);
  892 + throw new PlatformException("uid:" + uid + "账号信息获取出错!", 400);
  893 + }
  894 +
  895 + // 获取地址信息
  896 + AddressInfo address = null;
  897 + try {
  898 + LOGGER.info("get user address info");
  899 + address = userProxyService.getAddressInfoNotHidden(uid);
  900 + if (address == null) {
  901 + throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
  902 + }
  903 + } catch (Exception e) {
  904 + LOGGER.error("get user address info error", e);
  905 + throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
  906 + }
  907 +
  908 + AddressInfo addressHidden = null;
  909 + try {
  910 + LOGGER.info("get user hidden address info");
  911 + addressHidden = userProxyService.getHiddenAddressInfo(uid);
  912 + if (addressHidden == null) {
  913 + throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
  914 + }
  915 + } catch (Exception e) {
  916 + LOGGER.error("get user hidden address info error", e);
  917 + throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
  918 + }
  919 +
  920 + LOGGER.info("增加事务记录");
  921 + ProductImportTran tran = new ProductImportTran();
  922 + tran.setStatus(0);
  923 + tran.setEditUid(editUid);
  924 + tran.setUid(uid);
  925 + tran.setCreateTime(now);
  926 + productImportTranMapper.insert(tran);
  927 + LOGGER.info("增加事务记录成功rec={}", tran);
  928 +
  929 + int batchNum = 40;
  930 + List<List<ProductImportTranItem>> batchLists = CollectionUtil.split(items, batchNum);
  931 + LOGGER.info("一共{}行,每批次{}行,一共{}批", items.size(), batchNum, batchLists.size());
  932 + for (int i = 0; i < batchLists.size(); i++) {
  933 + LOGGER.info("一共{}行,每批次{}行,一共{}批,处理批次{}...", items.size(), batchNum, batchLists.size(), i + 1);
  934 + List<ProductImportTranItem> batch = batchLists.get(i);
  935 + BatchImportPrdReq<ProductImportTranItem> batchReq = new BatchImportPrdReq<>();
  936 + batchReq.setHiddenBackAddress(addressHidden);
  937 + batchReq.setNoHiddenBackAddress(address);
  938 + batchReq.setProductList(batch);
  939 + batchReq.setTaskId(tran.getId());
  940 +
  941 + try {
  942 + LOGGER.info("batch import send taskId={}, batchId={}", tran.getId(), (i + 1));
  943 + serviceCaller.call("ufo-gateway.batchImportPrds", batchReq, Void.class, 10);
  944 + LOGGER.info("batch import send success taskId={}, batchId={}", tran.getId(), (i + 1));
  945 + } catch (Exception e) {
  946 + LOGGER.info("batch import send failed taskId={}, batchId={}", tran.getId(), (i + 1));
  947 + }
  948 + }
  949 + LOGGER.info("batch import over taskId={}", tran.getId());
  950 + }
  951 +
715 } 952 }
@@ -49,3 +49,7 @@ shops.gateway.url=http://instore-test1.dev.yohocorp.com @@ -49,3 +49,7 @@ shops.gateway.url=http://instore-test1.dev.yohocorp.com
49 offline.store.seller=70,50000638 49 offline.store.seller=70,50000638
50 50
51 ip.port.search.server=192.168.102.216:8080 51 ip.port.search.server=192.168.102.216:8080
  52 +
  53 +erp-gateway.url=http://java-yoho-erp-gateway.test3.ingress.dev.yohocorp.com/erp-gateway
  54 +uic.url=http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
  55 +
@@ -53,4 +53,7 @@ service.call.connectReqTimeout=15000 @@ -53,4 +53,7 @@ service.call.connectReqTimeout=15000
53 service.call.socketTimeout=15000 53 service.call.socketTimeout=15000
54 service.call.connectTimeout=15000 54 service.call.connectTimeout=15000
55 55
  56 +erp-gateway.url=${erp-gateway.url}
  57 +uic.url=${uic.url}
  58 +
56 59