Authored by mali

Merge branch 'gray' into test6.8.2

... ... @@ -12,4 +12,7 @@ import com.yoho.order.model.SellerOrderGoods;
public interface SellerOrderGoodsMapper {
List<SellerOrderGoods> selectByIds(@Param("idList") List<Integer> idList);
int updateSizeId(@Param("newSizeId")Integer newSizeId, @Param("oldSizeIdList")List<Integer> oldSizeIdList);
}
... ...
... ... @@ -47,7 +47,9 @@ public interface ProductSortMapper {
* @return
*/
ProductSort selectOneById(Integer id);
List<ProductSort> getChildren(Integer id);
/**
* 根据条件查询品类数据
*
... ...
... ... @@ -23,4 +23,6 @@ public interface StorageMapper {
int updateStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum, @Param("oldStorageNum")Integer oldStorageNum);
List<Storage> selectByIds(@Param("storageIdList")List<Integer> storageIdList);
int updateSizeId(@Param("newSizeId")Integer newSizeId, @Param("oldSizeIdList")List<Integer> oldSizeIdList);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yohobuy.ufo.model.common.PageModel;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yohobuy.ufo.model.common.PageModel;
/**
* 品类mapper
... ... @@ -38,7 +38,7 @@ public interface UfoSizeMapper {
* @param size
* @return
*/
int selectSizeCount(@Param("size") Size size);
int selectSizeCount(@Param("size") Size size, @Param("list")List<Integer> sortIdList);
/**
* 根据主键查询尺寸数据
... ... @@ -55,7 +55,7 @@ public interface UfoSizeMapper {
* @param pageModel
* @return
*/
List<Size> getSizePageList(@Param("size") Size size, @Param("page") PageModel pageModel);
List<Size> getSizePageList(@Param("size") Size size, @Param("list")List<Integer> sortIdList, @Param("page") PageModel pageModel);
/**
* 根据品类查询所有的尺码
... ... @@ -83,4 +83,19 @@ public interface UfoSizeMapper {
* @return
*/
List<Size> selectAllSize();
int addBind(Size size);
int updateBind(@Param("size")Size size);
Size getBySizeIdAndSortId(@Param("sizeId")Integer sizeId, @Param("sortId")Integer sortId);
Size getBindById(Integer id);
List<Size> selectAllSizeBySortIdList(@Param("sortIdList") List<Integer> sortIdList);
List<Size> getBindPageList(@Param("size") Size size, @Param("sortIdList")List<Integer> sortIdList, @Param("page") PageModel pageModel);
int getBindCount(@Param("size") Size size, @Param("sortIdList")List<Integer> sortIdList);
}
... ...
... ... @@ -20,6 +20,8 @@ public class Size implements Serializable {
* 尺码名
*/
private String sizeName;
private Integer sizeId;
/**
* 所属分类id
... ... @@ -45,6 +47,8 @@ public class Size implements Serializable {
* 更新时间
*/
private Integer updateTime;
private Integer del;
public Integer getId() {
return id;
... ... @@ -101,17 +105,27 @@ public class Size implements Serializable {
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
@Override
public String toString() {
return "Size{" +
"id=" + id +
", sizeName='" + sizeName + '\'' +
", sortId=" + sortId +
", sortName='" + sortName + '\'' +
", orderBy=" + orderBy +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
public Integer getDel() {
return del;
}
public void setDel(Integer del) {
this.del = del;
}
public Integer getSizeId() {
return sizeId;
}
public void setSizeId(Integer sizeId) {
this.sizeId = sizeId;
}
@Override
public String toString() {
return "Size [id=" + id + ", sizeName=" + sizeName + ", sizeId=" + sizeId + ", sortId=" + sortId + ", sortName="
+ sortName + ", orderBy=" + orderBy + ", createTime=" + createTime + ", updateTime=" + updateTime
+ ", del=" + del + "]";
}
}
... ...
... ... @@ -97,8 +97,14 @@
select <include refid="queryColumns"/>
from product_sort
</select>
<select id="getChildren" resultMap="productSortMap">
select <include refid="queryColumns"/>
from product_sort where parent_id = #{id}
</select>
<select id="selectSortByIdList" resultMap="productSortMap">
select id,sort_name
select id,sort_name,level, parent_id
from product_sort where id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
... ...
... ... @@ -31,4 +31,11 @@
</foreach>
</select>
<update id="updateSizeId">
update seller_order_goods set size_id=#{newSizeId} where size_id in
<foreach item="item" index="index" collection="oldSizeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -64,4 +64,11 @@
#{item}
</foreach>
</select>
<update id="updateSizeId">
update storage set size_id=#{newSizeId} where size_id in
<foreach item="item" index="index" collection="oldSizeIdList" open="(" separator="," close=")">
#{item}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -6,18 +6,19 @@
<id property="id" column="id"/>
<result property="sizeName" column="size_name"/>
<result property="sortId" column="sort_id"/>
<result property="sizeId" column="size_id"/>
<result property="orderBy" column="order_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="queryColumns">
size.id, size.size_name, CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, size.order_by
size.id, size.size_name
</sql>
<insert id="insertSize" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
insert into size(id, size_name, sort_id, order_by, create_time, update_time)
values (#{id}, #{sizeName}, #{sortId}, #{orderBy}, #{createTime}, #{updateTime})
<insert id="insertSize" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size" useGeneratedKeys="true" keyProperty="id" >
insert into size(id, size_name, order_by, create_time, update_time)
values (#{id}, #{sizeName}, #{orderBy}, #{createTime}, #{updateTime})
</insert>
... ... @@ -29,12 +30,6 @@
<if test="size.sizeName != null and size.sizeName !=''">
size_name = #{size.sizeName},
</if>
<if test="size.sortId != null and size.sortId != ''">
sort_id = #{size.sortId},
</if>
<if test="size.orderBy != null and size.orderBy != ''">
order_by = #{size.orderBy},
</if>
<if test="size.createTime != null">
create_time = #{size.createTime},
</if>
... ... @@ -46,45 +41,50 @@
</update>
<select id="selectOneById" resultMap="sizeMap">
select id, size_name, sort_id, order_by
select id, size_name
from size where id = #{id}
</select>
<sql id="queryPage">
from size
LEFT JOIN product_sort sort1
ON size.sort_id = sort1.id
left join product_sort sort2
on sort1.parent_id = sort2.id
<where>
<if test="size.sortName != null and size.sortName != ''">
sort1.sort_name like concat('%', #{size.sortName}, '%') or sort2.sort_name like concat('%', #{size.sortName}, '%')
</if>
<if test="size.sizeName != null and size.sizeName !=''">
and size.size_name like concat('%', #{size.sizeName}, '%')
</if>
<if test="list != null and list.size() > 0">
and sort_size.del = 0 and sort_size.sort_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</sql>
<select id="selectSizeCount" resultType="integer">
select count(*)
select count(*) from size
<if test="list != null and list.size() > 0">
inner join sort_size on size.id = sort_size.size_id
</if>
<include refid="queryPage"/>
</select>
<select id="getSizePageList" resultMap="sizeMap">
select <include refid="queryColumns"/>
select <include refid="queryColumns"/> from size
<if test="list != null and list.size() > 0">
inner join sort_size on size.id = sort_size.size_id
</if>
<include refid="queryPage"/>
order by size.update_time desc
order by id
limit #{page.startIndex}, #{page.pageSize}
</select>
<select id="selectAllSizeBySortId" resultMap="sizeMap">
select id, size_name
from size where 1=1
select s.id, s.size_name
from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
<if test="sortId != null and sortId >0 ">
and sort_id = #{sortId}
and ss.sort_id = #{sortId}
</if>
order by ss.order_by, ss.id
</select>
<select id="selectByIdList" resultMap="sizeMap">
... ... @@ -96,11 +96,100 @@
</select>
<select id="getOrderBySortLevel2Id" resultMap="sizeMap">
select id, sort_id, order_by from size where sort_id = #{sortId}
select s.id, s.size_name,ss.order_by
from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
<if test="sortId != null and sortId >0 ">
and ss.sort_id = #{sortId}
</if>
order by ss.order_by, ss.id
</select>
<select id="selectAllSize" resultMap="sizeMap">
select id, sort_id, size_name from size
select * from size
</select>
<insert id="addBind" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
insert into sort_size(id, sort_id,size_id,order_by, create_time, update_time,del)
values (#{id}, #{sortId},#{sizeId}, #{orderBy}, #{createTime}, #{updateTime},0)
</insert>
<update id="updateBind" parameterType="com.yoho.ufo.model.commoditybasicrole.size.Size">
update sort_size
<set>
<if test="size.sortId != null and size.sortId >0">
sort_id = #{size.sortId},
</if>
<if test="size.sizeId != null and size.sizeId >0">
size_id = #{size.sizeId},
</if>
<if test="size.orderBy != null">
order_by = #{size.orderBy},
</if>
<if test="size.createTime != null">
create_time = #{size.createTime},
</if>
<if test="size.updateTime != null">
update_time = #{size.updateTime},
</if>
<if test="size.del != null">
del = #{size.del}
</if>
</set>
where id = #{size.id}
</update>
<select id="getBySizeIdAndSortId" resultMap="sizeMap">
select id, size_id,sort_id,order_by
from sort_size where del = 0
<if test="sortId != null and sortId >0 ">
and sort_id = #{sortId}
</if>
<if test="sizeId != null and sizeId >0 ">
and size_id = #{sizeId}
</if>
</select>
<select id="selectAllSizeBySortIdList" resultMap="sizeMap">
select s.id, s.size_name,ss.order_by
from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
<if test="sortIdList != null and sortIdList.size() >0 ">
and ss.sort_id in
<foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
order by ss.order_by, ss.id
</select>
<select id="getBindPageList" resultMap="sizeMap">
select * from sort_size ss where del = 0
<if test="sortIdList != null and sortIdList.size() >0 ">
and ss.sort_id in
<foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="size.sizeId != null and size.sizeId >0">
and ss.size_id = #{size.sizeId}
</if>
order by ss.sort_id,ss.order_by
limit #{page.startIndex}, #{page.pageSize}
</select>
<select id="getBindCount" resultType="integer">
select count(*) from sort_size ss where del = 0
<if test="sortIdList != null and sortIdList.size() >0 ">
and ss.sort_id in
<foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="size.sizeId != null and size.sizeId >0">
and ss.size_id = #{size.sizeId}
</if>
</select>
<select id="getBindById" resultMap="sizeMap">
select * from sort_size ss where id = #{id}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -92,7 +92,7 @@ public class ProductSortController {
* @param sortId
* @return
*/
@RequestMapping(value = "/getLevel2SortBySortId", method = RequestMethod.GET)
@RequestMapping(value = "/getLevel2SortBySortId")
public ApiResponse<List<JSONObject>> getLevel2SortBySortId(Integer sortId) {
return new ApiResponse<>(productSortService.getLevel2SortBySortId(sortId));
}
... ...
... ... @@ -55,4 +55,43 @@ public class SizeController {
LOGGER.info("queryAllSize4Goods method in.");
return new ApiResponse<>(sizeService.queryAllSize4Goods(sortId));
}
@RequestMapping(value = "/queryAllSize")
public ApiResponse<Object> queryAllSize() {
LOGGER.info("queryAllSize method in.");
return new ApiResponse<>(sizeService.queryAllSize());
}
@RequestMapping(value = "/queryAllSecondSize4Goods", method = RequestMethod.GET)
public ApiResponse<Object> queryAllSecondSize4Goods(Integer sortId) {
LOGGER.info("queryAllSecondSize4Goods method in.");
return new ApiResponse<>(sizeService.queryAllSecondSize4Goods(sortId));
}
@RequestMapping(value = "/addOrUpdateBind", method = RequestMethod.GET)
public ApiResponse<Object> addOrUpdateBind(SizeRequestBo sizeRequestBo) {
LOGGER.info("addOrUpdateBind method in.");
return new ApiResponse<>(sizeService.addOrUpdateBind(sizeRequestBo));
}
@RequestMapping(value = "/removeBind", method = RequestMethod.GET)
public ApiResponse<Object> removeBind(SizeRequestBo sizeRequestBo) {
LOGGER.info("removeBind method in.");
return new ApiResponse<>(sizeService.removeBind(sizeRequestBo));
}
@RequestMapping(value = "/getBindInfo")
public ApiResponse<Object> getBindInfo(SizeRequestBo sizeRequestBo) {
LOGGER.info("getBindInfo method in.");
return new ApiResponse<>(sizeService.getBindInfo(sizeRequestBo));
}
@RequestMapping(value = "/exchangeData")
public ApiResponse<Object> exchangeData(String pass) {
LOGGER.info("exchangeData method in.");
if(pass==null || !pass.equals("99089909001")) {
return new ApiResponse<>(400, "pass err!");
}
return new ApiResponse<>(sizeService.exchangeData());
}
}
... ...
package com.yoho.ufo.service;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.size.SizeRequestBo;
import com.yohobuy.ufo.model.request.size.SizeResponseBo;
import java.util.List;
import java.util.Map;
/**
* 品类接口
... ... @@ -40,4 +42,18 @@ public interface ISizeService {
* @return
*/
List<JSONObject> queryAllSize4Goods(Integer sortId);
int addOrUpdateBind(SizeRequestBo sizeRequestBo);
int removeBind(SizeRequestBo sizeRequestBo);
List<JSONObject> queryAllSecondSize4Goods(Integer sortId);
List<JSONObject> queryAllSize();
PageResponseBO<SizeResponseBo> getBindInfo(SizeRequestBo sizeRequestBo);
ApiResponse<Object> exchangeData();
void replaceOrderOldSizeId(Map<Integer, List<Integer>> idReplace);
}
... ...
package com.yoho.ufo.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.exception.ServiceException;
import com.yoho.order.dal.SellerOrderGoodsMapper;
import com.yoho.ufo.dal.ProductSortMapper;
import com.yoho.ufo.dal.StorageMapper;
import com.yoho.ufo.dal.UfoSizeMapper;
import com.yoho.ufo.model.brand.BrandSeries;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yoho.ufo.service.ISizeService;
import com.yoho.ufo.util.CollectionUtil;
import com.yoho.ufo.util.OrikaUtils;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageModel;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.size.SizeRequestBo;
import com.yohobuy.ufo.model.request.size.SizeResponseBo;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author kun.wang
... ... @@ -33,37 +45,87 @@ public class SizeServiceImpl implements ISizeService {
@Autowired
private UfoSizeMapper ufoSizeMapper;
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private ISizeService sizeService;
@Override
public int saveOrUpdateSize(SizeRequestBo sizeRequestBo) {
LOGGER.info("saveOrUpdateSize param = {}", sizeRequestBo);
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
if (size.getId() == null || size.getId() == 0) {
// 判断排序值是否已存在
List<Size> sizeList = ufoSizeMapper.getOrderBySortLevel2Id(size.getSortId());
List<Integer> orderBys = sizeList.stream().map(size1 -> size1.getOrderBy()).collect(Collectors.toList());
if (orderBys.contains(size.getOrderBy())) {
throw new ServiceException(201, "排序值" + size.getOrderBy() + "已存在!");
}
size.setCreateTime(DateUtil.currentTimeSeconds());
size.setUpdateTime(size.getCreateTime());
size.setDel(0);
size.setUpdateTime(0);
// 新增
return ufoSizeMapper.insertSize(size);
} else {
List<Size> sizeList = ufoSizeMapper.getOrderBySortLevel2Id(size.getSortId());
for (Size size1 : sizeList) {
if (!size1.getId().equals(size.getId())) {
if (size1.getOrderBy().equals(size.getOrderBy())) {
throw new ServiceException(201, "排序值" + size.getOrderBy() + "已存在!");
}
}
}
// 更新
size.setUpdateTime(DateUtil.currentTimeSeconds());
return ufoSizeMapper.updateSize(size);
}
}
@Override
public int addOrUpdateBind(SizeRequestBo sizeRequestBo) {
LOGGER.info("addOrUpdateBind param = {}", sizeRequestBo);
Integer bindId = sizeRequestBo.getId();
Integer sizeId = sizeRequestBo.getSizeId();
Integer sortId = sizeRequestBo.getSortId();
Integer orderBy = sizeRequestBo.getOrderBy();
if (orderBy == null || orderBy < 1) {
throw new ServiceException(400, "请填写排序值");
}
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
if (bindId != null && bindId > 0) {
Size binded = ufoSizeMapper.getBindById(bindId);
if (binded == null) {
throw new ServiceException(400, "该绑定关系不存在");
}
size.setSizeId(null);
size.setSortId(null);
size.setUpdateTime(DateUtil.currentTimeSeconds());
return ufoSizeMapper.updateBind(size);
} else {
if (sizeId == null || sizeId < 1) {
throw new ServiceException(400, "请选择尺码");
}
if (sortId == null || sortId < 1) {
throw new ServiceException(400, "请选择品类");
}
Size binded = ufoSizeMapper.getBySizeIdAndSortId(sizeId, sortId);
if (binded != null) {
throw new ServiceException(400, "该绑定关系已经存在");
}
size.setCreateTime(DateUtil.currentTimeSeconds());
size.setUpdateTime(0);
return ufoSizeMapper.addBind(size);
}
}
@Override
public int removeBind(SizeRequestBo sizeRequestBo) {
LOGGER.info("removeBind param = {}", sizeRequestBo);
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
Size binded = ufoSizeMapper.getBindById(sizeRequestBo.getId());
if (binded != null) {
size.setDel(1);
size.setUpdateTime(DateUtil.currentTimeSeconds());
return ufoSizeMapper.updateBind(size);
} else {
throw new ServiceException(400, "该绑定关系不存在");
}
}
@Override
public SizeResponseBo getSizeById(Integer id) {
... ... @@ -72,26 +134,36 @@ public class SizeServiceImpl implements ISizeService {
}
@Override
public PageResponseBO<SizeResponseBo> getSizePageList(SizeRequestBo sizeRequestBo) {
LOGGER.info("getSizePageList param = {}", sizeRequestBo);
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
PageModel pageModel = sizeRequestBo.toPageModel();
int count = ufoSizeMapper.selectSizeCount(size);
if (count == 0) {
LOGGER.warn("getSizePageList count is 0. param = {}", sizeRequestBo);
return new PageResponseBO<>();
}
List<Size> sizeList = ufoSizeMapper.getSizePageList(size, pageModel);
List<SizeResponseBo> responseBos = OrikaUtils.mapToList(sizeList, SizeResponseBo.class);
return new PageResponseBO<>(count, responseBos, pageModel.getCurrentPage(), pageModel.getPageSize());
}
public PageResponseBO<SizeResponseBo> getSizePageList(SizeRequestBo sizeRequestBo) {
LOGGER.info("getSizePageList param = {}", sizeRequestBo);
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
PageModel pageModel = sizeRequestBo.toPageModel();
List<Integer> sortIdList = null;
if (sizeRequestBo.getSortId() != null && sizeRequestBo.getSortId() > 0) {
ProductSort sort = productSortMapper.selectOneById(sizeRequestBo.getSortId());
if (sort != null) {
sortIdList = new ArrayList<>();
sortIdList.add(sizeRequestBo.getSortId());
if (sort.getParentId() != null && sort.getParentId() > 0) {
sortIdList.add(sort.getParentId());
}
}
}
int count = ufoSizeMapper.selectSizeCount(size, sortIdList);
if (count == 0) {
LOGGER.warn("getSizePageList count is 0. param = {}", sizeRequestBo);
return new PageResponseBO<>();
}
List<Size> sizeList = ufoSizeMapper.getSizePageList(size, sortIdList, pageModel);
List<SizeResponseBo> responseBos = OrikaUtils.mapToList(sizeList, SizeResponseBo.class);
return new PageResponseBO<>(count, responseBos, pageModel.getCurrentPage(), pageModel.getPageSize());
}
/**
* 查询所有的尺码,下拉框使用
* @return
*/
public List<JSONObject> queryAllSize4Goods(Integer sortId) {
// TODO 可以添加缓存
List<Size> sizes = ufoSizeMapper.selectAllSizeBySortId(sortId);
List<JSONObject> result = new ArrayList<>();
JSONObject jsonObject;
... ... @@ -104,6 +176,117 @@ public class SizeServiceImpl implements ISizeService {
revealEmptyItem(result);
return result;
}
/**
* 查询所有的尺码,下拉框使用
* @return
*/
@Override
public List<JSONObject> queryAllSize() {
List<Size> sizes = ufoSizeMapper.selectAllSize();
List<JSONObject> result = new ArrayList<>();
JSONObject jsonObject;
for (Size item : sizes) {
jsonObject = new JSONObject();
jsonObject.put("id", item.getId());
jsonObject.put("text", item.getSizeName());
result.add(jsonObject);
}
revealEmptyItem(result);
return result;
}
/**
* 查询所有的尺码,下拉框使用
* @return
*/
@Override
public List<JSONObject> queryAllSecondSize4Goods(Integer sortId) {
List<JSONObject> result = new ArrayList<>();
ProductSort sort = productSortMapper.selectOneById(sortId);
List<Size> sizes;
if (sort != null) {
List<Integer> idList = new ArrayList<>();
idList.add(sortId);
if (sort.getParentId() != null && sort.getParentId() > 0) {
idList.add(sort.getParentId());
}
sizes = ufoSizeMapper.selectAllSizeBySortIdList(idList);
} else {
sizes = new ArrayList<>();
}
JSONObject jsonObject;
for (Size item : sizes) {
jsonObject = new JSONObject();
jsonObject.put("id", item.getId());
jsonObject.put("text", item.getSizeName());
result.add(jsonObject);
}
revealEmptyItem(result);
return result;
}
@Override
public PageResponseBO<SizeResponseBo> getBindInfo(SizeRequestBo sizeRequestBo) {
LOGGER.info("getBindInfo param = {}", sizeRequestBo);
Size size = OrikaUtils.map(sizeRequestBo, Size.class);
PageModel pageModel = sizeRequestBo.toPageModel();
List<Integer> sortIdList = null;
if (sizeRequestBo.getSortId2() != null && sizeRequestBo.getSortId2() > 0) {
sortIdList = new ArrayList<>();
sortIdList.add(sizeRequestBo.getSortId2());
} else if (sizeRequestBo.getSortId() != null && sizeRequestBo.getSortId() > 0) {
ProductSort sort = productSortMapper.selectOneById(sizeRequestBo.getSortId());
if (sort != null) {
sortIdList = new ArrayList<>();
sortIdList.add(sizeRequestBo.getSortId());
List<ProductSort> children = productSortMapper.getChildren(sort.getId());
sortIdList.addAll(CollectionUtil.map(children, ProductSort::getId));
}
}
int count = ufoSizeMapper.getBindCount(size, sortIdList);
if (count == 0) {
LOGGER.warn("getBindInfo count is 0. param = {}", sizeRequestBo);
return new PageResponseBO<>();
}
List<Size> sizeList = ufoSizeMapper.getBindPageList(size, sortIdList, pageModel);
List<Integer> rSizeIdList = CollectionUtil.map(sizeList, Size::getSizeId);
List<Integer> rSortIdList = CollectionUtil.map(sizeList, Size::getSortId);
List<ProductSort> sorts = productSortMapper.selectSortByIdList(rSortIdList);
List<Size> sizes = ufoSizeMapper.selectByIdList(rSizeIdList);
Map<Integer, Size> sizeMap = CollectionUtil.extractMap(sizes, Size::getId);
Map<Integer, ProductSort> sortMap = CollectionUtil.extractMap(sorts, ProductSort::getId);
List<SizeResponseBo> responseBos = new ArrayList<>();
for (Size s : sizeList) {
Size s0 = sizeMap.get(s.getSizeId());
ProductSort ps0 = sortMap.get(s.getSortId());
SizeResponseBo bo = new SizeResponseBo();
bo.setId(s.getId());
bo.setOrderBy(s.getOrderBy());
bo.setSortId(s.getSortId());
bo.setSizeId(s.getSizeId());
if (s0 == null || StringUtils.isBlank(s0.getSizeName())) {
bo.setSizeName("");
} else {
bo.setSizeName(s0.getSizeName());
}
if (ps0 == null || StringUtils.isBlank(ps0.getSortName())) {
bo.setSortName("");
} else {
String sortName = ps0.getSortName();
if (ps0.getParentId() != null && ps0.getParentId() > 0) {
ProductSort ps1 = sortMap.get(ps0.getParentId());
if (ps1 != null && StringUtils.isNotBlank(ps1.getSortName())) {
sortName = ps1.getSortName() + "/" + sortName;
}
}
bo.setSortName(sortName);
}
responseBos.add(bo);
}
return new PageResponseBO<>(count, responseBos, pageModel.getCurrentPage(), pageModel.getPageSize());
}
private void revealEmptyItem(List<JSONObject> jsonObjectList) {
JSONObject jsonObject;
... ... @@ -112,4 +295,98 @@ public class SizeServiceImpl implements ISizeService {
jsonObjectList.add(jsonObject);
}
}
@Override
@Transactional
@Database(DataSource = "ufo_product")
public ApiResponse<Object> exchangeData() {
List<Size> allSize = ufoSizeMapper.selectAllSize();
LOGGER.info("开始切换品类尺码数据, 总数 {}", allSize.size());
Map<String, List<Size>> bindMap = CollectionUtil.groupingBy(allSize, Size::getSizeName);
LOGGER.info("开始切换品类尺码数据, bindMap {}", bindMap);
int time = DateUtil.currentTimeSeconds();
try {
Map<Integer, List<Integer>> idReplace = new HashMap<>();
List<String> allSizeName = new ArrayList<>(bindMap.keySet());
Collections.sort(allSizeName);
for (String sName : allSizeName) {
LOGGER.info("切换品类尺码数据, 处理尺码:{}", sName);
List<Size> binded = bindMap.get(sName);
Size s = new Size();
s.setSizeName(sName);
s.setSortId(0);
Integer orderBy = 0;
if (CollectionUtils.isNotEmpty(binded)) {
orderBy = binded.get(0).getOrderBy();
if (orderBy == null) {
orderBy = 0;
} else {
orderBy *= 100;
if(StringUtils.equals("S", sName)) {
orderBy += 50;
}
}
}
s.setOrderBy(orderBy);
s.setCreateTime(time);
s.setUpdateTime(0);
LOGGER.info("切换品类尺码数据, 构建新尺码:{}", s);
ufoSizeMapper.insertSize(s);
LOGGER.info("切换品类尺码数据, 保存新尺码成功:{}", s);
LOGGER.info("切换品类尺码数据, 获取 {} 绑定的类别", sName);
if (CollectionUtils.isNotEmpty(binded)) {
idReplace.put(s.getId(), CollectionUtil.distinct(binded, Size::getId));
LOGGER.info("切换品类尺码数据, 尺码名称:{},品类总数:{}, 明细:{}", sName, binded.size(), binded);
for (Size b : binded) {
if (b.getSortId() == null || b.getSortId() < 1) {
LOGGER.info("切换品类尺码数据, 尺码名称:{},品类id无效跳过:{}", sName, b.getSortId());
}
LOGGER.info("切换品类尺码数据, 尺码名称:{},构建品类关联:{}", sName, b);
Size ss = new Size();
ss.setSizeId(s.getId());
ss.setSortId(b.getSortId());
ss.setOrderBy(b.getOrderBy());
ss.setDel(0);
ss.setCreateTime(time);
ss.setUpdateTime(0);
LOGGER.info("切换品类尺码数据, 尺码名称:{},构建品类关联结果:{}", sName, ss);
ufoSizeMapper.addBind(ss);
LOGGER.info("切换品类尺码数据, 尺码名称:{},保存品类关联成功:{}", sName, ss);
}
}
}
for (Map.Entry<Integer, List<Integer>> entry : idReplace.entrySet()) {
Integer newId = entry.getKey();
List<Integer> oldList = entry.getValue();
LOGGER.info("切换品类尺码数据, sku老尺码信息换成新的:new:{}, old:{}", newId, oldList);
LOGGER.info("切换品类尺码数据, sku老尺码信息换成新的 rollbackSql :update ufo_product.storage set size_id={} where size_id = {}", oldList.get(0), newId);
int exCount = storageMapper.updateSizeId(newId, oldList);
LOGGER.info("切换品类尺码数据, sku老尺码信息换成新的:new:{}, 修改数:{}", newId, exCount);
}
sizeService.replaceOrderOldSizeId(idReplace);
} catch (Exception e) {
LOGGER.error("切换类别尺码数据错误!", e);
throw new ServiceException(200, "执行失败:" + e.getMessage());
}
return new ApiResponse<>(200, "执行成功!");
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Database(DataSource = "ufo_order")
public void replaceOrderOldSizeId(Map<Integer, List<Integer>> idReplace) {
for (Map.Entry<Integer, List<Integer>> entry : idReplace.entrySet()) {
Integer newId = entry.getKey();
List<Integer> oldList = entry.getValue();
LOGGER.info("切换品类尺码数据, order老尺码信息换成新的:new:{}, old:{}", newId, oldList);
LOGGER.info("切换品类尺码数据, sku老尺码信息换成新的 rollbackSql :update ufo_order.seller_order_goods set size_id={} where size_id = {}", oldList.get(0), newId);
int exCount = sellerOrderGoodsMapper.updateSizeId(newId, oldList);
LOGGER.info("切换品类尺码数据, order老尺码信息换成新的:new:{}, 修改数:{}", newId, exCount);
}
}
}
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="categoryEditForm" id="categoryEditForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="level" id="level"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="20%"><label>一级分类</label></td>
<td>
<input id="cat1" name="cat1" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td width="20%"><label>二级分类</label></td>
<td>
<input id="cat2" name="cat2" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td width="20%"><label>尺码</label></td>
<td>
<input id="sizeId" name="sizeId" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td width="20%"><span style="color:red">*</span><label>排序值</label></td>
<td>
<input class="easyui-numberbox" id="orderBy" name="orderBy" data-options="validType:'length[1,10]'" style="width: 380px;"/>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
$("#categoryEditForm #orderBy").numberbox({
required: true,
precision:0,
min:1,
missingMessage: "排序值不能为空",
prompt: "请输入",
width: 240
});
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
async: false,
url: contextPath + '/productSort/getLevel1SortIdAndName',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#cat2").myCombobox({
prompt: "选择二级分类",
width: 200,
valueField: "id",
textField: "text",
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
$("#cat1").myCombobox({
prompt: "选择一级分类",
width: 200,
data: data.data,
valueField: "id",
textField: "text",
required: true,
missingMessage: "一级品类不能为空",
onSelect: function (rec) {
$("#cat2").myCombobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
}
});
}
});
$("#sizeId").myCombobox({
prompt: "选择尺码",
url: contextPath + "/size/queryAllSize",
width: 200,
valueField: "id",
textField: "text",
required: true,
missingMessage: "尺码不能为空",
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
});
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/ufoPlatform/js/include.js"></script>
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
<script>
document.write(addHead('商品基础规则 /物理类目-尺码', ''));
</script>
<style>
.div_search input {
margin-top: 20px;
}
.div_search .textbox {
margin-top: 20px;
}
.div_search .easyui-linkbutton {
margin-top: 20px;
}
</style>
<div style="margin-left: 30px;" class="div_search">
<a id="addBind" class="easyui-linkbutton btn-success">添加尺码关联</a>
</div>
<div style="margin-left: 30px;" class="div_search">
<input id="searchSize" type="text">
<input id="searchCat1" type="text"/>
<input id="searchCat2" 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>
</div>
</div>
<div region="center">
<div style="margin-left: 30px;margin-top: 20px;height: 660px">
<table id="sortSizeTable"></table>
</div>
</div>
<script type="text/javascript">
var editId;
$(function () {
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
async: false,
url: contextPath + '/productSort/getLevel1SortIdAndName',
success: function (data) {
if (data.code != 200 || !data.data || data.data.length == 0) {
return;
}
$("#searchCat2").myCombobox({
prompt: "选择二级分类",
width: 200,
valueField: "id",
textField: "text",
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
$("#searchCat1").myCombobox({
prompt: "选择一级分类",
width: 200,
data: data.data,
valueField: "id",
textField: "text",
onSelect: function (rec) {
$("#searchCat2").myCombobox('clear');
$("#searchCat2").myCombobox('reload', contextPath + "/productSort/getLevel2SortBySortId?sortId=" + rec.id);
}
});
}
});
$("#searchSize").myCombobox({
prompt: "选择尺码",
url: contextPath + "/size/queryAllSize",
width: 200,
valueField: "id",
textField: "text",
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
// 搜索
$("#searchLinkButton").linkbutton({
onClick: function () {
$("#sortSizeTable").myDatagrid("load",
{
"sizeId": $('#searchSize').combobox('getValue'),
"sortId": $('#searchCat1').combobox("getValue"),
"sortId2": $('#searchCat2').combobox("getValue")
});
}
});
// 搜索全部
$("#searchAllLinkButton").linkbutton({
onClick: function () {
$("#sortSizeTable").myDatagrid("load", {});
}
});
$('#addBind').linkbutton({
iconCls: "icon-edit",
onClick: function () {
editRow(0);
}
});
$("#sortSizeTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/size/getBindInfo",
method: 'POST',
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "关联ID",
field: "id",
width: 40,
align: "center"
}, {
title: "品类ID",
field: "sortId",
width: 40,
align: "center"
}, {
title: "品类名称",
field: "sortName",
width: 80,
align: "center"
}, {
title: "尺码ID",
field: "sizeId",
width: 40,
align: "center"
}, {
title: "尺码名称",
field: "sizeName",
width: 80,
align: "center"
}, {
title: "排序",
field: "orderBy",
width: 80,
align: "center"
}, {
title: "操作",
field: "operations",
width: 80,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
str += "<a role='remove' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>删除</a>";
return str;
}
}]],
cache: false,
pagination: true,
pageSize: 20,
//pageList: [100, 200, 300],
idField: "id",
treeField:'treeField',
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
// 编辑
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
editRow(id);
}
});
// 关闭品类
$(this).myDatagrid("getPanel").find("a[role='remove']").linkbutton({
iconCls: "icon-more",
onClick: function () {
var d = {};
d.id = $(this).attr("dataId");
$.ajax({
contentType: "application/json",
dataType: "json",
data : d,
type: "GET",
async: false,
url: contextPath + '/size/removeBind',
success: function (data) {
if (data.code == 200) {
$("#sortSizeTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: "操作成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
}
});
function editRow(id) {
editId = id;
if (id != 0) {
$.messager.prompt("修改排序值", "请输入新的排序值", function (data) {
if (data) {
function isNumber(value) {
var patrn = /^[0-9]*$/;
if (patrn.exec(value) == null || value == "") {
return false
} else {
return true
}
}
if(!isNumber(data)) {
$.messager.alert("失败", "输入值有误!", "error");
return;
}
var d = {};
d.id = id;
d.orderBy = data;
$.ajax({
contentType: "application/json",
dataType: "json",
data : d,
type: "GET",
async: false,
url: contextPath + '/size/addOrUpdateBind',
success: function (data) {
if (data.code == 200) {
$("#sortSizeTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: "操作成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
return;
}
var div = $("<div>").appendTo($(document.body));
var title = "编辑品类尺码";
var message = "确认修改品类信息吗?";
if (id == 0) {
title = "添加品类尺码";
message = "确认添加品类信息吗?";
}
$(div).myDialog({
width: "550px",
height: "400px",
title: title,
href: contextPath + "/html/commodityBasicRules/physicalCategory/addBind.html",
queryParams: {
id: id
},
modal: true,
collapsible: true,
cache: false,
buttons: [{
id: "saveBtn",
text: "保存",
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if(flag) {
var d = {};
d.id = id;
d.sortId = $('#cat2').combobox('getValue');
if(!d.sortId) {
d.sortId = $('#cat1').combobox('getValue');
}
d.sizeId = $('#sizeId').combobox('getValue');
d.orderBy = $('#orderBy').textbox('getValue');
$.ajax({
contentType: "application/json",
dataType: "json",
data : d,
type: "GET",
async: false,
url: contextPath + '/size/addOrUpdateBind',
success: function (data) {
if (data.code == 200) {
$(div).dialog("close");
$("#sortSizeTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: "操作成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
}]
});
}
});
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -4,12 +4,6 @@
<input type="hidden" name="id" id="id"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span><label>分类</label></td>
<td>
<input id="sortId" name="sortId" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>尺码名</td>
... ... @@ -17,11 +11,6 @@
<input id="sizeName" name="sizeName" class="easyui-textbox" data-options="validType:'length[1,20]'" style="width: 380px;"/></td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>排序值</td>
<td width="50%">
<input id="orderBy" name="orderBy" class="easyui-numberbox" data-options="validType:'length[1,10]'" style="width: 380px;"/></td>
</tr>
</table>
</div>
</form>
... ...
... ... @@ -99,16 +99,6 @@
width: 80,
align: "center"
}, {
title: "所属分类",
field: "sortName",
width: 100,
align: "center"
}, {
title: "排序值",
field: "orderBy",
width: 100,
align: "center"
}, {
title: "操作",
field: "operations",
width: 80,
... ... @@ -143,7 +133,7 @@
$("#sizeTable").myDatagrid("load",
{
"sizeName": $('#sizeName').textbox('getValue'),
"sortName": $('#sortName').combobox("getText")
"sortId": $('#sortName').combobox("getValue")
});
}
});
... ... @@ -169,7 +159,7 @@
}
$(div).myDialog({
width: "500px",
height: "360px",
height: "250px",
title: title,
href: contextPath + "/html/commodityBasicRules/size/sizeEdit.html",
queryParams: {
... ... @@ -184,11 +174,11 @@
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if (flag) {
var sortId = $('#sizeEditForm #sortId').combobox("getValue");
/* var sortId = $('#sizeEditForm #sortId').combobox("getValue");
if (sortId == '' || sortId == null || sortId == undefined) {
$.messager.alert("提示", '请选择分类!', "error");
return false;
}
} */
var url = contextPath + "/size/saveOrUpdateSize";
$("#sizeEditForm").form("submit", {
url: url,
... ...
... ... @@ -735,7 +735,7 @@
sortId = sortId || 0;
// 获取所有尺寸
$.get(contextPath + '/size/queryAllSize4Goods?sortId=' + sortId, function(ret) {
$.get(contextPath + '/size/queryAllSecondSize4Goods?sortId=' + sortId, function(ret) {
if (ret && ret.code == 200) {
$('.group-size .size').html('');
$.each(ret.data || [], function(index, item) {
... ...