| | |
| | | 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;
|
| | | #if($table.sub)
|
| | | import java.util.ArrayList;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import ${packageName}.domain.${subClassName};
|
| | | #end
|
| | | 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 结果
|
| | | */
|
| | | #if($table.sub)
|
| | | @Transactional
|
| | | #end
|
| | | @Override
|
| | | public int insert${ClassName}(${ClassName} ${className})
|
| | | {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.javaField == 'createTime')
|
| | | ${className}.setCreateTime(DateUtils.getNowDate());
|
| | | #end
|
| | | #end
|
| | | #if($table.sub)
|
| | | int rows = ${className}Mapper.insert${ClassName}(${className});
|
| | | insert${subClassName}(${className});
|
| | | return rows;
|
| | | #else
|
| | | return ${className}Mapper.insert${ClassName}(${className});
|
| | | #end
|
| | | }
|
| | |
|
| | | /**
|
| | | * 修改${functionName}
|
| | | * |
| | | * @param ${className} ${functionName}
|
| | | * @return 结果
|
| | | */
|
| | | #if($table.sub)
|
| | | @Transactional
|
| | | #end
|
| | | @Override
|
| | | public int update${ClassName}(${ClassName} ${className})
|
| | | {
|
| | | #foreach ($column in $columns)
|
| | | #if($column.javaField == 'updateTime')
|
| | | ${className}.setUpdateTime(DateUtils.getNowDate());
|
| | | #end
|
| | | #end
|
| | | #if($table.sub)
|
| | | ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
|
| | | insert${subClassName}(${className});
|
| | | #end
|
| | | return ${className}Mapper.update${ClassName}(${className});
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量删除${functionName}
|
| | | * |
| | | * @param ${pkColumn.javaField}s 需要删除的${functionName}ID
|
| | | * @return 结果
|
| | | */
|
| | | #if($table.sub)
|
| | | @Transactional
|
| | | #end
|
| | | @Override
|
| | | public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s)
|
| | | {
|
| | | #if($table.sub)
|
| | | ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
| | | #end
|
| | | 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})
|
| | | {
|
| | | #if($table.sub)
|
| | | ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
| | | #end
|
| | | return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField});
|
| | | }
|
| | | #if($table.sub)
|
| | |
|
| | | /**
|
| | | * 新增${subTable.functionName}信息
|
| | | * |
| | | * @param ${className} ${functionName}对象
|
| | | */
|
| | | public void insert${subClassName}(${ClassName} ${className})
|
| | | {
|
| | | List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
|
| | | Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
|
| | | if (StringUtils.isNotNull(${subclassName}List))
|
| | | {
|
| | | List<${subClassName}> list = new ArrayList<${subClassName}>();
|
| | | for (${subClassName} ${subclassName} : ${subclassName}List)
|
| | | {
|
| | | ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
|
| | | list.add(${subclassName});
|
| | | }
|
| | | if (list.size() > 0)
|
| | | {
|
| | | ${className}Mapper.batch${subClassName}(list);
|
| | | }
|
| | | }
|
| | | }
|
| | | #end
|
| | | }
|
| | | package ${packageName}.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | #if($table.crud || $table.sub) |
| | | import com.ruoyi.common.mybatis.core.page.TableDataInfo; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | #end |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import ${packageName}.domain.bo.${ClassName}Bo; |
| | | import ${packageName}.domain.vo.${ClassName}Vo; |
| | | import ${packageName}.domain.${ClassName}; |
| | | import ${packageName}.mapper.${ClassName}Mapper; |
| | | import ${packageName}.service.I${ClassName}Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | |
| | | /** |
| | | * ${functionName}Service业务层处理 |
| | | * |
| | | * @author ${author} |
| | | * @date ${datetime} |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class ${ClassName}ServiceImpl implements I${ClassName}Service { |
| | | |
| | | private final ${ClassName}Mapper baseMapper; |
| | | |
| | | /** |
| | | * 查询${functionName} |
| | | */ |
| | | @Override |
| | | public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){ |
| | | return baseMapper.selectVoById(${pkColumn.javaField}); |
| | | } |
| | | |
| | | #if($table.crud || $table.sub) |
| | | /** |
| | | * 查询${functionName}列表 |
| | | */ |
| | | @Override |
| | | public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo); |
| | | Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | #end |
| | | |
| | | /** |
| | | * 查询${functionName}列表 |
| | | */ |
| | | @Override |
| | | public List<${ClassName}Vo> queryList(${ClassName}Bo bo) { |
| | | LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo); |
| | | return baseMapper.selectVoList(lqw); |
| | | } |
| | | |
| | | private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery(); |
| | | #foreach($column in $columns) |
| | | #if($column.query) |
| | | #set($queryType=$column.queryType) |
| | | #set($javaField=$column.javaField) |
| | | #set($javaType=$column.javaType) |
| | | #set($columnName=$column.columnName) |
| | | #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) |
| | | #set($mpMethod=$column.queryType.toLowerCase()) |
| | | #if($queryType != 'BETWEEN') |
| | | #if($javaType == 'String') |
| | | #set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())') |
| | | #else |
| | | #set($condition='bo.get'+$AttrName+'() != null') |
| | | #end |
| | | lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName()); |
| | | #else |
| | | lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null, |
| | | ${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName")); |
| | | #end |
| | | #end |
| | | #end |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | | * 新增${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean insertByBo(${ClassName}Bo bo) { |
| | | ${ClassName} add = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | #set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)}) |
| | | if (flag) { |
| | | bo.set$pk(add.get$pk()); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 修改${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean updateByBo(${ClassName}Bo bo) { |
| | | ${ClassName} update = BeanUtil.toBean(bo, ${ClassName}.class); |
| | | validEntityBeforeSave(update); |
| | | return baseMapper.updateById(update) > 0; |
| | | } |
| | | |
| | | /** |
| | | * 保存前的数据校验 |
| | | */ |
| | | private void validEntityBeforeSave(${ClassName} entity){ |
| | | //TODO 做一些数据校验,如唯一约束 |
| | | } |
| | | |
| | | /** |
| | | * 批量删除${functionName} |
| | | */ |
| | | @Override |
| | | public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) { |
| | | if(isValid){ |
| | | //TODO 做一些业务上的校验,判断是否需要校验 |
| | | } |
| | | return baseMapper.deleteBatchIds(ids) > 0; |
| | | } |
| | | } |