forked from sfms3.0/sfms3.0
5 changed files with 162 additions and 162 deletions
@ -1,99 +1,79 @@ |
|||||
package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; |
package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; |
||||
|
|
||||
import org.springframework.stereotype.Service; |
|
||||
import javax.annotation.Resource; |
|
||||
import org.springframework.validation.annotation.Validated; |
|
||||
|
|
||||
import java.util.*; |
import java.util.*; |
||||
|
import javax.validation.*; |
||||
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
||||
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
||||
import ${PageResultClassName}; |
import ${PageResultClassName}; |
||||
|
|
||||
import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; |
|
||||
import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper; |
|
||||
|
|
||||
import static ${ServiceExceptionUtilClassName}.exception; |
|
||||
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*; |
|
||||
|
|
||||
/** |
/** |
||||
* ${table.classComment} Service |
* ${table.classComment} Service 接口 |
||||
* |
* |
||||
* @author ${table.author} |
* @author ${table.author} |
||||
*/ |
*/ |
||||
@Service |
public interface ${table.className}Service { |
||||
@Validated |
|
||||
public class ${table.className}Service { |
|
||||
|
|
||||
@Resource |
|
||||
private ${table.className}Mapper ${classNameVar}Mapper; |
|
||||
|
|
||||
|
|
||||
public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { |
|
||||
// 插入 |
|
||||
${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO); |
|
||||
${classNameVar}Mapper.insert(${classNameVar}); |
|
||||
// 返回 |
|
||||
return ${classNameVar}.getId(); |
|
||||
} |
|
||||
|
|
||||
public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { |
|
||||
// 校验存在 |
|
||||
validate${simpleClassName}Exists(updateReqVO.getId()); |
|
||||
// 更新 |
|
||||
${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO); |
|
||||
${classNameVar}Mapper.updateById(updateObj); |
|
||||
} |
|
||||
|
|
||||
public void delete${simpleClassName}(${primaryColumn.javaType} id) { |
/** |
||||
// 校验存在 |
* 创建${table.classComment} |
||||
validate${simpleClassName}Exists(id); |
* |
||||
// 删除 |
* @param createReqVO 创建信息 |
||||
${classNameVar}Mapper.deleteById(id); |
* @return 编号 |
||||
} |
*/ |
||||
|
${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO); |
||||
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) { |
|
||||
if (${classNameVar}Mapper.selectById(id) == null) { |
|
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) { |
/** |
||||
return ${classNameVar}Mapper.selectById(id); |
* 更新${table.classComment} |
||||
} |
* |
||||
|
* @param updateReqVO 更新信息 |
||||
|
*/ |
||||
|
void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO); |
||||
|
|
||||
public List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids) { |
/** |
||||
return ${classNameVar}Mapper.selectBatchIds(ids); |
* 删除${table.classComment} |
||||
} |
* |
||||
|
* @param id 编号 |
||||
|
*/ |
||||
|
void delete${simpleClassName}(${primaryColumn.javaType} id); |
||||
|
|
||||
public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { |
/** |
||||
return ${classNameVar}Mapper.selectPage(pageReqVO); |
* 获得${table.classComment} |
||||
} |
* |
||||
|
* @param id 编号 |
||||
|
* @return ${table.classComment} |
||||
|
*/ |
||||
|
${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id); |
||||
|
|
||||
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO) { |
/** |
||||
return ${classNameVar}Mapper.selectList(exportReqVO); |
* 获得${table.classComment}列表 |
||||
} |
* |
||||
|
* @param ids 编号 |
||||
|
* @return ${table.classComment}列表 |
||||
|
*/ |
||||
|
List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids); |
||||
|
|
||||
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart) { |
/** |
||||
if (CollUtil.isEmpty(datas)) { |
* 获得${table.classComment}分页 |
||||
throw exception(${simpleClassName_underlineCase.toUpperCase()}_IMPORT_LIST_IS_EMPTY); |
* |
||||
} |
* @param pageReqVO 分页查询 |
||||
|
* @return ${table.classComment}分页 |
||||
|
*/ |
||||
|
PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO); |
||||
|
|
||||
List<${table.className}ExcelVO> errorList = new ArrayList<>(); |
/** |
||||
datas.forEach(item -> { |
* 获得${table.classComment}列表, 用于 Excel 导出 |
||||
if(errorList == null){ |
* |
||||
// 判断如果不存在,在进行插入 |
* @param exportReqVO 查询条件 |
||||
${table.className}DO obj = ${classNameVar}Mapper.selectByCode(item.getCode()); |
* @return ${table.classComment}列表 |
||||
if (obj == null&& mode != 3) { |
*/ |
||||
${classNameVar}Mapper.insert(${table.className}Convert.INSTANCE.convert(item)); |
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO); |
||||
} |
|
||||
else if (obj != null && mode != 2) {// 如果存在,判断是否允许更新 |
|
||||
${table.className}DO ${classNameVar}DO = ${table.className}Convert.INSTANCE.convert(item); |
|
||||
${classNameVar}DO.setId(obj.getId()); |
|
||||
${classNameVar}Mapper.updateById(obj); |
|
||||
} |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
return errorList; |
/** |
||||
} |
* 导入${table.classComment}主信息 |
||||
|
* |
||||
|
* @param datas 导入${table.classComment}主信息列表 |
||||
|
* @param mode 导入模式1更新2追加3覆盖 |
||||
|
* @param updatePart 是否支持更新 |
||||
|
* @return 导入结果 |
||||
|
*/ |
||||
|
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart); |
||||
} |
} |
||||
|
@ -1,79 +1,99 @@ |
|||||
package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; |
package ${basePackage}.module.${table.moduleName}.service.${table.businessName}; |
||||
|
|
||||
|
import org.springframework.stereotype.Service; |
||||
|
import javax.annotation.Resource; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
|
||||
import java.util.*; |
import java.util.*; |
||||
import javax.validation.*; |
|
||||
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
import ${basePackage}.module.${table.moduleName}.controller.${sceneEnum.basePackage}.${table.businessName}.vo.*; |
||||
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
import ${basePackage}.module.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO; |
||||
import ${PageResultClassName}; |
import ${PageResultClassName}; |
||||
|
|
||||
|
import ${basePackage}.module.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; |
||||
|
import ${basePackage}.module.${table.moduleName}.dal.mysql.${table.businessName}.${table.className}Mapper; |
||||
|
|
||||
|
import static ${ServiceExceptionUtilClassName}.exception; |
||||
|
import static ${basePackage}.module.${table.moduleName}.enums.ErrorCodeConstants.*; |
||||
|
|
||||
/** |
/** |
||||
* ${table.classComment} Service 接口 |
* ${table.classComment} Service |
||||
* |
* |
||||
* @author ${table.author} |
* @author ${table.author} |
||||
*/ |
*/ |
||||
public interface ${table.className}Service { |
@Service |
||||
|
@Validated |
||||
|
public class ${table.className}Service { |
||||
|
|
||||
/** |
@Resource |
||||
* 创建${table.classComment} |
private ${table.className}Mapper ${classNameVar}Mapper; |
||||
* |
|
||||
* @param createReqVO 创建信息 |
|
||||
* @return 编号 |
|
||||
*/ |
|
||||
${primaryColumn.javaType} create${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO); |
|
||||
|
|
||||
/** |
|
||||
* 更新${table.classComment} |
|
||||
* |
|
||||
* @param updateReqVO 更新信息 |
|
||||
*/ |
|
||||
void update${simpleClassName}(@Valid ${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO); |
|
||||
|
|
||||
/** |
public ${primaryColumn.javaType} create${simpleClassName}(${sceneEnum.prefixClass}${table.className}CreateReqVO createReqVO) { |
||||
* 删除${table.classComment} |
// 插入 |
||||
* |
${table.className}DO ${classNameVar} = ${table.className}Convert.INSTANCE.convert(createReqVO); |
||||
* @param id 编号 |
${classNameVar}Mapper.insert(${classNameVar}); |
||||
*/ |
// 返回 |
||||
void delete${simpleClassName}(${primaryColumn.javaType} id); |
return ${classNameVar}.getId(); |
||||
|
} |
||||
|
|
||||
/** |
public void update${simpleClassName}(${sceneEnum.prefixClass}${table.className}UpdateReqVO updateReqVO) { |
||||
* 获得${table.classComment} |
// 校验存在 |
||||
* |
validate${simpleClassName}Exists(updateReqVO.getId()); |
||||
* @param id 编号 |
// 更新 |
||||
* @return ${table.classComment} |
${table.className}DO updateObj = ${table.className}Convert.INSTANCE.convert(updateReqVO); |
||||
*/ |
${classNameVar}Mapper.updateById(updateObj); |
||||
${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id); |
} |
||||
|
|
||||
/** |
public void delete${simpleClassName}(${primaryColumn.javaType} id) { |
||||
* 获得${table.classComment}列表 |
// 校验存在 |
||||
* |
validate${simpleClassName}Exists(id); |
||||
* @param ids 编号 |
// 删除 |
||||
* @return ${table.classComment}列表 |
${classNameVar}Mapper.deleteById(id); |
||||
*/ |
} |
||||
List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids); |
|
||||
|
|
||||
/** |
private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) { |
||||
* 获得${table.classComment}分页 |
if (${classNameVar}Mapper.selectById(id) == null) { |
||||
* |
throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); |
||||
* @param pageReqVO 分页查询 |
} |
||||
* @return ${table.classComment}分页 |
} |
||||
*/ |
|
||||
PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO); |
|
||||
|
|
||||
/** |
public ${table.className}DO get${simpleClassName}(${primaryColumn.javaType} id) { |
||||
* 获得${table.classComment}列表, 用于 Excel 导出 |
return ${classNameVar}Mapper.selectById(id); |
||||
* |
} |
||||
* @param exportReqVO 查询条件 |
|
||||
* @return ${table.classComment}列表 |
|
||||
*/ |
|
||||
List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO); |
|
||||
|
|
||||
/** |
public List<${table.className}DO> get${simpleClassName}List(Collection<${primaryColumn.javaType}> ids) { |
||||
* 导入${table.classComment}主信息 |
return ${classNameVar}Mapper.selectBatchIds(ids); |
||||
* |
} |
||||
* @param datas 导入${table.classComment}主信息列表 |
|
||||
* @param mode 导入模式1更新2追加3覆盖 |
public PageResult<${table.className}DO> get${simpleClassName}Page(${sceneEnum.prefixClass}${table.className}PageReqVO pageReqVO) { |
||||
* @param updatePart 是否支持更新 |
return ${classNameVar}Mapper.selectPage(pageReqVO); |
||||
* @return 导入结果 |
} |
||||
*/ |
|
||||
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart); |
public List<${table.className}DO> get${simpleClassName}List(${sceneEnum.prefixClass}${table.className}ExportReqVO exportReqVO) { |
||||
|
return ${classNameVar}Mapper.selectList(exportReqVO); |
||||
|
} |
||||
|
|
||||
|
public List<${table.className}ExcelVO> import${table.className}List(List<${table.className}ExcelVO> datas, Integer mode, boolean updatePart) { |
||||
|
if (CollUtil.isEmpty(datas)) { |
||||
|
throw exception(${simpleClassName_underlineCase.toUpperCase()}_IMPORT_LIST_IS_EMPTY); |
||||
|
} |
||||
|
|
||||
|
List<${table.className}ExcelVO> errorList = new ArrayList<>(); |
||||
|
datas.forEach(item -> { |
||||
|
if(errorList == null){ |
||||
|
// 判断如果不存在,在进行插入 |
||||
|
${table.className}DO obj = ${classNameVar}Mapper.selectByCode(item.getCode()); |
||||
|
if (obj == null&& mode != 3) { |
||||
|
${classNameVar}Mapper.insert(${table.className}Convert.INSTANCE.convert(item)); |
||||
|
} |
||||
|
else if (obj != null && mode != 2) {// 如果存在,判断是否允许更新 |
||||
|
${table.className}DO ${classNameVar}DO = ${table.className}Convert.INSTANCE.convert(item); |
||||
|
${classNameVar}DO.setId(obj.getId()); |
||||
|
${classNameVar}Mapper.updateById(obj); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
return errorList; |
||||
|
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue