From 75908cfb66083e8b66aa5de2e3173f9529776086 Mon Sep 17 00:00:00 2001 From: "java_cuibaocheng@163.com" Date: Wed, 15 Nov 2023 17:23:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=8F=A3=E5=9F=BA=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF-=E6=97=A5=E5=BF=97=E4=B8=AD=E5=A2=9E=E5=8A=A0IP?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=20server-other=20=E4=B8=AD=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20server-other:=20=20=20population-insert-log:=20true=20#?= =?UTF-8?q?=E4=BA=BA=E5=8F=A3=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=BC=80=E5=85=B3?= =?UTF-8?q?=20=20=20population-update-log:=20true=20#=E4=BA=BA=E5=8F=A3?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E4=BF=AE=E6=94=B9=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E5=BC=80=E5=85=B3=20=20=20populatio?= =?UTF-8?q?n-delete-log:=20true=20#=E4=BA=BA=E5=8F=A3=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=88=A0=E9=99=A4=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/properties/ProjectProperties.java | 26 +++++++++ .../PopulationLogAppController.java | 6 ++ .../dtos/populationlog/PopulationLogDTO.java | 10 ++++ .../IPopulationInfoService.java | 2 + .../impl/PopulationInfoServiceImpl.java | 10 +++- .../impl/PopulationLogServiceImpl.java | 58 ++++++++++++++++++- .../populationlog/population-log-mapper.xml | 4 ++ .../populationinfo/list-creator.html | 2 +- .../templates/populationinfo/list.html | 11 +++- .../templates/populationinfo/log.html | 5 +- 10 files changed, 129 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/cm/population/config/properties/ProjectProperties.java b/src/main/java/com/cm/population/config/properties/ProjectProperties.java index b8cbfd7..9eb5c34 100644 --- a/src/main/java/com/cm/population/config/properties/ProjectProperties.java +++ b/src/main/java/com/cm/population/config/properties/ProjectProperties.java @@ -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; diff --git a/src/main/java/com/cm/population/controller/app/api/populationlog/PopulationLogAppController.java b/src/main/java/com/cm/population/controller/app/api/populationlog/PopulationLogAppController.java index a09373a..6ac396f 100644 --- a/src/main/java/com/cm/population/controller/app/api/populationlog/PopulationLogAppController.java +++ b/src/main/java/com/cm/population/controller/app/api/populationlog/PopulationLogAppController.java @@ -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") diff --git a/src/main/java/com/cm/population/pojo/dtos/populationlog/PopulationLogDTO.java b/src/main/java/com/cm/population/pojo/dtos/populationlog/PopulationLogDTO.java index 16cf737..5b0778c 100644 --- a/src/main/java/com/cm/population/pojo/dtos/populationlog/PopulationLogDTO.java +++ b/src/main/java/com/cm/population/pojo/dtos/populationlog/PopulationLogDTO.java @@ -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; } diff --git a/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java b/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java index bc2f31f..6b338d6 100644 --- a/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java +++ b/src/main/java/com/cm/population/service/populationinfo/IPopulationInfoService.java @@ -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 listByHouseId(String houseId); void updateCreator(String populationInfoId, String creator); + } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java b/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java index 5be1a9f..85a7d24 100644 --- a/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java +++ b/src/main/java/com/cm/population/service/populationinfo/impl/PopulationInfoServiceImpl.java @@ -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 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 ids) { + if (projectProperties.getPopulationDeleteLog()) iPopulationLogService.delete(token, StringUtils.join(ids, "_")); Map 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); } + } \ No newline at end of file diff --git a/src/main/java/com/cm/population/service/populationlog/impl/PopulationLogServiceImpl.java b/src/main/java/com/cm/population/service/populationlog/impl/PopulationLogServiceImpl.java index 4c4594f..0ce3343 100644 --- a/src/main/java/com/cm/population/service/populationlog/impl/PopulationLogServiceImpl.java +++ b/src/main/java/com/cm/population/service/populationlog/impl/PopulationLogServiceImpl.java @@ -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 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()) { diff --git a/src/main/resources/mybatis/mapper/populationlog/population-log-mapper.xml b/src/main/resources/mybatis/mapper/populationlog/population-log-mapper.xml index ca744bd..74f84ec 100644 --- a/src/main/resources/mybatis/mapper/populationlog/population-log-mapper.xml +++ b/src/main/resources/mybatis/mapper/populationlog/population-log-mapper.xml @@ -11,6 +11,7 @@ + @@ -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 diff --git a/src/main/resources/templates/populationinfo/list-creator.html b/src/main/resources/templates/populationinfo/list-creator.html index bf02ce2..1105613 100644 --- a/src/main/resources/templates/populationinfo/list-creator.html +++ b/src/main/resources/templates/populationinfo/list-creator.html @@ -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 ''; } diff --git a/src/main/resources/templates/populationinfo/list.html b/src/main/resources/templates/populationinfo/list.html index 9736a8d..aa5be1f 100644 --- a/src/main/resources/templates/populationinfo/list.html +++ b/src/main/resources/templates/populationinfo/list.html @@ -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 ''; } diff --git a/src/main/resources/templates/populationinfo/log.html b/src/main/resources/templates/populationinfo/log.html index 3f2da4e..5ad2b4c 100644 --- a/src/main/resources/templates/populationinfo/log.html +++ b/src/main/resources/templates/populationinfo/log.html @@ -42,6 +42,9 @@ {{ item.populationInfoContent }}


+                                        

+ IP地址 : {{ item.populationInfoIp ? item.populationInfoIp : '无' }} +

{{# } }} @@ -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);