PrizeService.java 2.3 KB
package com.w1hd.zzhnc.service;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.testng.util.Strings;

import com.w1hd.zzhnc.dao.LotteryLogDao;
import com.w1hd.zzhnc.dao.PrizeDao;
import com.w1hd.zzhnc.model.Goods;
import com.w1hd.zzhnc.model.Lotterylog;
import com.w1hd.zzhnc.model.Prize;
import com.w1hd.zzhnc.util.PageResults;
import com.w1hd.zzhnc.util.RedisUtil;
import com.w1hd.zzhnc.vo.Lotterylog_Vo;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class PrizeService {

	
	final String LotteryLogID_ = RedisUtil.PROJECTNAME.concat("_").concat("lotteryLog_");//中奖记里
	@Autowired
	PrizeDao prizeDao;
	
	@Autowired
	LotteryLogDao lotteryLogDao;

	public boolean add(Prize prize) {
		return prizeDao.insert(prize) > 0;
	}

	public boolean update(Prize p) {
		return prizeDao.updateByPrimaryKeySelective(p) > 0;
	}

	public PageResults<Prize> search(String key, Integer page, Integer size) {

		Example ex = new Example(Prize.class);
		Criteria c = ex.createCriteria();
		if (!Strings.isNullOrEmpty(key)) {
			c.andCondition(" (name like \"%" + key + "%\" )");
		}
		c.andEqualTo("deleted", false);
		RowBounds row = new RowBounds((page - 1) * size, size);
		List<Prize> list = prizeDao.selectByExampleAndRowBounds(ex, row);
		int count = prizeDao.selectCountByExample(ex);
		PageResults<Prize> pageResults = new PageResults<>();
		pageResults.setTotal(count);
		pageResults.setPage(page);
		pageResults.setPageSize(size);
		pageResults.setRows(list);
		return pageResults;
	}

	public boolean delete(String id) {
		return prizeDao.deleteByPrimaryKey(id) > 0;
	}
	
	
	
	/**获取我的奖品*/
	public List<Lotterylog> getMyLotteryLog(Integer fansId){
	
		Example ex = new Example(Lotterylog.class);
		Criteria c = ex.createCriteria();
		c.andEqualTo("fansid",fansId);
		List<Lotterylog> list = lotteryLogDao.selectByExample(ex);
		return list;
	}

	/**核销一个奖品记录*/
	public Lotterylog updateLotteryLog(Integer id, Integer fansId) {
		Lotterylog lotterylog = lotteryLogDao.selectByPrimaryKey(id);
		lotterylog.setStatus(2);
		lotteryLogDao.updateByPrimaryKey(lotterylog);
		return lotterylog;
	}

}