Authored by mlge

新增--标签管理

package com.yohobuy.platform.grass.restapi;
import com.yohobuy.platform.grass.service.IlabelService;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassLabelReq;
import com.yohobuy.platform.model.grass.response.GrassLabelBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by meiling.ge on 2019/1/10.
*/
@Controller
@RequestMapping("/grassLabelManage")
public class GrassLabelController {
private static final Logger logger = LoggerFactory.getLogger(GrassLabelController.class);
@Autowired
private IlabelService ilabelService;
@RequestMapping("/getGrassLabelList")
@ResponseBody
public ApiResponse getGrassLabelList(GrassLabelReq req){
PageResponseVO<GrassLabelBo> result = ilabelService.getGrassLabelList(req);
return new ApiResponse.ApiResponseBuilder().data(result).build();
}
@RequestMapping("/addUpGrassLabel")
@ResponseBody
public ApiResponse addUpGrassLabel(GrassLabelReq req){
logger.info("enter getRedpacketList,req={}",req);
ilabelService.addUpLabel(req);
return new ApiResponse.ApiResponseBuilder().build();
}
@RequestMapping("/deleteGrassLabel")
@ResponseBody
public ApiResponse deleteGrassLabel(GrassLabelReq req){
logger.info("enter updatePacketStatus,req = {}", req);
ilabelService.deleteLabel(req);
return new ApiResponse.ApiResponseBuilder().build();
}
}
... ...
... ... @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* Created by meiling.ge on 2019/1/8.
*/
... ... @@ -45,7 +47,23 @@ public class LabelGroupController {
@ResponseBody
public ApiResponse deleteLabelGroup(LabelGroupReq req){
logger.info("enter updatePacketStatus,req = {}", req);
labelGroupService.deleteLabelGroup(req);
int flag = labelGroupService.deleteLabelGroup(req);
if(flag == 2){
return new ApiResponse.ApiResponseBuilder().code(403).message("该分组下存在标签,删除失败!").build();
}
return new ApiResponse.ApiResponseBuilder().build();
}
/**
* 标签页 --标签分组下拉列表
* @return
*/
@RequestMapping("/getAllLabelGroupInfo")
@ResponseBody
public ApiResponse getAllLabelGroupInfo(){
logger.info("enter getAllLabelGroupInfo");
List<LabelGroupBo> data = labelGroupService.getAllLabelGroupInfo();
return new ApiResponse.ApiResponseBuilder().data(data).build();
}
}
... ...
... ... @@ -5,6 +5,8 @@ import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.LabelGroupReq;
import com.yohobuy.platform.model.grass.response.LabelGroupBo;
import java.util.List;
/**
* Created by meiling.ge on 2019/1/8.
*/
... ... @@ -14,5 +16,7 @@ public interface IlabelGroupService {
void addUpLabelGroup(LabelGroupReq req);
void deleteLabelGroup(LabelGroupReq req);
int deleteLabelGroup(LabelGroupReq req);
List<LabelGroupBo> getAllLabelGroupInfo();
}
... ...
package com.yohobuy.platform.grass.service;
import com.yohobuy.platform.dal.grass.model.GrassLabel;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassLabelReq;
import com.yohobuy.platform.model.grass.request.LabelGroupReq;
import com.yohobuy.platform.model.grass.response.GrassLabelBo;
import com.yohobuy.platform.model.grass.response.LabelGroupBo;
import java.util.List;
/**
* Created by meiling.ge on 2019/1/8.
*/
public interface IlabelService {
PageResponseVO<GrassLabelBo> getGrassLabelList(GrassLabelReq req);
void addUpLabel(GrassLabelReq req);
void deleteLabel(GrassLabelReq req);
}
... ...
... ... @@ -67,9 +67,27 @@ public class LabelGroupServiceImpl implements IlabelGroupService {
}
@Override
public void deleteLabelGroup(LabelGroupReq req) {
public int deleteLabelGroup(LabelGroupReq req) {
logger.info("enter deleteLabelGroup id={}", req.getId());
grassLabelGroupDAO.deleteByPrimaryKey(req.getId());
Integer id = req.getId();
LabelGroup labelGroup = grassLabelGroupDAO.selectByPrimaryKey(id);
if(labelGroup.getLabelAmount() > 0){
return 2;
}
grassLabelGroupDAO.deleteByPrimaryKey(id);
logger.info("deleteLabelGroup success! id={}", req.getId());
return 1;
}
/**
* 标签页下拉列表
* @return
*/
@Override
public List<LabelGroupBo> getAllLabelGroupInfo() {
List<LabelGroup> labelGroups = grassLabelGroupDAO.selectLabelGroupWithStatus();
List<LabelGroupBo> result = BeanTool.copyList(labelGroups, LabelGroupBo.class);
return result;
}
}
... ...
package com.yohobuy.platform.grass.service.impl;
import com.yohobuy.platform.common.util.BeanTool;
import com.yohobuy.platform.common.util.DateUtil;
import com.yohobuy.platform.dal.grass.IGrassLabelDAO;
import com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO;
import com.yohobuy.platform.dal.grass.model.GrassLabel;
import com.yohobuy.platform.dal.grass.model.LabelGroup;
import com.yohobuy.platform.grass.service.IlabelGroupService;
import com.yohobuy.platform.grass.service.IlabelService;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassLabelReq;
import com.yohobuy.platform.model.grass.request.LabelGroupReq;
import com.yohobuy.platform.model.grass.response.GrassLabelBo;
import com.yohobuy.platform.model.grass.response.LabelGroupBo;
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;
/**
* Created by meiling.ge on 2019/1/8.
*/
@Service
public class LabelServiceImpl implements IlabelService {
private static final Logger logger = LoggerFactory.getLogger(LabelServiceImpl.class);
@Autowired
private IGrassLabelDAO grassLabelDAO;
@Autowired
private IGrassLabelGroupDAO labelGroupDAO;
@Override
public PageResponseVO<GrassLabelBo> getGrassLabelList(GrassLabelReq req) {
logger.info("enter getGrassLabelList req={} ", req);
String labelName = req.getLabelName();
Integer groupId = req.getGroupId();
Integer status = req.getStatus();
int total = grassLabelDAO.CountByCondition(labelName, groupId, status);
List<GrassLabel> grassLabels = new ArrayList<>();
if(total > 0){
grassLabels = grassLabelDAO.selectByPageCondition(labelName, groupId, status, req.getStart(), req.getSize());
}
List<GrassLabelBo> data = BeanTool.copyList(grassLabels,GrassLabelBo.class);
PageResponseVO<GrassLabelBo> result = new PageResponseVO<>();
logger.info("getGrassLabelList success! req={}, total={}, data.size={}", req, total, data.size());
result.setList(data);
result.setTotal(total);
result.setPage(req.getPage());
result.setSize(req.getSize());
return result;
}
@Override
public void addUpLabel(GrassLabelReq req) {
logger.info("enter addUpLabel req={}", req);
Integer id = req.getId();
GrassLabel record = new GrassLabel();
record.setId(id);
record.setLabelName(req.getLabelName());
record.setGroupId(req.getGroupId());
record.setStatus(req.getStatus());
if(id != null){//修改
record.setUpdateTime(DateUtil.getCurrentTimeSeconds());
GrassLabel oldGrassLabel = grassLabelDAO.selectByPrimaryKey(id);
if(oldGrassLabel.getGroupId().intValue() != req.getGroupId().intValue() ){//分组改变了,对应的分组的统计需要改下
labelGroupDAO.updateLabelNum(oldGrassLabel.getGroupId(), false);//减1
labelGroupDAO.updateLabelNum(req.getGroupId(), true);//加1
}
grassLabelDAO.updateByPrimaryKeySelective(record);
logger.info("addUpLabel update success! req={},oldGrassLabel={}",req,oldGrassLabel);
}else{//新增
record.setCreateTime(DateUtil.getCurrentTimeSeconds());
grassLabelDAO.insert(record);
//组对应的数量加1
labelGroupDAO.updateLabelNum(req.getGroupId(), true);
logger.info("addUpLabel insert success! req={}",req);
}
}
@Override
public void deleteLabel(GrassLabelReq req) {
logger.info("enter deleteLabel req={} ",req);
grassLabelDAO.deleteByPrimaryKey(req.getId());
labelGroupDAO.updateLabelNum(req.getGroupId(),false);
}
}
... ...
... ... @@ -327,6 +327,7 @@ datasources:
- com.yohobuy.platform.dal.guang.IRelationshipImageDAO
- com.yohobuy.platform.dal.guang.ResourceTabMapper
- com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO
- com.yohobuy.platform.dal.grass.IGrassLabelDAO
yhb_promotion:
servers:
... ...
... ... @@ -326,6 +326,7 @@ datasources:
- com.yohobuy.platform.dal.guang.IRelationshipImageDAO
- com.yohobuy.platform.dal.guang.ResourceTabMapper
- com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO
- com.yohobuy.platform.dal.grass.IGrassLabelDAO
yhb_promotion:
servers:
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="activityAddForm" id="activityAddForm" method="post" enctype="multipart/form-data">
<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 >
<span style="color:red">*</span><label>标签名称</label> <br>
<input id="labelName" name="labelName" class="easyui-textbox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td >
<span style="color:red">*</span><label>分组名称</label> <br>
<input id="groupId" name="groupId" class="easyui-textbox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>标签状态</label> <br>
<input type="radio" value="1" checked name="status" style="width:30px">开启</input>
<input type="radio" value="0" name="status" style="width:30px">关闭</input>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
$("#labelName").textbox({
required: true,
missingMessage: "标签名称不能为空",
prompt: "请输入标签名称"
});
$("#groupId").combobox({
valueField : "id",
textField : "groupName",
required:false,
prompt: "请选择分组",
url : contextPath + "/labelGroupManage/getAllLabelGroupInfo",
loadFilter: function (data) {
var data = defaultLoadFilter(data);
data.unshift({'id': '', 'groupName': '--请选择分组--'});
return data;
}
});
var data = paramObject.mkData;
if (data){
$("#labelName").textbox("setValue", data.labelName);
if(data.status == 0){
$(":radio[name='status'][value='0']").prop("checked",true);
}else if(data.status == 1){
$(":radio[name='status'][value='1']").prop("checked",true);
}
$("#groupId").combobox('setValue', data.groupId);
}
});
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Yoho!Buy运营平台</title>
<script src="/pfcms/js/include.js"></script>
<script src="/pfcms/js/ajaxfileupload.js"></script>
<style>
.btn-long {
width: 120px;
height: 37px;
line-height: 37px;
font-size: 15px;
color: white;
border-radius: 5px;
display: inline-block;
cursor: pointer;
text-align: center;
}
.btn-long:hover {
opacity: 0.9;
}
</style>
</head>
<body class="easyui-layout" >
<div region="north" style="height: 200px;">
<script>
document.write(addHead('运营管理', '标签管理'));
</script>
<div style="margin-left: 20px;margin-top: 10px">
<input class="easyui-textbox" id="labelNameParam" style="width: 140px">
</input>
<input class="easyui-combobox" id="groupIdParam" >
</input>
<input class="easyui-combobox" id="statusParam" >
</input>
<a id="searchBtn" class="btn-info">查询</a>
<!--<a id="addActivityBtn" class="btn-success">新增</a>-->
<a id="allBtn" class="btn-info">全部</a>
</div>
<div style="margin-left: 20px;margin-top: 10px">
<a id="addBtn" class="btn-long" style="background-color: #5CB85C;">+新建标签</a>
</div>
</div>
<div region="center" id="labelList" style="margin-left: 20px">
<table id="labelListTable"></table>
</div>
</body>
<script>
$(function() {
//用于页面刷新后的数据行定位
var index ="";
$("#allBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
$("#labelListTable").datagrid("load", {});
}
});
$("#labelNameParam").textbox({
required:false,
prompt: "请输入标签名称"
});
$("#groupIdParam").combobox({
valueField : "id",
textField : "groupName",
required:false,
prompt: "请选择分组",
url : contextPath + "/labelGroupManage/getAllLabelGroupInfo",
loadFilter: function (data) {
var data = defaultLoadFilter(data);
data.unshift({'id': '', 'groupName': '--请选择分组--'});
return data;
}
});
$("#statusParam").combobox({
valueField : "value",
textField : "text",
required:false,
prompt: "请选择状态",
data:[{text:"请选择状态",value:""},{text:"开启",value:"1"},{text:"关闭",value:"0"}]
});
$("#searchBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
$("#labelListTable").datagrid("load", {
labelName: $("#labelNameParam").textbox("getValue"),
groupId:$("#groupIdParam").combobox("getValue"),
status: $("#statusParam").combobox("getValue")
});
}
});
$("#addBtn").click(function () {
getEditDialog(null);
});
// 检索按钮
$("#labelListTable").myDatagrid({
fit: true,
fitColumns: true,
striped: true,
/*queryParams: {
rewardName: $("#rewardName1").textbox("getValue"),
status: $("#rewardstatus1").combobox("getValue"),
type: $("#rewardtype1").combobox("getValue")
},*/
url: contextPath + "/grassLabelManage/getGrassLabelList",
method: 'POST',
loadFilter: function (data) {
var tmp = defaultLoadFilter(data);
tmp.rows = tmp.list;
return tmp;
},
columns: [[
{
title: "ID",
field: "id",
width: 15,
align: "center"
},
{
title: "标签名称",
field: "labelName",
width: 30,
align: "left"
},
{
title: "标签分组",
field: "groupName",
width: 20,
align: "left"
}, {
title: "状态",
field: "status",
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
if(value == '0'){
return "关闭";
}
if(value == '1'){
return "开启";
}
}
},
{
title: "操作",
field: "ddg",
width: 40,
align: "center",
formatter: function (value, rowData, rowIndex) {
var str = "<a role='edit' dataId='"+ rowData.id +"' style='margin-left:10px;background-color: #31b0d5' index='"+ rowIndex +"'>编辑</a>";
str += "<a role='close' style='margin-left:10px;background-color: #ffa951' dataId='"+ rowData.id +"' index='"+ rowIndex +"' groupId='"+rowData.groupId+"'>删除</a>";
return str;
}
}
]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: true,
onLoadSuccess: function (data) {
if(index != ""){
$(this).datagrid("scrollTo",index);
index = "";
}
$(this).datagrid("getPanel").find("a[role='close']").linkbutton({
iconCls: "icon-redo",
onClick: function () {
var close_id = $(this).attr("dataId");
var group_id = $(this).attr("groupId");
index = $(this).attr("index");
$.messager.confirm("确认", "确认删除该分组吗?", function (flag) {
if(flag){
$.post(contextPath + "/grassLabelManage/deleteGrassLabel", {
id : close_id,
groupId: group_id
}, function(data) {
if (data.code == CODE_SUCCESS) {
$("#labelListTable").datagrid("reload");
window.self.$.messager.show({
title : "提示",
msg : "删除成功!"
});
} else {
window.self.$.messager.alert("失败", data.message, "error");
}
});
}
});
}
});
// 编辑
$(this).datagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls : "icon-edit",
onClick : function() {
index = $(this).attr("index");
var row = $("#labelListTable").datagrid('getData').rows[index];
getEditDialog(row);
}
});
}
});
// 编辑分组
function getEditDialog(data){
var labelList = $("<div id='labelList'>").appendTo($(document.body));
var title = data == null ? "新建标签":"修改标签";
var textVar = data == null ? "保存":"保存";
var msgVar = data == null ? "确认新增标签吗?":"确认保存标签吗?";
window.self.paramObject.mkData = data;
$(labelList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
$("#activityAddForm").form("submit", {
url: contextPath + "/grassLabelManage/addUpGrassLabel",
onSubmit: function (param) {
if(data != null){
param.id = data.id;
}
// param.status = $("input[name='statusRadio'][checked]").val();
if (!$("#activityAddForm").form("validate")) {
return false;
}
var groupId = $("#groupId").combobox('getValue');
if(groupId == null || groupId == ""){
$.messager.alert("info", "提交失败,请选择分组", "info");
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(labelList).dialog("close");
$("#labelListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(labelList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/labelManage/labelEdit.html",
});
}
});
</script>
</html>
\ No newline at end of file
... ...