Merge remote-tracking branch 'origin/master'

This commit is contained in:
sgjj 2019-12-26 14:53:30 +08:00
commit eeff1573b1
9 changed files with 422 additions and 39 deletions

View File

@ -1,46 +1,32 @@
package net.mingsoft.cms.action.web;
import java.util.List;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import net.mingsoft.base.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.BindingResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.ModelMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.base.util.JSONObject;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.base.filter.DateValueFilter;
import net.mingsoft.base.filter.DoubleValueFilter;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.annotation.LogAnn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.ContentEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 文章管理控制层
* @author 铭飞开发团队
@ -186,7 +172,7 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
}
/**
* @param content 文章实体
* @param contents 文章实体
*/
@ApiOperation(value = "批量删除文章列表接口")
@PostMapping("/delete")
@ -255,6 +241,26 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
return ResultData.build().success(content);
}
@ApiOperation(value = "查看文章点击数")
@ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
@GetMapping(value = "/{contentId}/hit")
@ResponseBody
public void hit(@PathVariable @ApiIgnore int contentId, HttpServletRequest request, HttpServletResponse response){
if(contentId<=0){
this.outString(response, "document.write(0)");
return;
}
ContentEntity content = (ContentEntity)contentBiz.getEntity(contentId);
if(content == null){
this.outString(response, "document.write(0)");
return;
}
if(content.getAppId() == null || content.getAppId() != BasicUtil.getAppId()){
this.outString(response, "document.write(0)");
return;
}
this.outString(response, "document.write(" + content.getContentHit() + ")");
return;
}
}

View File

@ -0,0 +1,81 @@
package net.mingsoft.cms.aop;
import net.mingsoft.basic.aop.BaseAop;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.biz.IHistoryLogBiz;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.cms.entity.HistoryLogEntity;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author 铭飞开源团队
* @date 2019/12/23
*/
@Component
@Aspect
public class CotentAop extends BaseAop {
/**
* 注入文章业务
*/
@Autowired
private IContentBiz contentBiz;
/**
* 注入浏览记录业务
*/
@Autowired
private IHistoryLogBiz historyLogBiz;
/**
* 文章浏览记录
* 如果该文章该ip已经记录过则不在重复记录
* @param pjp
* @return
* @throws Throwable
*/
@Around("execution(* net.mingsoft.cms.action.web.ContentAction.get(..))")
public Object get(ProceedingJoinPoint pjp) throws Throwable{
// 获取方法参数
ContentEntity content = getType(pjp, ContentEntity.class);
// 如果id为空则直接发行
if(content.getId()==null) {
return pjp.proceed();
}
content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
//如果文章不存在则直接发行
if(content == null){
return pjp.proceed();
}
//查询判断该ip是否已经有浏览记录了
HistoryLogEntity historyLog = new HistoryLogEntity();
historyLog.setContentId(content.getId());
historyLog.setHlIp(BasicUtil.getIp());
historyLog.setHlIsMobile(BasicUtil.isMobileDevice());
HistoryLogEntity _historyLog = (HistoryLogEntity)historyLogBiz.getEntity(historyLog);
//如果该ip该文章没有浏览记录则保存浏览记录
//并且更新点击数
if(_historyLog == null || StringUtils.isBlank(_historyLog.getId())){
historyLogBiz.saveEntity(historyLog);
//更新点击数
ContentEntity updateContent = new ContentEntity();
updateContent.setId(content.getId());
if(content.getContentHit() == null){
updateContent.setContentHit(1);
}else{
updateContent.setContentHit(content.getContentHit()+1);
}
contentBiz.updateEntity(updateContent);
}
return pjp.proceed();
}
}

View File

@ -0,0 +1,14 @@
package net.mingsoft.cms.biz;
import net.mingsoft.base.biz.IBaseBiz;
/**
* 文章浏览记录业务
* @author 铭飞开发团队
* 创建日期2019-12-23 9:24:03<br/>
* 历史修订<br/>
*/
public interface IHistoryLogBiz extends IBaseBiz {
}

View File

@ -0,0 +1,52 @@
/**
The MIT License (MIT) * Copyright (c) 2019 铭飞科技
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.mingsoft.cms.biz.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao;
import java.util.*;
import net.mingsoft.cms.entity.HistoryLogEntity;
import net.mingsoft.cms.biz.IHistoryLogBiz;
import net.mingsoft.cms.dao.IHistoryLogDao;
/**
* 文章浏览记录管理持久化层
* @author 铭飞开发团队
* 创建日期2019-12-23 9:24:03<br/>
* 历史修订<br/>
*/
@Service("cmshistoryLogBizImpl")
public class HistoryLogBizImpl extends BaseBizImpl implements IHistoryLogBiz {
@Autowired
private IHistoryLogDao historyLogDao;
@Override
protected IBaseDao getDao() {
// TODO Auto-generated method stub
return historyLogDao;
}
}

View File

@ -0,0 +1,14 @@
package net.mingsoft.cms.dao;
import net.mingsoft.base.dao.IBaseDao;
import java.util.*;
import net.mingsoft.cms.entity.HistoryLogEntity;
/**
* 文章浏览记录持久层
* @author 铭飞开发团队
* 创建日期2019-12-23 9:24:03<br/>
* 历史修订<br/>
*/
public interface IHistoryLogDao extends IBaseDao {
}

View File

@ -0,0 +1,121 @@
<?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="net.mingsoft.cms.dao.IHistoryLogDao">
<resultMap id="resultMap" type="net.mingsoft.cms.entity.HistoryLogEntity">
<id column="id" property="id" /><!--编号 -->
<result column="content_id" property="contentId" /><!--文章编号 -->
<result column="hl_ip" property="hlIp" /><!--浏览ip -->
<result column="hl_people_id" property="hlPeopleId" /><!--用户id -->
<result column="hl_is_mobile" property="hlIsMobile" /><!--是否为移动端 -->
<result column="create_by" property="createBy" /><!--创建人 -->
<result column="create_date" property="createDate" /><!--创建时间 -->
<result column="update_by" property="updateBy" /><!--修改人 -->
<result column="update_date" property="updateDate" /><!--修改时间 -->
<result column="del" property="del" /><!--删除标记 -->
</resultMap>
<!--保存-->
<insert id="saveEntity" useGeneratedKeys="true" keyProperty="id"
parameterType="net.mingsoft.cms.entity.HistoryLogEntity" >
insert into cms_history_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="contentId != null and contentId != ''">content_id,</if>
<if test="hlIp != null and hlIp != ''">hl_ip,</if>
<if test="hlPeopleId != null and hlPeopleId != ''">hl_people_id,</if>
<if test="hlIsMobile != null">hl_is_mobile,</if>
<if test="createBy &gt; 0">create_by,</if>
<if test="createDate != null">create_date,</if>
<if test="updateBy &gt; 0">update_by,</if>
<if test="updateDate != null">update_date,</if>
<if test="del != null">del,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="contentId != null and contentId != ''">#{contentId},</if>
<if test="hlIp != null and hlIp != ''">#{hlIp},</if>
<if test="hlPeopleId != null and hlPeopleId != ''">#{hlPeopleId},</if>
<if test="hlIsMobile != null">#{hlIsMobile},</if>
<if test="createBy &gt; 0">#{createBy},</if>
<if test="createDate != null">#{createDate},</if>
<if test="updateBy &gt; 0">#{updateBy},</if>
<if test="updateDate != null">#{updateDate},</if>
<if test="del != null">#{del},</if>
</trim>
</insert>
<!--更新-->
<update id="updateEntity" parameterType="net.mingsoft.cms.entity.HistoryLogEntity">
update cms_history_log
<set>
<if test="contentId != null and contentId != ''">content_id=#{contentId},</if>
<if test="hlIp != null and hlIp != ''">hl_ip=#{hlIp},</if>
<if test="hlPeopleId != null and hlPeopleId != ''">hl_people_id=#{hlPeopleId},</if>
<if test="hlIsMobile != null">hl_is_mobile=#{hlIsMobile},</if>
<if test="createBy &gt; 0">create_by=#{createBy},</if>
<if test="createDate != null">create_date=#{createDate},</if>
<if test="updateBy &gt; 0">update_by=#{updateBy},</if>
<if test="updateDate != null">update_date=#{updateDate},</if>
<if test="del != null">del=#{del},</if>
</set>
where id = #{id}
</update>
<!--根据id获取-->
<select id="getEntity" resultMap="resultMap" parameterType="int">
select * from cms_history_log where id=#{id}
</select>
<!--根据实体获取-->
<select id="getByEntity" resultMap="resultMap" parameterType="net.mingsoft.cms.entity.HistoryLogEntity">
select * from cms_history_log
<where>
<if test="contentId != null and contentId != ''">and content_id=#{contentId}</if>
<if test="hlIp != null and hlIp != ''">and hl_ip=#{hlIp}</if>
<if test="hlPeopleId != null and hlPeopleId != ''">and hl_people_id=#{hlPeopleId}</if>
<if test="hlIsMobile != null"> and hl_is_mobile=#{hlIsMobile} </if>
<if test="createBy &gt; 0"> and create_by=#{createBy} </if>
<if test="createDate != null"> and create_date=#{createDate} </if>
<if test="updateBy &gt; 0"> and update_by=#{updateBy} </if>
<if test="updateDate != null"> and update_date=#{updateDate} </if>
<if test="del != null"> and del=#{del} </if>
</where>
limit 0,1
</select>
<!--删除-->
<delete id="deleteEntity" parameterType="int">
delete from cms_history_log where id=#{id}
</delete>
<!--批量删除-->
<delete id="delete" >
delete from cms_history_log
<where>
id in <foreach collection="ids" item="item" index="index"
open="(" separator="," close=")">#{item}</foreach>
</where>
</delete>
<!--查询全部-->
<select id="queryAll" resultMap="resultMap">
select * from cms_history_log order by id desc
</select>
<!--条件查询-->
<select id="query" resultMap="resultMap">
select * from cms_history_log
<where>
<if test="contentId != null and contentId != ''"> and content_id=#{contentId}</if>
<if test="hlIp != null and hlIp != ''"> and hl_ip=#{hlIp}</if>
<if test="hlPeopleId != null and hlPeopleId != ''"> and hl_people_id=#{hlPeopleId}</if>
<if test="hlIsMobile != null"> and hl_is_mobile=#{hlIsMobile} </if>
<if test="createBy &gt; 0"> and create_by=#{createBy} </if>
<if test="createDate != null"> and create_date=#{createDate} </if>
<if test="updateBy &gt; 0"> and update_by=#{updateBy} </if>
<if test="updateDate != null"> and update_date=#{updateDate} </if>
<if test="del != null"> and del=#{del} </if>
<include refid="net.mingsoft.base.dao.IBaseDao.sqlWhere"></include>
</where>
order by id desc
</select>
</mapper>

