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

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

/* Automatic generated by CrudCodeGenerator wirtten by Gerald Chen
 *
 * @(#)SysLogServiceImpl.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.SysLog;
import com.github.javaclub.base.domain.query.SysLogQuery;
import com.github.javaclub.base.mapper.SysLogMapper;
import com.github.javaclub.base.service.SysLogService;
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;

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

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

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

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

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

	@Override
	public QueryResult findListWithCount(SysLogQuery query) {
		QueryResult queryResult = new QueryResult();
		
		QueryWrapper qw = query.queryWrapper();
		Page page = new Page<>(query.getPageNo(), query.getPageSize());
		IPage pageResult = sysLogMapper.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