mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-02 11:44:59 +08:00
添加 serviceImpl.vm 的模板
This commit is contained in:
parent
5442f6522e
commit
59be930f2e
@ -1,109 +0,0 @@
|
|||||||
package ${packageName}.service.impl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
|
||||||
#break
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import ${packageName}.mapper.${ClassName}Mapper;
|
|
||||||
import ${packageName}.domain.${ClassName};
|
|
||||||
import ${packageName}.service.I${ClassName}Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ${functionName}Service业务层处理
|
|
||||||
*
|
|
||||||
* @author ${author}
|
|
||||||
* @date ${datetime}
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class ${ClassName}ServiceImpl implements I${ClassName}Service
|
|
||||||
{
|
|
||||||
@Autowired
|
|
||||||
private ${ClassName}Mapper ${className}Mapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询${functionName}
|
|
||||||
*
|
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
|
||||||
* @return ${functionName}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
|
||||||
{
|
|
||||||
return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询${functionName}列表
|
|
||||||
*
|
|
||||||
* @param ${className} ${functionName}
|
|
||||||
* @return ${functionName}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
|
|
||||||
{
|
|
||||||
return ${className}Mapper.select${ClassName}List(${className});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增${functionName}
|
|
||||||
*
|
|
||||||
* @param ${className} ${functionName}
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int insert${ClassName}(${ClassName} ${className})
|
|
||||||
{
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.javaField == 'createTime')
|
|
||||||
${className}.setCreateTime(DateUtils.getNowDate());
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
return ${className}Mapper.insert${ClassName}(${className});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改${functionName}
|
|
||||||
*
|
|
||||||
* @param ${className} ${functionName}
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int update${ClassName}(${ClassName} ${className})
|
|
||||||
{
|
|
||||||
#foreach ($column in $columns)
|
|
||||||
#if($column.javaField == 'updateTime')
|
|
||||||
${className}.setUpdateTime(DateUtils.getNowDate());
|
|
||||||
#end
|
|
||||||
#end
|
|
||||||
return ${className}Mapper.update${ClassName}(${className});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量删除${functionName}
|
|
||||||
*
|
|
||||||
* @param ${pkColumn.javaField}s 需要删除的${functionName}ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s)
|
|
||||||
{
|
|
||||||
return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除${functionName}信息
|
|
||||||
*
|
|
||||||
* @param ${pkColumn.javaField} ${functionName}ID
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField})
|
|
||||||
{
|
|
||||||
return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
|
|
||||||
}
|
|
||||||
}
|
|
@ -75,4 +75,7 @@ public interface SysErrorCodeConstants {
|
|||||||
// ========== 文件 1002009000 ==========
|
// ========== 文件 1002009000 ==========
|
||||||
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
|
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
|
||||||
|
|
||||||
|
// ========== 字典类型(测试) 1002010000 ==========
|
||||||
|
ErrorCode TEST_DEMO_NOT_EXISTS = new ErrorCode(1002010000, "字典类型不存在}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.system.service.test.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||||
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoCreateReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoUpdateReqVO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.convert.test.SysTestDemoConvert;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.test.SysTestDemoMapper;
|
||||||
|
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO;
|
||||||
|
import cn.iocoder.dashboard.modules.system.service.test.SysTestDemoService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.TEST_DEMO_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典类型 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋艿
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class SysTestDemoServiceImpl implements SysTestDemoService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysTestDemoMapper testDemoMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createTestDemo(SysTestDemoCreateReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
SysTestDemoDO testDemo = SysTestDemoConvert.INSTANCE.convert(createReqVO);
|
||||||
|
testDemoMapper.insert(testDemo);
|
||||||
|
// 返回
|
||||||
|
return testDemo.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTestDemo(SysTestDemoUpdateReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
this.validateTestDemoExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
SysTestDemoDO updateObj = SysTestDemoConvert.INSTANCE.convert(updateReqVO);
|
||||||
|
testDemoMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteTestDemo(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
this.validateTestDemoExists(id);
|
||||||
|
// 更新
|
||||||
|
testDemoMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateTestDemoExists(Long id) {
|
||||||
|
if (testDemoMapper.selectById(id) == null) {
|
||||||
|
throw ServiceExceptionUtil.exception(TEST_DEMO_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTestDemoDO getTestDemo(Long id) {
|
||||||
|
return testDemoMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysTestDemoDO> getTestDemoList(Collection<Long> ids) {
|
||||||
|
return testDemoMapper.selectBatchIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<SysTestDemoDO> getTestDemoPage(SysTestDemoPageReqVO pageReqVO) {
|
||||||
|
return testDemoMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
|||||||
import cn.hutool.extra.template.TemplateConfig;
|
import cn.hutool.extra.template.TemplateConfig;
|
||||||
import cn.hutool.extra.template.TemplateEngine;
|
import cn.hutool.extra.template.TemplateEngine;
|
||||||
import cn.hutool.extra.template.TemplateUtil;
|
import cn.hutool.extra.template.TemplateUtil;
|
||||||
|
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||||
@ -59,11 +60,12 @@ public class ToolCodegenEngine {
|
|||||||
// 全局 Java Bean
|
// 全局 Java Bean
|
||||||
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
|
globalBindingMap.put("PageResultClassName", PageResult.class.getName());
|
||||||
globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName());
|
globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName());
|
||||||
|
globalBindingMap.put("ServiceExceptionUtilClassName", ServiceExceptionUtil.class.getName());
|
||||||
// VO 类,独有字段
|
// VO 类,独有字段
|
||||||
globalBindingMap.put("PageParamClassName", PageParam.class.getName());
|
globalBindingMap.put("PageParamClassName", PageParam.class.getName());
|
||||||
// DO 类,独有字段
|
// DO 类,独有字段
|
||||||
globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS);
|
globalBindingMap.put("baseDOFields", ToolCodegenBuilder.BASE_DO_FIELDS);
|
||||||
globalBindingMap.put("baseDOClassName", BaseDO.class.getName());
|
globalBindingMap.put("BaseDOClassName", BaseDO.class.getName());
|
||||||
globalBindingMap.put("QueryWrapperClassName", QueryWrapperX.class.getName());
|
globalBindingMap.put("QueryWrapperClassName", QueryWrapperX.class.getName());
|
||||||
globalBindingMap.put("BaseMapperClassName", BaseMapperX.class.getName());
|
globalBindingMap.put("BaseMapperClassName", BaseMapperX.class.getName());
|
||||||
}
|
}
|
||||||
@ -92,8 +94,8 @@ public class ToolCodegenEngine {
|
|||||||
// String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
|
// String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
|
||||||
// String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap);
|
// String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap);
|
||||||
// String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap);
|
// String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap);
|
||||||
String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap);
|
// String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap);
|
||||||
// String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap);
|
String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.business
|
|||||||
import lombok.*;
|
import lombok.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import ${baseDOClassName};
|
import ${BaseDOClassName};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${table.classComment} DO
|
* ${table.classComment} DO
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
// ========== ${table.classCommet} TODO 补充编号 ==========
|
// ========== ${table.classComment} TODO 补充编号 ==========
|
||||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_FOUND = new ErrorCode(TODO 补充编号, "${table.classComment}不存在}");
|
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${table.classComment}不存在}");
|
||||||
|
@ -10,6 +10,12 @@ import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
|
|||||||
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
|
import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO;
|
||||||
import ${PageResultClassName};
|
import ${PageResultClassName};
|
||||||
|
|
||||||
|
import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
|
||||||
|
import ${basePackage}.${table.moduleName}.dal.mysql.dao.${table.businessName}.${table.className}Mapper;
|
||||||
|
import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service;
|
||||||
|
|
||||||
|
import ${ServiceExceptionUtilClassName};
|
||||||
|
|
||||||
import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName.substring(0,1).toUpperCase()}${simpleModuleName.substring(1)}ErrorCodeConstants.*;
|
import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName.substring(0,1).toUpperCase()}${simpleModuleName.substring(1)}ErrorCodeConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,14 +23,58 @@ import static ${basePackage}.${table.moduleName}.enums.${simpleModuleName.substr
|
|||||||
*
|
*
|
||||||
* @author ${table.author}
|
* @author ${table.author}
|
||||||
*/
|
*/
|
||||||
|
@Service
|
||||||
@Validated
|
@Validated
|
||||||
public class ${table.className}ServiceImpl implements {table.className}Service {
|
public class ${table.className}ServiceImpl implements ${table.className}Service {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ${table.className}Mapper ${classNameVar}Mapper;
|
private ${table.className}Mapper ${classNameVar}Mapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ${primaryColumn.javaType} create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO) {
|
public ${primaryColumn.javaType} create${simpleClassName}(${table.className}CreateReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO);
|
||||||
|
${classNameVar}Mapper.insert(${classNameVar});
|
||||||
|
// 返回
|
||||||
|
return ${classNameVar}.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update${simpleClassName}(${table.className}UpdateReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
this.validate${simpleClassName}Exists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO);
|
||||||
|
${classNameVar}Mapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
// 校验存在
|
||||||
|
this.validate${simpleClassName}Exists(id);
|
||||||
|
// 更新
|
||||||
|
${classNameVar}Mapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) {
|
||||||
|
if (${classNameVar}Mapper.selectById(id) == null) {
|
||||||
|
throw ServiceExceptionUtil.exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) {
|
||||||
|
return ${classNameVar}Mapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids) {
|
||||||
|
return ${classNameVar}Mapper.selectBatchIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<${table.className}DO> get${simpleClassName}Page(${table.className}PageReqVO pageReqVO) {
|
||||||
|
return ${classNameVar}Mapper.selectPage(pageReqVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user