增加钉钉数据同步日志

This commit is contained in:
jinqiming 2020-11-13 17:10:41 +08:00
parent 1131ecc5a0
commit 07e14e6c04
25 changed files with 1563 additions and 86 deletions

View File

@ -0,0 +1,126 @@
package com.snow.web.controller.system;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.snow.common.annotation.Log;
import com.snow.common.enums.BusinessType;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.service.ISysDingtalkSyncLogService;
import com.snow.common.core.controller.BaseController;
import com.snow.common.core.domain.AjaxResult;
import com.snow.common.utils.poi.ExcelUtil;
import com.snow.common.core.page.TableDataInfo;
/**
* 钉钉同步日志记录Controller
*
* @author snow
* @date 2020-11-13
*/
@Controller
@RequestMapping("/system/log")
public class SysDingtalkSyncLogController extends BaseController
{
private String prefix = "system/log";
@Autowired
private ISysDingtalkSyncLogService sysDingtalkSyncLogService;
@RequiresPermissions("system:log:view")
@GetMapping()
public String log()
{
return prefix + "/log";
}
/**
* 查询钉钉同步日志记录列表
*/
@RequiresPermissions("system:log:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(SysDingtalkSyncLog sysDingtalkSyncLog)
{
startPage();
List<SysDingtalkSyncLog> list = sysDingtalkSyncLogService.selectSysDingtalkSyncLogList(sysDingtalkSyncLog);
return getDataTable(list);
}
/**
* 导出钉钉同步日志记录列表
*/
@RequiresPermissions("system:log:export")
@Log(title = "钉钉同步日志记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(SysDingtalkSyncLog sysDingtalkSyncLog)
{
List<SysDingtalkSyncLog> list = sysDingtalkSyncLogService.selectSysDingtalkSyncLogList(sysDingtalkSyncLog);
ExcelUtil<SysDingtalkSyncLog> util = new ExcelUtil<SysDingtalkSyncLog>(SysDingtalkSyncLog.class);
return util.exportExcel(list, "log");
}
/**
* 新增钉钉同步日志记录
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存钉钉同步日志记录
*/
@RequiresPermissions("system:log:add")
@Log(title = "钉钉同步日志记录", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(SysDingtalkSyncLog sysDingtalkSyncLog)
{
return toAjax(sysDingtalkSyncLogService.insertSysDingtalkSyncLog(sysDingtalkSyncLog));
}
/**
* 修改钉钉同步日志记录
*/
@GetMapping("/edit/{logId}")
public String edit(@PathVariable("logId") Long logId, ModelMap mmap)
{
SysDingtalkSyncLog sysDingtalkSyncLog = sysDingtalkSyncLogService.selectSysDingtalkSyncLogById(logId);
mmap.put("sysDingtalkSyncLog", sysDingtalkSyncLog);
return prefix + "/edit";
}
/**
* 修改保存钉钉同步日志记录
*/
@RequiresPermissions("system:log:edit")
@Log(title = "钉钉同步日志记录", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(SysDingtalkSyncLog sysDingtalkSyncLog)
{
return toAjax(sysDingtalkSyncLogService.updateSysDingtalkSyncLog(sysDingtalkSyncLog));
}
/**
* 删除钉钉同步日志记录
*/
@RequiresPermissions("system:log:remove")
@Log(title = "钉钉同步日志记录", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(sysDingtalkSyncLogService.deleteSysDingtalkSyncLogByIds(ids));
}
}

View File

@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增钉钉同步日志记录')" />
<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-log-add">
<div class="form-group">
<label class="col-sm-3 control-label is-required">模块标题:</label>
<div class="col-sm-8">
<input name="title" class="form-control" type="text" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">模块类型:</label>
<div class="col-sm-8">
<select name="moduleType" class="form-control m-b" th:with="type=${@dict.getType('dingtalk_module_type')}" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">业务类型:</label>
<div class="col-sm-8">
<select name="businessType" class="form-control m-b" th:with="type=${@dict.getType('dingtalk_oper_type')}" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">方法名称:</label>
<div class="col-sm-8">
<input name="method" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求方式:</label>
<div class="col-sm-8">
<input name="requestMethod" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作类别:</label>
<div class="col-sm-8">
<select name="operatorType" class="form-control m-b">
<option value="">所有</option>
</select>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作人员:</label>
<div class="col-sm-8">
<input name="operName" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">部门名称:</label>
<div class="col-sm-8">
<input name="deptName" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求URL</label>
<div class="col-sm-8">
<input name="operUrl" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主机地址:</label>
<div class="col-sm-8">
<input name="operIp" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作地点:</label>
<div class="col-sm-8">
<input name="operLocation" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求原参数:</label>
<div class="col-sm-8">
<textarea name="operSourceParam" class="form-control" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求钉钉参数:</label>
<div class="col-sm-8">
<textarea name="operDingtalkParam" class="form-control" required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">返回参数:</label>
<div class="col-sm-8">
<textarea name="jsonResult" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作状态:</label>
<div class="col-sm-8">
<div class="radio-box">
<input type="radio" name="status" value="">
<label th:for="status" th:text="未知"></label>
</div>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">错误消息:</label>
<div class="col-sm-8">
<textarea name="errorMsg" class="form-control"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作时间:</label>
<div class="col-sm-8">
<div class="input-group date">
<input name="operTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
var prefix = ctx + "system/log"
$("#form-log-add").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/add", $('#form-log-add').serialize());
}
}
$("input[name='operTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
</script>
</body>
</html>

View File

@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改钉钉同步日志记录')" />
<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-log-edit" th:object="${sysDingtalkSyncLog}">
<input name="logId" th:field="*{logId}" type="hidden">
<div class="form-group">
<label class="col-sm-3 control-label is-required">模块标题:</label>
<div class="col-sm-8">
<input name="title" th:field="*{title}" class="form-control" type="text" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">模块类型:</label>
<div class="col-sm-8">
<select name="moduleType" class="form-control m-b" th:with="type=${@dict.getType('dingtalk_module_type')}" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{moduleType}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">业务类型:</label>
<div class="col-sm-8">
<select name="businessType" class="form-control m-b" th:with="type=${@dict.getType('dingtalk_oper_type')}" required>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{businessType}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">方法名称:</label>
<div class="col-sm-8">
<input name="method" th:field="*{method}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求方式:</label>
<div class="col-sm-8">
<input name="requestMethod" th:field="*{requestMethod}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作类别:</label>
<div class="col-sm-8">
<select name="operatorType" class="form-control m-b">
<option value="">所有</option>
</select>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作人员:</label>
<div class="col-sm-8">
<input name="operName" th:field="*{operName}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">部门名称:</label>
<div class="col-sm-8">
<input name="deptName" th:field="*{deptName}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求URL</label>
<div class="col-sm-8">
<input name="operUrl" th:field="*{operUrl}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">主机地址:</label>
<div class="col-sm-8">
<input name="operIp" th:field="*{operIp}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作地点:</label>
<div class="col-sm-8">
<input name="operLocation" th:field="*{operLocation}" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求原参数:</label>
<div class="col-sm-8">
<textarea name="operSourceParam" class="form-control" required>[[*{operSourceParam}]]</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">请求钉钉参数:</label>
<div class="col-sm-8">
<textarea name="operDingtalkParam" class="form-control" required>[[*{operDingtalkParam}]]</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">返回参数:</label>
<div class="col-sm-8">
<textarea name="jsonResult" class="form-control">[[*{jsonResult}]]</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作状态:</label>
<div class="col-sm-8">
<div class="radio-box">
<input type="radio" name="status" value="">
<label th:for="status" th:text="未知"></label>
</div>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">错误消息:</label>
<div class="col-sm-8">
<textarea name="errorMsg" class="form-control">[[*{errorMsg}]]</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">操作时间:</label>
<div class="col-sm-8">
<div class="input-group date">
<input name="operTime" th:value="${#dates.format(sysDingtalkSyncLog.operTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
var prefix = ctx + "system/log";
$("#form-log-edit").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-log-edit').serialize());
}
}
$("input[name='operTime']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
</script>
</body>
</html>

View File

@ -0,0 +1,220 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('钉钉同步日志记录列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
<label>模块标题:</label>
<input type="text" name="title"/>
</li>
<li>
<label>模块类型:</label>
<select name="moduleType" th:with="type=${@dict.getType('dingtalk_module_type')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</li>
<li>
<label>业务类型:</label>
<select name="businessType" th:with="type=${@dict.getType('dingtalk_oper_type')}">
<option value="">所有</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</li>
<li>
<label>方法名称:</label>
<input type="text" name="method"/>
</li>
<li>
<label>请求方式:</label>
<input type="text" name="requestMethod"/>
</li>
<li>
<label>操作类别:</label>
<select name="operatorType">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
</li>
<li>
<label>操作人员:</label>
<input type="text" name="operName"/>
</li>
<li>
<label>部门名称:</label>
<input type="text" name="deptName"/>
</li>
<li>
<label>请求URL</label>
<input type="text" name="operUrl"/>
</li>
<li>
<label>主机地址:</label>
<input type="text" name="operIp"/>
</li>
<li>
<label>操作地点:</label>
<input type="text" name="operLocation"/>
</li>
<li>
<label>操作状态:</label>
<select name="status">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
</li>
<li class="select-time">
<label>操作时间:</label>
<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginOperTime]"/>
<span>-</span>
<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endOperTime]"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:log:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:log:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:log:remove">
<i class="fa fa-remove"></i> 删除
</a>
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:log:export">
<i class="fa fa-download"></i> 导出
</a>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('system:log:edit')}]];
var removeFlag = [[${@permission.hasPermi('system:log:remove')}]];
var moduleTypeDatas = [[${@dict.getType('dingtalk_module_type')}]];
var businessTypeDatas = [[${@dict.getType('dingtalk_oper_type')}]];
var prefix = ctx + "system/log";
$(function() {
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove",
exportUrl: prefix + "/export",
modalName: "钉钉同步日志记录",
columns: [{
checkbox: true
},
{
field: 'logId',
title: '日志主键',
visible: false
},
{
field: 'title',
title: '模块标题'
},
{
field: 'moduleType',
title: '模块类型',
formatter: function(value, row, index) {
return $.table.selectDictLabel(moduleTypeDatas, value);
}
},
{
field: 'businessType',
title: '业务类型',
formatter: function(value, row, index) {
return $.table.selectDictLabel(businessTypeDatas, value);
}
},
{
field: 'method',
title: '方法名称'
},
{
field: 'requestMethod',
title: '请求方式'
},
{
field: 'operatorType',
title: '操作类别'
},
{
field: 'operName',
title: '操作人员'
},
{
field: 'deptName',
title: '部门名称'
},
{
field: 'operUrl',
title: '请求URL'
},
{
field: 'operIp',
title: '主机地址'
},
{
field: 'operLocation',
title: '操作地点'
},
{
field: 'operSourceParam',
title: '请求原参数'
},
{
field: 'operDingtalkParam',
title: '请求钉钉参数'
},
{
field: 'jsonResult',
title: '返回参数'
},
{
field: 'status',
title: '操作状态'
},
{
field: 'errorMsg',
title: '错误消息'
},
{
field: 'operTime',
title: '操作时间'
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.logId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.logId + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
}]
};
$.table.init(options);
});
</script>
</body>
</html>

