1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package ${package}.${moduleName}.service.impl;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import ${package}.${moduleName}.entity.${ClassName}Entity;
- import ${package}.${moduleName}.mapper.${ClassName}Mapper;
- import ${package}.${moduleName}.service.${ClassName}Service;
- import org.springframework.stereotype.Service;
- #if($ChildClassName)
- import cn.hutool.core.collection.CollUtil;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import ${package}.${moduleName}.entity.${ChildClassName}Entity;
- import ${package}.${moduleName}.mapper.${ChildClassName}Mapper;
- import org.springframework.transaction.annotation.Transactional;
- import lombok.RequiredArgsConstructor;
- import java.util.Objects;
- #end
- /**
- * ${tableComment}
- *
- * @author ${author}
- * @date ${datetime}
- */
- @Service
- #if($ChildClassName)
- @RequiredArgsConstructor
- #end
- public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}Entity> implements ${ClassName}Service {
- #if($ChildClassName)
- private final ${ChildClassName}Mapper ${childClassName}Mapper;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean saveDeep(${ClassName}Entity ${className}) {
- baseMapper.insert(${className});
- for (${ChildClassName}Entity ${childClassName} : ${className}.get${ChildClassName}List()) {
- ${childClassName}.$str.setProperty($childField)(${className}.$str.getProperty($mainField)());
- ${childClassName}Mapper.insert( ${childClassName});
- }
- return Boolean.TRUE;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean updateDeep(${ClassName}Entity ${className}) {
- baseMapper.updateById(${className});
- for (${ChildClassName}Entity ${childClassName} : ${className}.get${ChildClassName}List()) {
- #set($getChildPkName=$str.getProperty(${pk.attrName}))
- if (Objects.isNull(${childClassName}.$getChildPkName())) {
- ${childClassName}.$str.setProperty($childField)(${className}.getId());
- ${childClassName}Mapper.insert(${childClassName});
- } else {
- ${childClassName}Mapper.updateById(${childClassName});
- }
- }
- return Boolean.TRUE;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean removeDeep(Long[] ids) {
- baseMapper.deleteBatchIds(CollUtil.toList(ids));
- ${childClassName}Mapper.delete(Wrappers.<${ChildClassName}Entity>lambdaQuery().in(${ChildClassName}Entity::$str.getProperty($childField), ids));
- return Boolean.TRUE;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public Boolean removeChild(Long[] ids) {
- ${childClassName}Mapper.deleteBatchIds(CollUtil.toList(ids));
- return Boolean.TRUE;
- }
- #end
- }
|