GoodsService.java
1.7 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
package com.w1hd.zzhnc.service;
import java.sql.Date;
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.GoodsDao;
import com.w1hd.zzhnc.model.Goods;
import com.w1hd.zzhnc.util.PageResults;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;
@Service
public class GoodsService {
@Autowired
GoodsDao goodsDao;
public List<Goods> getHomeData() {
Example ex = new Example(Goods.class);
ex.createCriteria().andEqualTo("deleted", false).andEqualTo("isHome", true);
RowBounds r = new RowBounds(0, 5);
return goodsDao.selectByExampleAndRowBounds(ex, r);
}
public Goods update(Goods goods) {
goods.setUpdateTime(new Date(System.currentTimeMillis()));
if (goods.getId() == null || goods.getId() == 0) {
goods.setCreatetime(new Date(System.currentTimeMillis()));
goodsDao.insert(goods);
} else {
goodsDao.updateByPrimaryKey(goods);
}
return goods;
}
public PageResults<Goods> seacrh(String key, Integer sellerId, Integer page, Integer size) {
Example ex = new Example(Goods.class);
Criteria c = ex.createCriteria();
if (!Strings.isNullOrEmpty(key)) {
c.andCondition(" (description like \"%" + key + "%\" or name like \"%" + key + "%\")");
}
if (sellerId != null && sellerId > 0) {
c.andEqualTo("sellerId", sellerId);
}
c.andEqualTo("deleted", false);
RowBounds row = new RowBounds(page, size);
List<Goods> list = goodsDao.selectByExampleAndRowBounds(ex, row);
PageResults<Goods> pageResults = new PageResults<>();
return pageResults;
}
}