ServiceImpl.java.ftl 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package ${package}.modules.${moduleName}.service<#if subModuleName??>.${subModuleName}</#if>.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import ${package}.common.service.impl.CrudServiceImpl;
  4. import ${package}.common.constant.Constant;
  5. import ${package}.modules.${moduleName}.dao<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Dao;
  6. import ${package}.modules.${moduleName}.dto<#if subModuleName??>.${subModuleName}</#if>.${ClassName}DTO;
  7. import ${package}.modules.${moduleName}.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Entity;
  8. import ${package}.modules.${moduleName}.service<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Service;
  9. import ${package}.modules.security.user.SecurityUser;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.stereotype.Service;
  12. import java.util.Map;
  13. /**
  14. * ${tableComment}
  15. *
  16. * @author ${author} ${email}
  17. * @since ${version} ${date}
  18. */
  19. @Service
  20. public class ${ClassName}ServiceImpl extends CrudServiceImpl<${ClassName}Dao, ${ClassName}Entity, ${ClassName}DTO> implements ${ClassName}Service {
  21. @Override
  22. public QueryWrapper<${ClassName}Entity> getWrapper(Map<String, Object> params){
  23. QueryWrapper<${ClassName}Entity> wrapper = new QueryWrapper<>();
  24. <#list columnList as column>
  25. <#if column.query>
  26. <#if column.formType == 'date'>
  27. String startDate = (String)params.get("startDate");
  28. String endDate = (String)params.get("endDate");
  29. wrapper.ge(StringUtils.isNotBlank(startDate), "${column.columnName}", startDate);
  30. wrapper.le(StringUtils.isNotBlank(endDate), "${column.columnName}", endDate);
  31. <#elseif column.formType == 'datetime'>
  32. String startDateTime = (String)params.get("startDateTime");
  33. String endDateTime = (String)params.get("endDateTime");
  34. wrapper.ge(StringUtils.isNotBlank(startDateTime), "${column.columnName}", startDateTime);
  35. wrapper.le(StringUtils.isNotBlank(endDateTime), "${column.columnName}", endDateTime);
  36. <#else>
  37. String ${column.attrName} = (String)params.get("${column.attrName}");
  38. <#switch column.queryType>
  39. <#case "=">
  40. wrapper.eq(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  41. <#break>
  42. <#case "!=">
  43. wrapper.ne(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  44. <#break>
  45. <#case ">">
  46. wrapper.gt(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  47. <#break>
  48. <#case ">=">
  49. wrapper.ge(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  50. <#break>
  51. <#case "<">
  52. wrapper.lt(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  53. <#break>
  54. <#case "<=">
  55. wrapper.le(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  56. <#break>
  57. <#case "like">
  58. wrapper.like(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  59. <#break>
  60. <#case "left like">
  61. wrapper.likeLeft(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  62. <#break>
  63. <#case "right like">
  64. wrapper.likeRight(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  65. <#break>
  66. <#default>
  67. wrapper.ne(StringUtils.isNotBlank(${column.attrName}), "${column.columnName}", ${column.attrName});
  68. </#switch>
  69. </#if>
  70. </#if>
  71. <#if column.columnName == 'tenant_code'>
  72. wrapper.eq("tenant_code", TenantContext.getTenantCode(SecurityUser.getUser()));
  73. </#if>
  74. </#list>
  75. return wrapper;
  76. }
  77. }