com.github.javaclub.base.service.impl.UserRoleServiceImpl Maven / Gradle / Ivy
/* Automatic generated by CrudCodeGenerator wirtten by Gerald Chen
*
* @(#)UserRoleServiceImpl.java 2023-09-06
*
* Copyright (c) 2023 - 2099. All Rights Reserved.
*
*/
package com.github.javaclub.base.service.impl;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.javaclub.base.domain.UserRole;
import com.github.javaclub.base.domain.query.UserRoleQuery;
import com.github.javaclub.base.mapper.UserRoleMapper;
import com.github.javaclub.base.service.UserRoleService;
import com.github.javaclub.sword.BizException;
import com.github.javaclub.sword.core.BizObjects;
import com.github.javaclub.sword.core.Numbers;
import com.github.javaclub.sword.domain.QueryResult;
import com.github.javaclub.sword.domain.ResultDO;
import com.github.javaclub.sword.domain.enumtype.BasicMessage;
/**
* UserRoleService 业务逻辑实现
*
* @version $Id: UserRoleServiceImpl.java 2023-09-06 19:11:12 Exp $
*/
@Service
public class UserRoleServiceImpl extends ServiceImpl implements UserRoleService {
static final Logger log = LoggerFactory.getLogger(UserRoleServiceImpl.class);
@Autowired
private UserRoleMapper userRoleMapper;
/**
* 创建时的业务校验
*
* @param userRole 业务实体
*/
void doCreateCheck(UserRole userRole) {
BizObjects.requireNotNull(userRole, "DB实体不能为空");
// TODO Auto-generated method stub
}
/**
* 更新时的业务校验
*
* @param userRole 业务实体
*/
UserRole doUpdateCheck(UserRole userRole) {
BizObjects.requireNotNull(userRole, "DB实体不能为空");
BizObjects.requireNotNullGtZero(userRole.getId(), "主键ID不能为空");
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDO saveEntity(UserRole userRole) {
try {
if (null == userRole.getId()) {
Long id = create(userRole);
if (Numbers.isPositiveNumber(id)) {
return ResultDO.success(true);
}
}
UserRole db = userRoleMapper.selectById(userRole.getId());
if (null == db) {
return ResultDO.failure(BasicMessage.NOT_FOUND);
}
boolean suc = update(userRole);
if (suc) {
return ResultDO.success(true);
}
} catch (BizException e) {
return ResultDO.failure(e.getMessage(), e.getCode());
} catch (Exception e) {
return ResultDO.failure("数据库执行失败!", BasicMessage.EXCEPTIONED.getCode());
}
return ResultDO.failure();
}
@Override
public Long create(UserRole userRole) {
this.doCreateCheck(userRole);
int num = userRoleMapper.insert(userRole);
if (0 >= num) {
throw new BizException(BasicMessage.DB_INSERT_FAILED.getCode(), "创建记录失败!");
}
return userRole.getId();
}
@Override
public boolean update(UserRole userRole) {
this.doUpdateCheck(userRole);
int num = userRoleMapper.updateById(userRole);
return num > 0;
}
@Override
public UserRole selectById(Long id) {
return userRoleMapper.selectById(id);
}
@Override
public UserRole selectOne(UserRoleQuery query) {
QueryWrapper qw = query.queryWrapper();
List list = userRoleMapper.selectList(qw);
if(null != list && list.size() > 0) {
return list.get(0);
}
return null;
}
@Override
public int count(UserRoleQuery query) {
Integer count = userRoleMapper.selectCount(query.queryWrapper());
return null != count ? count.intValue() : 0;
}
@Override
public List findList(UserRoleQuery query) {
QueryWrapper qw = query.queryWrapper();
return userRoleMapper.selectList(qw);
}
@Override
public QueryResult findListWithCount(UserRoleQuery query) {
QueryResult queryResult = new QueryResult();
QueryWrapper qw = query.queryWrapper();
Page page = new Page<>(query.getPageNo(), query.getPageSize());
IPage pageResult = userRoleMapper.selectPage(page, qw);
if (null != pageResult) {
queryResult.setTotalCount(pageResult.getTotal());
queryResult.setEntry(pageResult.getRecords());
queryResult.setSuccess(true);
}
return queryResult;
}
}