View File

@ -0,0 +1,41 @@
package com.snow.common.annotation;
import com.snow.common.enums.*;
import org.springframework.web.bind.annotation.RequestParam;
import java.lang.annotation.*;
/**
* 自定义操作日志记录注解
*
* @author snow
*/
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DingTalkSyncLog
{
/**
* 模块描述
*/
public DingTalkListenerType dingTalkListenerType();
/**
*钉钉同步方式
*/
public DingTalkSyncType dingTalkSyncType() default DingTalkSyncType.AUTOMATIC;
/**
* 请求钉钉的URL
* @return
*/
public String dingTalkUrl() default"";
/**
* 是否保存请求的参数
*/
public boolean isSaveRequestData() default true;
}

View File

@ -0,0 +1,29 @@
package com.snow.common.enums;
/**
* 业务操作类型
*
* @author snow
*/
public enum DingTalkBusinessType
{
/**
* 其它
*/
OTHER,
/**
* 新增
*/
INSERT,
/**
* 修改
*/
UPDATE,
/**
* 删除
*/
DELETE
}

View File

@ -13,15 +13,15 @@ public enum DingTalkListenerType {
DEPARTMENT_DELETED(3,2,"部门删除"), DEPARTMENT_DELETED(3,2,"部门删除"),
USER_CREATED(5,1,"用户创建"), USER_CREATE(1,1,"用户创建"),
USER_DELETE(6,1,"用户删除"), USER_DELETE(3,1,"用户删除"),
CALL_BACK_REGISTER(20,10, "回调注册"), CALL_BACK_REGISTER(1,10, "回调注册"),
CALL_BACK_UPDATE(21,10, "回调更新"), CALL_BACK_UPDATE(2,10, "回调更新"),
CALL_BACK_DELETE(22,10, "回调删除"), CALL_BACK_DELETE(3,10, "回调删除"),
CALL_BACK_FAILED_RESULT(23,10, "获取回调失败结果"), CALL_BACK_FAILED_RESULT(23,10, "获取回调失败结果"),
; ;

View File

@ -0,0 +1,31 @@
package com.snow.common.enums;
/**
* 操作状态
*
* @author snow
*/
public enum DingTalkSyncType
{
/**
* 自动
*/
AUTOMATIC(1),
/**
* 手动
*/
MANUAL(2);
private final Integer code;
private DingTalkSyncType(Integer code)
{
this.code = code;
}
public Integer getCode()
{
return code;
}
}

View File

@ -0,0 +1,42 @@
package com.snow.common.exception;
/**
* @author qimingjin
* @Title:
* @Description:
* @date 2020/11/13 14:54
*/
public class DingTalkSyncException extends RuntimeException {
private static final long serialVersionUID = 1L;
private String requestParam;
protected final String message;
public DingTalkSyncException(String requestParam,String message)
{
this.requestParam = requestParam;
this.message = message;
}
public DingTalkSyncException(String message)
{
this.message = message;
}
public DingTalkSyncException(String requestParam,String message, Throwable e)
{
super(message, e);
this.message = message;
this.requestParam = requestParam;
}
@Override
public String getMessage()
{
return message;
}
public String getRequestParam() {
return requestParam;
}
}

View File

@ -0,0 +1,193 @@
package com.snow.dingtalk.aspectj;
import com.snow.common.annotation.DingTalkSyncLog;
import com.snow.common.enums.BusinessStatus;
import com.snow.common.exception.DingTalkSyncException;
import com.snow.common.json.JSON;
import com.snow.common.utils.ServletUtils;
import com.snow.common.utils.StringUtils;
import com.snow.framework.manager.AsyncManager;
import com.snow.framework.manager.factory.AsyncFactory;
import com.snow.framework.util.ShiroUtils;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.domain.SysUser;
import com.taobao.api.ApiException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.Map;
/**
* 操作日志记录处理
*
* @author snow
*/
@Aspect
@Component
public class DingTalkSyncLogAspect
{
private static final Logger log = LoggerFactory.getLogger(DingTalkSyncLogAspect.class);
// 配置织入点
@Pointcut("@annotation(com.snow.common.annotation.DingTalkSyncLog)")
public void logPointCut()
{
}
/**
* 处理完请求后执行
*
* @param joinPoint 切点
*/
@AfterReturning(pointcut = "logPointCut()", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, Object jsonResult)
{
handleLog(joinPoint, null, jsonResult);
}
/**
* 拦截异常操作
*
* @param joinPoint 切点
* @param e 异常
*/
@AfterThrowing(value = "logPointCut()", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, Exception e)
{
handleLog(joinPoint, e, null);
}
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult)
{
try
{
// 获得注解
DingTalkSyncLog controllerLog = getAnnotationLog(joinPoint);
if (controllerLog == null)
{
return;
}
// 获取当前的用户
SysUser currentUser = ShiroUtils.getSysUser();
// *========数据库日志=========*//
SysDingtalkSyncLog sysDingtalkSyncLog = new SysDingtalkSyncLog();
if(StringUtils.isNotNull(currentUser)){
sysDingtalkSyncLog.setOperName(currentUser.getUserName());
if (StringUtils.isNotNull(currentUser.getDept())
&& StringUtils.isNotEmpty(currentUser.getDept().getDeptName()))
{
sysDingtalkSyncLog.setDeptName(currentUser.getDept().getDeptName());
}
// 请求的地址
String ip = ShiroUtils.getIp();
sysDingtalkSyncLog.setOperIp(ip);
}else {
sysDingtalkSyncLog.setOperName("");
sysDingtalkSyncLog.setDeptName("");
}
sysDingtalkSyncLog.setStatus(BusinessStatus.SUCCESS.ordinal());
// 返回参数
sysDingtalkSyncLog.setJsonResult(StringUtils.substring(JSON.marshal(jsonResult), 0, 2000));
sysDingtalkSyncLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
if (e != null)
{
if(e instanceof DingTalkSyncException){
sysDingtalkSyncLog.setStatus(BusinessStatus.FAIL.ordinal());
sysDingtalkSyncLog.setOperDingtalkParam(((DingTalkSyncException) e).getRequestParam());
sysDingtalkSyncLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
}else if(e instanceof ApiException){
sysDingtalkSyncLog.setStatus(BusinessStatus.FAIL.ordinal());
// sysDingtalkSyncLog.setOperDingtalkParam(((ApiException) e).getErrMsg());
sysDingtalkSyncLog.setErrorMsg(StringUtils.substring(((ApiException) e).getErrMsg(), 0, 2000));
}
else {
sysDingtalkSyncLog.setStatus(BusinessStatus.FAIL.ordinal());
sysDingtalkSyncLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
}
}
// 设置方法名称
String className = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
sysDingtalkSyncLog.setMethod(className + "." + methodName + "()");
// 设置请求方式
sysDingtalkSyncLog.setRequestMethod(ServletUtils.getRequest().getMethod());
// 处理设置注解上的参数
getControllerMethodDescription(controllerLog,joinPoint, sysDingtalkSyncLog);
// 保存数据库
AsyncManager.me().execute(AsyncFactory.recordDingTalkSyncOper(sysDingtalkSyncLog));
}
catch (Exception exp)
{
// 记录本地异常日志
log.error("==前置通知异常==");
log.error("异常信息:{}", exp.getMessage());
exp.printStackTrace();
}
}
/**
* 获取注解中对方法的描述信息 用于Service层注解
*
* @param log 日志
* @param sysDingtalkSyncLog 操作日志
* @throws Exception
*/
public void getControllerMethodDescription(DingTalkSyncLog log,JoinPoint joinPoint, SysDingtalkSyncLog sysDingtalkSyncLog) throws Exception
{
sysDingtalkSyncLog.setTitle(log.dingTalkListenerType().getInfo());
sysDingtalkSyncLog.setModuleType(log.dingTalkListenerType().getType());
sysDingtalkSyncLog.setBusinessType(log.dingTalkListenerType().getCode());
// 设置操作人类别
sysDingtalkSyncLog.setOperatorType(log.dingTalkSyncType().getCode());
// 是否需要保存request参数和值
if (log.isSaveRequestData())
{
// 获取参数的信息传入到数据库中
setRequestValue(sysDingtalkSyncLog,joinPoint);
}
}
/**
* 获取请求的参数放到log中
*
* @param operLog 操作日志
* @throws Exception 异常
*/
private void setRequestValue(SysDingtalkSyncLog operLog ,JoinPoint joinPoint) throws Exception
{
//获取切面的参数
Object[] args = joinPoint.getArgs();
operLog.setOperSourceParam(StringUtils.substring(com.alibaba.fastjson.JSON.toJSONString(args), 0, 4000));
}
/**
* 是否存在注解如果存在就获取
*/
private DingTalkSyncLog getAnnotationLog(JoinPoint joinPoint) throws Exception
{
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
if (method != null)
{
return method.getAnnotation(DingTalkSyncLog.class);
}
return null;
}
}

