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

com.quhaodian.site.data.service.impl.AppServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.8.6
Show newest version
package com.quhaodian.site.data.service.impl;

import com.quhaodian.data.core.Finder;
import com.quhaodian.user.word.AdaptiveRandomWordFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.quhaodian.data.core.Updater;
import com.quhaodian.site.data.dao.AppDao;
import com.quhaodian.site.data.entity.App;
import com.quhaodian.site.data.service.AppService;

import com.quhaodian.data.page.Filter;
import com.quhaodian.data.page.Order;
import com.quhaodian.data.page.Page;
import com.quhaodian.data.page.Pageable;
import java.util.List;

import com.quhaodian.data.utils.FilterUtils;


/**
* Created by imake on 2017年07月25日11:33:24.
*/
@Service
@Transactional
public class AppServiceImpl implements AppService {

	private AppDao dao;


	@Override
	@Transactional(readOnly = true)
	public App findById(Long id) {
		return dao.findById(id);
	}

	@Override
	public App findByKey(String key) {
		Finder finder=Finder.create();
		finder.append("from App a where a.appKey=:appKey");
		finder.setParam("appKey",key);
		return dao.findOne(finder);
	}


	@Override
    @Transactional
	public App save(App bean) {
		dao.save(bean);
		return bean;
	}

	@Override
    @Transactional
	public App update(App bean) {
		Updater updater = new Updater(bean);
		return dao.updateByUpdater(updater);
	}

	@Override
    @Transactional
	public App deleteById(Long id) {
		App bean = dao.findById(id);
        dao.deleteById(id);
		return bean;
	}

	@Override
    @Transactional	
	public App[] deleteByIds(Long[] ids) {
		App[] beans = new App[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}


	@Autowired
	public void setDao(AppDao dao) {
		this.dao = dao;
	}

	@Override
    public Page page(Pageable pageable){
         return dao.page(pageable);
    }


    @Override
	public Page page(Pageable pageable, Object search) {
		List filters=	FilterUtils.getFilters(search);
		if (filters!=null) {
			pageable.getFilters().addAll(filters);
		}
		return dao.page(pageable);
	}

    @Override
    public List list(int first, Integer size, List filters, List orders) {
        return dao.list(first,size,filters,orders);}

	@Override
	public App visit(Long id) {
		App entity = dao.findById(id);
		if (entity != null) {
			Long counts = entity.getCounts();
			if (counts == null) {
				counts = 0l;
			}
			counts++;
			entity.setCounts(counts);
		}
		return entity;
	}

	@Override
	public String key() {
		String result = "";
		AdaptiveRandomWordFactory f = new AdaptiveRandomWordFactory();
		f.setMinLength(8);
		f.setMaxLength(12);
		f.setCharacters("1234567890abcdefhjkmnpwx");
		result = f.getNextWord();
		while (dao.count(Filter.eq("appKey", result)) > 0) {
			result = f.getNextWord();
		}
		return result;
	}

	@Override
	public String secret() {
		AdaptiveRandomWordFactory f = new AdaptiveRandomWordFactory();
		f.setMinLength(16);
		f.setMaxLength(32);
		f.setCharacters("1234567890abcdefhjkmnpwx");
		return f.getNextWord();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy