Authored by caoyan

商品池增加排序值

package com.yoho.ufo.dal;
import com.yoho.ufo.model.goodsmanage.ProductPool;
import com.yoho.ufo.model.goodsmanage.ProductPoolDetails;
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.goodsmanage.ProductPoolDetails;
/**
* 商品池详情mapper
... ... @@ -38,4 +37,16 @@ public interface UfoProductPoolDetailMapper {
* @return
*/
int deleteProductPoolDetail(@Param("productPoolId") Integer productPoolId, @Param("productId") Integer productId);
/**
* 根据条件查询数据
* @param poolId
* @param productId
* @return
*/
List<ProductPoolDetails> selectByPoolIdAndProductId(@Param("poolId") Integer poolId, @Param("productId") Integer productId);
List<ProductPoolDetails> selectByPoolIdAndOrderBy(@Param("poolId") Integer poolId, @Param("orderBy") Integer orderBy);
int updateProductOrderBy(@Param("poolId") Integer poolId, @Param("productId") Integer productId, @Param("orderBy") int orderBy);
}
... ...
... ... @@ -58,6 +58,8 @@ public class ProductDetails implements Serializable {
*/
private Integer delStatus;
private Integer orderBy;
public Integer getId() {
return id;
}
... ... @@ -130,6 +132,13 @@ public class ProductDetails implements Serializable {
this.delStatus = delStatus;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
@Override
public String toString() {
... ... @@ -143,6 +152,7 @@ public class ProductDetails implements Serializable {
", brandName='" + brandName + '\'' +
", sortName='" + sortName + '\'' +
", delStatus=" + delStatus +
", orderBy=" + orderBy +
'}';
}
}
... ...
package com.yoho.ufo.model.goodsmanage;
import com.yoho.ufo.annotation.BatchImportField;
import java.io.Serializable;
import com.yoho.ufo.annotation.BatchImportField;
/**
* 商品池详情
* @author kun.wang
... ... @@ -52,6 +52,12 @@ public class ProductPoolDetails implements Serializable {
*/
private String sortName;
/**
* 排序值
*/
@BatchImportField(index = 1)
private Integer orderBy;
public Integer getId() {
return id;
}
... ... @@ -116,6 +122,13 @@ public class ProductPoolDetails implements Serializable {
this.sortName = sortName;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
@Override
public String toString() {
... ... @@ -128,6 +141,7 @@ public class ProductPoolDetails implements Serializable {
", productName='" + productName + '\'' +
", brandName='" + brandName + '\'' +
", sortName='" + sortName + '\'' +
", orderBy='" + orderBy + '\'' +
'}';
}
}
... ...
... ... @@ -6,7 +6,8 @@
</resultMap>
<sql id="queryColumns">
product.id, product.product_code, product.product_name, product.product_code, brand.brand_name, CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, product.del_status
product.id, product.product_code, product.product_name, product.product_code, brand.brand_name,
CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, product.del_status, pool_detail.order_by
</sql>
<select id="queryProductIdsByProductIds" parameterType="java.util.Set" resultType="integer">
... ... @@ -60,6 +61,7 @@
select <include refid="queryColumns"/>
<include refid="queryTable"/>
<include refid="queryParam"/>
order by pool_detail.order_by desc
limit #{page.startIndex}, #{page.pageSize}
</select>
... ...
<?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.UfoProductPoolDetailMapper">
<resultMap id="productPoolDetails" type="com.yoho.ufo.model.goodsmanage.ProductPoolDetails">
<resultMap id="BaseResultMap" type="com.yoho.ufo.model.goodsmanage.ProductPoolDetails">
<result column="id" property="id" jdbcType="INTEGER" />
<result column="pool_id" property="poolId" jdbcType="INTEGER" />
<result column="product_id" property="productId" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="order_by" property="orderBy" jdbcType="INTEGER" />
</resultMap>
<sql id="queryColumns">
product.id, product.product_code, product.product_name, product.product_code, brand.brand_name, product_sort.sort_name
<sql id="Base_Column_List">
id, pool_id, product_id, create_time, order_by
</sql>
<insert id="batchInsertProductPoolDetails" parameterType="list">
insert into product_pool_detail(pool_id, product_id, create_time) values
insert into product_pool_detail(pool_id, product_id, create_time, order_by) values
<foreach collection="list" item="item" separator="," index="index">
(#{item.poolId}, #{item.productId}, #{item.createTime})
(#{item.poolId}, #{item.productId}, #{item.createTime}, #{item.order_by})
</foreach>
</insert>
... ... @@ -25,4 +27,31 @@
<delete id="deleteProductPoolDetail">
DELETE FROM product_pool_detail WHERE pool_id = #{productPoolId} AND product_id = #{productId}
</delete>
<select id="selectByPoolIdAndProductId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from product_pool_detail where 1=1
<if test="poolId != null">
and pool_id = #{poolId}
</if>
<if test="productId != null">
and product_id = #{productId}
</if>
</select>
<select id="selectByPoolIdAndOrderBy" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from product_pool_detail where 1=1
<if test="poolId != null">
and pool_id = #{poolId}
</if>
<if test="orderBy != null">
and order_by = #{orderBy}
</if>
</select>
<update id="updateProductOrderBy">
update product_pool_detail set order_by=#{orderBy} where pool_id=#{poolId} and product_id=#{productId}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.productpool;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.IProductPoolDetailsService;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
... ... @@ -46,4 +47,38 @@ public class ProductPoolDetailsController {
LOGGER.info("getProductPoolDetailsPageList param = {}", productPoolDetailsRequestBo);
return new ApiResponse<>(productPoolDetailsService.getProductPoolDetailsPageList(productPoolDetailsRequestBo));
}
@RequestMapping(value = "/saveProduct", method = RequestMethod.POST)
public ApiResponse<Void> saveProduct(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
LOGGER.info("saveProduct param = {}", productPoolDetailsRequestBo);
int result =0;
try {
result= productPoolDetailsService.saveProduct(productPoolDetailsRequestBo);
} catch (PlatformException px) {
LOGGER.warn("saveProduct PlatformException.param = {}, errorMsg = {}", productPoolDetailsRequestBo, px.getMessage());
return new ApiResponse<>(400, px.getMessage(), null);
}
if(result == 0) {
return new ApiResponse<>(500, "添加失败!", null);
}
return new ApiResponse<>();
}
@RequestMapping(value = "/updateProductOrderBy", method = RequestMethod.POST)
public ApiResponse<Void> updateProductOrderBy(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
LOGGER.info("updateProductOrderBy param = {}", productPoolDetailsRequestBo);
int result =0;
try {
result= productPoolDetailsService.updateProductOrderBy(productPoolDetailsRequestBo);
} catch (PlatformException px) {
LOGGER.warn("saveProduct PlatformException.param = {}, errorMsg = {}", productPoolDetailsRequestBo, px.getMessage());
return new ApiResponse<>(400, px.getMessage(), null);
}
if(result == 0) {
return new ApiResponse<>(500, "更新失败!", null);
}
return new ApiResponse<>();
}
}
... ...
package com.yoho.ufo.service;
import com.yoho.ufo.exception.PlatformException;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo;
import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo;
... ... @@ -29,4 +30,20 @@ public interface IProductPoolDetailsService {
*/
int deleteProductById(Integer id, Integer productPoolId);
/**
* 添加商品
* @param requestBo
* @return
* @throws PlatformException
*/
int saveProduct(ProductPoolDetailsRequestBo requestBo) throws PlatformException;
/**
* 更新排序值
* @param requestBo
* @return
* @throws PlatformException
*/
int updateProductOrderBy(ProductPoolDetailsRequestBo requestBo) throws PlatformException;
}
... ...
package com.yoho.ufo.service.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.yoho.ufo.dal.UfoProductDetailsMapper;
import com.yoho.ufo.dal.UfoProductPoolDetailMapper;
... ... @@ -53,15 +54,24 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService {
// 重复的商品id集合
List<String> repeatProductIds = new ArrayList<>();
//重复的排序值orderByNum集合
List<String> repeatOrderByProductIds = Lists.newArrayList();
// 导入的商品id
List<Integer> importProductIds = new ArrayList<>();
//导入的商品排序值orderBy
List<Integer> importOrderBys = Lists.newArrayList();
for (int i = 0; i < dataList.size(); i++) {
ProductPoolDetails productPoolDetails = (ProductPoolDetails) dataList.get(i);
// 商品id
Integer productId = productPoolDetails.getProductId();
Integer orderBy = productPoolDetails.getOrderBy();
if (importProductIds.contains(productId)) {
repeatProductIds.add(String.valueOf(productId));
}
if(importOrderBys.contains(orderBy)) {
repeatOrderByProductIds.add(String.valueOf(productId));
}
// 商品池id
productPoolDetails.setPoolId(poolId);
productPoolDetails.setCreateTime(DateUtil.getCurrentTimeSeconds());
... ... @@ -73,6 +83,10 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService {
return "上传失败!商品编码" + String.join("、 ", repeatProductIds) + "重复,请修改后重新上传!";
}
if (CollectionUtils.isNotEmpty(repeatOrderByProductIds)) {
return "上传失败!商品编码" + String.join("、 ", repeatOrderByProductIds) + "排序值重复,请修改后重新上传!";
}
// 每次查询数量
Integer queryCount = 100;
... ...
package com.yoho.ufo.service.impl;
import java.util.List;
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 com.google.common.collect.Lists;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.dal.UfoProductDetailsMapper;
import com.yoho.ufo.dal.UfoProductPoolDetailMapper;
import com.yoho.ufo.dal.UfoProductPoolMapper;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.model.goodsmanage.ProductDetails;
import com.yoho.ufo.model.goodsmanage.ProductPool;
import com.yoho.ufo.model.goodsmanage.ProductPoolDetails;
import com.yoho.ufo.service.IProductPoolDetailsService;
import com.yoho.ufo.util.OrikaUtils;
import com.yohobuy.ufo.model.common.PageModel;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo;
import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 商品池详情管理
... ... @@ -33,6 +41,9 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService
@Autowired
private UfoProductDetailsMapper ufoProductDetailsMapper;
@Autowired
private UfoProductPoolMapper ufoProductPoolMapper;
@Override
public PageResponseBO<ProductPoolDetailsResponseBo> getProductPoolDetailsPageList(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
LOGGER.info("getProductPoolDetailsPageList param = {}", productPoolDetailsRequestBo);
... ... @@ -53,4 +64,61 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService
LOGGER.info("deleteProductById productId = {}, productPoolId = {}", productId, productPoolId);
return ufoProductPoolDetailMapper.deleteProductPoolDetail(productPoolId, productId);
}
@Override
public int saveProduct(ProductPoolDetailsRequestBo requestBo) throws PlatformException {
//校验
if(null == requestBo) {
return 0;
}
checkParam(requestBo);
//插入数据库
ProductPoolDetails product = new ProductPoolDetails();
product.setPoolId(requestBo.getPoolId());
product.setProductId(requestBo.getProductId());
product.setOrderBy(requestBo.getOrderBy());
product.setCreateTime(DateUtil.getCurrentTimeSecond());
List<ProductPoolDetails> productList = Lists.newArrayList(product);
return ufoProductPoolDetailMapper.batchInsertProductPoolDetails(productList);
}
@Override
public int updateProductOrderBy(ProductPoolDetailsRequestBo requestBo) throws PlatformException {
//校验
if(null == requestBo || null == requestBo.getPoolId() || null == requestBo.getProductId()) {
return 0;
}
//查询是否已存在
List<ProductPoolDetails> productList = ufoProductPoolDetailMapper.selectByPoolIdAndOrderBy(requestBo.getPoolId(), requestBo.getOrderBy());
if(CollectionUtils.isNotEmpty(productList)) {
throw new PlatformException("该排序值在商品池中已存在!", 400);
}
//更新记录
return ufoProductPoolDetailMapper.updateProductOrderBy(requestBo.getPoolId(), requestBo.getProductId(), requestBo.getOrderBy());
}
private void checkParam(ProductPoolDetailsRequestBo requestBo) throws PlatformException{
Integer poolId = requestBo.getPoolId();
Integer productId = requestBo.getProductId();
Integer orderByNum = requestBo.getOrderBy();
//判断商品池是否存在
ProductPool pool = ufoProductPoolMapper.selectOneById(poolId);
if(null == pool) {
throw new PlatformException("添加失败!商品池不存在!", 400);
}
//判断商品是否存在
List<ProductPoolDetails> productList = ufoProductPoolDetailMapper.selectByPoolIdAndProductId(poolId, productId);
if(CollectionUtils.isNotEmpty(productList)) {
throw new PlatformException("添加失败!商品池中该商品已存在!", 400);
}
productList = ufoProductPoolDetailMapper.selectByPoolIdAndOrderBy(poolId, orderByNum);
if(CollectionUtils.isNotEmpty(productList)) {
throw new PlatformException("添加失败!商品池中该排序值已存在!", 400);
}
}
}
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<title>main</title>
<script src="/ufoPlatform/js/include.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div id="addDiv" region="center">
<div style="margin-left: 30px; margin-top: 20px;" >
<label>商品编码:</label><input type="text" id="productId" style="width:150px"/>
<label>排序值:</label><input type="text" id="orderBy" style="width:70px"/>
</div>
</div>
<script>
$(function () {
$("#productId").textbox({
prompt: "请输入"
});
$("#orderBy").textbox({
prompt: "请输入"
});
});
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -7,7 +7,7 @@
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
<div region="north" style="height: 150px">
<script>
document.write(addHead('商品池详情', ''));
</script>
... ... @@ -33,6 +33,7 @@
<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>
<a id="returnList" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">返回列表</a>
<a id="addProduct" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-add'">添加商品</a>
</div>
</div>
<div region="center">
... ... @@ -66,7 +67,14 @@
location.href = contextPath + "/html/commodityManage/commodityPoolManage/commodityPoolManage.html";
}
});
var poolId = parseURL(window.location.href).poolId;
$('#addProduct').linkbutton({
onClick: function () {
addPage(poolId);
}
});
$("#id").textbox({
prompt: "商品编码"
... ... @@ -120,6 +128,14 @@
width: 170,
align: "center"
}, {
title: "商品排序",
field: "orderBy",
width: 100,
align: "center",
formatter: function (value, rowData) {
return "<input type='text' value=" + value + " style='width:80px;text-align:center' onblur='updateOrderBy(" + rowData.id + "," + "this.value)'>";
}
}, {
title: "操作",
field: "operations",
width: 80,
... ... @@ -176,7 +192,6 @@
});
}
/**
* 提取出搜索参数
*/
... ... @@ -220,8 +235,103 @@
$("#productPoolDetailsTable").myDatagrid("load", param);
}
});
});
function addPage(poolId) {
var div = $("<div id='addDiv'>").appendTo($(document.body));
var url = contextPath + "/html/commodityManage/commodityPoolManage/addProduct.html";
$(div).myDialog({
width: "40%",
height: "30%",
title: "添加商品",
href: url,
modal: true,
collapsible: true,
cache: false,
buttons: [{
text: "取消",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
},{
text: "确认",
id: "saveBtn",
iconCls: "icon-save",
onClick: function () {
saveProduct(poolId);
}
}]
});
}
function saveProduct(poolId){
var productId = $("#productId").textbox("getValue");
var orderBy = $("#orderBy").textbox("getValue");
if(productId==''){
alert("商品编码不能为空!");
return;
}
if(orderBy==''){
alert("排序值不能为空!");
return;
}
if(!isIntNum(productId)){
alert("商品编码必须是全数字!")
return;
}
if(!isIntNum(orderBy)){
alert("排序值必须是全数字!")
return;
}
$.post(contextPath + "/productPoolDetails/saveProduct", {
poolId : poolId,
productId : productId,
orderBy : orderBy
}, function(data) {
if (data.code == 200) {
$("#addDiv").dialog("close");
$("#productPoolDetailsTable").datagrid("reload");
window.self.$.messager.show({
title : "提示",
msg : "添加商品成功!"
});
}else {
window.self.$.messager.alert("失败", data.message, "error");
}
});
}
function isIntNum(val){
var regPos = /^\d+$/; // 非负整数
if(regPos.test(val)){
return true;
}else{
return false;
}
}
function updateOrderBy(productId, orderBy){
var poolId = parseURL(window.location.href).poolId;
$.post(contextPath + "/productPoolDetails/updateProductOrderBy", {
poolId : poolId,
productId : productId,
orderBy : orderBy
}, function(data) {
if (data.code == 200) {
$("#productPoolDetailsTable").datagrid("reload");
window.self.$.messager.show({
title : "提示",
msg : "更新排序值成功!"
});
}else {
window.self.$.messager.alert("失败", data.message, "error");
}
});
}
</script>
</body>
... ...