All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.base.service.impl.RoleMenuServiceImpl Maven / Gradle / Ivy

/* Automatic generated by CrudCodeGenerator wirtten by Gerald Chen
 *
 * @(#)RoleMenuServiceImpl.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.RoleMenu;
import com.github.javaclub.base.domain.query.RoleMenuQuery;
import com.github.javaclub.base.mapper.RoleMenuMapper;
import com.github.javaclub.base.service.RoleMenuService;
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;

/**
 * RoleMenuService 业务逻辑实现
 *
 * @version $Id: RoleMenuServiceImpl.java 2023-09-06 19:11:12 Exp $
 */
@Service
public class RoleMenuServiceImpl extends ServiceImpl implements RoleMenuService {
	
	static final Logger log = LoggerFactory.getLogger(RoleMenuServiceImpl.class);
	
	@Autowired
	private RoleMenuMapper roleMenuMapper;

	/**
	 * 创建时的业务校验
	 * 
	 * @param roleMenu 业务实体
	 */
	void doCreateCheck(RoleMenu roleMenu) {
	    BizObjects.requireNotNull(roleMenu, "DB实体不能为空");
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 更新时的业务校验
	 * 
	 * @param roleMenu 业务实体
	 */
	RoleMenu doUpdateCheck(RoleMenu roleMenu) {
		BizObjects.requireNotNull(roleMenu, "DB实体不能为空");
		BizObjects.requireNotNullGtZero(roleMenu.getId(), "主键ID不能为空");
		// TODO Auto-generated method stub
		
		return null;
	}

	@Override
	public ResultDO saveEntity(RoleMenu roleMenu) {
		try {
			if (null == roleMenu.getId()) {
				Long id = create(roleMenu);
				if (Numbers.isPositiveNumber(id)) {
					return ResultDO.success(true);
				}
			}
			RoleMenu db = roleMenuMapper.selectById(roleMenu.getId());
			if (null == db) {
				return ResultDO.failure(BasicMessage.NOT_FOUND);
			}
			boolean suc = update(roleMenu);
			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(RoleMenu roleMenu) {
		this.doCreateCheck(roleMenu);
		int num = roleMenuMapper.insert(roleMenu);
		if (0 >= num) {
			throw new BizException(BasicMessage.DB_INSERT_FAILED.getCode(), "创建记录失败!");
		}
		return roleMenu.getId();
	}
	
	@Override
	public boolean update(RoleMenu roleMenu) {
		this.doUpdateCheck(roleMenu);
		int num = roleMenuMapper.updateById(roleMenu);
		return num > 0;
	}
	
	@Override
	public RoleMenu selectById(Long id) {
		return roleMenuMapper.selectById(id);
	}
	
	@Override
	public RoleMenu selectOne(RoleMenuQuery query) {
		QueryWrapper qw = query.queryWrapper();
		List list = roleMenuMapper.selectList(qw);
		if(null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public int count(RoleMenuQuery query) {
		Integer count = roleMenuMapper.selectCount(query.queryWrapper());
		return null != count ? count.intValue() : 0;
	}

	@Override
	public List findList(RoleMenuQuery query) {
		QueryWrapper qw = query.queryWrapper();
		return roleMenuMapper.selectList(qw);
	}

	@Override
	public QueryResult findListWithCount(RoleMenuQuery query) {
		QueryResult queryResult = new QueryResult();
		
		QueryWrapper qw = query.queryWrapper();
		Page page = new Page<>(query.getPageNo(), query.getPageSize());
		IPage pageResult = roleMenuMapper.selectPage(page, qw);
		
		if (null != pageResult) {
			queryResult.setTotalCount(pageResult.getTotal());
			queryResult.setEntry(pageResult.getRecords());
			queryResult.setSuccess(true);
		}
		return queryResult;
	}
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy