add - 接口日志

master
yinq 1 year ago
parent e11344ddd1
commit 45268e1897

@ -0,0 +1,98 @@
package com.aucma.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.system.domain.SysPortLog;
import com.aucma.system.service.ISysPortLogService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;
/**
* MESController
*
* @author Yinq
* @date 2023-09-20
*/
@RestController
@RequestMapping("/system/portLog" )
public class SysPortLogController extends BaseController {
@Autowired
private ISysPortLogService sysPortLogService;
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:list')" )
@GetMapping("/list" )
public TableDataInfo list(SysPortLog sysPortLog) {
startPage();
List<SysPortLog> list = sysPortLogService.selectSysPortLogList(sysPortLog);
return getDataTable(list);
}
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:export')" )
@Log(title = "MES接口日志" , businessType = BusinessType.EXPORT)
@PostMapping("/export" )
public void export(HttpServletResponse response, SysPortLog sysPortLog) {
List<SysPortLog> list = sysPortLogService.selectSysPortLogList(sysPortLog);
ExcelUtil<SysPortLog> util = new ExcelUtil<SysPortLog>(SysPortLog. class);
util.exportExcel(response, list, "MES接口日志数据" );
}
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:query')" )
@GetMapping(value = "/{objId}" )
public AjaxResult getInfo(@PathVariable("objId") Long objId) {
return success(sysPortLogService.selectSysPortLogByObjId(objId));
}
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:add')" )
@Log(title = "MES接口日志" , businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysPortLog sysPortLog) {
return toAjax(sysPortLogService.insertSysPortLog(sysPortLog));
}
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:edit')" )
@Log(title = "MES接口日志" , businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysPortLog sysPortLog) {
return toAjax(sysPortLogService.updateSysPortLog(sysPortLog));
}
/**
* MES
*/
@PreAuthorize("@ss.hasPermi('system:portLog:remove')" )
@Log(title = "MES接口日志" , businessType = BusinessType.DELETE)
@DeleteMapping("/{objIds}" )
public AjaxResult remove(@PathVariable Long[] objIds) {
return toAjax(sysPortLogService.deleteSysPortLogByObjIds(objIds));
}
}

@ -0,0 +1,180 @@
package com.aucma.system.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.aucma.common.annotation.Excel;
import com.aucma.common.core.domain.BaseEntity;
/**
* MES sys_port_log
*
* @author Yinq
* @date 2023-09-20
*/
public class SysPortLog extends BaseEntity
{
private static final long serialVersionUID=1L;
/** 主键标识 */
private Long objId;
/** 工厂编码 */
@Excel(name = "工厂编码")
private String factoryCode;
/** 接口标题 */
@Excel(name = "接口标题")
private String logTitle;
/** 方法名称 */
@Excel(name = "方法名称")
private String logMethod;
/** 请求参数 */
@Excel(name = "请求参数")
private String operationParam;
/** 返回消息一 */
@Excel(name = "返回消息一")
private String resultOne;
/** 返回消息二 */
@Excel(name = "返回消息二")
private String resultTwo;
/** 返回消息三 */
@Excel(name = "返回消息三")
private String resultThree;
/** 错误消息 */
@Excel(name = "错误消息")
private String errorMsg;
/** 操作人 */
@Excel(name = "操作人")
private String operationUser;
/** 操作时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date operationTime;
public void setObjId(Long objId)
{
this.objId = objId;
}
public Long getObjId()
{
return objId;
}
public void setFactoryCode(String factoryCode)
{
this.factoryCode = factoryCode;
}
public String getFactoryCode()
{
return factoryCode;
}
public void setLogTitle(String logTitle)
{
this.logTitle = logTitle;
}
public String getLogTitle()
{
return logTitle;
}
public void setLogMethod(String logMethod)
{
this.logMethod = logMethod;
}
public String getLogMethod()
{
return logMethod;
}
public void setOperationParam(String operationParam)
{
this.operationParam = operationParam;
}
public String getOperationParam()
{
return operationParam;
}
public void setResultOne(String resultOne)
{
this.resultOne = resultOne;
}
public String getResultOne()
{
return resultOne;
}
public void setResultTwo(String resultTwo)
{
this.resultTwo = resultTwo;
}
public String getResultTwo()
{
return resultTwo;
}
public void setResultThree(String resultThree)
{
this.resultThree = resultThree;
}
public String getResultThree()
{
return resultThree;
}
public void setErrorMsg(String errorMsg)
{
this.errorMsg = errorMsg;
}
public String getErrorMsg()
{
return errorMsg;
}
public void setOperationUser(String operationUser)
{
this.operationUser = operationUser;
}
public String getOperationUser()
{
return operationUser;
}
public void setOperationTime(Date operationTime)
{
this.operationTime = operationTime;
}
public Date getOperationTime()
{
return operationTime;
}
@Override
public String toString(){
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("objId",getObjId())
.append("factoryCode",getFactoryCode())
.append("logTitle",getLogTitle())
.append("logMethod",getLogMethod())
.append("operationParam",getOperationParam())
.append("resultOne",getResultOne())
.append("resultTwo",getResultTwo())
.append("resultThree",getResultThree())
.append("errorMsg",getErrorMsg())
.append("operationUser",getOperationUser())
.append("operationTime",getOperationTime())
.toString();
}
}

@ -0,0 +1,61 @@
package com.aucma.system.mapper;
import java.util.List;
import com.aucma.system.domain.SysPortLog;
/**
* MESMapper
*
* @author Yinq
* @date 2023-09-20
*/
public interface SysPortLogMapper
{
/**
* MES
*
* @param objId MES
* @return MES
*/
public SysPortLog selectSysPortLogByObjId(Long objId);
/**
* MES
*
* @param sysPortLog MES
* @return MES
*/
public List<SysPortLog> selectSysPortLogList(SysPortLog sysPortLog);
/**
* MES
*
* @param sysPortLog MES
* @return
*/
public int insertSysPortLog(SysPortLog sysPortLog);
/**
* MES
*
* @param sysPortLog MES
* @return
*/
public int updateSysPortLog(SysPortLog sysPortLog);
/**
* MES
*
* @param objId MES
* @return
*/
public int deleteSysPortLogByObjId(Long objId);
/**
* MES
*
* @param objIds
* @return
*/
public int deleteSysPortLogByObjIds(Long[] objIds);
}

@ -0,0 +1,61 @@
package com.aucma.system.service;
import java.util.List;
import com.aucma.system.domain.SysPortLog;
/**
* MESService
*
* @author Yinq
* @date 2023-09-20
*/
public interface ISysPortLogService
{
/**
* MES
*
* @param objId MES
* @return MES
*/
public SysPortLog selectSysPortLogByObjId(Long objId);
/**
* MES
*
* @param sysPortLog MES
* @return MES
*/
public List<SysPortLog> selectSysPortLogList(SysPortLog sysPortLog);
/**
* MES
*
* @param sysPortLog MES
* @return
*/
public int insertSysPortLog(SysPortLog sysPortLog);
/**
* MES
*
* @param sysPortLog MES
* @return
*/
public int updateSysPortLog(SysPortLog sysPortLog);
/**
* MES
*
* @param objIds MES
* @return
*/
public int deleteSysPortLogByObjIds(Long[] objIds);
/**
* MES
*
* @param objId MES
* @return
*/
public int deleteSysPortLogByObjId(Long objId);
}

@ -0,0 +1,99 @@
package com.aucma.system.service.impl;
import java.util.List;
import com.aucma.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.aucma.system.mapper.SysPortLogMapper;
import com.aucma.system.domain.SysPortLog;
import com.aucma.system.service.ISysPortLogService;
import static com.aucma.common.utils.SecurityUtils.getUsername;
/**
* MESService
*
* @author Yinq
* @date 2023-09-20
*/
@Service
public class SysPortLogServiceImpl implements ISysPortLogService
{
@Autowired
private SysPortLogMapper sysPortLogMapper;
/**
* MES
*
* @param objId MES
* @return MES
*/
@Override
public SysPortLog selectSysPortLogByObjId(Long objId)
{
return sysPortLogMapper.selectSysPortLogByObjId(objId);
}
/**
* MES
*
* @param sysPortLog MES
* @return MES
*/
@Override
public List<SysPortLog> selectSysPortLogList(SysPortLog sysPortLog)
{
return sysPortLogMapper.selectSysPortLogList(sysPortLog);
}
/**
* MES
*
* @param sysPortLog MES
* @return
*/
@Override
public int insertSysPortLog(SysPortLog sysPortLog)
{
sysPortLog.setOperationUser(getUsername());
sysPortLog.setOperationTime(DateUtils.getNowDate());
return sysPortLogMapper.insertSysPortLog(sysPortLog);
}
/**
* MES
*
* @param sysPortLog MES
* @return
*/
@Override
public int updateSysPortLog(SysPortLog sysPortLog)
{
return sysPortLogMapper.updateSysPortLog(sysPortLog);
}
/**
* MES
*
* @param objIds MES
* @return
*/
@Override
public int deleteSysPortLogByObjIds(Long[] objIds)
{
return sysPortLogMapper.deleteSysPortLogByObjIds(objIds);
}
/**
* MES
*
* @param objId MES
* @return
*/
@Override
public int deleteSysPortLogByObjId(Long objId)
{
return sysPortLogMapper.deleteSysPortLogByObjId(objId);
}
}

@ -0,0 +1,51 @@
package com.aucma.system.utils;
import com.aucma.common.utils.spring.SpringUtils;
import com.aucma.system.domain.SysPortLog;
import com.aucma.system.service.ISysPortLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.TimerTask;
/**
*
*
* @author ruoyi
*/
public class PortLogUtils
{
private static final Logger logger = LoggerFactory.getLogger(PortLogUtils.class);
/**
*
* @param factoryCode
* @param logTitle
* @param logMethod
* @param operationParam
* @param resultOne
* @param errorMsg
*/
public static void savePortLog(String factoryCode, String logTitle, String logMethod, String operationParam, String resultOne , String errorMsg)
{
try {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
SysPortLog sysPortLog = new SysPortLog();
sysPortLog.setFactoryCode(factoryCode);
sysPortLog.setLogTitle(logTitle);
sysPortLog.setLogMethod(logMethod);
sysPortLog.setOperationParam(operationParam);
sysPortLog.setResultOne(resultOne);
sysPortLog.setErrorMsg(errorMsg);
SpringUtils.getBean(ISysPortLogService.class).insertSysPortLog(sysPortLog);
}
};
timerTask.run();
} catch (Exception e) {
logger.error("保存MES接口日志错误" + e.getMessage());
}
}
}