View File

@ -6,13 +6,20 @@ import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest; import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse; import com.dingtalk.api.response.OapiGettokenResponse;
import com.snow.common.constant.Constants; import com.snow.common.constant.Constants;
import com.snow.common.enums.BusinessStatus;
import com.snow.common.enums.BusinessType; import com.snow.common.enums.BusinessType;
import com.snow.common.enums.DingTalkSyncType;
import com.snow.common.utils.ServletUtils;
import com.snow.common.utils.StringUtils; import com.snow.common.utils.StringUtils;
import com.snow.common.utils.spring.SpringUtils; import com.snow.common.utils.spring.SpringUtils;
import com.snow.framework.util.ShiroUtils;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.domain.SysOperLog; import com.snow.system.domain.SysOperLog;
import com.snow.system.domain.SysUser;
import com.snow.system.service.ISysConfigService; import com.snow.system.service.ISysConfigService;
import com.snow.system.service.ISysOperLogService; import com.snow.system.service.ISysOperLogService;
import com.snow.system.service.impl.SysConfigServiceImpl; import com.snow.system.service.impl.SysConfigServiceImpl;
import com.snow.system.service.impl.SysDingtalkSyncLogServiceImpl;
import com.snow.system.service.impl.SysOperLogServiceImpl; import com.snow.system.service.impl.SysOperLogServiceImpl;
import com.taobao.api.ApiException; import com.taobao.api.ApiException;
@ -32,6 +39,7 @@ public class BaseService {
private SysOperLogServiceImpl iSysOperLogService=SpringUtils.getBean("sysOperLogServiceImpl"); private SysOperLogServiceImpl iSysOperLogService=SpringUtils.getBean("sysOperLogServiceImpl");
private SysDingtalkSyncLogServiceImpl sysDingtalkSyncLogService=SpringUtils.getBean("sysDingtalkSyncLogServiceImpl");
/** /**
* 获取token * 获取token
* @return * @return
@ -49,7 +57,7 @@ public class BaseService {
OapiGettokenResponse response = client.execute(request); OapiGettokenResponse response = client.execute(request);
if(response.getErrcode()==0){ if(response.getErrcode()==0){
timedCache.put(TOKEN,response.getAccessToken()); timedCache.put(TOKEN,response.getAccessToken());
syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getMessage(),"getDingTalkToken()", com.alibaba.fastjson.JSON.toJSONString(request)); syncDingTalkSuccessOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getMessage(),"getDingTalkToken()", com.alibaba.fastjson.JSON.toJSONString(request));
return response.getAccessToken(); return response.getAccessToken();
}else { }else {
//记录获取token失败日志 //记录获取token失败日志
@ -107,5 +115,4 @@ public class BaseService {
sysOperLog.setStatus(0); sysOperLog.setStatus(0);
iSysOperLogService.insertOperlog(sysOperLog); iSysOperLogService.insertOperlog(sysOperLog);
} }
} }

View File

@ -2,9 +2,12 @@ package com.snow.dingtalk.listener;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.snow.common.enums.DingTalkListenerType; import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.enums.DingTalkSyncType;
import com.snow.common.utils.spring.SpringUtils; import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.service.impl.CallBackServiceImpl; import com.snow.dingtalk.service.impl.CallBackServiceImpl;
import com.snow.system.domain.DingtalkCallBack; import com.snow.system.domain.DingtalkCallBack;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.event.SyncEvent; import com.snow.system.event.SyncEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -27,6 +30,7 @@ public class CallBackService implements ISyncDingTalkInfo {
DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT(); DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT();
Integer code = eventType.getCode(); Integer code = eventType.getCode();
if(code.equals(DingTalkListenerType.CALL_BACK_REGISTER.getCode())){ if(code.equals(DingTalkListenerType.CALL_BACK_REGISTER.getCode())){
// new SysDingtalkSyncLog(eventType,"registerCallBack",BaseConstantUrl.REGISTER_CALL_BACK,DingTalkSyncType.AUTOMATIC.)
callBackServiceImpl.registerCallBack((DingtalkCallBack) syncEvent.getSource()); callBackServiceImpl.registerCallBack((DingtalkCallBack) syncEvent.getSource());
} }
else if( code.equals(DingTalkListenerType.CALL_BACK_UPDATE.getCode())){ else if( code.equals(DingTalkListenerType.CALL_BACK_UPDATE.getCode())){

View File

@ -22,7 +22,7 @@ public class SyncDingTalkInfoFactory {
if(type.equals(DingTalkListenerType.DEPARTMENT_CREATE.getType())){ if(type.equals(DingTalkListenerType.DEPARTMENT_CREATE.getType())){
return new DepartmentEventService(); return new DepartmentEventService();
} }
else if(type.equals(DingTalkListenerType.USER_CREATED.getType())){ else if(type.equals(DingTalkListenerType.USER_CREATE.getType())){
return new UserEventService(); return new UserEventService();
} }
else if(type.equals(DingTalkListenerType.CALL_BACK_REGISTER.getType())){ else if(type.equals(DingTalkListenerType.CALL_BACK_REGISTER.getType())){

View File

@ -25,7 +25,7 @@ public class UserEventService implements ISyncDingTalkInfo {
log.info("调用钉钉用户回调传入的原始参数:{}"+JSON.toJSONString(syncEvent)); log.info("调用钉钉用户回调传入的原始参数:{}"+JSON.toJSONString(syncEvent));
DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT(); DingTalkListenerType eventType =(DingTalkListenerType) syncEvent.getT();
Integer code = eventType.getCode(); Integer code = eventType.getCode();
if(code.equals(DingTalkListenerType.USER_CREATED.getCode())){ if(code.equals(DingTalkListenerType.USER_CREATE.getCode())){
userService.createUser((SysUser) syncEvent.getSource()); userService.createUser((SysUser) syncEvent.getSource());
} }
else if( code.equals(DingTalkListenerType.USER_DELETE.getCode())){ else if( code.equals(DingTalkListenerType.USER_DELETE.getCode())){

View File

@ -21,7 +21,7 @@ public interface CallBackService {
* 更新事件 * 更新事件
* @param dingtalkCallBack * @param dingtalkCallBack
*/ */
void updateCallBack(DingtalkCallBack dingtalkCallBack); Boolean updateCallBack(DingtalkCallBack dingtalkCallBack);
/** /**
* 删除事件 * 删除事件

View File

@ -7,13 +7,19 @@ import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*; import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*; import com.dingtalk.api.response.*;
import com.snow.common.annotation.DingTalkSyncLog;
import com.snow.common.constant.Constants; import com.snow.common.constant.Constants;
import com.snow.common.enums.DingTalkBusinessType;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.enums.DingTalkSyncType;
import com.snow.common.exception.DingTalkSyncException;
import com.snow.common.utils.StringUtils; import com.snow.common.utils.StringUtils;
import com.snow.dingtalk.common.BaseConstantUrl; import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService; import com.snow.dingtalk.common.BaseService;
import com.snow.dingtalk.service.CallBackService; import com.snow.dingtalk.service.CallBackService;
import com.snow.system.domain.DingtalkCallBack; import com.snow.system.domain.DingtalkCallBack;
import com.taobao.api.ApiException; import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -26,11 +32,12 @@ import java.util.List;
* @date 2020/11/3 11:19 * @date 2020/11/3 11:19
*/ */
@Service @Service
@Slf4j
public class CallBackServiceImpl extends BaseService implements CallBackService { public class CallBackServiceImpl extends BaseService implements CallBackService {
public static final String TOKEN="call_back_dingtalk_token";
@Override @Override
@DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.CALL_BACK_REGISTER,dingTalkUrl=BaseConstantUrl.REGISTER_CALL_BACK,dingTalkSyncType=DingTalkSyncType.AUTOMATIC)
public void registerCallBack(DingtalkCallBack dingtalkCallBack) { public void registerCallBack(DingtalkCallBack dingtalkCallBack) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.REGISTER_CALL_BACK); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.REGISTER_CALL_BACK);
OapiCallBackRegisterCallBackRequest request = new OapiCallBackRegisterCallBackRequest(); OapiCallBackRegisterCallBackRequest request = new OapiCallBackRegisterCallBackRequest();
@ -40,20 +47,18 @@ public class CallBackServiceImpl extends BaseService implements CallBackService
request.setCallBackTag(dingtalkCallBack.getEventNameList()); request.setCallBackTag(dingtalkCallBack.getEventNameList());
try { try {
OapiCallBackRegisterCallBackResponse response = client.execute(request,getDingTalkToken()); OapiCallBackRegisterCallBackResponse response = client.execute(request,getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()!=0){
syncDingTalkErrorOperLog(BaseConstantUrl.REGISTER_CALL_BACK,response.getMessage(),"registerCallBack()", JSON.toJSONString(request)); throw new DingTalkSyncException(JSON.toJSONString(request),response.getErrmsg());
}else {
//记录获取token失败日志
syncDingTalkErrorOperLog(BaseConstantUrl.REGISTER_CALL_BACK,response.getErrmsg(),"registerCallBack()", JSON.toJSONString(request));
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.REGISTER_CALL_BACK,e.getMessage(),"registerCallBack()", JSON.toJSONString(request)); log.error("注册钉钉回调registerCallBack异常{}",e.getMessage());
e.printStackTrace(); throw new DingTalkSyncException(JSON.toJSONString(request),e.getErrMsg());
} }
} }
@Override @Override
public void updateCallBack(DingtalkCallBack dingtalkCallBack) { @DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.CALL_BACK_UPDATE,dingTalkUrl=BaseConstantUrl.UPDATE_CALL_BACK,dingTalkSyncType=DingTalkSyncType.AUTOMATIC)
public Boolean updateCallBack(DingtalkCallBack dingtalkCallBack) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.UPDATE_CALL_BACK); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.UPDATE_CALL_BACK);
OapiCallBackUpdateCallBackRequest request = new OapiCallBackUpdateCallBackRequest(); OapiCallBackUpdateCallBackRequest request = new OapiCallBackUpdateCallBackRequest();
request.setUrl(dingtalkCallBack.getUrl()); request.setUrl(dingtalkCallBack.getUrl());
@ -63,33 +68,30 @@ public class CallBackServiceImpl extends BaseService implements CallBackService
try { try {
OapiCallBackUpdateCallBackResponse response = client.execute(request,getDingTalkToken()); OapiCallBackUpdateCallBackResponse response = client.execute(request,getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.UPDATE_CALL_BACK,response.getMessage(),"updateCallBack()", JSON.toJSONString(request)); return response.isSuccess();
}else { }else {
//记录获取token失败日志 throw new DingTalkSyncException(JSON.toJSONString(request),response.getErrmsg());
syncDingTalkErrorOperLog(BaseConstantUrl.UPDATE_CALL_BACK,response.getErrmsg(),"updateCallBack()", JSON.toJSONString(request));
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.UPDATE_CALL_BACK,e.getMessage(),"updateCallBack()", JSON.toJSONString(request)); log.error("更新钉钉回调updateCallBack异常{}",e.getMessage());
e.printStackTrace(); throw new DingTalkSyncException(JSON.toJSONString(request),e.getErrMsg());
} }
} }
@Override @Override
@DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.CALL_BACK_DELETE,dingTalkUrl=BaseConstantUrl.DELETE_CALL_BACK,dingTalkSyncType=DingTalkSyncType.AUTOMATIC)
public void deleteCallBack(DingtalkCallBack dingtalkCallBack) { public void deleteCallBack(DingtalkCallBack dingtalkCallBack) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DELETE_CALL_BACK); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DELETE_CALL_BACK);
OapiCallBackDeleteCallBackRequest request = new OapiCallBackDeleteCallBackRequest(); OapiCallBackDeleteCallBackRequest request = new OapiCallBackDeleteCallBackRequest();
request.setHttpMethod("GET"); request.setHttpMethod("GET");
try { try {
OapiCallBackDeleteCallBackResponse response = client.execute(request, getDingTalkToken()); OapiCallBackDeleteCallBackResponse response = client.execute(request, getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()!=0){
syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,response.getMessage(),"deleteCallBack()", JSON.toJSONString(request)); throw new DingTalkSyncException(JSON.toJSONString(request),response.getErrmsg());
}else {
//记录获取token失败日志
syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,response.getErrmsg(),"deleteCallBack()", JSON.toJSONString(request));
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.DELETE_CALL_BACK,e.getMessage(),"deleteCallBack()", JSON.toJSONString(request)); log.error("删除钉钉回调deleteCallBack异常{}",e.getMessage());
e.printStackTrace(); throw new DingTalkSyncException(JSON.toJSONString(request),e.getErrMsg());
} }
} }
@ -102,7 +104,7 @@ public class CallBackServiceImpl extends BaseService implements CallBackService
OapiCallBackGetCallBackFailedResultResponse response = client.execute(request, getDingTalkToken()); OapiCallBackGetCallBackFailedResultResponse response = client.execute(request, getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
List<OapiCallBackGetCallBackFailedResultResponse.Failed> failedList = response.getFailedList(); List<OapiCallBackGetCallBackFailedResultResponse.Failed> failedList = response.getFailedList();
syncDingTalkErrorOperLog(BaseConstantUrl.CALL_BACK_FAILED_RESULT,response.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request)); syncDingTalkSuccessOperLog(BaseConstantUrl.CALL_BACK_FAILED_RESULT,response.getMessage(),"getCallBackFailedResult()", JSON.toJSONString(request));
return failedList; return failedList;
}else { }else {
//记录获取token失败日志 //记录获取token失败日志
@ -114,40 +116,5 @@ public class CallBackServiceImpl extends BaseService implements CallBackService
} }
return null; return null;
} }
/**
* 获取token
* @return
*/
@Deprecated
public String getCallBackDingTalkToken(DingtalkCallBack dingtalkCallBack){
//创建缓存缓存默认是7100S
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(7100);
if(StringUtils.isEmpty(timedCache.get(TOKEN))){
DefaultDingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.GET_TOKEN_URL);
OapiGettokenRequest request = new OapiGettokenRequest();
request.setAppkey(dingtalkCallBack.getAppKey());
request.setAppsecret(dingtalkCallBack.getAppSecret());
request.setHttpMethod(Constants.GET);
try {
OapiGettokenResponse response = client.execute(request);
if(response.getErrcode()==0){
timedCache.put(TOKEN,response.getAccessToken());
syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getMessage(),"getCallBackDingTalkToken()", JSON.toJSONString(request));
return response.getAccessToken();
}else {
//记录获取token失败日志
syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,response.getErrmsg(),"getCallBackDingTalkToken()", JSON.toJSONString(request));
return null;
}
} catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,e.getMessage(),"getCallBackDingTalkToken()",JSON.toJSONString(request));
e.printStackTrace();
}
return null;
}else {
return timedCache.get(TOKEN);
}
}
} }

View File

@ -7,6 +7,10 @@ import com.dingtalk.api.request.OapiDepartmentCreateRequest;
import com.dingtalk.api.request.OapiDepartmentListRequest; import com.dingtalk.api.request.OapiDepartmentListRequest;
import com.dingtalk.api.response.OapiDepartmentCreateResponse; import com.dingtalk.api.response.OapiDepartmentCreateResponse;
import com.dingtalk.api.response.OapiDepartmentListResponse; import com.dingtalk.api.response.OapiDepartmentListResponse;
import com.snow.common.annotation.DingTalkSyncLog;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.enums.DingTalkSyncType;
import com.snow.common.exception.DingTalkSyncException;
import com.snow.common.utils.spring.SpringUtils; import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.common.BaseConstantUrl; import com.snow.dingtalk.common.BaseConstantUrl;
import com.snow.dingtalk.common.BaseService; import com.snow.dingtalk.common.BaseService;
@ -15,6 +19,7 @@ import com.snow.dingtalk.service.DepartmentService;
import com.snow.system.service.impl.SysDeptServiceImpl; import com.snow.system.service.impl.SysDeptServiceImpl;
import com.taobao.api.ApiException; import com.taobao.api.ApiException;
import com.taobao.api.Constants; import com.taobao.api.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -26,11 +31,13 @@ import java.util.List;
* @create: 2020-10-31 12:59 * @create: 2020-10-31 12:59
**/ **/
@Service(value = "departmentServiceImpl") @Service(value = "departmentServiceImpl")
@Slf4j
public class DepartmentServiceImpl extends BaseService implements DepartmentService { public class DepartmentServiceImpl extends BaseService implements DepartmentService {
private SysDeptServiceImpl sysDeptServiceImpl=SpringUtils.getBean("sysDeptServiceImpl"); private SysDeptServiceImpl sysDeptServiceImpl=SpringUtils.getBean("sysDeptServiceImpl");
@Override @Override
@DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.DEPARTMENT_CREATE,dingTalkUrl=BaseConstantUrl.DEPARTMENT_CREATE)
public Long createDepartment(DepartmentCreateRequest departmentDTO){ public Long createDepartment(DepartmentCreateRequest departmentDTO){
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DEPARTMENT_CREATE); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DEPARTMENT_CREATE);
OapiDepartmentCreateRequest request = new OapiDepartmentCreateRequest(); OapiDepartmentCreateRequest request = new OapiDepartmentCreateRequest();
@ -43,16 +50,15 @@ public class DepartmentServiceImpl extends BaseService implements DepartmentServ
try { try {
OapiDepartmentCreateResponse response = client.execute(request,getDingTalkToken()); OapiDepartmentCreateResponse response = client.execute(request,getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getMessage(),"createDepartment",JSON.toJSONString(request));
return response.getId(); return response.getId();
}else { }else {
syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,response.getErrmsg(),"createDepartment",JSON.toJSONString(request)); throw new DingTalkSyncException(JSON.toJSONString(request),response.getErrmsg());
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_CREATE,e.getMessage(),"createDepartment",JSON.toJSONString(request));
e.printStackTrace(); e.printStackTrace();
log.error("钉钉创建部门createDepartment异常{}",e.getMessage());
throw new DingTalkSyncException(JSON.toJSONString(request),e.getErrMsg());
} }
return null;
} }
@ -66,7 +72,7 @@ public class DepartmentServiceImpl extends BaseService implements DepartmentServ
try { try {
OapiDepartmentListResponse response = client.execute(request, getDingTalkToken()); OapiDepartmentListResponse response = client.execute(request, getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_LIST,response.getMessage(),"getDingTalkDepartmentList",JSON.toJSONString(request)); syncDingTalkSuccessOperLog(BaseConstantUrl.DEPARTMENT_LIST,response.getMessage(),"getDingTalkDepartmentList",JSON.toJSONString(request));
return response.getDepartment(); return response.getDepartment();
}else { }else {
syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_LIST,response.getErrmsg(),"getDingTalkDepartmentList",JSON.toJSONString(request)); syncDingTalkErrorOperLog(BaseConstantUrl.DEPARTMENT_LIST,response.getErrmsg(),"getDingTalkDepartmentList",JSON.toJSONString(request));
@ -79,9 +85,4 @@ public class DepartmentServiceImpl extends BaseService implements DepartmentServ
} }
public void sycnDepartmentData(){
List<OapiDepartmentListResponse.Department> dingTalkDepartmentList = getDingTalkDepartmentList();
}
} }

