net.mingsoft.msend.action.LogAction Maven / Gradle / Ivy
/**
* The MIT License (MIT) * Copyright (c) 2018 铭飞科技
*
* 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.msend.action;
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.annotation.LogAnn;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.msend.biz.ILogBiz;
import net.mingsoft.msend.entity.LogEntity;
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.ModelAttribute;
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 铭飞开发团队
* @version
* 版本号:0.0
* 创建日期:2017-8-24 14:41:18
* 历史修订:
*/
@Api(value = "发送日志管理接口")
@Controller("sendLogAction")
@RequestMapping("/${ms.manager.path}/msend/log")
public class LogAction extends net.mingsoft.msend.action.BaseAction {
/**
* 注入发送日志业务层
*/
@Autowired
private ILogBiz logBiz;
/**
* 返回主界面index
*/
@GetMapping("/index")
public String index(HttpServletResponse response, HttpServletRequest request) {
return "/msend/log/index";
}
/**
* 查询发送日志列表
* @param log 发送日志实体
* log参数包含字段信息参考:
* logId
* appId 应用编号
* logDatetime 时间
* logContent 接收内容
* logReceive 接收人
* logType 日志类型0邮件1短信
*
返回
* [
* {
* logId:
* appId: 应用编号
* logDatetime: 时间
* logContent: 接收内容
* logReceive: 接收人
* logType: 日志类型0邮件1短信
* }
* ]
*/
@ApiOperation(value = "查询发送日志列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "logDatetime", value = "时间", required = false, paramType = "query"),
@ApiImplicitParam(name = "logContent", value = "接收内容", required = false, paramType = "query"),
@ApiImplicitParam(name = "logReceive", value = "接收人", required = false, paramType = "query"),
@ApiImplicitParam(name = "logType", value = "日志类型0邮件1短信", required = false, paramType = "query")
})
@GetMapping("/list")
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore LogEntity log, HttpServletResponse response, HttpServletRequest request, ModelMap model) {
BasicUtil.startPage();
List logList = logBiz.query(log);
return ResultData.build().success(new EUListBean(logList, (int) BasicUtil.endPage(logList).getTotal()));
}
/**
* 返回编辑界面log_form
*/
@GetMapping("/form")
public String form(@ModelAttribute @ApiIgnore LogEntity log, HttpServletResponse response, HttpServletRequest request, ModelMap model) {
if (log.getLogId() != null) {
BaseEntity logEntity = logBiz.getEntity(log.getLogId());
model.addAttribute("logEntity", logEntity);
}
return "/msend/log/form";
}
/**
* 获取发送日志
* @param log 发送日志实体
* log参数包含字段信息参考:
* logId
* appId 应用编号
* logDatetime 时间
* logContent 接收内容
* logReceive 接收人
* logType 日志类型0邮件1短信
* 返回
* {
* logId:
* appId: 应用编号
* logDatetime: 时间
* logContent: 接收内容
* logReceive: 接收人
* logType: 日志类型0邮件1短信
* }
*/
@ApiOperation(value = "获取发送日志接口")
@ApiImplicitParam(name = "logId", value = "日志编号", required = true, paramType = "query")
@GetMapping("/get")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore LogEntity log, HttpServletResponse response, HttpServletRequest request, ModelMap model) {
if (log.getLogId() <= 0) {
return ResultData.build().error(getResString("err.error", this.getResString("log.id")));
}
LogEntity _log = (LogEntity) logBiz.getEntity(log.getLogId());
return ResultData.build().success(_log);
}
/**
* 保存发送日志实体
* @param log 发送日志实体
* log参数包含字段信息参考:
* logId
* appId 应用编号
* logDatetime 时间
* logContent 接收内容
* logReceive 接收人
* logType 日志类型0邮件1短信
* 返回
* {
* logId:
* appId: 应用编号
* logDatetime: 时间
* logContent: 接收内容
* logReceive: 接收人
* logType: 日志类型0邮件1短信
* }
*/
@ApiOperation(value = "保存发送日志实体接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "logDatetime", value = "时间", required = true, paramType = "query"),
@ApiImplicitParam(name = "logContent", value = "接收内容", required = true, paramType = "query"),
@ApiImplicitParam(name = "logReceive", value = "接收人", required = true, paramType = "query"),
@ApiImplicitParam(name = "logType", value = "日志类型0邮件1短信", required = true, paramType = "query")
})
@LogAnn(title = "保存发送日志实体接口",businessType= BusinessTypeEnum.INSERT)
@PostMapping("/save")
@ResponseBody
public ResultData save(@ModelAttribute @ApiIgnore LogEntity log, HttpServletResponse response, HttpServletRequest request) {
//验证时间的值是否合法
if (StringUtil.isBlank(log.getLogDatetime())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.datetime")));
}
if (!StringUtil.checkLength(log.getLogDatetime() + "", 1, 19)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.datetime"), "1", "19"));
}
//验证接收内容的值是否合法
if (StringUtil.isBlank(log.getLogContent())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.content")));
}
if (!StringUtil.checkLength(log.getLogContent() + "", 1, 255)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.content"), "1", "255"));
}
//验证接收人的值是否合法
if (StringUtil.isBlank(log.getLogReceive())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.receive")));
}
if (!StringUtil.checkLength(log.getLogReceive() + "", 1, 0)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.receive"), "1", "0"));
}
//验证日志类型0邮件1短信的值是否合法
if (StringUtil.isBlank(log.getLogType())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.type")));
}
if (!StringUtil.checkLength(log.getLogType() + "", 1, 10)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.type"), "1", "10"));
}
logBiz.saveEntity(log);
return ResultData.build().success(log);
}
/**
* @param log 发送日志实体
* log参数包含字段信息参考:
* logId:多个logId直接用逗号隔开,例如logId=1,2,3,4
* 批量删除发送日志
* 返回
* {code:"错误编码",
* result:"true|false",
* resultMsg:"错误信息"
* }
*/
@ApiOperation(value = "批量删除日志接口")
@LogAnn(title = "批量删除日志接口",businessType= BusinessTypeEnum.DELETE)
@PostMapping("/delete")
@ResponseBody
public ResultData delete(@RequestBody List logs, HttpServletResponse response, HttpServletRequest request) {
int[] ids = new int[logs.size()];
for (int i = 0; i < logs.size(); i++) {
ids[i] = logs.get(i).getLogId();
}
logBiz.delete(ids);
return ResultData.build().success();
}
/**
* 更新发送日志信息发送日志
* @param log 发送日志实体
* log参数包含字段信息参考:
* logId
* appId 应用编号
* logDatetime 时间
* logContent 接收内容
* logReceive 接收人
* logType 日志类型0邮件1短信
* 返回
* {
* logId:
* appId: 应用编号
* logDatetime: 时间
* logContent: 接收内容
* logReceive: 接收人
* logType: 日志类型0邮件1短信
* }
*/
@ApiOperation(value = "更新发送日志信息发送日志接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "logId", value = "日志编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "logDatetime", value = "时间", required = true, paramType = "query"),
@ApiImplicitParam(name = "logContent", value = "接收内容", required = true, paramType = "query"),
@ApiImplicitParam(name = "logReceive", value = "接收人", required = true, paramType = "query"),
@ApiImplicitParam(name = "logType", value = "日志类型0邮件1短信", required = true, paramType = "query")
})
@LogAnn(title = "更新发送日志信息发送日志接口",businessType= BusinessTypeEnum.UPDATE)
@PostMapping("/update")
@ResponseBody
public ResultData update(@ModelAttribute @ApiIgnore LogEntity log, HttpServletResponse response,
HttpServletRequest request) {
//验证时间的值是否合法
if (StringUtil.isBlank(log.getLogDatetime())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.datetime")));
}
if (!StringUtil.checkLength(log.getLogDatetime() + "", 1, 19)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.datetime"), "1", "19"));
}
//验证接收内容的值是否合法
if (StringUtil.isBlank(log.getLogContent())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.content")));
}
if (!StringUtil.checkLength(log.getLogContent() + "", 1, 255)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.content"), "1", "255"));
}
//验证接收人的值是否合法
if (StringUtil.isBlank(log.getLogReceive())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.receive")));
}
if (!StringUtil.checkLength(log.getLogReceive() + "", 1, 0)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.receive"), "1", "0"));
}
//验证日志类型0邮件1短信的值是否合法
if (StringUtil.isBlank(log.getLogType())) {
return ResultData.build().error(getResString("err.empty", this.getResString("log.type")));
}
if (!StringUtil.checkLength(log.getLogType() + "", 1, 10)) {
return ResultData.build().error(getResString("err.length", this.getResString("log.type"), "1", "10"));
}
logBiz.updateEntity(log);
return ResultData.build().success(log);
}
}