Authored by mlge

Merge branch 'dev_grass_20190108' of http://git.yoho.cn/platform/platform-cms in…

…to dev_grass_20190108
package com.yohobuy.platform.grass.restapi;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.grass.service.IGrassArticleService;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
... ... @@ -12,9 +17,17 @@ public class GrassArticleController {
private static final Logger logger = LoggerFactory.getLogger(GrassArticleController.class);
@RequestMapping("/publishArticle")
public ApiResponse publishArticle(){
@Autowired
IGrassArticleService grassArticleService;
@RequestMapping("/publishArticle")
public ApiResponse publishArticle(@RequestBody GrassArticleReq req){
logger.info("grassArticle publishArticle begin, req is {}", req);
try {
grassArticleService.publishArticle(req);
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
return new ApiResponse.ApiResponseBuilder().build();
}
... ...
package com.yohobuy.platform.grass.restapi;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
* Created by yoho on 2019/1/10.
*/
@RestController
@RequestMapping("/grassHtml")
public class GrassHtmlContentController {
static Logger logger = LoggerFactory.getLogger(GrassHtmlContentController.class);
@RequestMapping("/getHtmlContent")
public byte[] getHtmlContent(@RequestBody String url, HttpServletRequest request){
logger.info("getContentHtml: request url is {}", url);
if(StringUtils.isEmpty(url)){
return null;
}
if(url.startsWith("/pfcms/")){
url = url.substring(7);
}
FileInputStream fis = null;
try{
String filePath = request.getServletContext().getRealPath(url);
fis = new FileInputStream(filePath);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
logger.info("getContentHtml: request url is {}, result bytes length is {}", url, fis.available());
return buffer;
}catch (Exception e){
logger.error("getContentHtml: output html bytes failed, url is {}, error is {}", url, e);
}finally {
if(fis != null){
try{
fis.close();
}catch (Exception e){
logger.error("getContentHtml: close inputStream failed, url is {}, error is {}", url, e);
}
}
}
return null;
}
}
... ...
package com.yohobuy.platform.grass.service;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
/**
*/
public interface IGrassArticleService {
void publishArticle(GrassArticleReq req) throws PlatformException;
}
... ...
package com.yohobuy.platform.grass.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.common.util.DateUtil;
import com.yohobuy.platform.dal.grass.IGrassArticleDao;
import com.yohobuy.platform.dal.grass.IGrassArticleImageDao;
import com.yohobuy.platform.dal.grass.IGrassArticleSknDao;
import com.yohobuy.platform.dal.grass.model.GrassArticle;
import com.yohobuy.platform.dal.grass.model.GrassArticleImage;
import com.yohobuy.platform.dal.grass.model.GrassArticleSkn;
import com.yohobuy.platform.grass.service.IGrassArticleService;
import com.yohobuy.platform.model.grass.request.GrassArticleReq;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
/**
*/
@Component
public class GrassArticleServiceImpl implements IGrassArticleService{
private static final Logger logger = LoggerFactory.getLogger(GrassArticleServiceImpl.class);
@Resource
private IGrassArticleDao grassArticleDao;
@Resource
private IGrassArticleImageDao grassArticleImageDao;
@Resource
private IGrassArticleSknDao grassArticleSknDao;
@Override
public void publishArticle(GrassArticleReq req) throws PlatformException {
logger.info("enter publishArticle, req is {}", req);
publishCheck(req);
GrassArticle article = new GrassArticle();
article.setAuthorUid(req.getArticleUid());
article.setArticleContent(req.getContent());
article.setPublishTime(DateUtil.getCurrentTimeSeconds());
article.setTopicId(req.getTopicId());
try{
grassArticleDao.insertArticleSeletive(article);
logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
}catch (Exception e){
logger.warn("insert grass article fail, uid is {}, e is {}",req.getArticleUid(), e );
throw new PlatformException("publish article failed", 402);
}
try{
List<GrassArticleImage> imageList = Lists.newArrayList();
String[] urls = req.getArticleImages().split(",");
for (String img: urls) {
GrassArticleImage image = new GrassArticleImage();
image.setArticleId(article.getId());
image.setImgSrc(img);
image.setCreateTime(DateUtil.getCurrentTimeSeconds());
imageList.add(image);
}
grassArticleImageDao.insertArticleImgs(imageList);
logger.info("insert grass article images success, ariticle id is {}, imageList size is {}", article.getId(), imageList.size());
}catch (Exception e){
logger.warn("insert article images fail,ariticle id is {}, e is {}",article.getId(), e );
}
try{
List<GrassArticleSkn> sknList = Lists.newArrayList();
String[] skns = req.getArticleSkns().split(",");
for (String skn: skns) {
GrassArticleSkn grassArticleSkn = new GrassArticleSkn();
grassArticleSkn.setArticleId(article.getId());
grassArticleSkn.setProductSkn(Integer.valueOf(skn));
grassArticleSkn.setCreateTime(DateUtil.getCurrentTimeSeconds());
sknList.add(grassArticleSkn);
}
grassArticleSknDao.insertArticleSkns(sknList);
logger.info("insert grass article skns success, ariticle id is {}, sknList size is {}", article.getId(), sknList.size());
}catch (Exception e){
logger.warn("insert article skns fail,ariticle id is {}, e is {}",article.getId(), e );
}
}
private void publishCheck(GrassArticleReq req) throws PlatformException {
if(req.getArticleUid() ==null){
logger.info("publishCheck uid is null");
throw new PlatformException("publish uid is null", 403);
}
if(StringUtils.isEmpty(req.getArticleImages())){
logger.info("publishCheck images is null");
throw new PlatformException("publish images is null", 403);
}
if(StringUtils.isEmpty(req.getArticleSkns())){
logger.info("publishCheck skn is null");
throw new PlatformException("publish skn is null", 403);
}
}
}
... ...
... ... @@ -24,7 +24,7 @@
<dependency>
<groupId>com.yoho.service.platform.model</groupId>
<artifactId>platform-service-model</artifactId>
<version>1.2.3-6.8.4-SNAPSHOT</version>
<version>1.2.3-6.8.5-grass-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhplatform</groupId>
... ... @@ -59,7 +59,7 @@
<dependency>
<groupId>com.yohobuy.platform</groupId>
<artifactId>platform-common</artifactId>
<version>1.0.3-6.8.4-SNAPSHOT</version>
<version>1.0.3-6.8.5-grass-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
... ...
... ... @@ -326,6 +326,9 @@ datasources:
- com.yohobuy.platform.dal.guang.IPlustarCategoryDAO
- com.yohobuy.platform.dal.guang.IRelationshipImageDAO
- com.yohobuy.platform.dal.guang.ResourceTabMapper
- com.yohobuy.platform.dal.grass.IGrassArticleDao
- com.yohobuy.platform.dal.grass.IGrassArticleImageDao
- com.yohobuy.platform.dal.grass.IGrassArticleSknDao
- com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO
- com.yohobuy.platform.dal.grass.IGrassLabelDAO
... ...
... ... @@ -325,6 +325,9 @@ datasources:
- com.yohobuy.platform.dal.guang.IPlustarCategoryDAO
- com.yohobuy.platform.dal.guang.IRelationshipImageDAO
- com.yohobuy.platform.dal.guang.ResourceTabMapper
- com.yohobuy.platform.dal.grass.IGrassArticleDao
- com.yohobuy.platform.dal.grass.IGrassArticleImageDao
- com.yohobuy.platform.dal.grass.IGrassArticleSknDao
- com.yohobuy.platform.dal.grass.IGrassLabelGroupDAO
- com.yohobuy.platform.dal.grass.IGrassLabelDAO
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="publishArticleForm" id="publishArticleForm" 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 >
<span style="color:red">*</span><label>手动搜索商品</label> <br>
<input id="skn" name="skn" class="easyui-textbox" style="width: 380px;"/>
<a id="searchBtn" class="go-search btn btn-primary">搜索商品</a>
</td>
</tr>
</table>
</div>
</form>
</div>
<div region="center" id="labelGroupList" style="margin-left: 20px">
<table id="labelGroupListTable"></table>
</div>
<script>
$("#searchBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
$("#labelGroupListTable").datagrid("load", {});
}
});
$("#skn").textbox({
prompt: "请输入skn,多个以逗号隔开"
});
$("#labelGroupListTable").myDatagrid({
fit: true,
fitColumns: true,
striped: true,
/*queryParams: {
rewardName: $("#rewardName1").textbox("getValue"),
status: $("#rewardstatus1").combobox("getValue"),
type: $("#rewardtype1").combobox("getValue")
},*/
// url: "http://admin.portal.yohobuy.com/yohosearch/search",
url: contextPath+"/labelGroupManage/getLabelGroupList",
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: "groupName",
width: 30,
align: "left"
},
{
title: "所属标签数",
field: "labelAmount",
width: 20,
align: "labelAmount"
}, {
title: "状态",
field: "status",
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
if(value == '0'){
return "关闭";
}
if(value == '1'){
return "开启";
}
}
}
]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: true,
onLoadSuccess: function (data) {
}
});
</script>
... ...
<!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: 100px;">
<script>
document.write(addHead('运营管理', '种草内容发布'));
</script>
</div>
<div region="center" id="labelGroupList" style="margin-left: 20px">
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="publishArticleForm" id="publishArticleForm" 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 >
<span style="color:red">*</span><label>选择用户</label> <br>
<input id="articleUid" name="articleUid" class="easyui-textbox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>文字内容</label> <br>
<input id="content" name="content" class="easyui-textbox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>选择话题</label> <br>
<input id="topic" name="topicId" class="easyui-combobox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 20px">
<td >
<span style="color:red">*</span><label>选择图片</label>
<a id="addImage" class="btn-default" >选择图片+</a>
<input id="imgs" name="articleImages" hidden="hidden"/>
</td>
</tr>
<tr style="height: 60px">
<td id="imgTd">
<div id="imageUpload">
</div>
</td>
</tr>
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>关联商品</label> <br>
<a id="addSkn" class="btn-default" onclick="getEditDialog()" >新增商品+</a>
<input id="skns" name="articleSkns" hidden="hidden"/>
</td>
<td>
<img id="good1" src="" hidden>
<img id="good2" src="" hidden>
</td>
</tr>
<tr>
<td height="50" valign="bottom">
<input class="btn-primary" type="button" onclick="submit()" value="保存"/>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
<script>
var count = 1;
$(function () {
$("#articleUid").textbox({
required: true,
missingMessage: "发布用户不能为空",
prompt: "请输入发布用户"
});
$("#content").textbox({
required: true,
missingMessage: "发布内容不能为空",
prompt: "请输入发布内容"
});
$("#topic").combobox({
prompt: "请选择话题"
});
$("#imageUpload").imageUpload({
width: 171,
height: 120,
realInputName: "url",
url: contextPath + '/fileupload/uploadFile',
queryParams: {
bucket: "activity"
},
onBeforeSubmit: function () {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误",data.message);
return "";
}
return data.data.url;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
$("#imageUpload").after('<div id="imageUpload1">\n' +
' </div>');
oo(1);
return false;
}
});
function oo(num){
if(count >8){
return
}
$("#imageUpload"+num).imageUpload({
width: 171,
height: 120,
realInputName: "url",
url: contextPath + '/fileupload/uploadFile',
queryParams: {
bucket: "activity"
},
onBeforeSubmit: function () {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误",data.message);
return "";
}
return data.data.url;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
var nnum = num+1;
$("#imageUpload"+num).after('<div id="imageUpload'+nnum+'"> </div>');
count = count+1;
oo(nnum);
return false;
}
});
}
});
function submit(){
$("#publishArticleForm").form("submit",{
url : "http://localhost:8088/platform/grassArticle/publishArticle",
onSubmit : function(param) {
if (!$("#publishArticleForm").form("validate")) {
return false;
}
var imgs = '';
$("input[name='url']").each(function(j,item){
var url = item.val();
if(imgs == ''){
imgs = url;
}else{
imgs = imgs + ","+url;
}
});
$("#imgs").val(imgs);
return true;
},
success : function(data) {
if (data) {
data = $.parseJSON(data);
if (data.code == 200) {
$.messager.alert("保存成功");
} else {
$.messager.alert("保存失败", data.message, "error");
}
} else {
$.messager.alert("保存失败", data.message, "error");
}
}
});
}
// 编辑分组
function getEditDialog(data){
var labelGroupList = $("<div id='labelGroupList'>").appendTo($(document.body));
var title = "新增商品";
var textVar = "确认";
var msgVar = "确认新增吗?";
window.self.paramObject.mkData = data;
$(labelGroupList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(labelGroupList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/article/chooseSkns.html"
});
}
</script>
</html>
\ No newline at end of file
... ...