View File

@ -0,0 +1,88 @@
package net.mingsoft.cms.entity;
import com.alibaba.fastjson.annotation.JSONField;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import net.mingsoft.base.entity.BaseEntity;
import java.util.Date;
/**
* 文章浏览记录实体
* @author 铭飞开发团队
* 创建日期2019-12-23 9:24:03<br/>
* 历史修订<br/>
*/
public class HistoryLogEntity extends BaseEntity {
private static final long serialVersionUID = 1577064243576L;
/**
* 文章编号
*/
private String contentId;
/**
* 浏览ip
*/
private String hlIp;
/**
* 用户id
*/
private String hlPeopleId;
/**
* 是否为移动端
*/
private Boolean hlIsMobile;
/**
* 设置文章编号
*/
public void setContentId(String contentId) {
this.contentId = contentId;
}
/**
* 获取文章编号
*/
public String getContentId() {
return this.contentId;
}
/**
* 设置浏览ip
*/
public void setHlIp(String hlIp) {
this.hlIp = hlIp;
}
/**
* 获取浏览ip
*/
public String getHlIp() {
return this.hlIp;
}
/**
* 设置用户id
*/
public void setHlPeopleId(String hlPeopleId) {
this.hlPeopleId = hlPeopleId;
}
/**
* 获取用户id
*/
public String getHlPeopleId() {
return this.hlPeopleId;
}
/**
* 设置是否为移动端
*/
public void setHlIsMobile(Boolean hlIsMobile) {
this.hlIsMobile = hlIsMobile;
}
/**
* 获取是否为移动端
*/
public Boolean getHlIsMobile() {
return this.hlIsMobile;
}
}

View File

@ -0,0 +1,7 @@
#
#Mon Dec 23 09:24:03 CST 2019
content.id=\u6587\u7AE0\u7F16\u53F7
hl.ip=\u6D4F\u89C8ip
hl.people.id=\u7528\u6237id
hl.is.mobile=\u662F\u5426\u4E3A\u79FB\u52A8\u7AEF
id=\u7F16\u53F7

File diff suppressed because one or more lines are too long