View File

@ -7,6 +7,9 @@ import com.dingtalk.api.request.OapiV2UserCreateRequest;
import com.dingtalk.api.request.OapiV2UserDeleteRequest; import com.dingtalk.api.request.OapiV2UserDeleteRequest;
import com.dingtalk.api.response.OapiV2UserCreateResponse; import com.dingtalk.api.response.OapiV2UserCreateResponse;
import com.dingtalk.api.response.OapiV2UserDeleteResponse; import com.dingtalk.api.response.OapiV2UserDeleteResponse;
import com.snow.common.annotation.DingTalkSyncLog;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.common.exception.DingTalkSyncException;
import com.snow.common.utils.StringUtils; import com.snow.common.utils.StringUtils;
import com.snow.common.utils.spring.SpringUtils; import com.snow.common.utils.spring.SpringUtils;
import com.snow.dingtalk.common.BaseConstantUrl; import com.snow.dingtalk.common.BaseConstantUrl;
@ -36,6 +39,7 @@ public class UserServiceImpl extends BaseService implements UserService {
private SysPostServiceImpl sysPostService=SpringUtils.getBean("sysPostServiceImpl"); private SysPostServiceImpl sysPostService=SpringUtils.getBean("sysPostServiceImpl");
@Override @Override
@DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.USER_CREATE,dingTalkUrl=BaseConstantUrl.USER_CREATE)
public OapiV2UserCreateResponse.UserCreateResponse createUser(SysUser sysUser) { public OapiV2UserCreateResponse.UserCreateResponse createUser(SysUser sysUser) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_CREATE); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_CREATE);
OapiV2UserCreateRequest req = new OapiV2UserCreateRequest(); OapiV2UserCreateRequest req = new OapiV2UserCreateRequest();
@ -73,20 +77,19 @@ public class UserServiceImpl extends BaseService implements UserService {
try { try {
response = client.execute(req, getDingTalkToken()); response = client.execute(req, getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,response.getMessage(),"createUser",JSON.toJSONString(req));
OapiV2UserCreateResponse.UserCreateResponse result = response.getResult(); OapiV2UserCreateResponse.UserCreateResponse result = response.getResult();
return result; return result;
}else { }else {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,response.getErrmsg(),"createUser",JSON.toJSONString(req)); throw new DingTalkSyncException(JSON.toJSONString(req),response.getErrmsg());
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_CREATE,e.getMessage(),"createUser",JSON.toJSONString(req)); log.error("钉钉createUser异常{}",e.getErrMsg());
e.printStackTrace(); throw new DingTalkSyncException(JSON.toJSONString(req),e.getErrMsg());
} }
return null;
} }
@Override @Override
@DingTalkSyncLog(dingTalkListenerType = DingTalkListenerType.USER_DELETE,dingTalkUrl=BaseConstantUrl.USER_DELETE)
public void deleteUser(String ids) { public void deleteUser(String ids) {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_DELETE); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.USER_DELETE);
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest(); OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
@ -95,15 +98,15 @@ public class UserServiceImpl extends BaseService implements UserService {
try { try {
response = client.execute(req, getDingTalkToken()); response = client.execute(req, getDingTalkToken());
if(response.getErrcode()==0){ if(response.getErrcode()==0){
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,response.getMessage(),"deleteUser",JSON.toJSONString(req));
String requestId = response.getRequestId(); String requestId = response.getRequestId();
log.info("dingTalk删除用户返回{}",requestId); log.info("dingTalk删除用户返回{}",requestId);
}else { }else {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,response.getErrmsg(),"deleteUser",JSON.toJSONString(req)); throw new DingTalkSyncException(JSON.toJSONString(req),response.getErrmsg());
} }
} catch (ApiException e) { } catch (ApiException e) {
syncDingTalkErrorOperLog(BaseConstantUrl.USER_DELETE,e.getMessage(),"deleteUser",JSON.toJSONString(req)); log.error("钉钉deleteUser异常{}",e.getErrMsg());
e.printStackTrace(); e.printStackTrace();
throw new DingTalkSyncException(JSON.toJSONString(req),e.getErrMsg());
} }
} }
} }

