package ${basePackage}.${packageName}.service;
|
|
import cn.huge.base.common.exception.ServiceException;
|
import cn.huge.base.common.utils.DateUtils;
|
import cn.huge.base.common.utils.IdUtils;
|
import cn.huge.module.client.api.impl.UtilsClientImpl;
|
import ${basePackage}.${packageName}.dao.mapper.${className}Mapper;
|
import ${basePackage}.${packageName}.domain.po.${className};
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.PostConstruct;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @title: ${tableComments}业务逻辑处理
|
* @Description ${tableComments}业务逻辑处理
|
* @company hugeinfo
|
* @author ${author}
|
* @Time ${createTime}
|
* @version ${version}
|
*/
|
@Slf4j
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class ${className}Service extends ServiceImpl<${className}Mapper, ${className}>{
|
|
@Autowired
|
private ${className}Mapper mapper;
|
|
@Autowired
|
private UtilsClientImpl utilsClient;
|
|
/**
|
* 更新对象
|
* @param entity 对象
|
*/
|
public void update${className}(${className} entity){
|
try{
|
mapper.update${className}(entity);
|
}catch (Exception e){
|
log.error("[${className}Service.update${className}]调用失败,异常信息:"+e, e);
|
throw new ServiceException("${className}Service.update${className}", e);
|
}
|
}
|
|
/**
|
* 条件更新对象
|
* @param entity 对象
|
* @param terms 条件
|
*/
|
public void update${className}Terms(${className} entity, Map<String, Object> terms){
|
try{
|
mapper.update${className}Terms(entity, terms);
|
}catch (Exception e){
|
log.error("[${className}Service.update${className}Terms]调用失败,异常信息:"+e, e);
|
throw new ServiceException("${className}Service.update${className}Terms", e);
|
}
|
}
|
|
/**
|
* 根据编号物理删除
|
* @param id 查询条件集合
|
*/
|
public void delete${className}(String id){
|
try{
|
mapper.delete${className}(id);
|
}catch (Exception e){
|
log.error("[${className}Service.delete${className}]调用失败,异常信息:"+e, e);
|
throw new ServiceException("${className}Service.delete${className}", e);
|
}
|
}
|
|
/**
|
* 按条件查询
|
* @param terms 条件
|
* @return List
|
*/
|
public List<${className}> listTerms(Map<String, Object> terms){
|
return mapper.listTerms(terms);
|
}
|
|
/**
|
* 按条件统计
|
* @param terms 条件
|
* @return long
|
*/
|
public long countTerms(Map<String, Object> terms){
|
return mapper.countTerms(terms);
|
}
|
|
/**
|
* 按条件分页查询
|
* @param page 分页对象
|
* @param terms 条件
|
* @return Page
|
*/
|
public Page<${className}> pageQuery(PageRequest page, Map<String, Object> terms){
|
long total = mapper.countTerms(terms);
|
List<${className}> content = mapper.pageTerms(page, terms);
|
return new PageImpl<${className}>(content, page, total);
|
}
|
|
/**
|
* 新增或更新对象
|
* @param ${lowerName} 实体对象
|
*/
|
public void save${className}(${className} ${lowerName}){
|
try{
|
Date nowDate = DateUtils.getNowDate();
|
// 判断是否新增
|
if (IdUtils.checkNewId(${lowerName}.getId())){
|
${lowerName}.setId(utilsClient.getNewTimeId());
|
${lowerName}.setCreateTime(nowDate);
|
}
|
${lowerName}.setUpdateTime(nowDate);
|
this.saveOrUpdate(${lowerName});
|
}catch (Exception e){
|
log.error("[${className}Service.save${className}]调用失败,异常信息:"+e, e);
|
throw new ServiceException("${className}Service.save${className}", e);
|
}
|
}
|
|
}
|