提交 25c1f1f0 编写于 作者: ibiz4j's avatar ibiz4j

mapper

上级 a778de0b
......@@ -14,6 +14,7 @@ import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.IPSLinkDEField;
import net.ibizsys.model.dataentity.der.IPSDER1N;
import net.ibizsys.model.dataentity.der.IPSDERBase;
import net.ibizsys.model.dataentity.der.IPSDERInherit;
import net.ibizsys.model.dataentity.ds.IPSDEDataSetGroupParam;
import net.ibizsys.model.dataentity.ds.PSDEDataSetGroupParamImpl;
import org.springframework.util.Assert;
......@@ -111,6 +112,10 @@ public class EntityModel extends BaseModel {
return this;
}
public boolean isHasReferences()
{
return !ObjectUtils.isEmpty(references);
}
private Map<String,RelationshipModel> refMaps;
......@@ -363,6 +368,34 @@ public class EntityModel extends BaseModel {
}
public boolean isIndexSubDE()
{
if(this.getDataEntity().getMinorPSDERs()==null)
return false;
for(IPSDERBase MinorPSDER:this.getDataEntity().getMinorPSDERs())
{
if("DERINHERIT".equals(MinorPSDER.getDERType())||"DERINDEX".equals(MinorPSDER.getDERType())&& MinorPSDER.getMajorPSDataEntity().getVirtualMode()!=3 && MinorPSDER.getMajorPSDataEntity().getIndexTypePSDEField()!=null)
{
return true;
}
}
return false;
}
public boolean isLogicInherit()
{
if(this.getDataEntity().getMinorPSDERs()==null)
return false;
for(IPSDERBase MinorPSDER:this.getDataEntity().getMinorPSDERs())
{
if("DERINHERIT".equals(MinorPSDER.getDERType()) && MinorPSDER instanceof IPSDERInherit)
{
return ((IPSDERInherit)MinorPSDER).isLogicInherit();
}
}
return false;
}
private Map<String, POSchema> poSchemas;
......
package {{packageName}}.{{module}}.mapper;
import java.util.List;
import org.apache.ibatis.annotations.*;
import java.util.Map;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import java.util.Map;
import org.apache.ibatis.annotations.Select;
import {{packageName}}.{{module}}.domain.{{entity.codeName}};
import {{packageName}}.{{module}}.filter.{{entity.codeName}}SearchContext;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import om.baomidou.dynamic.datasource.annotation.DS;
import com.alibaba.fastjson.JSONObject;
{{#dsName}}
@DS("{{entity.dataSource}}")
{{/dsName}}
public interface {{entity.codeName}}Mapper extends BaseMapper<{{entity.codeName}}> {
{{#entity.dataSets}}
Page<{{entity.codeName}}> search{{codeName}}(IPage page, @Param("srf") {{entity.codeName}}SearchContext context, @Param("ew") Wrapper<{{entity.codeName}}> wrapper);
List<{{entity.codeName}}> list{{codeName}}(@Param("srf") {{entity.codeName}}SearchContext context, @Param("ew") Wrapper<{{entity.codeName}}> wrapper);
{{/entity.dataSets}}
@Override
{{#enableEntityCache}}
@Cacheable(value = "{{entity.codeName.lowerCase}}", key = "'row:'+#p0")
{{/enableEntityCache}}
{{entity.codeName}} selectById(Serializable id);
@Override
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", key = "'row:'+#p0.{{entity.keyField.codeName.camelCase}}")
{{/enableEntityCache}}
int insert({{entity.codeName}} entity);
@Override
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", key = "'row:'+#p0.{{entity.keyField.codeName.camelCase}}")
{{/enableEntityCache}}
int updateById(@Param(Constants.ENTITY) {{entity.codeName}} entity);
@Override
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", key = "'row:'+#p0.{{entity.keyField.codeName.camelCase}}", condition ="#p0 != null")
{{/enableEntityCache}}
int update(@Param(Constants.ENTITY) {{entity.codeName}} entity, @Param("ew") Wrapper<{{entity.codeName}}> updateWrapper);
@Override
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", key = "'row:'+#p0")
{{/enableEntityCache}}
int deleteById(Serializable id);
/**
* 自定义查询SQL
* @param sql
* @return
*/
@Select("${sql}")
List<JSONObject> selectBySQL(@Param("sql") String sql, @Param("et")Map param);
/**
* 自定义更新SQL
* @param sql
* @return
*/
@Update("${sql}")
boolean updateBySQL(@Param("sql") String sql, @Param("et")Map param);
/**
* 自定义插入SQL
* @param sql
* @return
*/
@Insert("${sql}")
boolean insertBySQL(@Param("sql") String sql, @Param("et")Map param);
/**
* 自定义删除SQL
* @param sql
* @return
*/
@Delete("${sql}")
boolean deleteBySQL(@Param("sql") String sql, @Param("et")Map param);
{{#entity.references}}
List<{{entity.codeName}}> selectBy{{fkField.codeName.pascalCase}}(@Param("{{fkField.name.lowerCase}}") Serializable {{fkField.codeName.camelCase}});
{{/entity.references}}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.cache.annotation.CacheEvict;
import com.baomidou.mybatisplus.extension.service.IService;
impott om.baomidou.dynamic.datasource.annotation.DS;
import om.baomidou.dynamic.datasource.annotation.DS;
import {{packageName}}.{{entity.module}}.domain.{{entity.codeName}};
import {{packageName}}.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
......
......@@ -73,14 +73,37 @@ public class {{entity.codeName}}ServiceImpl extends ServiceImpl<{{entity.codeNam
boolean checkKey({{entity.codeName}} et);
@Override
{{#eq transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq transactionMode "DEFAULT"}}@Transactional{{/eq}}
{{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean create({{entity.codeName}} et) {
{{#entity.hasReferences}}
fillParentData(et);
{{/entity.hasReferences}}
{{#entity.isIndexSubDE}}
createIndexMajorEntityData(et);
{{/entity.isIndexSubDE}}
{{#if entity.isLogicInheritDE}}
if(!update(et, (Wrapper) et.getUpdateWrapper(true).eq("{{entity.keyfield.name.lowerCase}", et.get{{keyfield.codeName.pascalCase}}())))
return false;
{{/else}}
if(!this.retBool(this.baseMapper.insert(et)))
return false;
{{/if}}
{{#each entity.nesteds}}
{{#unless listCode}}
{{#unless columnName}}
{{camelCase entityCodeName}}service.saveBy{{codeName.pascalCase}};
{{/unless}}
{{/unless}}
{{/each}}
{{#entity.hasReferences}}
${srfr7templcaseformat(MinorEntity.getCodeName())}Service.saveBy${srfr7templcaseformat(MajorDerField.codeName)?cap_first}(et.get${srfr7templcaseformat(keyfield.codeName)?cap_first}(), et.get${srfr7templcaseformat(listcode)?cap_first}());
{{/entity.hasReferences}}
}
{{#eq entity.actions.create.transactionMode "GLOBAL"}}@GlobalTransactional{{/eq}}{{#eq entity.actions.create.transactionMode "DEFAULT"}}@Transactional{{/eq}}
public boolean createBatch(List<{{entity.codeName}}> list) {
}
{{#enableEntityCache}}
@CacheEvict(value = "{{entity.codeName.lowerCase}}", allEntries = true)
{{/enableEntityCache}}
boolean createBatch(List<{{entity.codeName}}> list);
boolean update({{entity.codeName}} et);
{{#enableEntityCache}}
......
<?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="{{packageName}}.{{module}}.mapper.{{entity.codeName}}Mapper">
<!--通过mybatis将查询结果注入到entity中,通过配置autoMapping="true"由mybatis自动处理映射关系 -->
<resultMap id="${de.codeName}ResultMap" type="${pub.getPKGCodeName()}.core.${de.getPSSystemModule().codeName?lower_case}.domain.${de.codeName}" autoMapping="true">
<#if de.getKeyPSDEField().isPhisicalDEField()==true>
<id property="${srfr7templcaseformat(de.getKeyPSDEField().codeName)}" column="${de.getKeyPSDEField().getName()?lower_case}" /><!--主键字段映射-->
</#if>
<#comment>外键值字段映射:由于需要将一个数据库列注入到2个domian属性中(主关系实体对象),由于已经手动将列映射给主关系对象,所以autoMapping将不会自动注入外键id,需要再次声明映射关系</#comment>
<#comment>属性名称与代码名称不一致时,强制进行映射</#comment>
<#list item.getPSDEFields() as defield>
<#if defield.isKeyDEField()!=true && ((defield.getDataType())!"")!='ONE2MANYDATA'>
<#if srfr7templcaseformat(defield.codeName)?lower_case != defield.name?lower_case || defield.getDataType()=='PICKUP'>
<result property="${srfr7templcaseformat(defield.codeName)}" column="${defield.getName()?lower_case}" />
</#if>
</#if>
</#list>
</resultMap>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册