View File

@ -5,6 +5,8 @@ import java.util.TimerTask;
import com.snow.framework.shiro.session.OnlineSession; import com.snow.framework.shiro.session.OnlineSession;
import com.snow.framework.util.LogUtils; import com.snow.framework.util.LogUtils;
import com.snow.framework.util.ShiroUtils; import com.snow.framework.util.ShiroUtils;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.service.ISysDingtalkSyncLogService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.snow.common.constant.Constants; import com.snow.common.constant.Constants;
@ -81,6 +83,25 @@ public class AsyncFactory
}; };
} }
/**
* 操作日志记录
*
* @param operLog 操作日志信息
* @return 任务task
*/
public static TimerTask recordDingTalkSyncOper(final SysDingtalkSyncLog operLog)
{
return new TimerTask()
{
@Override
public void run()
{
// 远程查询操作地点
operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
SpringUtils.getBean(ISysDingtalkSyncLogService.class).insertSysDingtalkSyncLog(operLog);
}
};
}
/** /**
* 记录登陆信息 * 记录登陆信息
* *

View File

@ -0,0 +1,141 @@
package com.snow.system.domain;
import java.util.Date;
import com.snow.common.annotation.Excel;
import com.snow.common.core.domain.BaseEntity;
import com.snow.common.enums.DingTalkListenerType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 钉钉同步日志记录对象 sys_dingtalk_sync_log
*
* @author snow
* @date 2020-11-13
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysDingtalkSyncLog extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 日志主键 */
private Long logId;
/** 模块标题 */
@Excel(name = "模块标题")
private String title;
/** 模块类型0其它 1用户 2部门 3角色 10回调 */
@Excel(name = "模块类型", readConverterExp = "0=其它,1=用户,2=部门,3=角色,1=0回调")
private Integer moduleType;
/** 业务类型0其它 1新增 2修改 3删除 */
@Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除")
private Integer businessType;
/** 方法名称 */
@Excel(name = "方法名称")
private String method;
/** 请求方式 */
@Excel(name = "请求方式")
private String requestMethod;
/** 操作类别0其它 1自动同步 2手工同步 */
@Excel(name = "操作类别", readConverterExp = "0=其它,1=自动同步,2=手工同步")
private Integer operatorType;
/** 操作人员 */
@Excel(name = "操作人员")
private String operName;
/** 部门名称 */
@Excel(name = "部门名称")
private String deptName;
/** 请求URL */
@Excel(name = "请求URL")
private String operUrl;
/** 主机地址 */
@Excel(name = "主机地址")
private String operIp;
/** 操作地点 */
@Excel(name = "操作地点")
private String operLocation;
/** 请求原参数 */
@Excel(name = "请求原参数")
private String operSourceParam;
/** 请求钉钉参数 */
@Excel(name = "请求钉钉参数")
private String operDingtalkParam;
/** 返回参数 */
@Excel(name = "返回参数")
private String jsonResult;
/** 操作状态0正常 1异常 */
@Excel(name = "操作状态", readConverterExp = "0=正常,1=异常")
private Integer status;
/** 错误消息 */
@Excel(name = "错误消息")
private String errorMsg;
/** 操作时间 */
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date operTime;
private DingTalkListenerType dingTalkListenerType;
public SysDingtalkSyncLog(DingTalkListenerType dingTalkListenerType, String method, String operUrl, Integer operatorType, String operSourceParam, String operDingtalkParam, String jsonResult){
this.dingTalkListenerType=dingTalkListenerType;
this.method= method;
this.operUrl=operUrl;
this.operatorType=operatorType;
this.operSourceParam= operSourceParam;
this.operDingtalkParam=operDingtalkParam;
this.jsonResult= jsonResult;
}
public SysDingtalkSyncLog(DingTalkListenerType dingTalkListenerType,String method,String operUrl,Integer operatorType,String operSourceParam,String operDingtalkParam,String jsonResult, String errorMsg){
this.dingTalkListenerType=dingTalkListenerType;
this.method= method;
this.operUrl=operUrl;
this.operatorType=operatorType;
this.operSourceParam= operSourceParam;
this.operDingtalkParam=operDingtalkParam;
this.jsonResult= jsonResult;
this.errorMsg= errorMsg;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("logId", getLogId())
.append("title", getTitle())
.append("moduleType", getModuleType())
.append("businessType", getBusinessType())
.append("method", getMethod())
.append("requestMethod", getRequestMethod())
.append("operatorType", getOperatorType())
.append("operName", getOperName())
.append("deptName", getDeptName())
.append("operUrl", getOperUrl())
.append("operIp", getOperIp())
.append("operLocation", getOperLocation())
.append("operSourceParam", getOperSourceParam())
.append("operDingtalkParam", getOperDingtalkParam())
.append("jsonResult", getJsonResult())
.append("status", getStatus())
.append("errorMsg", getErrorMsg())
.append("operTime", getOperTime())
.toString();
}
}

