TdCCouponRuleDaoImpl.java
10.5 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package com.zteits.pay.dao.impl;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.date.DateUtil;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO;
import com.zteits.clouds.api.dto.pay.param.*;
import com.zteits.pay.dao.TdCCouponRuleDao;
import com.zteits.pay.domain.TdCCouponRule;
import com.zteits.pay.domain.TdCCouponRuleExample;
import com.zteits.pay.domain.TdCCouponRuleParkExample;
import com.zteits.pay.mapper.TdCCouponRuleMapper;
import com.zteits.pay.mapper.TdCCouponRuleParkMapper;
import com.zteits.pay.mapper.smapper.TdCCouponRuleSMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
/**
* Copyright: Copyright (c) 2017 zteits
*
* @Description:
* @version: v1.0.0
* @author: langlw
* @date: 2017/12/27 15
* Modification History:
* Date Author Version Description
* ---------------------------------------------------------*
* 2017/12/27 langlw v1.0.0 创建
*/
@Component
public class TdCCouponRuleDaoImpl implements TdCCouponRuleDao {
@Autowired
private TdCCouponRuleSMapper tdCCouponRuleSMapper;
@Autowired
private TdCCouponRuleMapper tdCCouponRuleMapper;
@Autowired
private TdCCouponRuleParkMapper tdCCouponRuleParkMapper;
@Override
public List<TdCCouponRuleDTO> queryCouponRuleList(TdCCouponRuleRequest request) {
return tdCCouponRuleSMapper.queryCouponRuleList(request);
}
/**
* 查询所有有效的优惠规则
* @param request
* @return
*/
@Override
public List<TdCCouponRule> getCouponRuleList(TdCCouponRuleRequest request) {
TdCCouponRuleExample example = new TdCCouponRuleExample();
example.createCriteria().andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
return tdCCouponRuleMapper.selectByExample(example);
}
@Override
public List<TdCCouponRuleDTO> queryAllSellingCoupons(TdCCouponPersonRequest request) {
return tdCCouponRuleSMapper.queryAllSellingCoupons(request);
}
@Override
public TdCCouponRule queryCouponRuleByCardNo(String cardNo) {
TdCCouponRuleExample example = new TdCCouponRuleExample();
example.createCriteria().andCardNoEqualTo(cardNo).andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
.andCardStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()).andEndTimeGreaterThan(new Date());
List<TdCCouponRule> tdCCouponRules = tdCCouponRuleMapper.selectByExample(example);
if(CollectionUtil.isEmpty(tdCCouponRules)){
return null;
}
return tdCCouponRules.get(0);
}
@Override
public List<String> queryCouponRuleByCardNoList(List<String> cardNos) {
return tdCCouponRuleSMapper.queryCouponRuleByCardNoList(cardNos);
}
@Override
public Boolean updateCouponRuleByCardNo(TdCCouponRule tdCCouponRule) {
TdCCouponRuleExample example = new TdCCouponRuleExample();
example.createCriteria().andCardNoEqualTo(tdCCouponRule.getCardNo())
.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value())
.andCardStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()).andEndTimeGreaterThan(new Date());
return tdCCouponRuleMapper.updateByExampleSelective(tdCCouponRule, example) > 0;
}
@Override
public List<TdCCouponRuleDTO> queryHotCouponRuleForList(QueryHotCouponRequest request) {
return tdCCouponRuleSMapper.queryHotCouponRuleForList(request);
}
@Override
public List<TdCCouponRuleDTO> queryColdCouponRuleForList(QueryHotCouponRequest request) {
return tdCCouponRuleSMapper.queryColdCouponRuleForList(request);
}
@Override
public List<TdCCouponRuleDTO> queryCouponRuleParkMsg(TdCCouponRuleRequest request) {
return tdCCouponRuleSMapper.queryCouponRuleParkMsg(request);
}
@Override
public TdCCouponRuleDTO selectByCardNo(TdCCouponRuleRequest request) {
TdCCouponRuleDTO tdCCouponRuleDTO = new TdCCouponRuleDTO();
TdCCouponRule tCCouponRule = tdCCouponRuleSMapper.selectByCardNo(request.getCardNo());
if(tCCouponRule!=null) {
BeanUtils.copyProperties(tCCouponRule, tdCCouponRuleDTO);
}
return tdCCouponRuleDTO;
}
/**
* 保存优惠券.<br/>
* @param request
* @return
*/
@Override
public Integer saveCouponRule(TdCCouponRuleSaveReq request) {
TdCCouponRule record = new TdCCouponRule();
BeanUtils.copyProperties(request,record);
return tdCCouponRuleMapper.insertSelective(record);
}
@Override
public Integer saveCouponRuleList(List<TdCCouponRule> tdCCouponRuleList) {
return tdCCouponRuleSMapper.saveCouponRuleList(tdCCouponRuleList);
}
/**
* 修改优惠券.<br/>
* @param request
* @return
*/
@Override
public Integer updateCouponRule(TdCCouponRuleSaveReq request) {
TdCCouponRule record = new TdCCouponRule();
BeanUtils.copyProperties(request,record);
return tdCCouponRuleMapper.updateByPrimaryKeySelective(record);
}
/**
* 删除优惠券.<br/>
* @param request
* @return
*/
@Override
public Integer deleteCouponRule(TdCCouponRuleSaveReq request) {
int deleteFlg = 0;
if(null != request && request.getId() != null){
TdCCouponRule tdCCouponRule = tdCCouponRuleMapper.selectByPrimaryKey(request.getId());
/**1.删除优惠券规则.*/
TdCCouponRule couponRuleouponRule = new TdCCouponRule();
couponRuleouponRule.setId(request.getId());
couponRuleouponRule.setDataState(request.getDataState());
deleteFlg = tdCCouponRuleMapper.updateByPrimaryKeySelective(couponRuleouponRule);
if(deleteFlg >0 ){
TdCCouponRuleParkExample example = new TdCCouponRuleParkExample();
example.createCriteria().andCardNoEqualTo(tdCCouponRule.getCardNo());
//2.删除停车场优惠券关系表
tdCCouponRuleParkMapper.deleteByExample(example);
}
}
return deleteFlg;
}
/**
* 分页查询优惠券规则
* @Auther: wangfs
* @param
* @return
*/
@Override
public PageInfo<TdCCouponRule> queryCouponRuleForPage(QueryCouponRuleReq request) {
//1.设置分页
PageHelper.startPage(request.getBaseRequest().getPageNum(),request.getBaseRequest().getPageSize());
//2.查询数据
TdCCouponRuleExample example = new TdCCouponRuleExample();
TdCCouponRuleExample.Criteria criteria = example.createCriteria();
TdCCouponRuleExample.Criteria criteria2 = example.createCriteria();
if(StringUtils.isNotEmpty(request.getCardNo())){
criteria.andCardNoEqualTo(request.getCardNo());
criteria2.andCardNoEqualTo(request.getCardNo());
}
if(StringUtils.isNotEmpty(request.getCardName())){
criteria.andCardNameLike("%"+request.getCardName()+"%");
criteria2.andCardNameLike("%"+request.getCardName()+"%");
}
if(StringUtils.isNotEmpty(request.getBatchNo())){
criteria.andBatchNoLike("%"+request.getBatchNo()+"%");
criteria2.andBatchNoLike("%"+request.getBatchNo()+"%");
}
if(request.getCouponsType() != null ){
criteria.andCouponsTypeEqualTo(request.getCouponsType());
criteria2.andCouponsTypeEqualTo(request.getCouponsType());
}
if(request.getIsUesed() != null ){
criteria.andIsUesedEqualTo(request.getIsUesed());
criteria2.andIsUesedEqualTo(request.getIsUesed());
}
if(CollectionUtils.isNotEmpty(request.getCardTypes())){
criteria.andCardTypeIn(request.getCardTypes());
criteria2.andCardTypeIn(request.getCardTypes());
}
if(CollectionUtils.isNotEmpty(request.getReceiveChannels())){
criteria.andReceiveChannelsIn(request.getReceiveChannels());
criteria2.andReceiveChannelsIn(request.getReceiveChannels());
}
if(null != request.getOrgId()){
criteria.andOrgIdEqualTo(request.getOrgId());
criteria2.andOrgIdEqualTo(request.getOrgId());
}
if(null != request.getOwener()){
criteria.andOwenerEqualTo(request.getOwener());
criteria2.andOwenerEqualTo(request.getOwener());
}
if(request.getDataState() != null){//生效
if((DataStatusEnum.DATA_STATUS_VALID.value()).equals(request.getDataState())){
criteria.andDataStateEqualTo(request.getDataState());
criteria.andBeginTimeLessThanOrEqualTo(new Date());
criteria.andEndTimeGreaterThanOrEqualTo(new Date());
criteria2.andDataStateEqualTo(request.getDataState());
criteria2.andBeginTimeLessThanOrEqualTo(new Date());
criteria2.andEndTimeGreaterThanOrEqualTo(new Date());
}
if((DataStatusEnum.DATA_STATUS_NO_VALID.value()).equals(request.getDataState())){//失效
criteria.andDataStateEqualTo(request.getDataState());
criteria2.andEndTimeLessThan(new Date());
}
if(2 == request.getDataState()){//未生效
criteria.andBeginTimeGreaterThan(new Date());
criteria.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
criteria2.andBeginTimeGreaterThan(new Date());
criteria2.andDataStateEqualTo(DataStatusEnum.DATA_STATUS_VALID.value());
}
}
if(request.getEndDate() != null){
criteria.andEndTimeBetween(DateUtil.beginOfDay(request.getEndDate()), DateUtil.endOfDay(request.getEndDate()));
criteria2.andEndTimeBetween(DateUtil.beginOfDay(request.getEndDate()), DateUtil.endOfDay(request.getEndDate()));
}
example.or(criteria2);
example.setOrderByClause("id desc");
List<TdCCouponRule> tdCCouponRules = tdCCouponRuleMapper.selectByExample(example);
return new PageInfo<TdCCouponRule>(tdCCouponRules);
}
@Override
public Integer deleteBatchCouponRule(TdCCouponRuleDeleteReq request) {
TdCCouponRuleExample example = new TdCCouponRuleExample();
TdCCouponRuleExample.Criteria criteria = example.createCriteria();
criteria.andIdIn(request.getIds());
TdCCouponRule tdCCouponRule = new TdCCouponRule();
tdCCouponRule.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
return tdCCouponRuleMapper.updateByExampleSelective(tdCCouponRule,example);
}
/**
* 根据优惠券规则CardNo修改优惠券规则为无效
* @param request
* @return
*/
@Override
public Integer updateCouponRuleNoValidByCardNo(TdCCouponRuleSaveReq request) {
TdCCouponRuleExample example = new TdCCouponRuleExample();
TdCCouponRuleExample.Criteria criteria = example.createCriteria();
criteria.andCardNoEqualTo(request.getCardNo());
TdCCouponRule tdCCouponRule = new TdCCouponRule();
tdCCouponRule.setDataState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
tdCCouponRule.setCardState(DataStatusEnum.DATA_STATUS_NO_VALID.value());
tdCCouponRule.setModfiyDate(new Date());
return tdCCouponRuleMapper.updateByExampleSelective(tdCCouponRule,example);
}
}