PrizeService.java
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}
}