提交 7d1e1652 编写于 作者: sq3536's avatar sq3536

qx

上级 d7223463
...@@ -22,7 +22,7 @@ import java.util.*; ...@@ -22,7 +22,7 @@ import java.util.*;
public class ApiMethodModel extends BaseModel { public class ApiMethodModel extends BaseModel {
private static String[] ignoreMethodNames = new String[]{"GET", "CREATE", "UPDATE", "REMOVE"}; private static String[] ignoreMethodNames = new String[]{"GET", "CREATE", "UPDATE", "REMOVE"};
private static String[] booleanMethodNames = new String[]{"CREATE", "UPDATE", "REMOVE", "SAVE", "CREATEBATCH", "UPDATEBATCH", "REMOVEBATCH", "SAVEBATCH"}; private static String[] booleanMethodNames = new String[]{"CREATE", "UPDATE", "SAVE", "CREATEBATCH", "UPDATEBATCH", "REMOVEBATCH", "SAVEBATCH"};
private static Map<String,String> lang=new HashMap<String,String>(){{ private static Map<String,String> lang=new HashMap<String,String>(){{
put("GET","获取"); put("GET","获取");
...@@ -155,7 +155,7 @@ public class ApiMethodModel extends BaseModel { ...@@ -155,7 +155,7 @@ public class ApiMethodModel extends BaseModel {
if(iPSDEServiceAPIMethodInput!=null&&iPSDEServiceAPIMethodInput.getPSDEMethodDTO()!=null) if(iPSDEServiceAPIMethodInput!=null&&iPSDEServiceAPIMethodInput.getPSDEMethodDTO()!=null)
param=iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getName().replace("FilterDTO", "SearchContext"); param=iPSDEServiceAPIMethodInput.getPSDEMethodDTO().getName().replace("FilterDTO", "SearchContext");
if("KEYFIELD".equalsIgnoreCase(iPSDEServiceAPIMethodInput.getType())){ if("KEYFIELD".equalsIgnoreCase(iPSDEServiceAPIMethodInput.getType())||this.getName().equalsIgnoreCase("Remove")){
param = ""; param = "";
inParam2=getApiEntity().getEntity().getKeyField().getType().java; inParam2=getApiEntity().getEntity().getKeyField().getType().java;
inParamName = StringAdvUtils.camelcase(apiEntity.getEntity().getKeyField().getCodeName()); inParamName = StringAdvUtils.camelcase(apiEntity.getEntity().getKeyField().getCodeName());
...@@ -245,7 +245,12 @@ public class ApiMethodModel extends BaseModel { ...@@ -245,7 +245,12 @@ public class ApiMethodModel extends BaseModel {
if(getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn()!=null&&getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getPSDEMethodDTO()!=null) if(getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn()!=null&&getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getPSDEMethodDTO()!=null)
param=getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getPSDEMethodDTO().getName(); param=getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getPSDEMethodDTO().getName();
if ("VOID".equalsIgnoreCase(getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getType())) { if ("Remove".equalsIgnoreCase(getName())) {
needDomain2Dto=false;
param = "Boolean";
outParam2 = "Boolean";
}
else if ("VOID".equalsIgnoreCase(getPSDEServiceAPIMethod().getPSDEServiceAPIMethodReturn().getType())) {
needDomain2Dto=isNeedDto2Domain(); needDomain2Dto=isNeedDto2Domain();
param = getInParam(); param = getInParam();
outParam2 = getInParam2(); outParam2 = getInParam2();
...@@ -278,4 +283,44 @@ public class ApiMethodModel extends BaseModel { ...@@ -278,4 +283,44 @@ public class ApiMethodModel extends BaseModel {
return outParam; return outParam;
} }
private Map permission;
public Map getPermission()
{
if( this.getName().equalsIgnoreCase("CheckKey")||this.getName().equalsIgnoreCase("GetDraft")||
(this.getPSDEServiceAPIMethod().getPSDEAction()!=null&&this.getPSDEServiceAPIMethod().getPSDEAction().getPSDEOPPriv()!=null&&
"NONE".equalsIgnoreCase(this.getPSDEServiceAPIMethod().getPSDEAction().getPSDEOPPriv().getName()))||
(this.getPSDEServiceAPIMethod().getPSDEDataSet()!=null&&this.getPSDEServiceAPIMethod().getPSDEDataSet().getPSDEOPPriv()!=null&&
"NONE".equalsIgnoreCase(this.getPSDEServiceAPIMethod().getPSDEDataSet().getPSDEOPPriv().getName())) )
return null;
permission=new HashMap();
permission.put("ano", "PreAuthorize");
this.getInParam();
if(this.getApiEntity()==null||this.getApiEntity().getEntity()==null||(!this.getApiEntity().getEntity().isHasScopes())) {
permission.put("cond","hasAnyAuthority('ROLE_SUPERADMIN','"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-"+this.getName()+"-all')");
}
else if("FETCH".equalsIgnoreCase(getPSDEServiceAPIMethod().getMethodType()))
{
permission.put("cond","hasAnyAuthority('ROLE_SUPERADMIN','"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-"+this.getName().replace("Fetch","search")+"-all')"+
" and hasPermission(#"+this.getInParamName()+",'"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-Get')");
}
else if(this.getName().equalsIgnoreCase("Get"))
{
permission.put("ano", "PostAuthorize");
permission.put("cond","hasPermission(this.$"+StringAdvUtils.camelcase(this.getApiEntity().getDefaultDto().getCodeName())+"Mapping.toDomain(returnObject.body),'"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-"+this.getName()+"')");
}
else if(this.getName().equalsIgnoreCase("Update")||this.getName().equalsIgnoreCase("Remove")||ObjectUtils.isEmpty(this.getInParam()))
{
permission.put("cond","hasPermission(this.$"+StringAdvUtils.camelcase(this.getApiEntity().getEntity().getCodeName())+"Service.get(#"+this.getInParamName2()+"),'"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-"+this.getName()+"')");
}
else if(this.getName().equalsIgnoreCase("Create")||this.getName().equalsIgnoreCase("Save")||this.isNeedDto2Domain())
{
permission.put("cond","hasPermission(this.$"+StringAdvUtils.camelcase(this.getApiEntity().getDefaultDto().getCodeName())+"Mapping.toDomain(#"+this.getInParamName()+"),'"+this.getApiEntity().getEntity().getSystem().getProjectName()+"-"+this.getApiEntity().getEntity().getCodeName()+"-"+this.getName()+"')");
}
return permission;
}
} }
...@@ -514,37 +514,45 @@ public class EntityModel extends BaseModel { ...@@ -514,37 +514,45 @@ public class EntityModel extends BaseModel {
return publishers; return publishers;
} }
private List<OptionItem> dataScopes;
public List<OptionItem> getDataScopes() public List<OptionItem> getDataScopes()
{ {
List<OptionItem> dataScopes=new ArrayList<>(); if(dataScopes==null)
dataScopes.add(new OptionItem().setId("all").setName("全部数据"));
boolean hasOrgId=false,hasDetpId=false,hasCreateBy=false;
for(FieldModel field:getFields())
{ {
if("ORGID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) dataScopes=new ArrayList<>();
hasOrgId=true; dataScopes.add(new OptionItem().setId("all").setName("全部数据"));
else if("ORGSECTORID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) boolean hasOrgId=false,hasDetpId=false,hasCreateBy=false;
hasDetpId=true; for(FieldModel field:getFields())
else if("CREATEMAN".equalsIgnoreCase(field.getDataEntityField().getPredefinedType())) {
hasCreateBy=true; if("ORGID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
} hasOrgId=true;
if(hasOrgId) else if("ORGSECTORID".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
{ hasDetpId=true;
dataScopes.add(new OptionItem().setId("curorg").setName("当前单位")); else if("CREATEMAN".equalsIgnoreCase(field.getDataEntityField().getPredefinedType()))
dataScopes.add(new OptionItem().setId("porg").setName("上级单位")); hasCreateBy=true;
dataScopes.add(new OptionItem().setId("sorg").setName("下级单位")); }
} if(hasOrgId)
if(hasDetpId) {
{ dataScopes.add(new OptionItem().setId("curorg").setName("当前单位"));
dataScopes.add(new OptionItem().setId("curorgdept").setName("当前部门")); dataScopes.add(new OptionItem().setId("porg").setName("上级单位"));
dataScopes.add(new OptionItem().setId("porgdept").setName("上级部门")); dataScopes.add(new OptionItem().setId("sorg").setName("下级单位"));
dataScopes.add(new OptionItem().setId("sorgdept").setName("下级部门")); }
if(hasDetpId)
{
dataScopes.add(new OptionItem().setId("curorgdept").setName("当前部门"));
dataScopes.add(new OptionItem().setId("porgdept").setName("上级部门"));
dataScopes.add(new OptionItem().setId("sorgdept").setName("下级部门"));
}
if(hasCreateBy)
dataScopes.add(new OptionItem().setId("createman").setName("创建人"));
} }
if(hasCreateBy)
dataScopes.add(new OptionItem().setId("createman").setName("创建人"));
return dataScopes; return dataScopes;
} }
public boolean isHasScopes() {
return getDataScopes().size()>1;
}
private Map<String, POSchema> poSchemas; private Map<String, POSchema> poSchemas;
public POSchema getDefaultPOSchema() public POSchema getDefaultPOSchema()
......
...@@ -66,6 +66,11 @@ public interface {{entity.codeName}}Mapper extends BaseMapper<{{entity.codeName} ...@@ -66,6 +66,11 @@ public interface {{entity.codeName}}Mapper extends BaseMapper<{{entity.codeName}
{{/enableEntityCache}} {{/enableEntityCache}}
int deleteById(Serializable id); int deleteById(Serializable id);
{{#enableEntityCache}}
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true)
{{/enableEntityCache}}
int deleteEntities(@Param("list") List<{{entity.codeName}}> list);
/** /**
* 自定义查询SQL * 自定义查询SQL
* @param sql * @param sql
......
...@@ -58,10 +58,6 @@ import {{packageName}}.core.{{module}}.service.{{codeName}}Service; ...@@ -58,10 +58,6 @@ import {{packageName}}.core.{{module}}.service.{{codeName}}Service;
@Service("{{entity.codeName}}Service") @Service("{{entity.codeName}}Service")
public class {{entity.codeName}}ServiceBase extends ServiceImpl<{{entity.codeName}}Mapper,{{entity.codeName}}> implements {{entity.codeName}}Service { public class {{entity.codeName}}ServiceBase extends ServiceImpl<{{entity.codeName}}Mapper,{{entity.codeName}}> implements {{entity.codeName}}Service {
protected {{entity.codeName}}Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{#entity.relEntities}} {{#entity.relEntities}}
{{#neq storage "NONE"}} {{#neq storage "NONE"}}
@Autowired @Autowired
...@@ -314,17 +310,19 @@ public class {{entity.codeName}}ServiceBase extends ServiceImpl<{{entity.codeNam ...@@ -314,17 +310,19 @@ public class {{entity.codeName}}ServiceBase extends ServiceImpl<{{entity.codeNam
{{/if}} {{/if}}
return true ; return true ;
} }
{{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids) { public boolean removeByEntities(List<{{entity.codeName}}> entities) {
{{#if (or entity.actions.update.psDEActionLogics entity.isIndexSubDE (not entity.keyField.phisicalDEField) entity.hasPSDERsMapping)}} {{#if (or entity.actions.update.psDEActionLogics entity.isIndexSubDE entity.hasPSDERsMapping)}}
for ({{entity.keyField.type.java}} et : ids) for ({{entity.codeName}} et : entities) {
getSelf().remove(et); if(!getSelf().remove(et))
return false;
}
return true;
{{else}} {{else}}
if(!removeByIds(ids)) this.baseMapper.deleteEntities(entities);
return false;
{{/if}}
return true; return true;
{{/if}}
} }
{{#entity.extActions}} {{#entity.extActions}}
......
...@@ -49,10 +49,6 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper; ...@@ -49,10 +49,6 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
@Service("{{entity.codeName}}Service") @Service("{{entity.codeName}}Service")
public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Service { public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Service {
protected {{entity.codeName}}Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{#entity.relEntities}} {{#entity.relEntities}}
{{#neq storage "NONE"}} {{#neq storage "NONE"}}
@Autowired @Autowired
...@@ -159,7 +155,7 @@ public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Servic ...@@ -159,7 +155,7 @@ public class {{entity.codeName}}ServiceBase implements {{entity.codeName}}Servic
} }
{{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}} {{#eq entity.actions.remove.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.remove.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids) { public boolean removeByEntities(List<{{entity.codeName}}> entities) {
return false; return false;
} }
......
...@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict; ...@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import cn.ibizlab.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.security.SpringContextHolder;
import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}}; import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext; import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
...@@ -26,11 +27,15 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo ...@@ -26,11 +27,15 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo
{{/dsName}} {{/dsName}}
public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}> { public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}> {
default {{entity.codeName}}Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{entity.codeName}} get({{entity.codeName}} et); {{entity.codeName}} get({{entity.codeName}} et);
default {{entity.codeName}} get({{entity.keyField.type.java}} key) { default {{entity.codeName}} get({{entity.keyField.type.java}} key) {
{{entity.codeName}} et = new {{entity.codeName}}(); {{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key); et.set{{pascalCase entity.keyField.codeName}}(key);
return get(et); return getSelf().get(et);
} }
default List<{{entity.codeName}}> getByIds(Collection<{{entity.keyField.type.java}}> ids) { default List<{{entity.codeName}}> getByIds(Collection<{{entity.keyField.type.java}}> ids) {
List<{{entity.codeName}}> entities =new ArrayList(); List<{{entity.codeName}}> entities =new ArrayList();
...@@ -39,7 +44,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}} ...@@ -39,7 +44,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
et.set{{pascalCase entity.keyField.codeName}}(key); et.set{{pascalCase entity.keyField.codeName}}(key);
entities.add(et); entities.add(et);
}); });
return getByEntities(entities); return getSelf().getByEntities(entities);
} }
List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities); List<{{entity.codeName}}> getByEntities(List<{{entity.codeName}}> entities);
...@@ -68,17 +73,24 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}} ...@@ -68,17 +73,24 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
default boolean remove({{entity.keyField.type.java}} key) { default boolean remove({{entity.keyField.type.java}} key) {
{{entity.codeName}} et = new {{entity.codeName}}(); {{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key); et.set{{pascalCase entity.keyField.codeName}}(key);
return remove(et); return getSelf().remove(et);
} }
default boolean remove(List<{{entity.keyField.type.java}}> key) { default boolean remove(List<{{entity.keyField.type.java}}> key) {
return removeBatch(key); return removeBatch(key);
} }
boolean remove({{entity.codeName}} et); boolean remove({{entity.codeName}} et);
{{#enableEntityCache}} default boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids) {
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) List<{{entity.codeName}}> entities =new ArrayList();
{{/enableEntityCache}} ids.forEach(key -> {
boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids); {{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key);
entities.add(et);
});
return getSelf().removeByEntities(entities);
}
boolean removeByEntities(List<{{entity.codeName}}> entities);
{{#each entity.extActions}} {{#each entity.extActions}}
default {{outParam}} {{camelCase codeName}}({{inParam}} {{inParamName}}) { default {{outParam}} {{camelCase codeName}}({{inParam}} {{inParamName}}) {
...@@ -115,7 +127,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}} ...@@ -115,7 +127,7 @@ public interface {{entity.codeName}}Service extends IService<{{entity.codeName}}
default boolean saveBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}},List<{{entity.codeName}}> list) { default boolean saveBy{{pascalCase fkField.codeName}}({{fkField.type.java}} {{camelCase fkField.codeName}},List<{{entity.codeName}}> list) {
{{packageName}}.core.{{module}}.domain.{{entityCodeName}} et = new {{packageName}}.core.{{module}}.domain.{{entityCodeName}}(); {{packageName}}.core.{{module}}.domain.{{entityCodeName}} et = new {{packageName}}.core.{{module}}.domain.{{entityCodeName}}();
et.set{{pascalCase relEntity.keyField.codeName}}({{camelCase fkField.codeName}}); et.set{{pascalCase relEntity.keyField.codeName}}({{camelCase fkField.codeName}});
return saveBy{{pascalCase fkField.codeName}}(et,list); return getSelf().saveBy{{pascalCase fkField.codeName}}(et,list);
} }
{{/entity.references}} {{/entity.references}}
......
...@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict; ...@@ -18,6 +18,7 @@ import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import cn.ibizlab.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.security.SpringContextHolder;
import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}}; import {{packageName}}.core.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext; import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
...@@ -26,6 +27,10 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo ...@@ -26,6 +27,10 @@ import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchCo
{{/dsName}} {{/dsName}}
public interface {{entity.codeName}}Service { public interface {{entity.codeName}}Service {
default {{entity.codeName}}Service getSelf() {
return SpringContextHolder.getBean(this.getClass());
}
{{entity.codeName}} get({{entity.codeName}} et); {{entity.codeName}} get({{entity.codeName}} et);
default {{entity.codeName}} get({{entity.keyField.type.java}} key) { default {{entity.codeName}} get({{entity.keyField.type.java}} key) {
{{entity.codeName}} et = new {{entity.codeName}}(); {{entity.codeName}} et = new {{entity.codeName}}();
...@@ -75,10 +80,17 @@ public interface {{entity.codeName}}Service { ...@@ -75,10 +80,17 @@ public interface {{entity.codeName}}Service {
} }
boolean remove({{entity.codeName}} et); boolean remove({{entity.codeName}} et);
{{#enableEntityCache}} default boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids) {
@CacheEvict(value = "{{lowerCase entity.codeName}}", allEntries = true) List<{{entity.codeName}}> entities =new ArrayList();
{{/enableEntityCache}} ids.forEach(key -> {
boolean removeBatch(Collection<{{entity.keyField.type.java}}> ids); {{entity.codeName}} et = new {{entity.codeName}}();
et.set{{pascalCase entity.keyField.codeName}}(key);
entities.add(et);
});
return getSelf().removeByEntities(entities);
}
boolean removeByEntities(List<{{entity.codeName}}> entities);
{{#each entity.extActions}} {{#each entity.extActions}}
default {{outParam}} {{camelCase codeName}}({{inParam}} {{inParamName}}) { default {{outParam}} {{camelCase codeName}}({{inParam}} {{inParamName}}) {
......
...@@ -23,7 +23,7 @@ import org.springframework.web.context.request.RequestAttributes; ...@@ -23,7 +23,7 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Map; import java.util.*;
/** /**
* 实体数据审计切面类 * 实体数据审计切面类
...@@ -41,7 +41,7 @@ public class AuditAspect ...@@ -41,7 +41,7 @@ public class AuditAspect
* 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置) * 实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* @param point * @param point
*/ */
@AfterReturning(value = "execution(* {{packageName}}.core.*.service.*.create(..)){{#system.enableES}}&& !execution(* {{packageName}}.core.es.service.*.create*(..)){{/system.enableES}}") @AfterReturning(value = "execution(* {{packageName}}.core.*.service.*.create*(..)){{#system.enableES}}&& !execution(* {{packageName}}.core.es.service.*.create*(..)){{/system.enableES}}")
@SneakyThrows @SneakyThrows
public void create(JoinPoint point) { public void create(JoinPoint point) {
HttpServletRequest request = null; HttpServletRequest request = null;
...@@ -60,6 +60,13 @@ public class AuditAspect ...@@ -60,6 +60,13 @@ public class AuditAspect
if(BeanCache.hasAudit(entity.getClass())) if(BeanCache.hasAudit(entity.getClass()))
dataAuditService.createAudit(request, entity, null); dataAuditService.createAudit(request, entity, null);
} }
else if(serviceParam instanceof List && !ObjectUtils.isEmpty(serviceParam)) {
List list=(List<?>) serviceParam;
if(list.get(0) instanceof EntityBase && BeanCache.hasAudit(list.get(0).getClass())) {
for(Object entity:list)
dataAuditService.createAudit(request, (EntityBase)entity, null);
}
}
} }
/** /**
...@@ -67,7 +74,7 @@ public class AuditAspect ...@@ -67,7 +74,7 @@ public class AuditAspect
* 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内 * 使用环切【@Around】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内
* @param point * @param point
*/ */
@Around("execution(* {{packageName}}.core.*.service.*.update(..)){{#system.enableES}}&& !execution(* {{packageName}}.core.es.service.*.update*(..)){{/system.enableES}}") @Around("execution(* {{packageName}}.core.*.service.*.update*(..)){{#system.enableES}}&& !execution(* {{packageName}}.core.es.service.*.update*(..)){{/system.enableES}}")
public Object update(ProceedingJoinPoint point) throws Throwable { public Object update(ProceedingJoinPoint point) throws Throwable {
HttpServletRequest request = null; HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
...@@ -79,11 +86,9 @@ public class AuditAspect ...@@ -79,11 +86,9 @@ public class AuditAspect
if(ObjectUtils.isEmpty(args) || args.length==0) { if(ObjectUtils.isEmpty(args) || args.length==0) {
return point.proceed(); return point.proceed();
} }
Object arg = args[0]; Object serviceParam = args[0];
if(arg instanceof EntityBase) { if(serviceParam instanceof EntityBase) {
EntityBase entity = (EntityBase) arg; EntityBase entity = (EntityBase) serviceParam;
if(BeanCache.hasAudit(entity.getClass())) if(BeanCache.hasAudit(entity.getClass()))
{ {
String idField = BeanCache.getKeyField(entity.getClass()); String idField = BeanCache.getKeyField(entity.getClass());
...@@ -99,16 +104,72 @@ public class AuditAspect ...@@ -99,16 +104,72 @@ public class AuditAspect
//执行更新操作 //执行更新操作
point.proceed(); point.proceed();
//记录审计日志 //记录审计日志
dataAuditService.updateAudit(request, beforeEntity , entity, null); if(beforeEntity!=null)
dataAuditService.updateAudit(request, beforeEntity , entity, null);
return true;
} }
else }
else if(serviceParam instanceof List && !ObjectUtils.isEmpty(serviceParam)) {
List list=(List<?>) serviceParam;
if(list.get(0) instanceof EntityBase && BeanCache.hasAudit(list.get(0).getClass())) {
EntityBase first=(EntityBase)list.get(0);
String idField = BeanCache.getKeyField(first.getClass());
if(ObjectUtils.isEmpty(idField)) {
return point.proceed();
}
List<EntityBase> beforeList=getEntitys(serviceObj,list,first.getClass());
Map<Object,EntityBase> beforeMap=new LinkedHashMap<>();
beforeList.forEach(before->{
beforeMap.put(before.get(idField),before);
});
point.proceed(); point.proceed();
return true; for(Object obj:list) {
EntityBase entity=(EntityBase)obj;
Object idValue=entity.get(idField);
EntityBase before=beforeMap.get(idValue);
if(before!=null)
dataAuditService.updateAudit(request, before, entity, idValue);
}
return true;
}
} }
return point.proceed(); return point.proceed();
} }
/**
* 实体数据更新切面,在成功更新数据后将新增数据内容记录审计日志内(审计明细【AuditInfo】中只记录审计属性变化情况,审计属性在平台属性中配置)
* 使用环切【@Around】获取要删除的完整数据,并将审计属性相关信息记录到审计日志中
* @param point
* @return
* @throws Throwable
*/
@AfterReturning(value = "execution(* {{packageName}}.core.*.service.*.remove*(..)){{#system.enableES}}&& !execution(* {{packageName}}.core.es.service.*.remove*(..)){{/system.enableES}}")
@SneakyThrows
public void remove(JoinPoint point) {
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if(requestAttributes!=null) {
request = ((ServletRequestAttributes)requestAttributes).getRequest();
}
Object [] args = point.getArgs();
if(ObjectUtils.isEmpty(args) || args.length==0) {
return;
}
Object serviceParam = args[0];
if(serviceParam instanceof EntityBase) {
EntityBase entity = (EntityBase)serviceParam;
//记录审计日志
if(BeanCache.hasAudit(entity.getClass()))
dataAuditService.removeAudit(request, entity, null);
}
else if(serviceParam instanceof List && !ObjectUtils.isEmpty(serviceParam)) {
List list=(List<?>) serviceParam;
if(list.get(0) instanceof EntityBase && BeanCache.hasAudit(list.get(0).getClass())) {
for(Object entity:list)
dataAuditService.removeAudit(request, (EntityBase)entity, null);
}
}
}
/** /**
* 获取实体 * 获取实体
...@@ -127,4 +188,16 @@ public class AuditAspect ...@@ -127,4 +188,16 @@ public class AuditAspect
} }
return null; return null;
} }
@SneakyThrows
private <T extends EntityBase> List<T> getEntitys(Object service, List<T> list, Class<T> clazz) {
if(!ObjectUtils.isEmpty(service)) {
EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("service", service);
oldContext.setVariable("list", list);
Expression oldExp = parser.parseExpression("#service.getByEntities(#list)");
return oldExp.getValue(oldContext, ArrayList.class);
}
return null;
}
} }
\ No newline at end of file
...@@ -9,7 +9,6 @@ import java.math.BigInteger; ...@@ -9,7 +9,6 @@ import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier; import org.springframework.cglib.beans.BeanCopier;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -57,17 +56,16 @@ public class {{apiEntity.codeName}}Resource { ...@@ -57,17 +56,16 @@ public class {{apiEntity.codeName}}Resource {
{{#each apiEntity.methods}} {{#each apiEntity.methods}}
{{#neq name "Select"}} {{#neq name "Select"}}
@ApiOperation(value = "{{apiName}}", tags = {"{{tags}}" }, notes = "{{notes}}") @ApiOperation(value = "{{apiName}}", tags = {"{{tags}}" }, notes = "{{notes}}")
{{#if permission}}
@{{permission.ano}}("{{permission.cond}}")
{{/if}}
{{#eq methodType "DEACTION"}} {{#eq methodType "DEACTION"}}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-{{name}}-all')")
{{#eq name "Update"}} {{#eq name "Update"}}
{{#if apiEntity.entity.lastModifyField}} {{#if apiEntity.entity.lastModifyField}}
@VersionCheck(entity = "{{lowerCase apiEntity.entity.codeName}}" , versionfield = "{{camelCase apiEntity.entity.lastModifyField.codeName}}") @VersionCheck(entity = "{{lowerCase apiEntity.entity.codeName}}" , versionfield = "{{camelCase apiEntity.entity.lastModifyField.codeName}}")
{{/if}} {{/if}}
{{/eq}} {{/eq}}
{{/eq}} {{/eq}}
{{#eq methodType "FETCH"}}
@PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-{{replace name "Fetch" "search"}}-all')")
{{/eq}}
@RequestMapping(method = RequestMethod.{{requestMethod}}, value = "{{requestPath}}") @RequestMapping(method = RequestMethod.{{requestMethod}}, value = "{{requestPath}}")
public ResponseEntity<{{outParam}}> {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}} public ResponseEntity<{{outParam}}> {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}
({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}{{#neq requestMethod 'GET'}}@Validated @RequestBody {{/neq}}{{body}}{{/if}}) { ({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}{{#neq requestMethod 'GET'}}@Validated @RequestBody {{/neq}}{{body}}{{/if}}) {
...@@ -90,12 +88,6 @@ public class {{apiEntity.codeName}}Resource { ...@@ -90,12 +88,6 @@ public class {{apiEntity.codeName}}Resource {
{{/if}} {{/if}}
{{/if}} {{/if}}
{{#if booleanReturn}} {{#if booleanReturn}}
{{#eq name "Remove"}}
if(ObjectUtils.isEmpty(list)) {
list=new ArrayList<>();
list.add({{#each pathVariables}}{{#if @last}}{{camelCase name}}{{/if}}{{/each}});
}
{{/eq}}
{{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{inParamName2}}); {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{inParamName2}});
{{outParam2}} rt = {{inParamName2}}; {{outParam2}} rt = {{inParamName2}};
{{else}} {{else}}
......
...@@ -101,6 +101,21 @@ ...@@ -101,6 +101,21 @@
in (<foreach collection="list" item="item" index="index" separator=","> ({{#each entity.keyFields as |field|}}{{#unless @first}},{{/unless}}#{ item.{{camelCase field.codeName}} }{{/each}}) </foreach>) in (<foreach collection="list" item="item" index="index" separator=","> ({{#each entity.keyFields as |field|}}{{#unless @first}},{{/unless}}#{ item.{{camelCase field.codeName}} }{{/each}}) </foreach>)
</select> </select>
<delete id="deleteEntities" parameterType="java.util.List">
{{#if entity.logicValid}}
update {{entity.tableName}} set
{{#if entity.logicValidField.type.number}}
{{entity.logicValidField.columnName}} = {{entity.inValidLogicValue}}
{{else}}
{{entity.logicValidField.columnName}} = '{{entity.inValidLogicValue}}'
{{/if}}
{{else}}
delete from {{entity.tableName}}
{{/if}}
where ({{#each entity.keyFields as |field|}}{{#unless @first}},{{/unless}}{{field.columnName}}{{/each}})
in (<foreach collection="list" item="item" index="index" separator=","> ({{#each entity.keyFields as |field|}}{{#unless @first}},{{/unless}}#{ item.{{camelCase field.codeName}} }{{/each}}) </foreach>)
</delete>
{{#each entity.dataQueries}} {{#each entity.dataQueries}}
<sql id="{{camelCase codeName}}" databaseId="{{dsType}}"> <sql id="{{camelCase codeName}}" databaseId="{{dsType}}">
<![CDATA[ <![CDATA[
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册