提交 1c00243f authored 作者: 吴德鹏's avatar 吴德鹏

广告投放页优化之商品排序

上级 07f4d43f
...@@ -150,4 +150,24 @@ public class AdvertisementItemController { ...@@ -150,4 +150,24 @@ public class AdvertisementItemController {
} }
return R.error("操作失败"); return R.error("操作失败");
} }
/**
* 修改广告页商品
*/
@RequestMapping("/updateAdvertisementItem")
@ResponseBody
public R updateAdvertisementItem(@RequestParam Map<String, Object> map) {
int res = advertisementItemService.updateAdvertisementItem(map);
if (res > 0) {
return R.ok();
}
return R.error("操作失败");
}
@RequestMapping("/getAdSort")
@ResponseBody
public R getAdSort(@RequestParam Map<String, Object> map) {
Integer sort = advertisementItemService.getAdSort(map);
return R.ok().put("sort", sort);
}
} }
...@@ -17,11 +17,15 @@ public interface AdvertisementItemDao extends BaseDao<AdvertisementItemEntity> { ...@@ -17,11 +17,15 @@ public interface AdvertisementItemDao extends BaseDao<AdvertisementItemEntity> {
int deleteByItem(@Param("itemId") String itemId, @Param("adId") String adId); int deleteByItem(@Param("itemId") String itemId, @Param("adId") String adId);
int getMaxSort(); int getMaxSort(@Param("adId") String adId);
int setItemTop(@Param("top") Integer top, @Param("itemId") String itemId, @Param("adId") String adId); int setItemTop(@Param("top") Integer top, @Param("itemId") String itemId, @Param("adId") String adId);
AdvertisementItemEntity getAdItemById(@Param("itemId") String itemId, @Param("adId") String adId); AdvertisementItemEntity getAdItemById(@Param("itemId") String itemId, @Param("adId") String adId);
int updateAdItem(AdvertisementItemEntity advertisementItemEntity); int updateAdItem(AdvertisementItemEntity advertisementItemEntity);
int existItemSort(@Param("adId") String adId, @Param("sort") Integer sort);
} }
...@@ -8,7 +8,7 @@ import java.util.Date; ...@@ -8,7 +8,7 @@ import java.util.Date;
* 表名 advertisement_item * 表名 advertisement_item
* *
* @author lipengjun * @author lipengjun
* @date 2020-10-07 15:50:04 * @date 2020-10-13 17:30:21
*/ */
public class AdvertisementItemEntity implements Serializable { public class AdvertisementItemEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -22,13 +22,17 @@ public class AdvertisementItemEntity implements Serializable { ...@@ -22,13 +22,17 @@ public class AdvertisementItemEntity implements Serializable {
*/ */
private String itemId; private String itemId;
/** /**
* 置顶 * 是否置顶 0: 不置顶 1:置顶
*/ */
private Integer isTop; private Integer isTop;
/** /**
* 排序 * 排序
*/ */
private Integer sort; private Integer sort;
/**
* 商品添加时间
*/
private Date createTime;
/** /**
* 设置:广告投放ID * 设置:广告投放ID
...@@ -57,14 +61,14 @@ public class AdvertisementItemEntity implements Serializable { ...@@ -57,14 +61,14 @@ public class AdvertisementItemEntity implements Serializable {
return itemId; return itemId;
} }
/** /**
* 设置:置顶 * 设置:是否置顶 0: 不置顶 1:置顶
*/ */
public void setIsTop(Integer isTop) { public void setIsTop(Integer isTop) {
this.isTop = isTop; this.isTop = isTop;
} }
/** /**
* 获取:置顶 * 获取:是否置顶 0: 不置顶 1:置顶
*/ */
public Integer getIsTop() { public Integer getIsTop() {
return isTop; return isTop;
...@@ -82,4 +86,17 @@ public class AdvertisementItemEntity implements Serializable { ...@@ -82,4 +86,17 @@ public class AdvertisementItemEntity implements Serializable {
public Integer getSort() { public Integer getSort() {
return sort; return sort;
} }
/**
* 设置:商品添加时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:商品添加时间
*/
public Date getCreateTime() {
return createTime;
}
} }
...@@ -14,6 +14,15 @@ public class TbCfStationItemEntityExtends extends TbCfStationItemEntity implemen ...@@ -14,6 +14,15 @@ public class TbCfStationItemEntityExtends extends TbCfStationItemEntity implemen
private String uname; private String uname;
private Integer isTop; private Integer isTop;
private Integer sort; private Integer sort;
private Integer itemSort;
public Integer getItemSort() {
return itemSort;
}
public void setItemSort(Integer itemSort) {
this.itemSort = itemSort;
}
public String getUname() { public String getUname() {
return uname; return uname;
......
package com.platform.service; package com.platform.service;
import com.platform.entity.AdvertisementItemEntity; import com.platform.entity.AdvertisementItemEntity;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
...@@ -75,4 +76,8 @@ public interface AdvertisementItemService { ...@@ -75,4 +76,8 @@ public interface AdvertisementItemService {
int deleteByItem(String itemId, String adId); int deleteByItem(String itemId, String adId);
int setItemTop(String itemId, String adId); int setItemTop(String itemId, String adId);
int updateAdvertisementItem(@RequestParam Map<String, Object> map);
Integer getAdSort(Map<String, Object> map);
} }
...@@ -4,13 +4,16 @@ import com.platform.dao.AdvertisementItemDao; ...@@ -4,13 +4,16 @@ import com.platform.dao.AdvertisementItemDao;
import com.platform.entity.AdvertisementItemEntity; import com.platform.entity.AdvertisementItemEntity;
import com.platform.service.AdvertisementItemService; import com.platform.service.AdvertisementItemService;
import com.platform.utils.IdUtil; import com.platform.utils.IdUtil;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
/** /**
* Service实现类 * Service实现类
...@@ -23,6 +26,8 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService { ...@@ -23,6 +26,8 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService {
@Autowired @Autowired
private AdvertisementItemDao advertisementItemDao; private AdvertisementItemDao advertisementItemDao;
final ReentrantLock lock = new ReentrantLock();
@Override @Override
public AdvertisementItemEntity queryObject(String adId) { public AdvertisementItemEntity queryObject(String adId) {
return advertisementItemDao.queryObject(adId); return advertisementItemDao.queryObject(adId);
...@@ -40,9 +45,14 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService { ...@@ -40,9 +45,14 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService {
@Override @Override
public int save(AdvertisementItemEntity advertisementItem) { public int save(AdvertisementItemEntity advertisementItem) {
advertisementItem.setIsTop(0); // advertisementItem.setIsTop(0);
advertisementItem.setSort(0); lock.lock();
return advertisementItemDao.save(advertisementItem); int maxSort = advertisementItemDao.getMaxSort(advertisementItem.getAdId());
advertisementItem.setSort(++maxSort);
advertisementItem.setCreateTime(new Date());
int res = advertisementItemDao.save(advertisementItem);
lock.unlock();
return res;
} }
@Override @Override
...@@ -90,7 +100,7 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService { ...@@ -90,7 +100,7 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService {
if (count >= 60) { if (count >= 60) {
return -1; return -1;
} }
int maxSort = advertisementItemDao.getMaxSort(); int maxSort = advertisementItemDao.getMaxSort(null);
byId.setSort(++maxSort); byId.setSort(++maxSort);
byId.setIsTop(1); byId.setIsTop(1);
} else { } else {
...@@ -100,4 +110,73 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService { ...@@ -100,4 +110,73 @@ public class AdvertisementItemServiceImpl implements AdvertisementItemService {
} }
return advertisementItemDao.updateAdItem(byId); return advertisementItemDao.updateAdItem(byId);
} }
//商品排序需求
//1、要更改的序号与原序号相同,不做处理
//2、要更改的序号没被商品占有,直接修改序号
//3、将序号调至后面
//4、将序号调至前面
@Override
public int updateAdvertisementItem(Map<String, Object> map) {
int res = 0;
String itemId = map.get("itemId").toString();
String adId = map.get("adId").toString();
String sort = map.get("sort").toString();
Integer itemSort = Integer.parseInt(sort);
if (itemId == null || itemId == "") {
return res;
}
if (adId == null || adId == "") {
return res;
}
if (sort == null || sort == "") {
return res;
}
AdvertisementItemEntity byId = advertisementItemDao.getAdItemById(itemId, adId);
//情况1
String firstSort = String.valueOf(byId.getSort());
if (sort.equals(firstSort)) {
return res;
}
//情况2
int count = advertisementItemDao.existItemSort(adId, itemSort);
if (count == 0) {
byId.setSort(itemSort);
res = advertisementItemDao.updateAdItem(byId);
} else {
//要更换的序号被占有
//情况3
if (byId.getSort() < itemSort) {
} else {
//情况4
}
}
return res;
}
@Override
public Integer getAdSort(Map<String, Object> map) {
String itemId = map.get("itemId").toString();
String adId = map.get("adId").toString();
if (itemId == null || itemId == "") {
return null;
}
if (adId == null || adId == "") {
return null;
}
AdvertisementItemEntity byId = advertisementItemDao.getAdItemById(itemId, adId);
if (byId != null) {
Integer sort = byId.getSort();
if (sort != null) {
return byId.getSort();
}
}
return 0;
}
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<result property="itemId" column="item_id"/> <result property="itemId" column="item_id"/>
<result property="isTop" column="is_top"/> <result property="isTop" column="is_top"/>
<result property="sort" column="sort"/> <result property="sort" column="sort"/>
<result property="createTime" column="create_time"/>
</resultMap> </resultMap>
<select id="queryObject" resultType="com.platform.entity.AdvertisementItemEntity"> <select id="queryObject" resultType="com.platform.entity.AdvertisementItemEntity">
...@@ -15,7 +16,8 @@ ...@@ -15,7 +16,8 @@
`ad_id`, `ad_id`,
`item_id`, `item_id`,
`is_top`, `is_top`,
`sort` `sort`,
`create_time`
from advertisement_item from advertisement_item
where ad_id = #{id} where ad_id = #{id}
</select> </select>
...@@ -25,12 +27,18 @@ ...@@ -25,12 +27,18 @@
`ad_id`, `ad_id`,
`item_id`, `item_id`,
`is_top`, `is_top`,
`sort` `sort`,
`create_time`
from advertisement_item from advertisement_item
where ad_id = #{adId} where ad_id = #{adId}
and item_id=#{itemId} and item_id=#{itemId}
</select> </select>
<select id="existItemSort" resultType="int">
select count(1) from advertisement_item where ad_id = #{adId} and sort=#{sort}
</select>
<select id="getAdItemCount" resultType="int"> <select id="getAdItemCount" resultType="int">
select count(1) from advertisement_item where ad_id = #{adId} select count(1) from advertisement_item where ad_id = #{adId}
<if test="itemId != null and itemId.trim() != ''"> <if test="itemId != null and itemId.trim() != ''">
...@@ -43,7 +51,10 @@ ...@@ -43,7 +51,10 @@
</update> </update>
<select id="getMaxSort" resultType="int"> <select id="getMaxSort" resultType="int">
select max(sort) from advertisement_item select IFNULL(max(sort),0) from advertisement_item
<if test="adId != null and adId.trim() != ''">
where ad_id=#{adId}
</if>
</select> </select>
<delete id="deleteByItem"> <delete id="deleteByItem">
...@@ -55,7 +66,8 @@ ...@@ -55,7 +66,8 @@
`ad_id`, `ad_id`,
`item_id`, `item_id`,
`is_top`, `is_top`,
`sort` `sort`,
`create_time`
from advertisement_item from advertisement_item
WHERE 1=1 WHERE 1=1
<if test="name != null and name.trim() != ''"> <if test="name != null and name.trim() != ''">
...@@ -87,12 +99,14 @@ ...@@ -87,12 +99,14 @@
`ad_id`, `ad_id`,
`item_id`, `item_id`,
`is_top`, `is_top`,
`sort`) `sort`,
`create_time`)
values( values(
#{adId}, #{adId},
#{itemId}, #{itemId},
#{isTop}, #{isTop},
#{sort}) #{sort},
#{createTime})
</insert> </insert>
<update id="update" parameterType="com.platform.entity.AdvertisementItemEntity"> <update id="update" parameterType="com.platform.entity.AdvertisementItemEntity">
...@@ -100,7 +114,8 @@ ...@@ -100,7 +114,8 @@
<set> <set>
<if test="itemId != null">`item_id` = #{itemId},</if> <if test="itemId != null">`item_id` = #{itemId},</if>
<if test="isTop != null">`is_top` = #{isTop},</if> <if test="isTop != null">`is_top` = #{isTop},</if>
<if test="sort != null">`sort` = #{sort}</if> <if test="sort != null">`sort` = #{sort},</if>
<if test="createTime != null">`create_time` = #{createTime}</if>
</set> </set>
where ad_id = #{adId} where ad_id = #{adId}
</update> </update>
......
...@@ -95,14 +95,14 @@ ...@@ -95,14 +95,14 @@
t.goodstwotype_title title, t.goodstwotype_title title,
o.goodstype_title goodtype, o.goodstype_title goodtype,
a.is_top, a.is_top,
a.sort a.sort itemSort
from advertisement_item a from advertisement_item a
left join tb_cf_station_item i on i.item_id=a.item_id left join tb_cf_station_item i on i.item_id=a.item_id
left JOIN tb_cf_goodstype o ON o.goodstype_id = i.item_category left JOIN tb_cf_goodstype o ON o.goodstype_id = i.item_category
left JOIN tb_cf_goodstwotype t ON i.item_categorytwo=t.goodstwotype_id left JOIN tb_cf_goodstwotype t ON i.item_categorytwo=t.goodstwotype_id
left JOIN tb_cf_descripiton d ON i.item_descrition_id=d.descripition_id left JOIN tb_cf_descripiton d ON i.item_descrition_id=d.descripition_id
where a.ad_id=#{adId} and i.enable_flag!=0 where a.ad_id=#{adId}
order by a.is_top desc,a.sort desc,i.create_time desc order by itemSort asc
<if test="offset != null and limit != null"> <if test="offset != null and limit != null">
limit #{offset}, #{limit} limit #{offset}, #{limit}
</if> </if>
......
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
<Form-item label="状态" prop="status"> <Form-item label="状态" prop="status">
<!--<i-input v-model="advertisement.status" placeholder="状态" style="width: 800px"/>--> <!--<i-input v-model="advertisement.status" placeholder="状态" style="width: 800px"/>-->
<i-select v-model="advertisement.status" placeholder="请选择" style="width: 800px"/> <i-select v-model="advertisement.status" placeholder="请选择" style="width: 800px"/>
<i-option v-for="v in versionList" :value="v.value">{{v.label}}</i-option> <i-option v-for="v in versionList" :value="v.value">{{v.label}}</i-option>
</i-select> </i-select>
</Form-item> </Form-item>
<!--<Form-item label="banner图" prop="picture"> <!--<Form-item label="banner图" prop="picture">
...@@ -288,6 +288,18 @@ ...@@ -288,6 +288,18 @@
</Form-item> </Form-item>
</i-form> </i-form>
</Card> </Card>
<Modal
v-model="modal1"
title="商品排序"
@on-ok="deal"
width="600px"
@on-cancel="cancel">
<i-form ref="formValidate" :model="advertisement" :rules="ruleValidate" :label-width="80">
<Form-item label="序号" prop="sort">
<i-input v-model="sort" placeholder="序号" style="width: 160px"/>
</Form-item>
</i-form>
</Modal>
</div> </div>
<script src="${rc.contextPath}/js/sys/advertisement.js?_${date.systemTime}"></script> <script src="${rc.contextPath}/js/sys/advertisement.js?_${date.systemTime}"></script>
......
...@@ -18,6 +18,9 @@ $(function () { ...@@ -18,6 +18,9 @@ $(function () {
let vm = new Vue({ let vm = new Vue({
el: '#rrapp', el: '#rrapp',
data: { data: {
itemId: 0,
modal1: false,
sort: '',
versionList: [ versionList: [
{ {
value: 1, value: 1,
...@@ -130,6 +133,44 @@ let vm = new Vue({ ...@@ -130,6 +133,44 @@ let vm = new Vue({
} }
}, },
methods: { methods: {
sortItem(e) {
let id = getSelectedRow("#jqGrid");
vm.modal1 = true;
vm.itemId = e;
Ajax.request({
url: "../advertisementitem/getAdSort?itemId=" + e + '&adId=' + id,
type: "POST",
contentType: "application/json",
successCallback: function (res) {
vm.sort = res.sort
}
});
},
deal() {
let id = getSelectedRow("#jqGrid");
let itemSort;
console.log('商品ID', vm.itemId)
console.log('广告ID', id)
itemSort = parseInt(vm.sort);
console.log('序号', itemSort)
Ajax.request({
url: "../advertisementitem/updateAdvertisementItem?itemId=" + vm.itemId + '&adId=' + id + '&sort=' + vm.sort,
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.btn_Search(id);
vm.modal1 = false;
});
}
});
},
cancel() {
vm.modal1 = false;
},
delItem(itemId) { delItem(itemId) {
let id = getSelectedRow("#jqGrid"); let id = getSelectedRow("#jqGrid");
confirm('确定要删除选中的记录?', function () { confirm('确定要删除选中的记录?', function () {
...@@ -255,6 +296,7 @@ let vm = new Vue({ ...@@ -255,6 +296,7 @@ let vm = new Vue({
url: '../advertisement/getAdvertisementItem?adId=' + id, url: '../advertisement/getAdvertisementItem?adId=' + id,
colModel: [ colModel: [
{label: 'itemId', name: 'itemId', key: true, index: 'item_id', hidden: true}, {label: 'itemId', name: 'itemId', key: true, index: 'item_id', hidden: true},
{label: '序号', name: 'itemSort', index: 'itemSort', width: 100},
{label: '商品图片', name: 'itemImg', index: 'item_img', width: 100, formatter: imageFormat}, {label: '商品图片', name: 'itemImg', index: 'item_img', width: 100, formatter: imageFormat},
{label: '商品编号', name: 'itemCode', index: 'item_code', width: 160}, {label: '商品编号', name: 'itemCode', index: 'item_code', width: 160},
{label: '商品名称', name: 'itemName', index: 'item_name', width: 160}, {label: '商品名称', name: 'itemName', index: 'item_name', width: 160},
...@@ -269,18 +311,16 @@ let vm = new Vue({ ...@@ -269,18 +311,16 @@ let vm = new Vue({
{label: '商品二级分类', name: 'title', index: 'title', width: 120}, {label: '商品二级分类', name: 'title', index: 'title', width: 120},
{label: '商品品名', name: 'dname', index: 'itemDescritionId', width: 120}, {label: '商品品名', name: 'dname', index: 'itemDescritionId', width: 120},
{ {
label: '操作', index: 'operate', width: 120, formatter: function (value, grid, rows) { label: '操作', index: 'operate', width: 160, formatter: function (value, grid, rows) {
if (rows.isTop == 1) { return '<span class="label label-info pointer" onclick="vm.delItem(\'' + rows.itemId + '\')">移除</span>&nbsp;&nbsp;' +
return '<span class="label label-danger pointer" onclick="vm.itemTop(\'' + rows.itemId + '\')">取消置顶</span>&nbsp;&nbsp;' + '<span class="label label-info pointer" onclick="vm.sortItem(\'' + rows.itemId + '\')">排序</span>&nbsp;&nbsp;'
'<span class="label label-info pointer" onclick="vm.delItem(\'' + rows.itemId + '\')">移除</span>&nbsp;&nbsp;'
}
return '<span class="label label-info pointer" onclick="vm.itemTop(\'' + rows.itemId + '\')">置顶</span>&nbsp;&nbsp;' +
'<span class="label label-info pointer" onclick="vm.delItem(\'' + rows.itemId + '\')">移除</span>&nbsp;&nbsp;'
} }
} } // beforeSelectRow: beforeSelectRow,
], ],
// beforeSelectRow: beforeSelectRow, multiboxonly: true
}); });
}); });
vm.btn_Search(id); vm.btn_Search(id);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论