View File

@ -0,0 +1,61 @@
package com.snow.system.mapper;
import java.util.List;
import com.snow.system.domain.SysDingtalkSyncLog;
/**
* 钉钉同步日志记录Mapper接口
*
* @author snow
* @date 2020-11-13
*/
public interface SysDingtalkSyncLogMapper
{
/**
* 查询钉钉同步日志记录
*
* @param logId 钉钉同步日志记录ID
* @return 钉钉同步日志记录
*/
public SysDingtalkSyncLog selectSysDingtalkSyncLogById(Long logId);
/**
* 查询钉钉同步日志记录列表
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 钉钉同步日志记录集合
*/
public List<SysDingtalkSyncLog> selectSysDingtalkSyncLogList(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 新增钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
public int insertSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 修改钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
public int updateSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 删除钉钉同步日志记录
*
* @param logId 钉钉同步日志记录ID
* @return 结果
*/
public int deleteSysDingtalkSyncLogById(Long logId);
/**
* 批量删除钉钉同步日志记录
*
* @param logIds 需要删除的数据ID
* @return 结果
*/
public int deleteSysDingtalkSyncLogByIds(String[] logIds);
}

View File

@ -0,0 +1,61 @@
package com.snow.system.service;
import java.util.List;
import com.snow.system.domain.SysDingtalkSyncLog;
/**
* 钉钉同步日志记录Service接口
*
* @author snow
* @date 2020-11-13
*/
public interface ISysDingtalkSyncLogService
{
/**
* 查询钉钉同步日志记录
*
* @param logId 钉钉同步日志记录ID
* @return 钉钉同步日志记录
*/
public SysDingtalkSyncLog selectSysDingtalkSyncLogById(Long logId);
/**
* 查询钉钉同步日志记录列表
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 钉钉同步日志记录集合
*/
public List<SysDingtalkSyncLog> selectSysDingtalkSyncLogList(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 新增钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
public int insertSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 修改钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
public int updateSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog);
/**
* 批量删除钉钉同步日志记录
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysDingtalkSyncLogByIds(String ids);
/**
* 删除钉钉同步日志记录信息
*
* @param logId 钉钉同步日志记录ID
* @return 结果
*/
public int deleteSysDingtalkSyncLogById(Long logId);
}

View File

@ -0,0 +1,97 @@
package com.snow.system.service.impl;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.snow.system.mapper.SysDingtalkSyncLogMapper;
import com.snow.system.domain.SysDingtalkSyncLog;
import com.snow.system.service.ISysDingtalkSyncLogService;
import com.snow.common.core.text.Convert;
/**
* 钉钉同步日志记录Service业务层处理
*
* @author snow
* @date 2020-11-13
*/
@Service
public class SysDingtalkSyncLogServiceImpl implements ISysDingtalkSyncLogService
{
@Autowired
private SysDingtalkSyncLogMapper sysDingtalkSyncLogMapper;
/**
* 查询钉钉同步日志记录
*
* @param logId 钉钉同步日志记录ID
* @return 钉钉同步日志记录
*/
@Override
public SysDingtalkSyncLog selectSysDingtalkSyncLogById(Long logId)
{
return sysDingtalkSyncLogMapper.selectSysDingtalkSyncLogById(logId);
}
/**
* 查询钉钉同步日志记录列表
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 钉钉同步日志记录
*/
@Override
public List<SysDingtalkSyncLog> selectSysDingtalkSyncLogList(SysDingtalkSyncLog sysDingtalkSyncLog)
{
return sysDingtalkSyncLogMapper.selectSysDingtalkSyncLogList(sysDingtalkSyncLog);
}
/**
* 新增钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
@Override
public int insertSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog)
{
sysDingtalkSyncLog.setOperTime(new Date());
return sysDingtalkSyncLogMapper.insertSysDingtalkSyncLog(sysDingtalkSyncLog);
}
/**
* 修改钉钉同步日志记录
*
* @param sysDingtalkSyncLog 钉钉同步日志记录
* @return 结果
*/
@Override
public int updateSysDingtalkSyncLog(SysDingtalkSyncLog sysDingtalkSyncLog)
{
return sysDingtalkSyncLogMapper.updateSysDingtalkSyncLog(sysDingtalkSyncLog);
}
/**
* 删除钉钉同步日志记录对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteSysDingtalkSyncLogByIds(String ids)
{
return sysDingtalkSyncLogMapper.deleteSysDingtalkSyncLogByIds(Convert.toStrArray(ids));
}
/**
* 删除钉钉同步日志记录信息
*
* @param logId 钉钉同步日志记录ID
* @return 结果
*/
@Override
public int deleteSysDingtalkSyncLogById(Long logId)
{
return sysDingtalkSyncLogMapper.deleteSysDingtalkSyncLogById(logId);
}
}

View File

@ -213,7 +213,7 @@ public class SysUserServiceImpl implements ISysUserService
// 新增用户与角色管理 // 新增用户与角色管理
insertUserRole(user.getUserId(), user.getRoleIds()); insertUserRole(user.getUserId(), user.getRoleIds());
//同步用户数据 //同步用户数据
SyncEvent syncEvent = new SyncEvent(user, DingTalkListenerType.USER_CREATED); SyncEvent syncEvent = new SyncEvent(user, DingTalkListenerType.USER_CREATE);
applicationContext.publishEvent(syncEvent); applicationContext.publishEvent(syncEvent);
return rows; return rows;
} }

