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

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

/* Automatic generated by CrudCodeGenerator wirtten by Gerald Chen
 *
 * @(#)IdemfactorServiceImpl.java	2023-09-04
 *
 * Copyright (c) 2023. 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.github.javaclub.base.domain.IdemfactorDO;
import com.github.javaclub.base.domain.query.IdemfactorQuery;
import com.github.javaclub.base.mapper.IdemfactorDAO;
import com.github.javaclub.base.service.IdemfactorService;
import com.github.javaclub.sword.core.BizObjects;
import com.github.javaclub.sword.domain.QueryResult;
import com.github.javaclub.sword.domain.ResultDO;
import com.github.javaclub.sword.domain.dto.BatchOperationDTO;
import com.github.javaclub.sword.domain.enumtype.BasicMessage;
import com.google.common.collect.Lists;

/**
 * IdemfactorServiceImpl
 *
 * @version $Id: IdemfactorServiceImpl.java 2023-09-04 21:11:32 Exp $
 */
@Service("idemfactorService")
public class IdemfactorServiceImpl implements IdemfactorService {
	
	static final Logger log = LoggerFactory.getLogger(IdemfactorServiceImpl.class);
	
	@Autowired
	private IdemfactorDAO idemfactorDAO;
	
	/**
	 * 创建时的业务校验
	 * 
	 * @param idemfactorDO 业务实体
	 */
	void doCreateCheck(IdemfactorDO idemfactorDO) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 更新时的业务校验
	 * 
	 * @param idemfactorDO 业务实体
	 */
	void doUpdateCheck(IdemfactorDO idemfactorDO) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ResultDO save(IdemfactorDO idemfactorDO) {
		if(null == idemfactorDO.getId()) {
			return create(idemfactorDO);
		}
		IdemfactorDO db = idemfactorDAO.getById(idemfactorDO.getId());
		if(null == db) {
			return ResultDO.failure(BasicMessage.NOT_FOUND);
		}
		return update(idemfactorDO);
	}

	@Override
	public ResultDO create(IdemfactorDO idemfactorDO) {
		ResultDO result = ResultDO.failure();
		try {
			this.doCreateCheck(idemfactorDO);
			int num = idemfactorDAO.insert(idemfactorDO);
			result = ResultDO.result(num > 0, "创建记录失败");
		} catch (Exception e) {
			log.error("", e);
			result.setMessage(e.getMessage());
		}
		return result;
	}

	@Override
	public BatchOperationDTO createBatch(List list) {
		BatchOperationDTO bod = new BatchOperationDTO();
		List toAdd = Lists.newArrayList();
		for (IdemfactorDO item : list) {
			try {
				this.doCreateCheck(item);
			} catch (Exception e) {
				bod.addFailure(item);
				continue;
			}
			toAdd.add(item);
		}
		
		try {
			if(toAdd.size() > 0) {
				idemfactorDAO.insertBatch(toAdd);
				bod.setSuccessList(toAdd);
			}
		} catch (Exception e) {
			bod.setMessage(e.getMessage());
			log.error("IdemfactorService createBatch", e);
		}
		
		return bod;
	}

	@Override
	public ResultDO update(IdemfactorDO idemfactorDO) {
		ResultDO result = ResultDO.failure();
		try {
			BizObjects.requireNotNull(idemfactorDO.getId(), "主键ID不能为空");
			this.doUpdateCheck(idemfactorDO);
			int num = idemfactorDAO.update(idemfactorDO);
			result = ResultDO.result(num > 0, "没有记录被更新");
		} catch (Exception e) {
			log.error("", e);
			result.setMessage(e.getMessage());
		}
		return result;
	}

	@Override
	public ResultDO deleteById(Long id) {
		ResultDO result = ResultDO.failure();
		try {
			int num = idemfactorDAO.deleteById(id);
			result = ResultDO.result(num > 0, "没有记录被删除");
		} catch (Exception e) {
			log.error("", e);
			result.setMessage(e.getMessage());
		}
		return result;
	}

	@Override
	public ResultDO getById(Long id) {
		ResultDO result = ResultDO.failure();
		try {
			IdemfactorDO dbRecord = idemfactorDAO.getById(id);
			if(null != dbRecord) {
				result = ResultDO.success(dbRecord);
			}
		} catch (Exception e) {
			log.error("", e);
			result.setMessage(e.getMessage());
		}
		
		return result;
	}
	
	@Override
	public IdemfactorDO selectById(Long id) {
		return idemfactorDAO.getById(id);
	}
	
	@Override
	public IdemfactorDO selectOne(IdemfactorQuery query) {
		List list = idemfactorDAO.queryList(query);
		if(null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public int count(IdemfactorQuery query) {
		return idemfactorDAO.count(query);
	}

	@Override
	public List findList(IdemfactorQuery query) {
		return idemfactorDAO.queryList(query);
	}

	@Override
	public QueryResult findListWithCount(IdemfactorQuery query) {
		QueryResult queryResult = new QueryResult();
		try {
			List list = idemfactorDAO.queryList(query);
			int count = idemfactorDAO.count(query);
			queryResult.setTotalCount(count);
			queryResult.setEntry(list);
			queryResult.setSuccess(true);
		} catch (Exception e) {
			log.error("", e);
			queryResult.setSuccess(false);
			queryResult.setMessage(e.getMessage());
		}
		return queryResult;
	}

	@Override
	public IdemfactorDO uniqueQuery(String identifier, Integer bizType, String value) {
		return idemfactorDAO.uniqueQuery(identifier, bizType, value);
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy