9 changed files with 580 additions and 12 deletions
@ -0,0 +1,150 @@ |
|||
package com.example.web.entity; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 信息跟踪表实体类 |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
public class InformationTra { |
|||
private Integer id; // 主键ID
|
|||
private String tracompany; // 修改者公司
|
|||
private String tradepartment; // 修改者部门
|
|||
private String traorganization; // 修改者组织
|
|||
private String trarole; // 修改者角色
|
|||
private String trauserName; // 修改者名字
|
|||
private String traassistant; // 修改协助人
|
|||
private String userId; // 客户ID
|
|||
private String operationEvent; // 操作事件
|
|||
private LocalDateTime operationTime; // 操作时间
|
|||
private LocalDateTime created_at; // 创建时间
|
|||
private LocalDateTime updated_at; // 更新时间
|
|||
private String originalData; // 原始数据JSON
|
|||
private String modifiedData; // 修改后数据JSON
|
|||
private String changedFields; // 变更字段列表JSON
|
|||
|
|||
public Integer getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(Integer id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getTracompany() { |
|||
return tracompany; |
|||
} |
|||
|
|||
public void setTracompany(String tracompany) { |
|||
this.tracompany = tracompany; |
|||
} |
|||
|
|||
public String getTradepartment() { |
|||
return tradepartment; |
|||
} |
|||
|
|||
public void setTradepartment(String tradepartment) { |
|||
this.tradepartment = tradepartment; |
|||
} |
|||
|
|||
public String getTraorganization() { |
|||
return traorganization; |
|||
} |
|||
|
|||
public void setTraorganization(String traorganization) { |
|||
this.traorganization = traorganization; |
|||
} |
|||
|
|||
public String getTrarole() { |
|||
return trarole; |
|||
} |
|||
|
|||
public void setTrarole(String trarole) { |
|||
this.trarole = trarole; |
|||
} |
|||
|
|||
public String getTrauserName() { |
|||
return trauserName; |
|||
} |
|||
|
|||
public void setTrauserName(String trauserName) { |
|||
this.trauserName = trauserName; |
|||
} |
|||
|
|||
public String getTraassistant() { |
|||
return traassistant; |
|||
} |
|||
|
|||
public void setTraassistant(String traassistant) { |
|||
this.traassistant = traassistant; |
|||
} |
|||
|
|||
public String getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public void setUserId(String userId) { |
|||
this.userId = userId; |
|||
} |
|||
|
|||
public String getOperationEvent() { |
|||
return operationEvent; |
|||
} |
|||
|
|||
public void setOperationEvent(String operationEvent) { |
|||
this.operationEvent = operationEvent; |
|||
} |
|||
|
|||
public LocalDateTime getOperationTime() { |
|||
return operationTime; |
|||
} |
|||
|
|||
public void setOperationTime(LocalDateTime operationTime) { |
|||
this.operationTime = operationTime; |
|||
} |
|||
|
|||
public LocalDateTime getCreated_at() { |
|||
return created_at; |
|||
} |
|||
|
|||
public void setCreated_at(LocalDateTime created_at) { |
|||
this.created_at = created_at; |
|||
} |
|||
|
|||
public LocalDateTime getUpdated_at() { |
|||
return updated_at; |
|||
} |
|||
|
|||
public void setUpdated_at(LocalDateTime updated_at) { |
|||
this.updated_at = updated_at; |
|||
} |
|||
|
|||
public String getOriginalData() { |
|||
return originalData; |
|||
} |
|||
|
|||
public void setOriginalData(String originalData) { |
|||
this.originalData = originalData; |
|||
} |
|||
|
|||
public String getModifiedData() { |
|||
return modifiedData; |
|||
} |
|||
|
|||
public void setModifiedData(String modifiedData) { |
|||
this.modifiedData = modifiedData; |
|||
} |
|||
|
|||
public String getChangedFields() { |
|||
return changedFields; |
|||
} |
|||
|
|||
public void setChangedFields(String changedFields) { |
|||
this.changedFields = changedFields; |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
package com.example.web.mapper; |
|||
|
|||
import com.example.web.annotation.DataSource; |
|||
import com.example.web.entity.InformationTra; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 信息跟踪表Mapper |
|||
*/ |
|||
@Mapper |
|||
public interface InformationTraMapper { |
|||
|
|||
/** |
|||
* 插入信息跟踪记录 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 影响行数 |
|||
*/ |
|||
@DataSource("wechat") |
|||
int insert(InformationTra informationTra); |
|||
|
|||
/** |
|||
* 根据用户ID查询最新的跟踪记录 |
|||
* @param userId 用户ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
@DataSource("wechat") |
|||
InformationTra selectLatestByUserId(String userId); |
|||
|
|||
/** |
|||
* 根据ID查询跟踪记录 |
|||
* @param id 主键ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
@DataSource("wechat") |
|||
InformationTra selectById(Integer id); |
|||
|
|||
/** |
|||
* 更新跟踪记录 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 影响行数 |
|||
*/ |
|||
@DataSource("wechat") |
|||
int update(InformationTra informationTra); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package com.example.web.service; |
|||
|
|||
import com.example.web.entity.InformationTra; |
|||
|
|||
/** |
|||
* 信息跟踪服务接口 |
|||
*/ |
|||
public interface InformationTraService { |
|||
|
|||
/** |
|||
* 记录用户操作 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean recordUserOperation(InformationTra informationTra); |
|||
|
|||
/** |
|||
* 根据用户ID查询最新的操作记录 |
|||
* @param userId 用户ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
InformationTra getLatestOperationByUserId(String userId); |
|||
|
|||
/** |
|||
* 根据ID查询操作记录 |
|||
* @param id 主键ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
InformationTra getOperationById(Integer id); |
|||
|
|||
/** |
|||
* 更新操作记录 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 是否成功 |
|||
*/ |
|||
boolean updateOperation(InformationTra informationTra); |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
package com.example.web.service.impl; |
|||
|
|||
import com.example.web.entity.InformationTra; |
|||
import com.example.web.mapper.InformationTraMapper; |
|||
import com.example.web.service.InformationTraService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
/** |
|||
* 信息跟踪服务实现类 |
|||
*/ |
|||
@Service |
|||
public class InformationTraServiceImpl implements InformationTraService { |
|||
|
|||
@Autowired |
|||
private InformationTraMapper informationTraMapper; |
|||
|
|||
/** |
|||
* 记录用户操作 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 是否成功 |
|||
*/ |
|||
@Override |
|||
public boolean recordUserOperation(InformationTra informationTra) { |
|||
try { |
|||
// 设置操作时间和创建时间
|
|||
if (informationTra.getOperationTime() == null) { |
|||
informationTra.setOperationTime(LocalDateTime.now()); |
|||
} |
|||
if (informationTra.getCreated_at() == null) { |
|||
informationTra.setCreated_at(LocalDateTime.now()); |
|||
} |
|||
if (informationTra.getUpdated_at() == null) { |
|||
informationTra.setUpdated_at(LocalDateTime.now()); |
|||
} |
|||
// 插入记录
|
|||
int result = informationTraMapper.insert(informationTra); |
|||
return result > 0; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据用户ID查询最新的操作记录 |
|||
* @param userId 用户ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
@Override |
|||
public InformationTra getLatestOperationByUserId(String userId) { |
|||
try { |
|||
return informationTraMapper.selectLatestByUserId(userId); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 根据ID查询操作记录 |
|||
* @param id 主键ID |
|||
* @return 信息跟踪实体 |
|||
*/ |
|||
@Override |
|||
public InformationTra getOperationById(Integer id) { |
|||
try { |
|||
return informationTraMapper.selectById(id); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 更新操作记录 |
|||
* @param informationTra 信息跟踪实体 |
|||
* @return 是否成功 |
|||
*/ |
|||
@Override |
|||
public boolean updateOperation(InformationTra informationTra) { |
|||
try { |
|||
// 设置更新时间
|
|||
if (informationTra.getUpdated_at() == null) { |
|||
informationTra.setUpdated_at(LocalDateTime.now()); |
|||
} |
|||
// 更新记录
|
|||
int result = informationTraMapper.update(informationTra); |
|||
return result > 0; |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
<?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.example.web.mapper.InformationTraMapper"> |
|||
|
|||
<!-- 插入信息跟踪记录 --> |
|||
<insert id="insert" parameterType="com.example.web.entity.InformationTra"> |
|||
INSERT INTO informationtra ( |
|||
tracompany, |
|||
tradepartment, |
|||
traorganization, |
|||
trarole, |
|||
trauserName, |
|||
traassistant, |
|||
userId, |
|||
operationEvent, |
|||
operationTime, |
|||
created_at, |
|||
updated_at, |
|||
originalData, |
|||
modifiedData, |
|||
changedFields |
|||
) VALUES ( |
|||
#{tracompany}, |
|||
#{tradepartment}, |
|||
#{traorganization}, |
|||
#{trarole}, |
|||
#{trauserName}, |
|||
#{traassistant}, |
|||
#{userId}, |
|||
#{operationEvent}, |
|||
#{operationTime}, |
|||
#{created_at}, |
|||
#{updated_at}, |
|||
#{originalData}, |
|||
#{modifiedData}, |
|||
#{changedFields} |
|||
) |
|||
</insert> |
|||
|
|||
<!-- 根据用户ID查询最新的跟踪记录 --> |
|||
<select id="selectLatestByUserId" parameterType="String" resultType="com.example.web.entity.InformationTra"> |
|||
SELECT * FROM informationtra |
|||
WHERE userId = #{userId} |
|||
ORDER BY operationTime DESC |
|||
LIMIT 1 |
|||
</select> |
|||
|
|||
<!-- 根据ID查询跟踪记录 --> |
|||
<select id="selectById" parameterType="Integer" resultType="com.example.web.entity.InformationTra"> |
|||
SELECT * FROM informationtra |
|||
WHERE id = #{id} |
|||
</select> |
|||
|
|||
<!-- 更新跟踪记录 --> |
|||
<update id="update" parameterType="com.example.web.entity.InformationTra"> |
|||
UPDATE informationtra SET |
|||
tracompany = #{tracompany}, |
|||
tradepartment = #{tradepartment}, |
|||
traorganization = #{traorganization}, |
|||
trarole = #{trarole}, |
|||
trauserName = #{trauserName}, |
|||
traassistant = #{traassistant}, |
|||
userId = #{userId}, |
|||
operationEvent = #{operationEvent}, |
|||
operationTime = #{operationTime}, |
|||
updated_at = #{updated_at}, |
|||
originalData = #{originalData}, |
|||
modifiedData = #{modifiedData}, |
|||
changedFields = #{changedFields} |
|||
WHERE id = #{id} |
|||
</update> |
|||
|
|||
</mapper> |
|||
Loading…
Reference in new issue