@ -0,0 +1,109 @@
<?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.aucma.system.mapper.SysPortLogMapper">
<resultMap type="SysPortLog" id="SysPortLogResult">
<result property="objId" column="obj_id" />
<result property="factoryCode" column="factory_code" />
<result property="logTitle" column="log_title" />
<result property="logMethod" column="log_method" />
<result property="operationParam" column="operation_param" />
<result property="resultOne" column="result_one" />
<result property="resultTwo" column="result_two" />
<result property="resultThree" column="result_three" />
<result property="errorMsg" column="error_msg" />
<result property="operationUser" column="operation_user" />
<result property="operationTime" column="operation_time" />
</resultMap>
<sql id="selectSysPortLogVo">
select obj_id, factory_code, log_title, log_method, operation_param,
result_one, result_two, result_three, error_msg, operation_user, operation_time from sys_port_log
</sql>
<select id="selectSysPortLogList" parameterType="SysPortLog" resultMap="SysPortLogResult">
<include refid="selectSysPortLogVo"/>
<where>
<if test="factoryCode != null and factoryCode != ''"> and factory_code like concat(concat('%', #{factoryCode}), '%')</if>
<if test="logTitle != null and logTitle != ''"> and log_title like concat(concat('%', #{logTitle}), '%')</if>
<if test="logMethod != null and logMethod != ''"> and log_method like concat(concat('%', #{logMethod}), '%')</if>
<if test="operationParam != null and operationParam != ''"> and operation_param = #{operationParam}</if>
<if test="resultOne != null and resultOne != ''"> and result_one = #{resultOne}</if>
<if test="resultTwo != null and resultTwo != ''"> and result_two = #{resultTwo}</if>
<if test="resultThree != null and resultThree != ''"> and result_three = #{resultThree}</if>
<if test="errorMsg != null and errorMsg != ''"> and error_msg = #{errorMsg}</if>
<if test="operationUser != null and operationUser != ''"> and operation_user = #{operationUser}</if>
<if test="params.beginOperationTime != null and params.beginOperationTime != '' and params.endOperationTime != null and params.endOperationTime != ''">
and operation_time between to_date(#{params.beginOperationTime},'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endOperationTime},'yyyy-mm-dd hh24:mi:ss')</if>
</where>
order by operation_time desc
</select>
<select id="selectSysPortLogByObjId" parameterType="Long" resultMap="SysPortLogResult">
<include refid="selectSysPortLogVo"/>
where obj_id = #{objId}
</select>
<insert id="insertSysPortLog" parameterType="SysPortLog">
<selectKey keyProperty="objId" resultType="long" order="BEFORE">
SELECT seq_sys_port_log.NEXTVAL as objId FROM DUAL
</selectKey>
insert into sys_port_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="objId != null">obj_id,</if>
<if test="factoryCode != null">factory_code,</if>
<if test="logTitle != null">log_title,</if>
<if test="logMethod != null">log_method,</if>
<if test="operationParam != null">operation_param,</if>
<if test="resultOne != null">result_one,</if>
<if test="resultTwo != null">result_two,</if>
<if test="resultThree != null">result_three,</if>
<if test="errorMsg != null">error_msg,</if>
<if test="operationUser != null">operation_user,</if>
<if test="operationTime != null">operation_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="objId != null">#{objId},</if>
<if test="factoryCode != null">#{factoryCode},</if>
<if test="logTitle != null">#{logTitle},</if>
<if test="logMethod != null">#{logMethod},</if>
<if test="operationParam != null">#{operationParam},</if>
<if test="resultOne != null">#{resultOne},</if>
<if test="resultTwo != null">#{resultTwo},</if>
<if test="resultThree != null">#{resultThree},</if>
<if test="errorMsg != null">#{errorMsg},</if>
<if test="operationUser != null">#{operationUser},</if>
<if test="operationTime != null">#{operationTime},</if>
</trim>
</insert>
<update id="updateSysPortLog" parameterType="SysPortLog">
update sys_port_log
<trim prefix="SET" suffixOverrides=",">
<if test="factoryCode != null">factory_code = #{factoryCode},</if>
<if test="logTitle != null">log_title = #{logTitle},</if>
<if test="logMethod != null">log_method = #{logMethod},</if>
<if test="operationParam != null">operation_param = #{operationParam},</if>
<if test="resultOne != null">result_one = #{resultOne},</if>
<if test="resultTwo != null">result_two = #{resultTwo},</if>
<if test="resultThree != null">result_three = #{resultThree},</if>
<if test="errorMsg != null">error_msg = #{errorMsg},</if>
<if test="operationUser != null">operation_user = #{operationUser},</if>
<if test="operationTime != null">operation_time = #{operationTime},</if>
</trim>
where obj_id = #{objId}
</update>
<delete id="deleteSysPortLogByObjId" parameterType="Long">
delete from sys_port_log where obj_id = #{objId}
</delete>
<delete id="deleteSysPortLogByObjIds" parameterType="String">
delete from sys_port_log where obj_id in
<foreach item="objId" collection="array" open="(" separator="," close=")">
#{objId}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save