feat: 项目集成mybatis-plus-generator 代码生成器
Closes https://gitee.com/youlaiorg/youlai-boot/issues/I80MH1
This commit is contained in:
102
src/test/resources/templates/serviceImpl.java.vm
Normal file
102
src/test/resources/templates/serviceImpl.java.vm
Normal file
@@ -0,0 +1,102 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${superServiceImplClassPackage};
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.youlai.system.common.util.DateUtils;
|
||||
|
||||
/**
|
||||
* $!{table.comment} 服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||
|
||||
private final ${entity}Converter converter;
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<${entity}PageVO>} $!{table.comment}分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams) {
|
||||
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<${entity}BO> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
// 格式化为数据库日期格式,避免日期比较使用格式化函数导致索引失效
|
||||
DateUtils.toDatabaseFormat(queryParams, "startTime", "endTime");
|
||||
|
||||
// 查询数据
|
||||
Page<${entity}BO> boPage = this.baseMapper.listPaged${entity}s(page, queryParams);
|
||||
|
||||
// 实体转换
|
||||
return converter.bo2PageVo(boPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}表单数据
|
||||
*
|
||||
* @param userId $!{table.comment}ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ${entity}Form get${entity}FormData(Long userId) {
|
||||
return this.baseMapper.get${entity}FormData(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增$!{table.comment}
|
||||
*
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean save${entity}(${entity}Form formData) {
|
||||
// 实体转换 form->entity
|
||||
SysUser entity = converter.form2Entity(formData);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新$!{table.comment}
|
||||
*
|
||||
* @param userId $!{table.comment}ID
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean update${entity}(Long id,${entity}Form formData) {
|
||||
${entity} entity = converter.form2Entity(formData);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{table.comment}
|
||||
*
|
||||
* @param idsStr $!{table.comment}ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entity}s(String idsStr) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的$!{table.comment}数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
return this.removeByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user