View File

@ -0,0 +1,133 @@
<?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="com.snow.system.mapper.SysDingtalkSyncLogMapper">
<resultMap type="SysDingtalkSyncLog" id="SysDingtalkSyncLogResult">
<result property="logId" column="log_id" />
<result property="title" column="title" />
<result property="moduleType" column="module_type" />
<result property="businessType" column="business_type" />
<result property="method" column="method" />
<result property="requestMethod" column="request_method" />
<result property="operatorType" column="operator_type" />
<result property="operName" column="oper_name" />
<result property="deptName" column="dept_name" />
<result property="operUrl" column="oper_url" />
<result property="operIp" column="oper_ip" />
<result property="operLocation" column="oper_location" />
<result property="operSourceParam" column="oper_source_param" />
<result property="operDingtalkParam" column="oper_dingtalk_param" />
<result property="jsonResult" column="json_result" />
<result property="status" column="status" />
<result property="errorMsg" column="error_msg" />
<result property="operTime" column="oper_time" />
</resultMap>
<sql id="selectSysDingtalkSyncLogVo">
select log_id, title, module_type, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_source_param, oper_dingtalk_param, json_result, status, error_msg, oper_time from sys_dingtalk_sync_log
</sql>
<select id="selectSysDingtalkSyncLogList" parameterType="SysDingtalkSyncLog" resultMap="SysDingtalkSyncLogResult">
<include refid="selectSysDingtalkSyncLogVo"/>
<where>
<if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>
<if test="moduleType != null "> and module_type = #{moduleType}</if>
<if test="businessType != null "> and business_type = #{businessType}</if>
<if test="method != null and method != ''"> and method like concat('%', #{method}, '%')</if>
<if test="requestMethod != null and requestMethod != ''"> and request_method = #{requestMethod}</if>
<if test="operatorType != null "> and operator_type = #{operatorType}</if>
<if test="operName != null and operName != ''"> and oper_name like concat('%', #{operName}, '%')</if>
<if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
<if test="operUrl != null and operUrl != ''"> and oper_url = #{operUrl}</if>
<if test="operIp != null and operIp != ''"> and oper_ip = #{operIp}</if>
<if test="operLocation != null and operLocation != ''"> and oper_location = #{operLocation}</if>
<if test="status != null "> and status = #{status}</if>
<if test="operTime != null "> and oper_time = #{operTime}</if>
</where>
</select>
<select id="selectSysDingtalkSyncLogById" parameterType="Long" resultMap="SysDingtalkSyncLogResult">
<include refid="selectSysDingtalkSyncLogVo"/>
where log_id = #{logId}
</select>
<insert id="insertSysDingtalkSyncLog" parameterType="SysDingtalkSyncLog" useGeneratedKeys="true" keyProperty="logId">
insert into sys_dingtalk_sync_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">title,</if>
<if test="moduleType != null">module_type,</if>
<if test="businessType != null">business_type,</if>
<if test="method != null">method,</if>
<if test="requestMethod != null">request_method,</if>
<if test="operatorType != null">operator_type,</if>
<if test="operName != null">oper_name,</if>
<if test="deptName != null">dept_name,</if>
<if test="operUrl != null">oper_url,</if>
<if test="operIp != null">oper_ip,</if>
<if test="operLocation != null">oper_location,</if>
<if test="operSourceParam != null and operSourceParam != ''">oper_source_param,</if>
<if test="operDingtalkParam != null and operDingtalkParam != ''">oper_dingtalk_param,</if>
<if test="jsonResult != null">json_result,</if>
<if test="status != null">status,</if>
<if test="errorMsg != null">error_msg,</if>
<if test="operTime != null">oper_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null and title != ''">#{title},</if>
<if test="moduleType != null">#{moduleType},</if>
<if test="businessType != null">#{businessType},</if>
<if test="method != null">#{method},</if>
<if test="requestMethod != null">#{requestMethod},</if>
<if test="operatorType != null">#{operatorType},</if>
<if test="operName != null">#{operName},</if>
<if test="deptName != null">#{deptName},</if>
<if test="operUrl != null">#{operUrl},</if>
<if test="operIp != null">#{operIp},</if>
<if test="operLocation != null">#{operLocation},</if>
<if test="operSourceParam != null and operSourceParam != ''">#{operSourceParam},</if>
<if test="operDingtalkParam != null and operDingtalkParam != ''">#{operDingtalkParam},</if>
<if test="jsonResult != null">#{jsonResult},</if>
<if test="status != null">#{status},</if>
<if test="errorMsg != null">#{errorMsg},</if>
<if test="operTime != null">#{operTime},</if>
</trim>
</insert>
<update id="updateSysDingtalkSyncLog" parameterType="SysDingtalkSyncLog">
update sys_dingtalk_sync_log
<trim prefix="SET" suffixOverrides=",">
<if test="title != null and title != ''">title = #{title},</if>
<if test="moduleType != null">module_type = #{moduleType},</if>
<if test="businessType != null">business_type = #{businessType},</if>
<if test="method != null">method = #{method},</if>
<if test="requestMethod != null">request_method = #{requestMethod},</if>
<if test="operatorType != null">operator_type = #{operatorType},</if>
<if test="operName != null">oper_name = #{operName},</if>
<if test="deptName != null">dept_name = #{deptName},</if>
<if test="operUrl != null">oper_url = #{operUrl},</if>
<if test="operIp != null">oper_ip = #{operIp},</if>
<if test="operLocation != null">oper_location = #{operLocation},</if>
<if test="operSourceParam != null and operSourceParam != ''">oper_source_param = #{operSourceParam},</if>
<if test="operDingtalkParam != null and operDingtalkParam != ''">oper_dingtalk_param = #{operDingtalkParam},</if>
<if test="jsonResult != null">json_result = #{jsonResult},</if>
<if test="status != null">status = #{status},</if>
<if test="errorMsg != null">error_msg = #{errorMsg},</if>
<if test="operTime != null">oper_time = #{operTime},</if>
</trim>
where log_id = #{logId}
</update>
<delete id="deleteSysDingtalkSyncLogById" parameterType="Long">
delete from sys_dingtalk_sync_log where log_id = #{logId}
</delete>
<delete id="deleteSysDingtalkSyncLogByIds" parameterType="String">
delete from sys_dingtalk_sync_log where log_id in
<foreach item="logId" collection="array" open="(" separator="," close=")">
#{logId}
</foreach>
</delete>
</mapper>