Springboot 技术整合--笔记11--集成Guns--7
2019-08-05 本文已影响0人
牵手生活
涉及的内容
- Entity实体类
- mybatis-plus的mapper文件.xml
- mybatis-plus的mapper的接口文件.java
- 接口服务实现类
- 控制器
- 分页html展示
- 消息列表html文件相关的js实现(分页查询&删除记录)
Entity实体类WechatMessage.java
mybatis-plus的更多注解参考https://mp.baomidou.com/guide/annotation.html#tablename
/**
* 微信消息WechatMessage
* 更多注解参考:https://mp.baomidou.com/guide/annotation.html#tablename
* @author 牵手生活
* @since 2019-04-01
*/
@TableName("nw_wechat_message")
public class WechatMessage implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.ID_WORKER)
private long _ID;
/**
* 对应微信的message.msgId
*/
@TableField("msg_id")
private long msgId;
/**
* 初始微信号
*/
@TableField("original_wechat_id")
private String wechatID;
/**
* 与message.msgSvrId一致
*/
@TableField("msg_svr_id")
@JsonProperty("msgSvrId") //如果jsoon返回到前天与本地定义不一样,可采用@JsonProperty注解
private String msgSvrId;
/**
* 与message.type类型一致
*/
@TableField("type")
private int type;
/**
* 状态
*/
@TableField("status")
private int status;
/**
* 发送方向
*/
@TableField("is_send")
private int isSend;
/**
* 发送时间-时间戳(必填)
*/
@TableField("create_time")
private long createTime;
/**
* 聊天对象
*/
@TableField("talker_original_wechat_id")
private String talker;
/**
* 聊天内容
*/
@TableField("content")
private String content;
/**
* 附件路径
*/
@TableField("img_path")
private String imgPath;
/**
* 系列号 :规则暂定为 MD5-32位小写(imei+create_at)
*/
@TableField("media_url")
private String mediaUrl;
public long get_ID() {
return _ID;
}
public void set_ID(long _ID) {
this._ID = _ID;
}
public long getMsgId() {
return msgId;
}
public void setMsgId(long msgId) {
this.msgId = msgId;
}
public String getWechatID() {
return wechatID;
}
public void setWechatID(String wechatID) {
this.wechatID = wechatID;
}
public String getMsgSvrId() {
return msgSvrId;
}
public void setMsgSvrId(String msgSvrId) {
this.msgSvrId = msgSvrId;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getIsSend() {
return isSend;
}
public void setIsSend(int isSend) {
this.isSend = isSend;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public String getTalker() {
return talker;
}
public void setTalker(String talker) {
this.talker = talker;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
public String getMediaUrl() {
return mediaUrl;
}
public void setMediaUrl(String mediaUrl) {
this.mediaUrl = mediaUrl;
}
@Override
public String toString() {
return "WechatMessage{" +
"_ID=" + _ID +
", msgId=" + msgId +
", pluginActvied=" + wechatID +
", msgSvrId='" + msgSvrId + '\'' +
", type=" + type +
", status=" + status +
", isSend=" + isSend +
", createTime=" + createTime +
", talker='" + talker + '\'' +
", content='" + content + '\'' +
", imgPath='" + imgPath + '\'' +
", mediaUrl='" + mediaUrl + '\'' +
'}';
}
}
mybatis-plus的mapper文件 -WechatMessageMapper.xml
<?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="cn.stylefeng.guns.modular.system.mapper.WechatMessageMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.stylefeng.guns.modular.system.entity.WechatMessage">
<id column="id" property="_ID" />
<result column="msg_id" property="msgId" />
<result column="original_wechat_id" property="wechatId" />
<result column="msg_svr_id" property="msgSvrId" />
<result column="type" property="type" />
<result column="status" property="status" />
<result column="is_send" property="isSend" />
<result column="create_time" property="createTime" />
<result column="talker_original_wechat_id" property="talker" />
<result column="content" property="content" />
<result column="img_path" property="imgPath" />
<result column="media_url" property="mediaUrl" />
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id AS "_ID", msg_id AS "msgId", original_wechat_id AS "wechatId", msg_svr_id AS "msgSvrId", type AS "type", status AS "status", is_send AS "isSend"
, FROM_UNIXTIME(CONVERT(create_time /1000 , signed),"%Y-%m-%d %H:%i:%s") AS "createTime"
, talker_original_wechat_id AS "talker", content AS "content", img_path AS "imgPath", media_url AS "mediaUrl"
</sql>
<select id="getWechatMessages" resultType="map">
select
<include refid="Base_Column_List"/>
from nw_wechat_message where 1 = 1
<if test="beginTime != null and beginTime !='' and endTime != null and endTime != ''">
and (create_time between #{beginTime} and #{endTime})
</if>
<if test="wechatId != null and wechatId !=''">
and original_wechat_id like CONCAT('%',#{wechatId},'%')
</if>
</select>
</mapper>
mybatis-plus的mapper的接口WechatMessageMapper.java
/**
* <p>
* 操作wechatMessage机器人 Mapper 接口
* mybatis-plus的 mapper.xml 路径配置的坑
* https://blog.csdn.net/u013234928/article/details/94060733
*/
public interface WechatMessageMapper extends BaseMapper<WechatMessage> {
/**
* 获取操作日志
*/
List<Map<String, Object>> getWechatMessages(@Param("page") Page page, @Param("beginTime") long beginTime, @Param("endTime") long endTime, @Param("wechatId") String wechatId);
}
服务实现类WechatMessageService.java
@Service
public class WechatMessageService extends ServiceImpl<WechatMessageMapper, WechatMessage> {
/**
* 获取wechatMessage列表
*/
public List<Map<String, Object>> getWechatMessages(Page page, long beginTime, long endTime, String wechatId) {
return this.baseMapper.getWechatMessages(page, beginTime, endTime, wechatId);
}
}
微信消息控制器WechatMessageController.java
/**
* 微信消息控制器
*
* @author 牵手生活
* @Date 2019年08月05日 下午1:08:17
*/
@Controller
@RequestMapping("/wechatMessage")
public class WechatMessageController extends BaseController {
private static String PREFIX = "/modular/system/wechatMessage/";
@Autowired
private GunsProperties gunsProperties;
@Autowired
private WechatMessageService wechatMessageService;
/**
* 跳转到查看wechatMessage列表的页面
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("")
public String index() {
return PREFIX + "wechatMessage.html";
}
/**
* 查询wechatMessage列表
*/
@RequestMapping("/list")
//@Permission(Const.ADMIN_NAME)
@ResponseBody
public Object list(@RequestParam(required = false) String deptId,
@RequestParam(required = false) String timeLimit, //时间区间 2019-07-01 - 2019-08-05
@RequestParam(required = false) String wechatId
) throws ParseException {
//拼接查询条件
long lBeginTime =0,lEndTime=0;
if (ToolUtil.isNotEmpty(timeLimit)) {
String beginTime = "";
String endTime = "";
String[] split = timeLimit.split(" - ");
beginTime = split[0]+ " 00:00:00";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(beginTime);
lBeginTime = date.getTime();
endTime = split[1]+ " 23:59:59";
date = simpleDateFormat.parse(endTime);
lEndTime = date.getTime();
System.out.println(lBeginTime+ "======="+lEndTime);
}
//获取分页参数
//分页插件会返回total将他set到LayuiPageInfo里面的count里面返回就是这个总数
Page page = LayuiPageFactory.defaultPage();
//Page page = new Page(1, 5);
//根据条件查询操作日志
List<Map<String, Object>> result = wechatMessageService.getWechatMessages(page, lBeginTime, lEndTime, wechatId);
page.setRecords(new LogWrapper(result).wrap());
return LayuiPageFactory.createPageInfo(page);
}
/**
* 删除wechatMessage
*/
@RequestMapping(value = "/delete")
@ResponseBody
//@BussinessLog(value = "删除通知", key = "id", dict = DeleteDict.class)
public Object delete(@RequestParam Long wechatMessageId) {
//缓存通知名称
LogObjectHolder.me().set(ConstantFactory.me().getNoticeTitle(wechatMessageId));
this.wechatMessageService.removeById(wechatMessageId);
return SUCCESS_TIP;
}
}
消息列表html文件wechatMessage.html
image.png@layout("/common/_container.html",{plugins:["ztree"],js:["/assets/modular/system/wechatMessage/wechatMessage.js"]}){
<div class="layui-body-header">
<span class="layui-body-header-title">微信消息管理</span>
</div>
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-sm12 layui-col-md3 layui-col-lg2">
<div class="layui-card">
<div class="layui-card-body mini-bar">
<div class="ztree" id="deptTree"></div>
</div>
</div>
</div>
<div class="layui-col-sm12 layui-col-md9 layui-col-lg10">
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-form toolbar">
<div class="layui-form-item">
<div class="layui-inline">
<input id="wechatId" class="layui-input" type="text" placeholder="微信号/对方微信号"/>
</div>
<div class="layui-inline">
<input id="timeLimit" class="layui-input" type="text" placeholder="聊天时间"/>
</div>
<div class="layui-inline">
<button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon"></i>搜索</button>
@if(shiro.hasPermission("/mgr/add")){
<button id="btnAdd" class="layui-btn icon-btn"><i class="layui-icon"></i>添加</button>
@}
<button id="btnExp" class="layui-btn icon-btn"><i class="layui-icon"></i>导出</button>
</div>
</div>
</div>
<table class="layui-table" id="wechatMessageTable" lay-filter="wechatMessageTable"></table>
</div>
</div>
</div>
</div>
</div>
<script type="text/html" id="tableBar">
@if(shiro.hasPermission("/mgr/edit")){
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
@}
@if(shiro.hasPermission("/mgr/delete")){
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
@}
</script>
@}
消息列表html文件相关的js实现
layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax'], function () {
var layer = layui.layer;
var form = layui.form;
var table = layui.table;
var $ZTree = layui.ztree;
var $ax = layui.ax;
var laydate = layui.laydate;
var admin = layui.admin;
/**
* 系统管理--用户管理
*/
var WechatMessage = {
tableId: "wechatMessageTable", //表格id
condition: {
name: "",
deptId: "",
timeLimit: ""
}
};
/**
* 初始化表格的列
*/
WechatMessage.initColumn = function () {
return [[
{type: 'checkbox'},
{field: '_ID', hide: true, sort: true, title: '消息id'},
{field: 'msgId', sort: true, title: '消息id'},
{field: 'wechatId', sort: true, title: '微信id'},
{field: 'msgSvrId', sort: true, title: '消息服务器id'},
{field: 'type', sort: true, title: '消息类型'},
{field: 'status', sort: true, title: '状态'},
{field: 'isSend', sort: true, title: '发送'},
{field: 'talker', sort: true, title: '聊天对象'},
{field: 'content', sort: true, title: '聊天内容'},
{field: 'createTime', sort: true, title: '聊天时间'},
{field: 'imgPath', sort: true, title: '附件路径imgPath'},
{field: 'mediaUrl', sort: true, title: '附件路径url'},
{align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 160}
]];
};
/**
* 选择部门时
*/
WechatMessage.onClickDept = function (e, treeId, treeNode) {
WechatMessage.condition.deptId = treeNode.id;
WechatMessage.search();
};
/**
* 点击查询按钮
*/
WechatMessage.search = function () {
var queryData = {};
queryData['deptId'] = WechatMessage.condition.deptId;
queryData['wechatId'] = $("#wechatId").val();
queryData['timeLimit'] = $("#timeLimit").val();
table.reload(WechatMessage.tableId, {where: queryData});
};
/**
* 弹出添加微信消息对话框
*/
WechatMessage.openAddUser = function () {
admin.putTempData('formOk', false);
top.layui.admin.open({
type: 2,
title: '添加微信消息',
content: Feng.ctxPath + '/wechatMessage/wechatMessage_add',
end: function () {
admin.getTempData('formOk') && table.reload(WechatMessage.tableId);
}
});
};
/**
* 导出excel按钮
*/
WechatMessage.exportExcel = function () {
var checkRows = table.checkStatus(WechatMessage.tableId);
if (checkRows.data.length === 0) {
Feng.error("请选择要导出的数据");
} else {
table.exportFile(tableResult.config.id, checkRows.data, 'xls');
}
};
/**
* 点击编辑用户按钮时
*
* @param data 点击按钮时候的行数据
*/
WechatMessage.onEditUser = function (data) {
admin.putTempData('formOk', false);
top.layui.admin.open({
type: 2,
title: '编辑用户',
content: Feng.ctxPath + '/wechatMessage/wechatMessage_edit?wechatMessageId=' + data._ID,
end: function () {
admin.getTempData('formOk') && table.reload(WechatMessage.tableId);
}
});
};
/**
* 点击删除wechatMessage按钮
*
* @param data 点击按钮时候的行数据
*/
WechatMessage.onDeleteUser = function (data) {
var operation = function () {
var ajax = new $ax(Feng.ctxPath + "/wechatMessage/delete", function () {
table.reload(WechatMessage.tableId);
Feng.success("删除成功!");
}, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!");
});
ajax.set("wechatMessageId", data._ID);
ajax.start();
};
Feng.confirm("是否删除微信消息id=" + data._ID +"微信msgId="+ data.msgId + "?", operation);
};
// 渲染表格
var tableResult = table.render({
elem: '#' + WechatMessage.tableId,
url: Feng.ctxPath + '/wechatMessage/list',
page: true,
height: "full-98",
cellMinWidth: 100,
cols: WechatMessage.initColumn()
});
//渲染时间选择框
laydate.render({
elem: '#timeLimit',
range: true,
max: Feng.currentDate()
});
//初始化左侧部门树
var ztree = new $ZTree("deptTree", "/dept/tree");
ztree.bindOnClick(WechatMessage.onClickDept);
ztree.init();
// 搜索按钮点击事件
$('#btnSearch').click(function () {
WechatMessage.search();
});
// 添加按钮点击事件
$('#btnAdd').click(function () {
WechatMessage.openAddUser();
});
// 导出excel
$('#btnExp').click(function () {
WechatMessage.exportExcel();
});
// 工具条点击事件
table.on('tool(' + WechatMessage.tableId + ')', function (obj) {
var data = obj.data;
var layEvent = obj.event;
if (layEvent === 'edit') {
WechatMessage.onEditUser(data);
} else if (layEvent === 'delete') {
WechatMessage.onDeleteUser(data);
}
});
});