人口基本信息-日志中增加IP记录功能

配置文件 server-other 中增加
server-other:
  population-insert-log: true #人口基础信息新增日志记录开关
  population-update-log: true #人口基础信息修改日志记录开关
  population-delete-log: true #人口基础信息删除日志记录开关
This commit is contained in:
java_cuibaocheng@163.com 2023-11-15 17:23:12 +08:00
parent aeb1dc7f65
commit 75908cfb66
10 changed files with 129 additions and 5 deletions

View File

@ -19,6 +19,32 @@ public class ProjectProperties {
private Integer port;
private String title;
private String areaUrl;
private Boolean populationUpdateLog = true;
private Boolean populationInsertLog = true;
private Boolean populationDeleteLog = true;
public Boolean getPopulationInsertLog() {
return populationInsertLog;
}
public void setPopulationInsertLog(Boolean populationInsertLog) {
this.populationInsertLog = populationInsertLog;
}
public Boolean getPopulationDeleteLog() {
return populationDeleteLog;
}
public void setPopulationDeleteLog(Boolean populationDeleteLog) {
this.populationDeleteLog = populationDeleteLog;
}
public Boolean getPopulationUpdateLog() {
return populationUpdateLog;
}
public void setPopulationUpdateLog(Boolean populationUpdateLog) {
this.populationUpdateLog = populationUpdateLog;
}
public Integer getPort() {
return port;

View File

@ -4,10 +4,13 @@ import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultData;
import com.cm.population.pojo.dtos.populationinfo.PopulationInfoDTO;
import com.cm.population.pojo.dtos.populationlog.PopulationLogDTO;
import com.cm.population.service.populationinfo.IPopulationInfoService;
import com.cm.population.service.populationlog.IPopulationLogService;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -28,6 +31,9 @@ public class PopulationLogAppController extends AbstractController {
@Autowired
private IPopulationLogService populationLogService;
@Autowired
private IPopulationInfoService populationInfoService;
@ApiOperation(value = "新增基础人口创建人日志", notes = "新增基础人口创建人日志接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header")

View File

@ -30,11 +30,21 @@ public class PopulationLogDTO {
private String populationInfoContent;
@ApiModelProperty(name = "populationInfoData", value = "日志内容")
private String populationInfoData;
@ApiModelProperty(name = "populationInfoIp", value = "日志IP")
private String populationInfoIp;
@ApiModelProperty(name = "creator")
private String creator;
@ApiModelProperty(name = "gmtCreate")
private String gmtCreate;
public String getPopulationInfoIp() {
return populationInfoIp;
}
public void setPopulationInfoIp(String populationInfoIp) {
this.populationInfoIp = populationInfoIp;
}
public String getPopulationInfoData() {
return populationInfoData;
}

View File

@ -2,6 +2,7 @@ package com.cm.population.service.populationinfo;
import com.cm.common.plugin.pojo.dtos.dataarea.DataAreaDTO;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import com.cm.population.pojo.dtos.areatree.AreaZtreeDTO;
import com.cm.population.pojo.dtos.population.PopulationDTO;
@ -205,4 +206,5 @@ public interface IPopulationInfoService {
List<PopulationInfoDTO> listByHouseId(String houseId);
void updateCreator(String populationInfoId, String creator);
}

View File

@ -9,11 +9,13 @@ import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
import com.cm.common.plugin.service.dataarea.IDataAreaService;
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResultData;
import com.cm.common.result.SuccessResultList;
import com.cm.common.token.app.AppTokenManager;
import com.cm.common.token.app.entity.AppTokenUser;
import com.cm.common.utils.HashMapUtil;
import com.cm.common.utils.UUIDUtil;
import com.cm.population.config.properties.ProjectProperties;
import com.cm.population.dao.areatree.IAreatreeDao;
import com.cm.population.dao.populationinfo.IPopulationInfoDao;
import com.cm.population.pojo.dtos.areatree.AreaZtreeDTO;
@ -187,6 +189,9 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul
private IReleaseService iReleaseService;
@Autowired
private ISecurityService iSecurityService;
@Autowired
private ProjectProperties projectProperties;
@Override
public PopulationInfoBaseDTO getBase(String populationInfoId) {
Map<String, Object> query = new HashMap<>();
@ -274,6 +279,7 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul
setSaveInfo(token, params);
}
populationInfoDao.save(params);
if (projectProperties.getPopulationInsertLog())
iPopulationLogService.saveInit(token, populationInfoId, params);// 记录日志
return populationInfoId;
}
@ -285,6 +291,7 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul
@Override
public void remove(String token, List<String> ids) {
if (projectProperties.getPopulationDeleteLog())
iPopulationLogService.delete(token, StringUtils.join(ids, "_"));
Map<String, Object> params = getHashMap(2);
params.put("populationInfoIds", ids);
@ -363,7 +370,7 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul
}
}
}
if (change.size() > 0)
if (change.size() > 0 && projectProperties.getPopulationUpdateLog())
iPopulationLogService.update(token, populationInfoId, change);// 记录日志
}
@ -508,4 +515,5 @@ public class PopulationInfoServiceImpl extends AbstractService implements IPopul
params.put("creator", creator);
populationInfoDao.updateCreator(params);
}
}

