Authored by LUOXC

Merge branch 'master' into hotfix_0131_隐藏质检不通过

Showing 24 changed files with 1471 additions and 264 deletions
package com.yoho.ufo.restapi;
import com.yoho.quartz.job.YhJob;
import com.yoho.ufo.service.model.*;
import com.yoho.ufo.service.model.ApiResponse;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by li.ma on 2019/2/1.
*/
@Controller
@RequestMapping("/scheduled")
public class ScheduledManualController implements ApplicationContextAware{
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@RequestMapping(value = "/scheduledManual")
@ResponseBody
public ApiResponse scheduledManual(@RequestParam(name = "scheduledName",required = true) String scheduledName) {
YhJob jobObject = applicationContext.getBean(scheduledName, YhJob.class);
jobObject.process(null);
return new ApiResponse(200, "处理成功", null);
}
}
... ...
... ... @@ -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;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class ProductImportTran {
private Integer id;
private Integer editUid;
private Integer uid;
private Integer status;
private Integer createTime;
private Integer updateTime;
private Integer num;
}
\ 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" />
<result column="num" property="num" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, edit_uid, uid, status, create_time, update_time,num
</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,num
)
values (#{id,jdbcType=INTEGER}, #{editUid,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{num,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>
<if test="num != null" >
num,
</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>
<if test="num != null" >
#{num,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
... ...
... ... @@ -5,11 +5,18 @@ import javax.annotation.Resource;
import com.yohobuy.ufo.model.request.product.ProductRequestBatchBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.CrossOrigin;
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;
... ... @@ -76,4 +83,37 @@ public class ProductController {
LOGGER.info("product.addOrUpdate param = {}", bo);
return productService.importProduct(bo);
}
@CrossOrigin(origins = "*")
@RequestMapping(value = "/batchImportFromXls", method = RequestMethod.POST)
public ApiResponse<Integer> 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 {
return 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);
}
}
@CrossOrigin(origins = "*")
@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);
ApiResponse<Integer> 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,226 @@ 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.getNum() == null
|| item.getNum() < exist.getNum()) {
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 ApiResponse<Integer> 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.intValue()) {
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();
int limit = 500;
if (count > limit) {
LOGGER.info("总数量大于{}!", limit);
throw new PlatformException("总数量不能大于"+limit+"!", 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());
}
Boolean userResp = null;
// 检查用户身份
try {
LOGGER.info("get user account info");
SellerReq req = new SellerReq();
req.setUid(uid);
userResp = serviceCaller.call("ufo-gateway.isNormalSuper", req, Boolean.class, 10);
LOGGER.info("get user account info result is {}", userResp);
} catch (Exception e) {
LOGGER.error("get user account info error", e);
throw new PlatformException("uid:" + uid + "账号信息获取出错!", 400);
}
if (userResp == null || !userResp) {
throw new PlatformException("uid:" + uid + "账号不是超级卖家或者余额不足!", 400);
}
// 获取地址信息
AddressInfo address = null;
try {
LOGGER.info("get user address info");
address = userProxyService.getAddressInfoNotHidden(uid);
} catch (Exception e) {
LOGGER.error("get user address info error", e);
throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
}
if (address == null) {
throw new PlatformException("uid:" + uid + "获取地址信息出错!", 400);
}
AddressInfo addressHidden = null;
try {
LOGGER.info("get user hidden address info");
addressHidden = userProxyService.getHiddenAddressInfo(uid);
} catch (Exception e) {
LOGGER.error("get user hidden address info error", e);
throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
}
if (addressHidden == null) {
throw new PlatformException("uid:" + uid + "获取加密地址信息出错!", 400);
}
LOGGER.info("增加事务记录");
ProductImportTran tran = new ProductImportTran();
tran.setStatus(0);
tran.setEditUid(editUid);
tran.setUid(uid);
tran.setCreateTime(now);
tran.setNum(count);
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());
batch.forEach(b -> b.setTranId(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());
return new ApiResponse<Integer>(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}
... ...
... ... @@ -13,7 +13,7 @@
<servlet-name>default</servlet-name>
<url-pattern>/common/ok.jsp</url-pattern>
<url-pattern>/common/productId.xlsx</url-pattern>
<url-pattern>/common/import.xlsx</url-pattern>
</servlet-mapping>
... ...
No preview for this file type
... ... @@ -9,12 +9,94 @@
<body class="easyui-layout" fit="true">
<div region="north" style="height: 220px">
<script>
document.write(addHead('商品库存信息', ''));
document.write(addHead('商品库存信息', ''));
</script>
<style>
.div_search input {margin-top: 20px; }
.div_search .textbox {margin-top: 20px;}
.div_search .easyui-linkbutton {margin-top: 20px;}
.div_search input {
margin-top: 20px;
}
.div_search .textbox {
margin-top: 20px;
}
.div_search .easyui-linkbutton {
margin-top: 20px;
}
.upload_tips_container {
display: flex;
display: -webkit-flex;
align-items: center;
-webkit-align-items: center;
justify-content: center;
-webkit-justify-content: center;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 99;
}
.upload_tips_container.hide{
display: none;
}
.upload_tips_container .upload_tips {
position: absolute;
min-width: 200px;
max-width: 800px;
min-height: 150px;
-webkit-border-radius: 10px;
border-radius: 10px;
/*left: 50%;*/
/*top: 50%;*/
/*margin-left: -150px;*/
/*margin-top: -250px;*/
background-color: #fff;
}
.upload_tips .tips_title {
width: 100%;
height: 40px;
border-bottom: 1px solid #f0f0f0;
line-height: 40px;
font-size: 24px;
text-align: center;
font-weight: bold;
color: #2baee9;
}
.tips_title .panel-tool-close {
position: absolute;
background: url('../../../js/jquery/easyui/themes/platform/images/new_close.png') no-repeat;
background-size: 100% 100%;
opacity: 0.3;
width: 16px;
height: 16px;
right: 10px;
margin-top: 10px;
}
.upload_tips .tips_content {
width: 100%;
min-height: 110px;
}
.upload_tips .tips_content p {
text-align: center;
font-size: 16px;
margin: 0;
padding: 20px;
}
.btn-download span {
line-height: 40px;
color: #87CEFA;
}
</style>
<div style="margin-left: 30px;" class="div_search">
<input id="id" type="text">
... ... @@ -29,6 +111,16 @@
<input id="skup" type="text">
<a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a>
<a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
<form id="uploadForm" style="display: inline-block;">
<div id="uploadExcelButton" class="easyui-linkbutton btn-info"
style="width: 100px; height: 40px;cursor: pointer;">
<input id="upload_excel" name="upload_excel" type="file"
style="display: inline-block;width: 200px;height: 40px;margin: 0;padding: 0;opacity: 0;position: absolute;"
accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
导入EXCEL
</div>
</form>
<a href="..\..\..\common/import.xlsx" style="height: 40px; display: inline-block; line-height: 40px;border: none; background: none;" class="easyui-linkbutton btn-info btn-download" target="_blank">下载样例.xlsx</a>
</div>
</div>
<div region="center">
... ... @@ -37,289 +129,415 @@
</div>
</div>
<div class="upload_tips_container hide">
<div class="upload_tips">
<div class="tips_title">
提示
<a id="btnCloseTip" href="javascript:void(0)" class="panel-tool-close"></a>
</div>
<div class="tips_content">
<p>文件上传中</p>
</div>
</div>
</div>
<script type="text/javascript">
var brandId;
$(function () {
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/brand/getBrandName',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#brandName").myCombobox({
prompt: "品牌名称",
width: 200,
data: data.data,
valueField: "id",
textField: "text"
});
}
});
var brandId;
var isAnimateStop; // 用于停止上传中的动画
var textTimeout; // 用于上传中动画
$("#storageNum").myCombobox({
prompt: "商品库存",
width: 200,
data: [{id: '1',text: '有库存'}, {id: '0',text: '无库存'}],
valueField: "id",
textField: "text"
$(function () {
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/brand/getBrandName',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#brandName").myCombobox({
prompt: "品牌名称",
width: 200,
data: data.data,
valueField: "id",
textField: "text"
});
}
});
$("#storageNum").myCombobox({
prompt: "商品库存",
width: 200,
data: [{id: '1', text: '有库存'}, {id: '0', text: '无库存'}],
valueField: "id",
textField: "text"
});
$("#productTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/storage/storageList",
method: 'POST',
/*queryParams: {
'brandName':'',
'status':''
},*/
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "商品编码",
field: "id",
width: 40,
align: "center"
}, {
title: "商品名称",
field: "productName",
width: 100,
align: "center",
}, {
title: "品牌",
field: "brandName",
width: 60,
align: "center"
}, {
title: "最低价",
field: "currentPrice",
width: 40,
align: "center",
formatter: function (value, rowData) {
if (value) {
return value;
}
return '--';
}
}, {
title: "可售库存",
field: "storage",
width: 20,
align: "center",
formatter: function (value, rowData) {
if (value) {
return value;
}
return 0;
}
}, {
title: "操作",
field: "operations",
width: 40,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' sortId = '" + rowData.midSortId + "' style='margin-left:10px'>库存详情</a>";
return str;
}
}]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
var midSortId = $(this).attr("sortId");
detailStorage(id, midSortId);
}
});
}
$("#productTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/storage/storageList",
method: 'POST',
/*queryParams: {
'brandName':'',
'status':''
},*/
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "商品编码",
field: "id",
width: 40,
align: "center"
}, {
title: "商品名称",
field: "productName",
width: 100,
align: "center",
}, {
title: "品牌",
field: "brandName",
width: 60,
align: "center"
}, {
title: "最低价",
field: "currentPrice",
width: 40,
align: "center",
formatter: function (value, rowData) {
if (value) {
return value;
}
return '--';
}
}, {
title: "可售库存",
field: "storage",
width: 20,
align: "center",
formatter: function (value, rowData) {
if (value) {
return value;
}
return 0;
}
}, {
title: "操作",
field: "operations",
width: 40,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' sortId = '" + rowData.midSortId + "' style='margin-left:10px'>库存详情</a>";
return str;
}
}]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
var midSortId = $(this).attr("sortId");
detailStorage(id, midSortId);
}
});
}
});
// 搜索
$("#searchLinkButton").linkbutton({
onClick: function () {
var param = getParams();
$("#productTable").myDatagrid("load", param);
}
// 搜索
$("#searchLinkButton").linkbutton({
onClick: function () {
var param = getParams();
$("#productTable").myDatagrid("load", param);
}
});
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/productSort/getLevel2SortBySortId',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#productSort").myCombobox({
prompt: "一级品类",
width: 200,
data: data.data,
valueField: "id",
textField: "text"
});
}
});
var mxSortCombobox = $("#maxSortId");
var mdSortCombobox = $("#middleSortId");
var sortComboboxUrl = contextPath + '/productSort/getLevel2SortBySortId?sortId='
mxSortCombobox.combobox({
url: sortComboboxUrl,
method: "get",
editable: false,
valueField: 'id',
textField: 'text',
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "一级品类"});
return data;
},
onSelect: function (rec) {
if (0 === rec.id) {
try {
mdSortCombobox.combobox('disable');
mdSortCombobox.combobox('setValue', '0');
} catch (e) {
}
return;
}
try {
mdSortCombobox.combobox('reload', sortComboboxUrl + rec.id);
mdSortCombobox.combobox('enable');
mdSortCombobox.combobox('setValue', '0');
} catch (e) {
}
},
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "一级分类"});
return data;
}
});
mdSortCombobox.combobox({
method: "get",
editable: false,
valueField: 'id',
textField: 'text',
data: [{text: '二级分类', id: '0'}],
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "请选择分类"});
return data;
},
onSelect: function (rec) {
if (0 === rec.id) {
return;
}
},
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "请选择二级分类"});
return data;
}
});
$("#id").textbox({
prompt: "商品编码"
});
$("#productName").textbox({
prompt: "商品名称"
});
$('#brandName').textbox({
prompt: "品牌名称"
});
$("#sellerUid").textbox({
prompt: "卖家UID"
});
$("#storageId").textbox({
prompt: "SKU"
});
$("#skup").textbox({
prompt: "SKU-p"
});
// 搜索全部
$("#searchAllLinkButton").linkbutton({
onClick: function () {
$('#brandName').combobox('clear');
$('#storageNum').combobox('clear');
$('#id').textbox('clear');
$('#productName').textbox('clear');
$('#sellerUid').textbox('clear');
$('#storageId').textbox('clear');
$('#skup').textbox('clear');
$('#maxSortId').combobox('clear');
$('#middleSortId').combobox('clear');
var param = {};
$("#productTable").myDatagrid("load", param);
}
});
/**
* 提取出搜索参数
*/
function getParams() {
var brandName = $('#brandName').combobox('getValue');
var storageNum = $('#storageNum').combobox('getValue');
var id = $('#id').textbox('getValue');
var productName = $('#productName').textbox('getValue');
var sellerUid = $('#sellerUid').textbox('getValue');
var storageId = $('#storageId').textbox('getValue');
var maxSortId = $('#maxSortId').combobox('getValue');
var midSortId = $('#middleSortId').combobox('getValue');
var skup = $('#skup').textbox('getValue');
var param = {};
if (undefined !== brandName && null !== brandName && "" !== brandName) {
param.brandId = brandName;
}
if (undefined !== storageNum && null !== storageNum && "" !== storageNum) {
param.storageNum = storageNum;
}
if (undefined !== id && null !== id && "" !== id) {
param.id = id;
}
if (undefined !== productName && null !== productName && "" !== productName) {
param.productName = productName;
}
if (undefined !== sellerUid && null !== sellerUid && "" !== sellerUid) {
param.sellerUid = sellerUid;
}
if (undefined !== storageId && null !== storageId && "" !== storageId) {
param.storageId = storageId;
}
if (undefined !== skup && null !== skup && "" !== skup) {
param.skup = skup;
}
if (maxSortId !== undefined && null !== maxSortId && "" !== maxSortId && 0 != maxSortId) {
param.maxSortId = maxSortId;
}
if (midSortId !== undefined && null !== midSortId && "" !== midSortId && 0 != midSortId) {
param.midSortId = midSortId;
}
return param;
}
function detailStorage(id, midSortId) {
this.location.href = contextPath + "/html/goods/storage/storageDetail.html?productId=" + id + "&midSortId=" + midSortId;
}
// 上传EXCEL
function uploadExcel() {
if ($('#upload_excel').val()) {
var formData = new FormData();
var name = $('#upload_excel').val();
formData.append('name', name);
formData.append('file', $('#upload_excel')[0].files[0]);
isAnimateStop = false;
console.log(formData.get('file'), formData.get('name'));
$('.upload_tips_container').removeClass('hide');
animateUploadText('上传中', 0, 500);
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/productSort/getLevel2SortBySortId',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#productSort").myCombobox({
prompt: "一级品类",
width: 200,
data: data.data,
valueField: "id",
textField: "text"
});
url: contextPath + '/product/batchImportFromXls',
data: formData,
method: 'POST',
cache: false,
processData: false,
contentType: false,
xhrFields: {withCredentials: true},
success: function (res) {
console.log(res);
if (res.code !== 200) {
clearTimeout(textTimeout);
isAnimateStop = true;
$('#upload_excel').val('');
animateUploadText(res.message, 0, 5000);
} else {
$('#upload_excel').val('');
checkTaskInfo(res.data);
}
});
var mxSortCombobox = $("#maxSortId");
var mdSortCombobox = $("#middleSortId");
var sortComboboxUrl = contextPath + '/productSort/getLevel2SortBySortId?sortId='
mxSortCombobox.combobox({
url: sortComboboxUrl,
method: "get",
editable: false,
valueField: 'id',
textField: 'text',
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "一级品类"});
return data;
},
onSelect: function (rec) {
if (0 === rec.id) {
try {
mdSortCombobox.combobox('disable');
mdSortCombobox.combobox('setValue', '0');
} catch (e) { }
return;
}
try {
mdSortCombobox.combobox('reload', sortComboboxUrl + rec.id);
mdSortCombobox.combobox('enable');
mdSortCombobox.combobox('setValue', '0');
} catch (e) { }
},
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "一级分类"});
return data;
}
});
mdSortCombobox.combobox({
method: "get",
editable: false,
valueField: 'id',
textField: 'text',
data: [{ text: '二级分类', id: '0'}],
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "请选择分类"});
return data;
},
onSelect: function (rec) {
if (0 === rec.id) {
return;
}
},
loadFilter: function (data) {
data = defaultLoadFilter(data);
data.unshift({id: 0, text: "请选择二级分类"});
return data;
}
}
});
}
}
$("#id").textbox({
prompt: "商品编码"
});
$("#productName").textbox({
prompt: "商品名称"
});
$("#sellerUid").textbox({
prompt: "卖家UID"
});
$("#storageId").textbox({
prompt: "SKU"
});
$("#skup").textbox({
prompt: "SKU-p"
});
$('#upload_excel').on('change', uploadExcel);
$('#btnCloseTip').on('click', function() {
if(isAnimateStop) {
$('.upload_tips_container').addClass('hide');
clearTimeout(textTimeout);
}
// 搜索全部
$("#searchAllLinkButton").linkbutton({
onClick: function () {
$('#brandName').combobox('clear');
$('#storageNum').combobox('clear');
$('#id').textbox('clear');
$('#productName').textbox('clear');
$('#sellerUid').textbox('clear');
$('#storageId').textbox('clear');
$('#skup').textbox('clear');
$('#maxSortId').combobox('clear');
$('#middleSortId').combobox('clear');
var param = {};
$("#productTable").myDatagrid("load", param);
}
});
});
/**
* 提取出搜索参数
*/
function getParams() {
var brandName = $('#brandName').combobox('getValue');
var storageNum = $('#storageNum').combobox('getValue');
var id = $('#id').textbox('getValue');
var productName = $('#productName').textbox('getValue');
var sellerUid = $('#sellerUid').textbox('getValue');
var storageId = $('#storageId').textbox('getValue');
var maxSortId = $('#maxSortId').combobox('getValue');
var midSortId = $('#middleSortId').combobox('getValue');
var skup = $('#skup').textbox('getValue');
var param = {};
if (undefined !== brandName && null !== brandName && "" !== brandName) {
param.brandId = brandName;
}
if (undefined !== storageNum && null !== storageNum && "" !== storageNum) {
param.storageNum = storageNum;
// 查询上传任务
function checkTaskInfo(id) {
$.ajax({
url: contextPath + '/product/getBatchImportResult',
data: {
tranId: id
},
method: 'POST',
xhrFields: {
withCredentials: true
},
success: function(res) {
console.log(res);
if(res.code === 200) {
switch (res.data.status) {
case 0:
setTimeout(checkTaskInfo, 2000, id);
break;
case 1:
clearTimeout(textTimeout);
isAnimateStop = true;
animateUploadText('上传成功!', 0, 2000);
break;
case 2:
clearTimeout(textTimeout);
isAnimateStop = true;
animateUploadText('任务完成,但是有错误!', 0, 5000);
break;
}
if (undefined !== id && null !== id && "" !== id) {
param.id = id;
}
if (undefined !== productName && null !== productName && "" !== productName) {
param.productName = productName;
}
if (undefined !== sellerUid && null !== sellerUid && "" !== sellerUid) {
param.sellerUid = sellerUid;
}
if (undefined !== storageId && null !== storageId && "" !== storageId) {
param.storageId = storageId;
}
if (undefined !== skup && null !== skup && "" !== skup) {
param.skup = skup;
}
if (maxSortId !== undefined && null !== maxSortId && "" !== maxSortId && 0 != maxSortId) {
param.maxSortId = maxSortId;
}
if (midSortId !== undefined && null !== midSortId && "" !== midSortId && 0 != midSortId) {
param.midSortId = midSortId;
}
return param;
}
}
})
}
function detailStorage(id, midSortId) {
this.location.href = contextPath + "/html/goods/storage/storageDetail.html?productId=" + id + "&midSortId=" + midSortId;
function animateUploadText(text, count, timeout) {
if(!timeout) {
timeout = 500;
}
if (!isAnimateStop) {
var arr = [];
if(count < 5) {
for(var i = 0; i < count; i ++) {
arr.push('.');
}
} else {
count = 0;
}
});
count++;
$('.upload_tips p').text(text + arr.join(''));
textTimeout = setTimeout(animateUploadText, timeout, text, count);
} else {
$('.upload_tips p').text(text);
isAnimateStop = true;
}
}
});
</script>
... ...