Authored by chenly5

新增文章渠道页面

package com.yohobuy.platform.grass.restapi;
import com.yohobuy.platform.dal.grass.model.GrassChannel;
import com.yohobuy.platform.grass.service.IChannelService;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassChannelReq;
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;
import java.util.List;
@Controller
@RequestMapping("/grassChannelManage")
public class GrassChannelController {
private static final Logger logger = LoggerFactory.getLogger(GrassChannelController.class);
@Autowired
private IChannelService channelService;
@RequestMapping("/getGrassChannelList")
@ResponseBody
public ApiResponse getGrassChannelList( GrassChannelReq req){
PageResponseVO<GrassChannel> result = channelService.getGrassChannelList(req);
return new ApiResponse.ApiResponseBuilder().data(result).build();
}
@RequestMapping("/addUpGrassChannel")
@ResponseBody
public ApiResponse addUpGrassChannel( GrassChannelReq req){
logger.info("enter addUpGrassChannel,req={}",req);
return channelService.addUpChannel(req);
}
@RequestMapping("/updateGrassArticleChannel")
@ResponseBody
public ApiResponse updateGrassArticleChannel( GrassChannelReq req){
logger.info("enter updateGrassArticleChannel,req={}",req);
return channelService.updateGrassArticleChannel(req);
}
@RequestMapping("/getAllGrassChannelInfo")
@ResponseBody
public ApiResponse getAllGrassChannelInfo(){
List<GrassChannel> result = channelService.getAllGrassChannelInfo();
return new ApiResponse.ApiResponseBuilder().data(result).build();
}
}
... ...
package com.yohobuy.platform.grass.service;
import com.yohobuy.platform.dal.grass.model.GrassChannel;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassChannelReq;
import java.util.List;
/**
* Created by meiling.ge on 2019/1/8.
*/
public interface IChannelService {
PageResponseVO<GrassChannel> getGrassChannelList(GrassChannelReq req);
ApiResponse addUpChannel(GrassChannelReq req);
ApiResponse updateGrassArticleChannel(GrassChannelReq req);
List<GrassChannel> getAllGrassChannelInfo();
}
... ...
package com.yohobuy.platform.grass.service.impl;
import com.yohobuy.platform.common.util.DateUtil;
import com.yohobuy.platform.dal.grass.IGrassArticleChannelDao;
import com.yohobuy.platform.dal.grass.IGrassChannelDAO;
import com.yohobuy.platform.dal.grass.model.GrassArticleChannel;
import com.yohobuy.platform.dal.grass.model.GrassChannel;
import com.yohobuy.platform.grass.service.IChannelService;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassChannelReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class ChannelServiceImpl implements IChannelService {
private static final Logger logger = LoggerFactory.getLogger(ChannelServiceImpl.class);
@Resource
private IGrassChannelDAO grassChannelDAO;
@Resource
private IGrassArticleChannelDao grassArticleChannelDao;
@Override
public PageResponseVO<GrassChannel> getGrassChannelList(GrassChannelReq req) {
logger.info("enter getGrassChannelList req={} ", req);
String channelName = req.getChannelName();
Integer status = req.getStatus();
int total = grassChannelDAO.CountByCondition(channelName, status);
List<GrassChannel> grassChannels = new ArrayList<>();
if(total > 0){
grassChannels = grassChannelDAO.selectByPageCondition(channelName, status, req.getStart(), req.getSize());
}
PageResponseVO<GrassChannel> result = new PageResponseVO<>();
logger.info("getGrassChannelList success! req={}, total={}, data.size={}", req, total, grassChannels.size());
result.setList(grassChannels);
result.setTotal(total);
result.setPage(req.getPage());
result.setSize(req.getSize());
return result;
}
@Override
public ApiResponse addUpChannel(GrassChannelReq req) {
try{
logger.info("enter addUpChannel req={}", req);
Integer id = req.getId();
GrassChannel record = new GrassChannel();
record.setId(id);
record.setChannelName(req.getChannelName());
record.setStatus(req.getStatus());
if(id != null){//修改
record.setUpdateTime(DateUtil.getCurrentTimeSeconds());
grassChannelDAO.updateByPrimaryKeySelective(record);
logger.info("addUpChannel update success! req={}",req);
}else{//新增
record.setCreateTime(DateUtil.getCurrentTimeSeconds());
grassChannelDAO.insert(record);
logger.info("addUpChannel insert success! req={}",req);
}
return new ApiResponse.ApiResponseBuilder().build();
}catch (Exception e){
logger.warn("addUpChannel req={} error, e{}",req, e);
return new ApiResponse.ApiResponseBuilder().code(201).build();
}
}
@Override
public ApiResponse updateGrassArticleChannel(GrassChannelReq req) {
if(req.getArticleId() == null ){
logger.warn("updateGrassArticleChannel articleId is null req={}",req);
return new ApiResponse.ApiResponseBuilder().code(201).build();
}
grassArticleChannelDao.deleteByArticleId(req.getArticleId());
if(StringUtils.isNotEmpty(req.getChannelIds())){
String channelIds = req.getChannelIds();
String[] channelIdArray = channelIds.split(",");
List<GrassArticleChannel> grassArticleChannelList = new ArrayList<>(channelIdArray.length);
for(int i = 0;i<channelIdArray.length;i++){
GrassArticleChannel articleChannel = new GrassArticleChannel();
articleChannel.setArticleId(req.getArticleId());
articleChannel.setChannelId(Integer.valueOf(channelIdArray[i]));
articleChannel.setCreateTime(System.currentTimeMillis());
grassArticleChannelList.add(articleChannel);
}
grassArticleChannelDao.insertArticleChannels(grassArticleChannelList);
}
return new ApiResponse.ApiResponseBuilder().build();
}
@Override
public List<GrassChannel> getAllGrassChannelInfo(){
return grassChannelDAO.selectAll();
}
}
... ...
... ... @@ -144,6 +144,12 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
@Value("${search.server.address}")
private String searchServerAddress;
@Resource
private IGrassArticleChannelDao grassArticleChannelDao;
@Resource
private IGrassChannelDAO grassChannelDAO;
private final static String BLOCK_TEXT = "text";
private final static String BLOCK_IMAGE = "image";
private final static String BLOCK_LINK = "link";
... ... @@ -1692,6 +1698,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
List<GrassArticleProduct> grassArticlePoductList = grassArticleProductDao.selectByArticleIds(ids);
List<GrassArticleLabel> labelList = grassArticleLabelDao.selectByArticleIdList(ids);
List<GrassArticleTopic> grassArticleTopics = grassArticleTopicDao.selectByArticleIdList(ids);
List<GrassArticleChannel> channelList = grassArticleChannelDao.selectByArticleIdList(ids);
//用户身份信息
List<GrassVirtualGroup> virtualGroups = virtualGroupDao.selectAllWithStatus();
Map<Integer,String> virtualGroupMap = virtualGroups.stream().collect(Collectors.toMap(GrassVirtualGroup::getId,GrassVirtualGroup::getGroupName));
... ... @@ -1712,6 +1719,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
Map<Integer, String> linkMap = Maps.newHashMap();
Map<Integer, List<GrassArticleProductBo>> sknMap = Maps.newHashMap();
Map<Integer, List<JSONObject>> labelMap = buildLabelInfoMap(labelList);
Map<Integer, List<JSONObject>> channelMap = buildChannelInfoMap(channelList);
Map<Integer, GrassTopic> topicMap = buildTopicInfoMap(grassArticleTopics);
Map<Integer,JSONObject> videoMap = Maps.newHashMap();
//笔记的封面图
... ... @@ -1798,6 +1806,7 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
}*/
rspBo.setImgList(imgMap.get(article.getId()));
rspBo.setLabelList(labelMap.get(article.getId()));
rspBo.setChannelList(channelMap.get(article.getId()));
rspBo.setIsTop(article.getIsTop());
rspBo.setIsRecommend(article.getIsRecommend());
rspBo.setAuthorizeAccount(article.getAuthorizeAccount());
... ... @@ -1922,6 +1931,33 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
return labelRspMap;
}
public Map<Integer, List<JSONObject>> buildChannelInfoMap(List<GrassArticleChannel> articleChannelList) {
Map<Integer, List<JSONObject>> channelRspMap = Maps.newHashMap();
if (CollectionUtils.isEmpty(articleChannelList)) {
return channelRspMap;
}
List<Integer> channelIdList = articleChannelList.stream().map(GrassArticleChannel::getChannelId).distinct().collect(Collectors.toList());
List<GrassChannel> channelList = grassChannelDAO.selectBatchByIds(Sets.newHashSet(channelIdList));
Map<Integer, String> channelInfoMap = new HashMap<>();
channelList.forEach(grassChannel -> {
channelInfoMap.put(grassChannel.getId(), grassChannel.getChannelName());
}
);
articleChannelList.forEach(grassArticleChannel -> {
List<JSONObject> list = channelRspMap.get(grassArticleChannel.getArticleId());
if (list == null) {
list = Lists.newArrayList();
}
JSONObject rspBO = new JSONObject();
rspBO.put("id", grassArticleChannel.getChannelId());
rspBO.put("name", channelInfoMap.get(grassArticleChannel.getChannelId()));
list.add(rspBO);
channelRspMap.put(grassArticleChannel.getArticleId(), list);
});
return channelRspMap;
}
public Map<Integer, GrassTopic> buildTopicInfoMap(List<GrassArticleTopic> grassArticleTopicList) {
Map<Integer, GrassTopic> topicRspMap = Maps.newHashMap();
if (CollectionUtils.isEmpty(grassArticleTopicList)) {
... ...
... ... @@ -363,6 +363,10 @@ datasources:
- com.yohobuy.platform.dal.grass.ITopicRewardsRelateDAO
- com.yohobuy.platform.dal.grass.IGrassArticleExtraDao
- com.yohobuy.platform.dal.cms.IGrassFindGoodsDAO
- com.yohobuy.platform.dal.grass.IGrassChannelDAO
- com.yohobuy.platform.dal.grass.IGrassArticleChannelDao
yhb_promotion:
servers:
... ...
... ... @@ -361,6 +361,8 @@ datasources:
- com.yohobuy.platform.dal.grass.ITopicRewardsRelateDAO
- com.yohobuy.platform.dal.grass.IGrassArticleExtraDao
- com.yohobuy.platform.dal.cms.IGrassFindGoodsDAO
- com.yohobuy.platform.dal.grass.IGrassChannelDAO
- com.yohobuy.platform.dal.grass.IGrassArticleChannelDao
yhb_promotion:
servers:
... ...
... ... @@ -37,6 +37,20 @@
opacity: 0.9;
}
.tag{
display: block;
float: left;
padding: 2px 5px;
background: #1caf9a;
margin-right: 5px;
margin-bottom: 5px;
margin-top: 5px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 13px;
}
</style>
</head>
<!--<body class="easyui-layout" fit="true" style="overflow-y: scroll" >-->
... ... @@ -752,8 +766,8 @@
window.self.paramObject.mkData = data;
$(labelList).myDialog({
title: title,
width: "20%",
height: "30%",
width: "30%",
height: "40%",
resizable: false,
buttons: [{
id: "saveBtn",
... ... @@ -762,21 +776,23 @@
handler: function () {
$("#articleMarkForm").form("submit", {
url: serverContextPath + "/grassArticle/updateMarkFlag",
url: serverContextPath + "/grassChannelManage/updateGrassArticleChannel",
onSubmit: function (param) {
if (data != null) {
param.articleId = data.articleId;
}
if($("#articleMarkForm #box1").is(":checked")){
param.markFlag = "1";
}else{
param.markFlag = "0";
}
if($("#articleMarkForm #box2").is(":checked")){
param.markFindgoods = "1";
}else{
param.markFindgoods = "0";
}
var channelIds = '';
$("input[name='channelId']").each(function(j,item){
var id = item.value;
if(channelIds == ''){
channelIds = id;
}else{
channelIds = channelIds + ","+id;
}
});
$("#channelIds").val(channelIds);
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
... ...
<!DOCTYPE html>
<style>
.tag{
display: block;
float: left;
padding: 2px 5px;
background: #1caf9a;
margin-right: 5px;
margin-bottom: 5px;
margin-top: 5px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 13px;
}
</style>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="articleMarkForm" id="articleMarkForm" method="post">
<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>
达人搭配:<input type="checkbox" id = "box1"/>
</td>
<td>
发现好货:<input type="checkbox" id = "box2"/>
<td style="width:100%;">
<label style="font-size: 14px;">选择渠道</label> <br>
<input id="channelId" name="channelId" class="easyui-combobox" style="width:50%; "/><br>
<input id="channelIds" name="channelIds" hidden="hidden"/>
<div id="channelList">
</div>
</td>
</tr>
</table>
... ... @@ -22,14 +43,66 @@
$(function () {
$("#channelId").combobox({
prompt: "请选择渠道",
required: false,
selectOnNavigation : true,
valueField: 'id',
textField: 'channelName',
multiple:true,
url : serverContextPath + "/grassChannelManage/getAllGrassChannelInfo",
loadFilter: function (data) {
return defaultLoadFilter(data);
},
onChange:function (data) {
var arr = $(this).combobox("getValues");
var textarr = $(this).combobox("getData");
var channelList='';
for (var i=0; i<arr.length;i++){
var text = '';
for (var j=0; j< textarr.length;j++){
if(arr[i] == textarr[j].id){
text=textarr[j].channelName;
}
}
channelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp'
}
$("#channelList").html(channelList);
},
onLoadSuccess:function () {
var arr = $(this).combobox("getValues");
var textarr = $(this).combobox("getData");
var channelList='';
for (var i=0; i<arr.length;i++){
var text = '';
for (var j=0; j< textarr.length;j++){
if(arr[i] == textarr[j].id){
text=textarr[j].channelName;
}
}
channelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp'
}
$("#channelList").html(channelList);
}
});
var data = paramObject.mkData;
if(data.markFlag == '1'){
$("#box1").attr("checked",true);
if (data){
var channelIds = [];
if(data.channelList!=null && data.channelList.length>0){
for (var i=0;i<data.channelList.length;i++){
channelIds.push(data.channelList[i].id);
}
}
$("#channelId").combobox('setValues',channelIds);
}
if(data.markFindgoods == '1'){
$("#box2").attr("checked",true);
}
$(document).on("click", ".labelTag", function () {
var index = $(this).attr("data-index");
var arr = $("#channelId").combobox("getValues");
$("#channelId").combobox("unselect",arr[index]);
});
});
... ...
<!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="channelName" name="channelName" 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 () {
$("#channelName").textbox({
required: true,
missingMessage: "渠道名称不能为空",
prompt: "请输入渠道名称"
});
var data = paramObject.mkData;
if (data){
$("#channelName").textbox("setValue", data.channelName);
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);
}
}
});
</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="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: "请输入渠道名称"
});
$("#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", {
channelName: $("#labelNameParam").textbox("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: serverContextPath + "/grassChannelManage/getGrassChannelList",
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: "channelName",
width: 30,
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>";
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");
index = $(this).attr("index");
$.messager.confirm("确认", "确认删除该渠道吗?", function (flag) {
if(flag){
$.post(serverContextPath + "/grassChannelManage/deleteGrassChannel", {
id : close_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 ? "保存":"保存";
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: serverContextPath + "/grassChannelManage/addUpGrassChannel",
onSubmit: function (param) {
if(data != null){
param.id = data.id;
}
if (!$("#activityAddForm").form("validate")) {
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("失败", "操作失败", "error");
}
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(labelList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/channelManage/channelEdit.html"
});
}
});
</script>
</html>
\ No newline at end of file
... ...