View File

@ -53,8 +53,11 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.record.BOFRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import springfox.documentation.spring.web.json.Json;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
@ -122,6 +125,11 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
if (creatorName.equals("admin")) {
creatorName = "超级管理员";
}
String ip = "获取失败";
try{
ip = getRemortIP();
}catch(Exception e) {
}
// 循环保存日志
for(PopulationInfoDTO dto : populationList) {
String populationInfoId = dto.getPopulationInfoId();
@ -143,6 +151,7 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
params.put("populationInfoOldCreatorName", oldCreatorName);
params.put("populationInfoOldCreator", oldCreator);
params.put("populationInfoContent", content);
params.put("populationInfoIp", ip);
params.put("creator", creator);
params.put("gmtCreate", gmtCreate);
populationLogDao.save(params);
@ -171,6 +180,11 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
if (creatorName.equals("admin")) {
creatorName = "超级管理员";
}
String ip = "获取失败";
try{
ip = getRemortIP();
}catch(Exception e) {
}
String gmtCreate = getTime();
PopulationInfoDTO dto = iPopulationInfoService.get(populationInfoId);
String content = "INSERT --- 登录人将." + dto.getName() + "[" + dto.getIdcard() + "]基础人员信息创建 操作人." + creatorName + "[" + creator + "]";
@ -183,6 +197,7 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
params.put("populationInfoOldCreator", "");
params.put("populationInfoContent", content);
params.put("populationInfoData", JSON.toJSONString(changeParams));
params.put("populationInfoIp", ip);
params.put("creator", creator);
params.put("gmtCreate", gmtCreate);
populationLogDao.save(params);
@ -210,6 +225,11 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
if (creatorName.equals("admin")) {
creatorName = "超级管理员";
}
String ip = "获取失败";
try{
ip = getRemortIP();
}catch(Exception e) {
}
String gmtCreate = getTime();
PopulationInfoDTO dto = iPopulationInfoService.get(populationInfoId);
String content = "UPDATE --- 登录人将." + dto.getName() + "[" + dto.getIdcard() + "]基础人员信息修改 操作人." + creatorName + "[" + creator + "]";
@ -222,6 +242,7 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
params.put("populationInfoOldCreator", "");
params.put("populationInfoContent", content);
params.put("populationInfoData", JSON.toJSONString(changeParams));
params.put("populationInfoIp", ip);
params.put("creator", creator);
params.put("gmtCreate", gmtCreate);
populationLogDao.save(params);
@ -264,6 +285,11 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
if (creatorName.equals("admin")) {
creatorName = "超级管理员";
}
String ip = "获取失败";
try{
ip = getRemortIP();
}catch(Exception e) {
}
// 循环保存日志
for(PopulationInfoDTO dto : populationList) {
String populationInfoId = dto.getPopulationInfoId();
@ -288,6 +314,7 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
params.put("populationInfoOldCreatorName", oldCreatorName);
params.put("populationInfoOldCreator", oldCreator);
params.put("populationInfoContent", content);
params.put("populationInfoIp", ip);
params.put("creator", creator);
params.put("gmtCreate", gmtCreate);
populationLogDao.save(params);
@ -295,6 +322,35 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
iPopulationInfoService.updateCreator(populationInfoId, creator);
}
}
private String getRemortIP() throws Exception {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String ip = request.getHeader("x-forwarded-for");
if (ip != null && ip.length() != 0 && !"unknown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值第一个ip才是真实ip
if (ip.indexOf(",") != -1) {
ip = ip.split(",")[0];
}
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
@Override
public List<PopulationLogDTO> list(String token, String populationInfoId) {
@ -318,7 +374,7 @@ public class PopulationLogServiceImpl extends AbstractService implements IPopula
if (!creator.equals("1")) {
for(PopulationLogDTO dto : list) {
dto.setPopulationInfoData(""); // 不给返回操作的数据
String populationInfoContent = dto.getPopulationInfoContent();
String populationInfoContent = dto.getPopulationInfoContent().replace("超级管理员[1]", "超级管理员");
Pattern pattern = Pattern.compile("[a-zA-Z0-9-]{36}");
Matcher matcher = pattern.matcher(populationInfoContent);
while(matcher.find()) {

View File

@ -11,6 +11,7 @@
<result column="population_info_old_creator" property="populationInfoOldCreator"/>
<result column="population_info_content" property="populationInfoContent"/>
<result column="population_info_data" property="populationInfoData"/>
<result column="population_info_ip" property="populationInfoIp"/>
<result column="creator" property="creator"/>
<result column="gmt_create" property="gmtCreate"/>
</resultMap>
@ -25,6 +26,7 @@
population_info_old_creator,
population_info_content,
population_info_data,
population_info_ip,
creator,
gmt_create
) VALUES(
@ -36,6 +38,7 @@
#{populationInfoOldCreator},
#{populationInfoContent},
#{populationInfoData},
#{populationInfoIp},
#{creator},
#{gmtCreate}
)
@ -51,6 +54,7 @@
t1.population_info_old_creator,
t1.population_info_content,
t1.population_info_data,
t1.population_info_ip,
t1.creator,
t1.gmt_create
FROM

View File

@ -212,7 +212,7 @@
return b;
}
},
{field: 'creator', width:120, title: '认领记录', align:'center',
{field: 'creator', width:120, title: '认领记录', align:'center', fixed: 'right',
templet: function(row) {
return '<button type="button" lay-event="bindEvent" class="layui-btn layui-btn-xs" >认领记录</button>';
}

View File

@ -209,7 +209,16 @@
return b;
}
},
{field: 'creator', width:120, title: '认领记录', align:'center',
{field: 'creatorName', width: 120, title: '当前认领人', align:'center',
templet: function(row) {
var rowData = row[this.field];
if(typeof(rowData) === 'undefined' || rowData == null || rowData == '') {
return '-';
}
return rowData;
}
},
{field: 'creator', width:120, title: '认领记录', align:'center', fixed: 'right',
templet: function(row) {
return '<button type="button" lay-event="bindEvent" class="layui-btn layui-btn-xs" >认领记录</button>';
}

View File

@ -42,6 +42,9 @@
{{ item.populationInfoContent }}
</p>
<pre id="{{ item.populationLogId }}"></pre>
<p style="color:#CD5C5C">
IP地址 : {{ item.populationInfoIp ? item.populationInfoIp : '无' }}
</p>
</div>
</li>
{{# } }}
@ -107,7 +110,7 @@
});
for(var i = 0 ; i < data.length ; i++) {
if (data[i].populationInfoData)
$('#' + data[i].populationLogId).jsonViewer(JSON.parse(data[i].populationInfoData), {collapsed:false});
$('#' + data[i].populationLogId).jsonViewer(JSON.parse(data[i].populationInfoData), {collapsed:true});
}
}, function(code, data) {
top.dialog.msg(data.msg);