提交 b80e2b6d 编写于 作者: zhouweidong's avatar zhouweidong

代码规范检查

上级 91733830
......@@ -13,11 +13,10 @@ import org.mapstruct.*;
import ${pub.getPKGCodeName()}.core.${de.getPSSystemModule().getCodeName()?lower_case}.domain.${de.codeName};
import ${pubPkgCodeName}.${itemSysApiCodeNameLC}.dto.${item.getCodeName()}DTO;
import ${pub.getPKGCodeName()}.util.domain.MappingBase;
import org.mapstruct.factory.Mappers;
@Mapper(componentModel = "spring", uses = {}, implementationName = "${mappingName}",
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ${item.getCodeName()}Mapping extends MappingBase<${item.codeName}DTO, ${de.codeName}> {
<#--<#comment>输出关系数据(子实体)</#comment>-->
......
......@@ -45,13 +45,13 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
*/
@Scheduled(fixedRate = 10000)
public void saveAudit() {
if(cacheMap.size()>0){
if(cacheMap.size()>0) {
log.info(String.format("正在保存审计数据,当前审计集合数量为[%s]",cacheMap.size()));
List temp=new ArrayList();
if(cacheMap.size()<500){
if(cacheMap.size()<500) {
temp.addAll(cacheMap);
}
else{
else {
temp.addAll(cacheMap.subList(0,500));
}
this.saveBatch(temp);
......@@ -69,17 +69,17 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
*/
@Override
public void createAudit(HttpServletRequest request, EntityBase entity, Object idValue, Map<String, Audit> auditFields) {
IBZDataAudit dataAudit =new IBZDataAudit();
IBZDataAudit dataAudit = new IBZDataAudit();
dataAudit.setOppersonid(AuthenticationUser.getAuthenticationUser().getUserid());
dataAudit.setOppersonname(String.format("%s[%s]",AuthenticationUser.getAuthenticationUser().getPersonname(),AuthenticationUser.getAuthenticationUser().getOrgname()));
dataAudit.setAudittype("CREATE");
dataAudit.setAuditobject(entity.getClass().getSimpleName());
dataAudit.setAuditobjectdata(idValue);
dataAudit.setOptime(new Timestamp(new Date().getTime()));
if(request!=null){
if(request != null) {
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
}
dataAudit.setAuditinfo(getAuditInfo(entity,auditFields));
dataAudit.setAuditinfo(getAuditInfo(entity, auditFields));
dataAudit.setIsdatachanged(1);
cacheMap.add(dataAudit);
}
......@@ -93,24 +93,24 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @param auditFields
*/
@SneakyThrows
public void updateAudit(HttpServletRequest request, EntityBase beforeEntity, Object serviceObj, Object idValue, Map<String, Audit> auditFields){
public void updateAudit(HttpServletRequest request, EntityBase beforeEntity, Object serviceObj, Object idValue, Map<String, Audit> auditFields) {
//获取更新后的实体
EntityBase afterEntity=getEntity(serviceObj,idValue);
EntityBase afterEntity = getEntity(serviceObj, idValue);
//获取更新后的审计内容
String auditInfo=getUpdateAuditInfo(beforeEntity,afterEntity,auditFields);//比较更新前后差异内容
int isDataChanged=1;
String auditInfo = getUpdateAuditInfo(beforeEntity, afterEntity, auditFields);//比较更新前后差异内容
int isDataChanged = 1;
//审计内容是否发生变化
if(StringUtils.isEmpty(auditInfo)){
isDataChanged=0;
if(StringUtils.isEmpty(auditInfo)) {
isDataChanged = 0;
}
IBZDataAudit dataAudit =new IBZDataAudit();
IBZDataAudit dataAudit = new IBZDataAudit();
dataAudit.setOppersonid(AuthenticationUser.getAuthenticationUser().getUserid());
dataAudit.setOppersonname(String.format("%s[%s]",AuthenticationUser.getAuthenticationUser().getPersonname(),AuthenticationUser.getAuthenticationUser().getOrgname()));
dataAudit.setOppersonname(String.format("%s[%s]", AuthenticationUser.getAuthenticationUser().getPersonname(), AuthenticationUser.getAuthenticationUser().getOrgname()));
dataAudit.setAudittype("UPDATE");
dataAudit.setAuditobject(afterEntity.getClass().getSimpleName());
dataAudit.setAuditobjectdata(idValue);
dataAudit.setOptime(new Timestamp(new Date().getTime()));
if(request!=null){
if(request!=null) {
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
}
dataAudit.setAuditinfo(auditInfo);
......@@ -125,55 +125,55 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @param idValue
* @param auditFields
*/
public void removeAudit(HttpServletRequest request,EntityBase entity,Object idValue,Map<String, Audit> auditFields){
IBZDataAudit dataAudit =new IBZDataAudit();
public void removeAudit(HttpServletRequest request, EntityBase entity, Object idValue, Map<String, Audit> auditFields) {
IBZDataAudit dataAudit = new IBZDataAudit();
dataAudit.setOppersonid(AuthenticationUser.getAuthenticationUser().getUserid());
dataAudit.setOppersonname(String.format("%s[%s]",AuthenticationUser.getAuthenticationUser().getPersonname(),AuthenticationUser.getAuthenticationUser().getOrgname()));
dataAudit.setOppersonname(String.format("%s[%s]", AuthenticationUser.getAuthenticationUser().getPersonname(), AuthenticationUser.getAuthenticationUser().getOrgname()));
dataAudit.setAudittype("REMOVE");
dataAudit.setAuditobject(entity.getClass().getSimpleName());
dataAudit.setAuditobjectdata(idValue);
dataAudit.setOptime(new Timestamp(new Date().getTime()));
if(request!=null){
if(request!=null) {
dataAudit.setIpaddress(getIpAddress(request, AuthenticationUser.getAuthenticationUser()));
}
dataAudit.setAuditinfo(getAuditInfo(entity,auditFields));
dataAudit.setAuditinfo(getAuditInfo(entity, auditFields));
dataAudit.setIsdatachanged(1);
cacheMap.add(dataAudit);
}
private String getAuditInfo(EntityBase entity, Map<String, Audit> auditFields){
String auditResult="";
if(auditFields.size()==0){
private String getAuditInfo(EntityBase entity, Map<String, Audit> auditFields) {
String auditResult = "";
if(auditFields.size() == 0) {
return auditResult;
}
Map<String, DEField> deFields= DEFieldCacheMap.getDEFields(entity.getClass());
if(deFields.size()==0){
Map<String, DEField> deFields = DEFieldCacheMap.getDEFields(entity.getClass());
if(deFields.size() == 0) {
return auditResult;
}
JSONArray auditFieldArray=new JSONArray();
JSONArray auditFieldArray = new JSONArray();
for (Map.Entry<String, Audit> auditField : auditFields.entrySet()) {
Object objFieldName=auditField.getKey();
String fieldName=String.valueOf(objFieldName);
DEField deField=null;
if(deFields.containsKey(fieldName)){
deField= deFields.get(fieldName);
Object objFieldName = auditField.getKey();
String fieldName = String.valueOf(objFieldName);
DEField deField = null;
if(deFields.containsKey(fieldName)) {
deField = deFields.get(fieldName);
}
if(ObjectUtils.isEmpty(deField)){
if(ObjectUtils.isEmpty(deField)) {
continue;
}
Object value=dataTransfer(entity.get(fieldName),deField.fieldType(),deField.format());
if(!StringUtils.isEmpty(value)){
JSONObject auditFieldObj=new JSONObject();
auditFieldObj.put("field",deField.value());
auditFieldObj.put("value",value);
if(!StringUtils.isEmpty(deField.dict())){
auditFieldObj.put("dict",deField.dict());
Object value = dataTransfer(entity.get(fieldName), deField.fieldType(), deField.format());
if(!StringUtils.isEmpty(value)) {
JSONObject auditFieldObj = new JSONObject();
auditFieldObj.put("field", deField.value());
auditFieldObj.put("value", value);
if(!StringUtils.isEmpty(deField.dict())) {
auditFieldObj.put("dict", deField.dict());
}
auditFieldArray.add(auditFieldObj);
}
}
if(auditFieldArray.size()>0){
auditResult=auditFieldArray.toString();
if(auditFieldArray.size()>0) {
auditResult = auditFieldArray.toString();
}
return auditResult;
}
......@@ -186,44 +186,44 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @return
*/
private String getUpdateAuditInfo(EntityBase oldData, EntityBase newData, Map<String, Audit> auditFields){
String auditResult="";
JSONArray auditFieldArray=new JSONArray();
if(auditFields.size()==0){
String auditResult = "";
JSONArray auditFieldArray = new JSONArray();
if(auditFields.size() == 0) {
return auditResult;
}
Map<String, DEField> deFields= DEFieldCacheMap.getDEFields(oldData.getClass());
if(deFields.size()==0){
Map<String, DEField> deFields = DEFieldCacheMap.getDEFields(oldData.getClass());
if(deFields.size() == 0){
return auditResult;
}
for (Map.Entry<String, Audit> auditField : auditFields.entrySet()) {
Object objFieldName=auditField.getKey();//获取注解字段
String fieldName=String.valueOf(objFieldName); //属性名称
DEField deField=null;
if(deFields.containsKey(fieldName)){
deField= deFields.get(fieldName);
Object objFieldName = auditField.getKey();//获取注解字段
String fieldName = String.valueOf(objFieldName); //属性名称
DEField deField = null;
if(deFields.containsKey(fieldName)) {
deField = deFields.get(fieldName);
}
if(ObjectUtils.isEmpty(deField)){
if(ObjectUtils.isEmpty(deField)) {
continue;
}
Object oldValue=oldData.get(fieldName);//老属性值
Object newValue=newData.get(fieldName);//新属性值
if(!compare(oldValue,newValue)){
oldValue=dataTransfer(oldValue,deField.fieldType(),deField.format());//属性值转换
newValue=dataTransfer(newValue,deField.fieldType(),deField.format());//属性值转换
JSONObject auditFieldObj=new JSONObject();
auditFieldObj.put("field",deField.value());
auditFieldObj.put("beforevalue",oldValue);
auditFieldObj.put("value",newValue);
if(!StringUtils.isEmpty(deField.dict())){
auditFieldObj.put("dict",deField.dict());
Object oldValue = oldData.get(fieldName);//老属性值
Object newValue = newData.get(fieldName);//新属性值
if(!compare(oldValue, newValue)) {
oldValue = dataTransfer(oldValue, deField.fieldType(), deField.format());//属性值转换
newValue = dataTransfer(newValue, deField.fieldType(), deField.format());//属性值转换
JSONObject auditFieldObj = new JSONObject();
auditFieldObj.put("field", deField.value());
auditFieldObj.put("beforevalue", oldValue);
auditFieldObj.put("value", newValue);
if(!StringUtils.isEmpty(deField.dict())) {
auditFieldObj.put("dict", deField.dict());
}
auditFieldArray.add(auditFieldObj);
}
}
if(auditFieldArray.size()>0){
auditResult=auditFieldArray.toString();
if(auditFieldArray.size()>0) {
auditResult = auditFieldArray.toString();
}
return auditResult;
}
......@@ -235,16 +235,16 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @param strFormat 转换字段格式化文本
* @return
*/
private String dataTransfer(Object value,String dataType, String strFormat){
if(value==null){
private String dataTransfer(Object value, String dataType, String strFormat) {
if(value==null) {
return "";
}
String transResult=value.toString();
if((dataType.equals("DATE") || dataType.equals("DATETIME") || dataType.equals("TIME")) && (!StringUtils.isEmpty(strFormat))){ //时间类型转换
Timestamp timestamp =(Timestamp)value;
Date date =timestamp;
SimpleDateFormat format =new SimpleDateFormat(strFormat);
transResult=format.format(date);
if((dataType.equals("DATE") || dataType.equals("DATETIME") || dataType.equals("TIME")) && (!StringUtils.isEmpty(strFormat))) { //时间类型转换
Timestamp timestamp = (Timestamp)value;
Date date = timestamp;
SimpleDateFormat format = new SimpleDateFormat(strFormat);
transResult = format.format(date);
}
return transResult;
}
......@@ -255,11 +255,11 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @param targetObj 比较目标对象
* @return
*/
private boolean compare(Object sourceObj,Object targetObj){
if(sourceObj==null && targetObj==null){
private boolean compare(Object sourceObj, Object targetObj) {
if(sourceObj == null && targetObj == null) {
return true;
}
if(sourceObj==null && targetObj!=null){
if(sourceObj == null && targetObj != null) {
return false;
}
return sourceObj.equals(targetObj);
......@@ -272,9 +272,9 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
* @return
*/
@SneakyThrows
private EntityBase getEntity(Object service, Object id){
EntityBase entity=null;
if(!ObjectUtils.isEmpty(service)){
private EntityBase getEntity(Object service, Object id) {
EntityBase entity = null;
if(!ObjectUtils.isEmpty(service)) {
EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("service",service);
oldContext.setVariable("id",id);
......@@ -291,15 +291,15 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
*/
public String getIpAddress(HttpServletRequest request, AuthenticationUser authenticationUser) {
//客户端有提交ip,以提交的ip为准
if(authenticationUser != null && !StringUtils.isEmpty(authenticationUser.getAddr())){
if(authenticationUser != null && !StringUtils.isEmpty(authenticationUser.getAddr())) {
return authenticationUser.getAddr();
}
if(request == null){
if(request == null) {
return "";
}
String Xip = request.getHeader("X-Real-IP");
String XFor = request.getHeader("X-Forwarded-For");
if(!StringUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)){
if(!StringUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)) {
//多次反向代理后会有多个ip值,第一个ip才是真实ip
int index = XFor.indexOf(",");
if(index != -1){
......@@ -309,7 +309,7 @@ public class SimpleAuditService extends ServiceImpl<IBZDataAuditMapper, IBZDataA
}
}
XFor = Xip;
if(!StringUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)){
if(!StringUtils.isEmpty(XFor) && !"unKnown".equalsIgnoreCase(XFor)) {
return XFor;
}
if (StringUtils.isEmpty(XFor) || "unknown".equalsIgnoreCase(XFor)) {
......
......@@ -26,21 +26,21 @@ public class SimpleFileService implements FileService {
@Override
public FileItem saveFile(MultipartFile multipartFile) {
FileItem item=null;
FileItem item = null;
// 获取文件名
String fileName = multipartFile.getOriginalFilename();
// 获取文件后缀
String extname="."+getExtensionName(fileName);
String extname ="."+getExtensionName(fileName);
try {
String fileid= DigestUtils.md5DigestAsHex(multipartFile.getInputStream());
String fileid = DigestUtils.md5DigestAsHex(multipartFile.getInputStream());
String fileFullPath = this.fileRoot+"ibizutil"+File.separator+fileid+File.separator+fileName;
File file = new File(fileFullPath);
File parent = new File(file.getParent());
if(!parent.exists()){
if(!parent.exists()) {
parent.mkdirs();
}
FileCopyUtils.copy(multipartFile.getInputStream(),Files.newOutputStream(file.toPath()));
item=new FileItem(fileid,fileName,fileid,fileName,(int)multipartFile.getSize(),extname);
FileCopyUtils.copy(multipartFile.getInputStream(), Files.newOutputStream(file.toPath()));
item = new FileItem(fileid, fileName, fileid, fileName, (int)multipartFile.getSize(), extname);
} catch (IOException e) {
throw new InternalServerErrorException("文件上传失败,"+e);
}
......
......@@ -27,19 +27,19 @@ import org.springframework.security.core.authority.AuthorityUtils;
@Primary
@Service("SimpleUserService")
@ConditionalOnExpression("(!${r'${ibiz.enablePermissionValid:false}'})&&'${r'${ibiz.auth.service:'}<#if sys.getPSSystemSetting()?? && sys.getPSSystemSetting().getDataAccCtrlArch()?? && sys.getPSSystemSetting().getDataAccCtrlArch()==1>IBZUAAUserService<#else>SimpleUserService</#if>${r'}'}'.equals('SimpleUserService')")
public class SimpleUserService implements AuthenticationUserService{
public class SimpleUserService implements AuthenticationUserService {
@Override
public AuthenticationUser loadUserByUsername(String username) {
AuthenticationUser user = new AuthenticationUser();
String[] data=username.split("[|]");
String loginname=username;
String domains="";
String password="";
String[] data = username.split("[|]");
String loginname = username;
String domains = "";
String password = "";
if(data.length==2) {
loginname=data[0].trim();
domains=data[1].trim();
loginname = data[0].trim();
domains = data[1].trim();
}
user.setUserid(username);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册