Authored by Lixiaodi

导入bo提交

... ... @@ -122,6 +122,30 @@ public class BatchService {
}
return retStr;
}
public <T> List<T> parseData(MultipartFile file, String partOfFileName, Class<T> cls) throws Exception {
// 先保存到临时目录
File localFile = createLocalFile(partOfFileName);
try {
file.transferTo(localFile);
logger.info("batch import {} to local: {}", file.getOriginalFilename(), localFile.getAbsolutePath());
// 将Xlsx数据解析为指定类
List<T> dataList = XlsxUtils.parse(localFile, cls);
return dataList;
} catch (POIXMLException e){
if (e.getMessage() != null && e.getMessage().contains("Package should contain a content type part [M1.13]")) {
throw new PlatformException("解析出错,请上传 Excel 2007 以上版本", e, 400);
}
logger.warn("batchImport find wrong." ,e);
// 处理完成后,删除本地临时文件
localFile.delete();
throw e;
} catch(Exception e) {
logger.warn("batchImport find wrong." ,e);
throw new PlatformException(e.getMessage(), e, 500);
}
}
/**
* 将批量数据导出为Excel文件
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.ProductImportTranItem;
public interface ProductImportTranItemMapper {
int deleteByPrimaryKey(Integer id);
int insert(ProductImportTranItem record);
int insertSelective(ProductImportTranItem record);
ProductImportTranItem selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ProductImportTranItem record);
int updateByPrimaryKey(ProductImportTranItem record);
ProductImportTranItem selectTranInfoByTranId(Integer tranId);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.ProductImportTran;
public interface ProductImportTranMapper {
int deleteByPrimaryKey(Integer id);
int insert(ProductImportTran record);
int insertSelective(ProductImportTran record);
ProductImportTran selectByPrimaryKey(Integer id);
ProductImportTran selectUserProcessing(Integer editUid);
int updateByPrimaryKeySelective(ProductImportTran record);
int updateByPrimaryKey(ProductImportTran record);
}
\ No newline at end of file
... ...
... ... @@ -67,6 +67,9 @@ public interface ProductMapper {
// 根据Id列表查询商品列表
List<Product> selectProductListByIds(@Param("productIdList")List<Integer> productIdList);
List<Product> selectProductListByProductCodes(@Param("productCodeList")List<String> productCodeList);
int updateStatusByPrimaryKey(@Param("id") Integer id,
... ...
... ... @@ -32,4 +32,6 @@ public interface StorageMapper {
@Param("suggestHighPrice") BigDecimal suggestHighPrice);
int updateBatchSuggestPrice(@Param("storageList") List<Storage> storageList);
List<Storage> selectByCondition(@Param("conditionSql") String conditionSql);
}
\ No newline at end of file
... ...
... ... @@ -104,4 +104,6 @@ public interface UfoSizeMapper {
* @return
*/
List<Size> selectBySizeName(@Param("sizeName") String sizeName);
List<Size> selectBySizeNameList(@Param("sizeNameList")List<String> sizeNameList);
}
... ...
package com.yoho.ufo.dal.model;
public class ProductImportTran {
private Integer id;
private Integer editUid;
private Integer uid;
private Integer status;
private Integer createTime;
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getEditUid() {
return editUid;
}
public void setEditUid(Integer editUid) {
this.editUid = editUid;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
import java.math.BigDecimal;
import com.yoho.ufo.annotation.BatchImportField;
import lombok.Data;
@Data
public class ProductImportTranItem {
private Integer id;
private Integer tranId;
@BatchImportField(index = 0)
private Integer uid;
@BatchImportField(index = 1)
private String productCode;
@BatchImportField(index = 2)
private String sizeName;
@BatchImportField(index = 3)
private BigDecimal price;
@BatchImportField(index = 4)
private Integer num;
private Integer storageId;
private Integer successdNum;
private Integer status;
private Integer createTime;
private Integer updateTime;
private Integer productId;
private Integer sizeId;
private Integer itemCount;
private Integer maxStatus;
}
\ 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.ProductImportTranItemMapper" >
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.ProductImportTranItem" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="tran_id" property="tranId" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="product_code" property="productCode" jdbcType="VARCHAR" />
<result column="size_name" property="sizeName" jdbcType="VARCHAR" />
<result column="price" property="price" jdbcType="DECIMAL" />
<result column="num" property="num" jdbcType="INTEGER" />
<result column="storage_id" property="storageId" jdbcType="INTEGER" />
<result column="successd_num" property="successdNum" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, tran_id, uid, product_code, size_name, price, num, storage_id, successd_num,
status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from product_import_tran_item
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from product_import_tran_item
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
insert into product_import_tran_item (id, tran_id, uid,
product_code, size_name, price,
num, storage_id, successd_num,
status, create_time, update_time
)
values (#{id,jdbcType=INTEGER}, #{tranId,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{productCode,jdbcType=VARCHAR}, #{sizeName,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
#{num,jdbcType=INTEGER}, #{storageId,jdbcType=INTEGER}, #{successdNum,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
insert into product_import_tran_item
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="tranId != null" >
tran_id,
</if>
<if test="uid != null" >
uid,
</if>
<if test="productCode != null" >
product_code,
</if>
<if test="sizeName != null" >
size_name,
</if>
<if test="price != null" >
price,
</if>
<if test="num != null" >
num,
</if>
<if test="storageId != null" >
storage_id,
</if>
<if test="successdNum != null" >
successd_num,
</if>
<if test="status != null" >
status,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="tranId != null" >
#{tranId,jdbcType=INTEGER},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
</if>
<if test="productCode != null" >
#{productCode,jdbcType=VARCHAR},
</if>
<if test="sizeName != null" >
#{sizeName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
#{price,jdbcType=DECIMAL},
</if>
<if test="num != null" >
#{num,jdbcType=INTEGER},
</if>
<if test="storageId != null" >
#{storageId,jdbcType=INTEGER},
</if>
<if test="successdNum != null" >
#{successdNum,jdbcType=INTEGER},
</if>
<if test="status != null" >
#{status,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
update product_import_tran_item
<set >
<if test="tranId != null" >
tran_id = #{tranId,jdbcType=INTEGER},
</if>
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="productCode != null" >
product_code = #{productCode,jdbcType=VARCHAR},
</if>
<if test="sizeName != null" >
size_name = #{sizeName,jdbcType=VARCHAR},
</if>
<if test="price != null" >
price = #{price,jdbcType=DECIMAL},
</if>
<if test="num != null" >
num = #{num,jdbcType=INTEGER},
</if>
<if test="storageId != null" >
storage_id = #{storageId,jdbcType=INTEGER},
</if>
<if test="successdNum != null" >
successd_num = #{successdNum,jdbcType=INTEGER},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.ProductImportTranItem" >
update product_import_tran_item
set tran_id = #{tranId,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
product_code = #{productCode,jdbcType=VARCHAR},
size_name = #{sizeName,jdbcType=VARCHAR},
price = #{price,jdbcType=DECIMAL},
num = #{num,jdbcType=INTEGER},
storage_id = #{storageId,jdbcType=INTEGER},
successd_num = #{successdNum,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectTranInfoByTranId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select count(*) as itemCount, sum(num) as num, sum(successd_num) as successdNum, min(status) as status,max(status) as maxStatus
from product_import_tran_item
where tran_id = #{tranId,jdbcType=INTEGER}
</select>
</mapper>
\ 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.ProductImportTranMapper" >
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.ProductImportTran" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="edit_uid" property="editUid" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, edit_uid, uid, status, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from product_import_tran
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from product_import_tran
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.ProductImportTran" useGeneratedKeys="true" keyProperty="id" >
insert into product_import_tran (id, edit_uid, uid,
status, create_time, update_time
)
values (#{id,jdbcType=INTEGER}, #{editUid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.yoho.ufo.dal.model.ProductImportTran" useGeneratedKeys="true" keyProperty="id" >
insert into product_import_tran
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="editUid != null" >
edit_uid,
</if>
<if test="uid != null" >
uid,
</if>
<if test="status != null" >
status,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="editUid != null" >
#{editUid,jdbcType=INTEGER},
</if>
<if test="uid != null" >
#{uid,jdbcType=INTEGER},
</if>
<if test="status != null" >
#{status,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.ProductImportTran" >
update product_import_tran
<set >
<if test="editUid != null" >
edit_uid = #{editUid,jdbcType=INTEGER},
</if>
<if test="uid != null" >
uid = #{uid,jdbcType=INTEGER},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.ProductImportTran" >
update product_import_tran
set edit_uid = #{editUid,jdbcType=INTEGER},
uid = #{uid,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectUserProcessing" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from product_import_tran
where edit_uid = #{editUid,jdbcType=INTEGER} and status=0 order by id desc limit 1
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -234,4 +234,13 @@
<select id="selectByProductName" resultMap="BaseResultMap">
select id, product_name from product where product_name like "%"#{productName}"%"
</select>
<select id="selectProductListByProductCodes" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status, age_level
from product where shelve_status = 1 and product_code in
<foreach item="item" index="index" collection="productCodeList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -100,4 +100,8 @@
</foreach>
</update>
<select id="selectByCondition" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price
from storage where ${conditionSql}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -195,4 +195,13 @@
<select id="selectBySizeName" resultMap="sizeMap">
select id, size_name from size where size_name = #{sizeName}
</select>
<select id="selectBySizeNameList" resultMap="sizeMap">
select id, size_name
from size where size_name in
<foreach item="item" index="index" collection="sizeNameList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -7,12 +7,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.yoho.ufo.dal.model.ProductImportTranItem;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.IProductService;
import com.yoho.ufo.service.impl.UserHelper;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.request.productpool.ProductPoolRequestBo;
import com.yohobuy.ufo.model.resp.product.ProductEditResponceBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
... ... @@ -76,4 +83,36 @@ public class ProductController {
LOGGER.info("product.addOrUpdate param = {}", bo);
return productService.importProduct(bo);
}
@RequestMapping(value = "/batchImportFromXls", method = RequestMethod.POST)
public ApiResponse<Void> batchImportFromXls(@RequestParam("file") MultipartFile file) {
Integer uid = new UserHelper().getUserId();
if (uid == null || uid < 1) {
return new ApiResponse<>(400, "请先登录!", null);
}
LOGGER.info("batchImportFromXls uid={},file = {}", uid, file);
if (file == null || file.getSize() == 0) {
return new ApiResponse<>(201, "请选择需要上传的问题件!", null);
}
try {
productService.batchImportFromXls(file, uid);
} catch (PlatformException px) {
LOGGER.warn("batchImportFromXls PlatformException. errorMsg = {}", px.getMessage());
return new ApiResponse<>(px.getCode(), px.getMessage(), null);
} catch (Exception e) {
LOGGER.error("batchImportFromXls error.", e);
return new ApiResponse<>(201, "系统异常", null);
}
return new ApiResponse<>();
}
@RequestMapping(value = "/getBatchImportResult")
public ApiResponse<ProductImportTranItem> batchImportFromXls(@RequestParam("tranId") Integer tranId) {
try {
return productService.getBatchImportResult(tranId);
} catch (PlatformException e) {
return new ApiResponse<>(e.getCode(), e.getMessage(), null);
}
}
}
... ...
package com.yoho.ufo.convert;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import java.util.Objects;
/**
* Created by chenchao on 2018/9/21.
*/
public class AddressInfoConvertor {
/**
* is_update = N 四级地址
is_update = Y 三级地址
* {
"area": "内蒙古自治区 呼和浩特市 回民区 新华西路办事处",
"address": "ghjkkl",
"tag_code": "",
"consignee": "uuuii",
"is_support": "Y",
"area_code": "150103001",
"mobile": "13512503760",
"address_id": "2395852",
"is_default": "Y",
"is_delivery": "Y",
"zip_code": "",
"uid": "500030962",
"is_cash_delivery": "Y",
"phone": "",
"is_update": "N",
"email": ""
}
* @param resp
* @return
*/
public static AddressInfo userAddressRsp2AddressInfo(JSONObject resp){
if (Objects.isNull(resp)){
return null;
}
AddressInfo addressInfo = new AddressInfo();
addressInfo.setAddress_id(resp.getInteger("address_id"));
addressInfo.setAreaCode(resp.getString("area_code"));
addressInfo.setArea(resp.getString("area"));
addressInfo.setAddress(resp.getString("address"));
addressInfo.setConsignee(resp.getString("consignee"));
addressInfo.setPhone(resp.getString("phone"));
addressInfo.setMobile(resp.getString("mobile"));
addressInfo.setZipCode(resp.getString("zip_code"));
addressInfo.setIsUpdate(resp.getString("is_update"));
return addressInfo;
}
}
... ...
package com.yoho.ufo.service;
import org.springframework.web.multipart.MultipartFile;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.ufo.dal.model.ProductImportTranItem;
import com.yoho.ufo.exception.PlatformException;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo;
... ... @@ -26,4 +30,8 @@ public interface IProductService {
ApiResponse<Void> changeProductStatus(ProductRequestBo bo);
ApiResponse<Void> importProduct(ProductRequestBatchBo bo);
void batchImportFromXls(MultipartFile file, Integer editUid) throws Exception;
ApiResponse<ProductImportTranItem> getBatchImportResult(Integer tranId) throws PlatformException;
}
... ...
package com.yoho.ufo.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.request.UserAddressReqBO;
import com.yoho.ufo.convert.AddressInfoConvertor;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* Created by chenchao on 2018/9/18.
*/
@Service
public class UserProxyService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
ServiceCaller serviceCaller;
@Value("${erp-gateway.url}")
private String erpGatewayUrl;
@Value("${uic.url:http://uic.yohoops.org/uic}")
private String uicUrl;
/**
* 获取用户信息
* @param uid
* @param addressId
* @return
*/
public AddressInfo getHiddenAddressInfo(int uid) {
String url = erpGatewayUrl + "/erp/passport/gethiddenAddress";
return getAddressInfoWithUrl(url,uid);
}
/**
* 获取用户信息
* 地址不隐藏星号
* @param uid
* @param addressId
* @return
*/
public AddressInfo getAddressInfoNotHidden(int uid) {
String url = erpGatewayUrl + "/erp/passport/getInnerAddress";
return getAddressInfoWithUrl(url,uid);
}
private AddressInfo getAddressInfoWithUrl(String url ,int uid) {
// 收货地址信息, 入口参数:uid, address_id
UserAddressReqBO userAddressReqBO = new UserAddressReqBO();
userAddressReqBO.setUid(uid);
//超时,使用默认地址,后续需要手动补充地址
ApiResponse defaultResponse = new ApiResponse();
Map<String,Object> params = Maps.newHashMap();
params.put("uid", uid);
params.put("debug", "XYZ");
AddressInfo addressInfo ;
ApiResponse userAddressBO ;
try {
userAddressBO = serviceCaller.get("users.getAddress", url, params,
ApiResponse.class, defaultResponse).get(500, TimeUnit.MILLISECONDS);
}catch (Exception ex){
logger.warn("in getAddressInfo fail, uid {}", uid, ex);
throw new ServiceException(ServiceError.ADDRESS_NULL);
}
JSONArray addressArray ;
if (userAddressBO == null || (addressArray = (JSONArray)userAddressBO.getData()) == null){
logger.warn("in getAddressInfo fail, uid {}", uid);
throw new ServiceException(ServiceError.ADDRESS_NULL);
}
JSONObject addressJsonObj = (JSONObject) addressArray.parallelStream().filter(addressJson -> {
Integer address_id = ((JSONObject)addressJson).getInteger("address_id");
String isDefault = ((JSONObject)addressJson).getString("is_default");
return Objects.nonNull(address_id) && StringUtils.equals(isDefault, "Y");
}).findFirst().orElse(null);
if (addressJsonObj == null){
logger.warn("in getAddressInfo fail, uid {}, addressArray {}", uid, addressArray);
throw new ServiceException(ServiceError.ADDRESS_NULL);
}
addressInfo = AddressInfoConvertor.userAddressRsp2AddressInfo(addressJsonObj);
return addressInfo;
}
/**
* http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
* //profile/getProfile?uid=600032978
* @param uid
* @return
*/
public static final String PRFILE_API = "/profile/getProfile";
public String getMobile(int uid){
String url = uicUrl + PRFILE_API;
Map<String,Object> params = Maps.newHashMap();
params.put("uid", uid);
ApiResponse userInfo ;
try {
userInfo = serviceCaller.get("users.getAddress", url, params,
ApiResponse.class, null).get(500, TimeUnit.MILLISECONDS);
}catch (Exception ex){
logger.warn("in getMobile fail, uid {}", uid, ex);
throw new ServiceException(ServiceError.USER_IS_NOT_EXIST);
}
JSONObject jsonObject;
String mobile;
if (userInfo == null || (jsonObject = (JSONObject)userInfo.getData()) == null
|| StringUtils.isBlank(mobile = jsonObject.getString("mobile_phone"))){
logger.warn("in getMobile fail, uid {}, userInfo {}", uid, userInfo);
throw new ServiceException(ServiceError.PROFILE_IS_NULL);
}
return mobile;
}
}
... ...
... ... @@ -4,10 +4,12 @@ import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.service.model.order.request.OrderRequest;
import com.yoho.ufo.dal.*;
import com.yoho.ufo.event.model.StorageNumEvent;
import com.yoho.ufo.model.brand.BrandSeries;
... ... @@ -15,6 +17,9 @@ import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
import com.yoho.ufo.util.ImagesConstant;
import com.yoho.ufo.util.ImagesHelper;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.req.BatchImportPrdReq;
import com.yohobuy.ufo.model.order.req.SellerReq;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -27,18 +32,23 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.yoho.ufo.dal.model.Goods;
import com.yoho.ufo.dal.model.GoodsImages;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.ProductImportTran;
import com.yoho.ufo.dal.model.ProductImportTranItem;
import com.yoho.ufo.dal.model.Storage;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yoho.ufo.exception.CommonException;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.model.brand.Brand;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yoho.ufo.service.IProductService;
import com.yoho.ufo.service.UserProxyService;
import com.yoho.ufo.util.CollectionUtil;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
... ... @@ -69,6 +79,10 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
private StoragePriceMapper storagePriceMapper;
@Autowired
private UfoSizeMapper sizeMapper;
@Autowired
private ProductImportTranMapper productImportTranMapper;
@Autowired
private ProductImportTranItemMapper productImportTranItemMapper;
/*@Autowired
private InboxService inboxService;*/
... ... @@ -80,6 +94,13 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
private UfoBrandSeriesMapper brandSeriesMapper;
@Autowired
private ProductIntroService productIntroService;
@Autowired
private UserProxyService userProxyService;
@Autowired
private BatchService batchService;
@Override
public ApiResponse<Void> addOrUpdate(ProductRequestBo bo, boolean isCheckUrl) {
checkProductInfo(bo, isCheckUrl);
... ... @@ -712,4 +733,220 @@ public static void main(String[] args) {
return new ApiResponse<>(200, "操作成功!");
}
@Override
public ApiResponse<ProductImportTranItem> getBatchImportResult(Integer tranId) throws PlatformException {
ProductImportTran exist = productImportTranMapper.selectByPrimaryKey(tranId);
if (exist == null) {
throw new PlatformException("任务不存在!", 400);
}
ProductImportTranItem item = productImportTranItemMapper.selectTranInfoByTranId(tranId);
if (item == null || item.getItemCount() == null || item.getItemCount() == 0) {
item = new ProductImportTranItem();
item.setStatus(0);
} else if (item.getStatus() != null && item.getStatus() > 0) {
ProductImportTran update = new ProductImportTran();
update.setId(tranId);
update.setStatus(item.getMaxStatus());
productImportTranMapper.updateByPrimaryKeySelective(update);
}
return new ApiResponse<>(200, "查询成功", item);
}
@Override
public void batchImportFromXls(MultipartFile file, Integer editUid) throws Exception {
LOGGER.info("用户{}开始导入商品数据!", editUid);
// 查看是否有正在执行
int now = (int) (System.currentTimeMillis() / 1000);
ProductImportTran exist;
if ((exist = productImportTranMapper.selectUserProcessing(editUid)) != null
&& (now - exist.getCreateTime()) < 300) {
LOGGER.warn("用户{}正在导入中,结束", editUid);
throw new PlatformException("有导入操作正在进行中!", 400);
}
List<ProductImportTranItem> items = batchService.parseData(file, "batchImportStoragePrice", ProductImportTranItem.class);
if (CollectionUtils.isEmpty(items)) {
LOGGER.info("用户{}导入的excel为空,结束", editUid);
throw new PlatformException("导入的excel数据为空!", 400);
}
LOGGER.info("Excel解析成功一共{}行", items.size());
Integer count = 0, uid = null;
Set<String> uniqSet = new HashSet<>();
for (int i = 0; i < items.size(); i++) {
ProductImportTranItem item = items.get(i);
if (StringUtils.isAnyBlank(item.getProductCode(), item.getSizeName())) {
LOGGER.info("第{}行数据:商品编码或尺码为空!", i + 1);
throw new PlatformException("第" + (i + 1) + "行数据:商品编码或尺码为空!", 400);
}
if (item.getUid() == null || item.getUid() < 1) {
LOGGER.info("第{}行数据:uid不合法!", i + 1);
throw new PlatformException("第" + (i + 1) + "行数据:uid:" + item.getUid() + "不合法!", 400);
}
if (uid == null) {
uid = item.getUid();
} else if (item.getUid() != uid) {
LOGGER.info("excel中存在多个uid!");
throw new PlatformException("excel中存在多个uid!", 400);
}
if (item.getNum() == null || item.getNum() < 1) {
LOGGER.info("第{}行数据:数量不合法!", i + 1);
throw new PlatformException("第" + (i + 1) + "行数据:数量" + item.getNum() + "不合法!", 400);
}
count += item.getNum();
if (count > 200) {
LOGGER.info("总数量大于200!");
throw new PlatformException("总数量不能大于200!", 400);
}
BigDecimal price = item.getPrice();
if (price == null || price.compareTo(BigDecimal.ZERO) <= 0
|| price.divideAndRemainder(BigDecimal.TEN)[1].compareTo(new BigDecimal("9")) != 0) {
LOGGER.info("第{}行数据:金额不合法!", i + 1);
throw new PlatformException("第" + (i + 1) + "行数据:金额" + price + "不合法!", 400);
}
String key = item.getProductCode() + " *SPLIT* " + item.getSizeName();
if (uniqSet.contains(key)) {
LOGGER.info("第{}行数据:货号{}+尺码{}有重复行!", i + 1, item.getProductCode(), item.getSizeName());
throw new PlatformException(
"第" + (i + 1) + "行数据:货号+尺码有重复行:" + item.getProductCode() + "," + item.getSizeName(), 400);
}
uniqSet.add(key);
}
List<String> productCodeList = CollectionUtil.distinct(items, ProductImportTranItem::getProductCode);
List<Product> productList = productMapper.selectProductListByProductCodes(productCodeList);
Map<String, Product> codeProductMap = CollectionUtil.extractMap(productList, Product::getProductCode);
for (int i = 0; i < items.size(); i++) {
ProductImportTranItem item = items.get(i);
Product p = codeProductMap.get(item.getProductCode());
if (p == null) {
LOGGER.info("第{}行数据:商品编码{}不存在!", i + 1, item.getProductCode());
throw new PlatformException("第" + (i + 1) + "行数据:商品编码" + item.getProductCode() + "不存在!", 400);
}
if (item.getPrice().compareTo(p.getMaxPrice()) > 0 || item.getPrice().compareTo(p.getMinPrice()) < 0) {
LOGGER.info("第{}行数据:价格{}超出规定范围!", i + 1, item.getPrice());
throw new PlatformException("第" + (i + 1) + "行数据:价格" + item.getPrice() + "超出规定范围!", 400);
}
item.setProductId(p.getId());
}
List<String> sizeNameList = CollectionUtil.distinct(items, ProductImportTranItem::getSizeName);
List<Size> sizeList = sizeMapper.selectBySizeNameList(sizeNameList);
Map<String, Size> sizeNameMap = CollectionUtil.extractMap(sizeList, Size::getSizeName);
for (int i = 0; i < items.size(); i++) {
ProductImportTranItem item = items.get(i);
Size s = sizeNameMap.get(item.getSizeName());
if (s == null) {
LOGGER.info("第{}行数据:尺码{}不存在!", i + 1, item.getSizeName());
throw new PlatformException("第" + (i + 1) + "行数据:尺码" + item.getSizeName() + "不存在!", 400);
}
item.setSizeId(s.getId());
}
StringBuilder sql = new StringBuilder();
Map<Integer, Set<Integer>> productIdSizeMap = new HashMap<>();
for (int i = 0; i < items.size(); i++) {
ProductImportTranItem item = items.get(i);
Size s = sizeNameMap.get(item.getSizeName());
Set<Integer> sizeIds = productIdSizeMap.get(item.getProductId());
if (sizeIds == null) {
sizeIds = new HashSet<>();
productIdSizeMap.put(item.getProductId(), sizeIds);
}
sizeIds.add(s.getId());
}
productIdSizeMap.forEach((k, v) -> {
sql.append("or (product_id=" + k + " and size_id in(" + StringUtils.join(v, ",") + ")) ");
});
List<Storage> storageList = storageMapper.selectByCondition(sql.substring(3));
Map<String, Storage> storageMap = CollectionUtil.extractMap(storageList,
s -> s.getProductId() + "_" + s.getSizeId());
for (int i = 0; i < items.size(); i++) {
ProductImportTranItem item = items.get(i);
Storage s = storageMap.get(item.getProductId() + "_" + item.getSizeId());
if (s == null) {
LOGGER.info("第{}行数据:商品{}无该尺码{}!", i + 1, item.getProductCode(), item.getSizeName());
throw new PlatformException(
"第" + (i + 1) + "行数据:该商品" + item.getProductCode() + "下的这个尺码" + item.getSizeName() + "不存在!",
400);
}
item.setStorageId(s.getId());
}
// 检查用户身份
try {
LOGGER.info("get user account info");
SellerReq req = new SellerReq();
req.setUid(uid);
Boolean userResp = serviceCaller.call("ufo-gateway.isNormalSuper", req, Boolean.class, 10);
LOGGER.info("get user account info result is {}", userResp);
if (userResp == null || !userResp) {
throw new PlatformException("uid:" + uid + "账号不是超级卖家或者余额不足!", 400);
}
} catch (Exception e) {
LOGGER.error("get user account info error", e);
throw new PlatformException("uid:" + uid + "账号信息获取出错!", 400);
}
// 获取地址信息
AddressInfo address = null;
try {
LOGGER.info("get user address info");
address = userProxyService.getAddressInfoNotHidden(uid);
if (address == null) {
throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
}
} catch (Exception e) {
LOGGER.error("get user address info error", e);
throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
}
AddressInfo addressHidden = null;
try {
LOGGER.info("get user hidden address info");
addressHidden = userProxyService.getHiddenAddressInfo(uid);
if (addressHidden == null) {
throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
}
} catch (Exception e) {
LOGGER.error("get user hidden address info error", e);
throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
}
LOGGER.info("增加事务记录");
ProductImportTran tran = new ProductImportTran();
tran.setStatus(0);
tran.setEditUid(editUid);
tran.setUid(uid);
tran.setCreateTime(now);
productImportTranMapper.insert(tran);
LOGGER.info("增加事务记录成功rec={}", tran);
int batchNum = 40;
List<List<ProductImportTranItem>> batchLists = CollectionUtil.split(items, batchNum);
LOGGER.info("一共{}行,每批次{}行,一共{}批", items.size(), batchNum, batchLists.size());
for (int i = 0; i < batchLists.size(); i++) {
LOGGER.info("一共{}行,每批次{}行,一共{}批,处理批次{}...", items.size(), batchNum, batchLists.size(), i + 1);
List<ProductImportTranItem> batch = batchLists.get(i);
BatchImportPrdReq<ProductImportTranItem> batchReq = new BatchImportPrdReq<>();
batchReq.setHiddenBackAddress(addressHidden);
batchReq.setNoHiddenBackAddress(address);
batchReq.setProductList(batch);
batchReq.setTaskId(tran.getId());
try {
LOGGER.info("batch import send taskId={}, batchId={}", tran.getId(), (i + 1));
serviceCaller.call("ufo-gateway.batchImportPrds", batchReq, Void.class, 10);
LOGGER.info("batch import send success taskId={}, batchId={}", tran.getId(), (i + 1));
} catch (Exception e) {
LOGGER.info("batch import send failed taskId={}, batchId={}", tran.getId(), (i + 1));
}
}
LOGGER.info("batch import over taskId={}", tran.getId());
}
}
... ...
... ... @@ -49,3 +49,7 @@ shops.gateway.url=http://instore-test1.dev.yohocorp.com
offline.store.seller=70,50000638
ip.port.search.server=192.168.102.216:8080
erp-gateway.url=http://java-yoho-erp-gateway.test3.ingress.dev.yohocorp.com/erp-gateway
uic.url=http://java-yoho-uic.test3.ingress.dev.yohocorp.com/uic
... ...
... ... @@ -53,4 +53,7 @@ service.call.connectReqTimeout=15000
service.call.socketTimeout=15000
service.call.connectTimeout=15000
erp-gateway.url=${erp-gateway.url}
uic.url=${uic.url}
... ...