Goods.java
2.0 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
package com.air.model;
import com.air.model.base.BaseGoods;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.teplot.common.BaseController;
import com.teplot.common.Response;
@SuppressWarnings("serial")
public class Goods extends BaseGoods<Goods> {
public static final Goods dao = new Goods();
public String table() {
return "WDS_"+getClass().getSimpleName();
}
/**
* 搜索接口
*
* @param uid
* 用户id
* @isOwner 是否为货主,货主true,货代false
* @param page
* 页码
* @param pageNum
* 每页数量
* @param key
* 搜索关键字
* @param status
* 货物状态 {@link GoodsStatus}
*
* @return
*/
public Response search(Integer uid, boolean isOwner, int page, int pageNum, String key, GoodsStatus status) {
Response ret = new Response(BaseController.CODE_SUCCESS);
StringBuilder sb = new StringBuilder();
sb.append(" from " + table());
String orderBy = " order by updateTime desc";
if (StrKit.isBlank(key)) {
sb.append(" where status=" + status.ordinal());
if (isOwner) {
sb.append(" and uid=" + uid);
} else {
if (status != GoodsStatus.ENTRUSTING) {
sb.append(" and orderUid=" + uid);
}
}
} else {
sb.append(" where (name like '%" + key + "%'");
sb.append(" or sendCity like '%" + key + "%'");
sb.append(" or destCity like '%" + key + "%'");
sb.append(" or receiver like '%" + key + "%')");
sb.append(" and status=" + status.ordinal());
if (isOwner) {
sb.append(" and uid=" + uid);
} else {
if (status != GoodsStatus.ENTRUSTING) {
sb.append(" and orderUid=" + uid);
}
}
}
Page<Goods> dataList = Goods.dao.paginate(page, pageNum, "select *", sb.toString() + orderBy);
if (dataList != null) {
ret.set("curPage", dataList.getPageNumber());
ret.set("totalPage", dataList.getTotalPage());
ret.set("totalSize", dataList.getTotalRow());
ret.setData(dataList.getList());
}
return ret;
}
}