puzhibing
2023-06-13 7860e5cb6db60aeb82c640651998f8294635df5b
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
package com.dsh.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsh.course.feignClient.activity.UserActivityClient;
import com.dsh.course.feignClient.activity.model.LargeCouponUpdateReq;
import com.dsh.course.feignClient.activity.model.UserLargeCouponReq;
import com.dsh.course.feignClient.order.OrderPrivateCarClient;
import com.dsh.course.feignClient.order.model.LargeListReq;
import com.dsh.course.feignClient.order.model.LargerAllReq;
import com.dsh.course.mapper.SysCouponRecordMapper;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.support.HttpKit;
import com.dsh.guns.core.util.SinataUtil;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.service.ITAuditRecordService;
import com.dsh.guns.modular.system.service.ITUserLargeService;
import com.dsh.guns.modular.system.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 大额优惠券
 *
 * @author fengshuonan
 * @Date 2020-06-05 14:31:28
 */
@Controller
@RequestMapping("/tUserLarge")
public class TUserLargeController extends BaseController {
 
    private String PREFIX = "/system/tUserLargeCoupon/";
 
    @Autowired
    private ITUserLargeService userLargeService;
 
    @Autowired
    private UserActivityClient activityClient;
 
    @Resource
    private SysCouponRecordMapper sysCouponRecordMapper;
 
    @Autowired
    private OrderPrivateCarClient orderPrivateCarClient;
 
    @Autowired
    private ITAuditRecordService recordService;
 
    /**
     * 跳转到车辆类型管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        model.addAttribute("companyId", UserExt.getUser().getObjectId());
        return PREFIX + "tUserLargeCoupon.html";
    }
 
    /**
     * 跳转到添加车辆类型管理
     */
    @RequestMapping("/tUserLarge_add")
    public String tCarModelAdd(Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        return PREFIX + "tUserLargeCoupon_add.html";
    }
    @RequestMapping("/tUserLarge_audit/{tCarModelId}")
    public String tCarModelAudit(@PathVariable Integer tCarModelId,Model model) {
        model.addAttribute("language", UserExt.getLanguage());
        model.addAttribute("id", tCarModelId);
        return PREFIX + "immediately.html";
    }
 
    /**
     * 跳转到修改车辆类型管理
     */
    @RequestMapping("/tUserLarge_update/{tCarModelId}")
    public String tCarModelUpdate(@PathVariable Integer tCarModelId, Model model) {
        TUserLargeCoupon tUserLargeCoupon = activityClient.getUserLargeCouponFromId(tCarModelId);
        model.addAttribute("item",tUserLargeCoupon);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        model.addAttribute("language",UserExt.getLanguage());
        model.addAttribute("sTime",format.format(tUserLargeCoupon.getStartTime()));
        model.addAttribute("eTime",format.format(tUserLargeCoupon.getEndTime()));
        return PREFIX + "tUserLargeCoupon_edit.html";
    }
 
    @RequestMapping("/tUserLarge_all")
    public String tUserLargeAll(Model model) {
        model.addAttribute("language",UserExt.getLanguage());
//        List<Integer> collect = sysCouponRecordMapper.selectList(new LambdaQueryWrapper<SysCouponRecord>().eq(SysCouponRecord::getCouponType, 3)).stream().map(SysCouponRecord::getId).collect(Collectors.toList());
        List<Integer> ids  =activityClient.getLargeCouponIds();
        Map<String,Object> map = new HashMap<>();
        if(ids.size()>0){
               map = orderPrivateCarClient.tUserLargeAll(new LargerAllReq(ids,null,null));
        }else {
            map.put("allMoney",0);
            map.put("num",0);
            map.put("userNum",0);
            map.put("money",0);
        }
        model.addAttribute("map",map);
        return PREFIX + "tUserLargeCoupon_all.html";
    }
 
    /**
     * 获取车辆类型管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,
                       String name,Integer status) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(createTime)){
            String[] timeArray = createTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        HttpServletRequest request = HttpKit.getRequest();
        int limit = Integer.valueOf(request.getParameter("limit"));     //每页多少条数据
        int offset = Integer.valueOf(request.getParameter("offset"));
 
        // 远程activity
        Page<Map<String, Object>> userLargeCoupons = activityClient.getUserLargeCoupon(new UserLargeCouponReq(limit,offset, beginTime, endTime, name, status,UserExt.getUser().getObjectId()));
        return super.packForBT(userLargeCoupons);
    }
    /**
     * 获取车辆类型管理列表
     */
    @RequestMapping(value = "/largeList")
    @ResponseBody
    public Object list(String useTime,
                       String user,String phone,String couponName ,String number) {
        String beginTime = null;
        String endTime = null;
        if (SinataUtil.isNotEmpty(useTime)){
            String[] timeArray = useTime.split(" - ");
            beginTime = timeArray[0];
            endTime = timeArray[1];
        }
        HttpServletRequest request = HttpKit.getRequest();
        int limit = Integer.valueOf(request.getParameter("limit"));     //每页多少条数据
        int offset = Integer.valueOf(request.getParameter("offset"));
        LambdaQueryWrapper<SysCouponRecord> like = new LambdaQueryWrapper<SysCouponRecord>().eq(SysCouponRecord::getCouponType, 3);
        if(Objects.nonNull(couponName)){
            like.like(SysCouponRecord::getName, couponName);
        }
        List<SysCouponRecord> sysCouponRecords = sysCouponRecordMapper.selectList(like);
 
 
        Page<Map<String, Object>> userLargeCoupons =new Page<>();
        if(sysCouponRecords.size()>0) {
            List<Integer> ids = sysCouponRecords.stream().map(SysCouponRecord::getId).collect(Collectors.toList());
            // 远程activity
            userLargeCoupons = orderPrivateCarClient.largeList(new LargeListReq(limit, offset, beginTime, endTime, user, phone, number,ids));
            List<Map<String, Object>> records = userLargeCoupons.getRecords();
            for (Map<String, Object> record : records) {
                for (SysCouponRecord sysCouponRecord : sysCouponRecords) {
                    if(record.get("cId")!=null) {
                        String couponId = record.get("cId").toString();
                        if (couponId.equals(sysCouponRecord.getId().toString())) {
                            record.put("couponName", sysCouponRecord.getName());
                        }
                    }
                }
            }
        }
        return super.packForBT(userLargeCoupons);
    }
 
    /**
     * 新增车辆类型管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TUserLargeCoupon tUserLargeCoupon,Integer type,String time) {
        String[] split = time.split(" - ");
        tUserLargeCoupon.setStartTime(DateUtil.parseDateOne(split[0]+" 00:00:00"));
        tUserLargeCoupon.setEndTime(DateUtil.parseDateOne(split[1]+" 23:59:59"));
        tUserLargeCoupon.setType(type);
        tUserLargeCoupon.setCompanyId(UserExt.getUser().getObjectId());
        activityClient.addLargeCoupon(tUserLargeCoupon);
        return SUCCESS_TIP;
    }
 
 
    @RequestMapping(value = "/immediately")
    @ResponseBody
    public Object immediately(Integer id,String remark,Integer state) {
        TUserLargeCoupon tUserLargeCoupon = activityClient.updateLargeCounpon(new LargeCouponUpdateReq(id,state,remark));
        TAuditRecord tAuditRecord = new TAuditRecord();
        if(state==3){
            tAuditRecord.setAuditStatus(2);
        }else {
            tAuditRecord.setAuditStatus(3);
        }
        tAuditRecord.setActivityId(tUserLargeCoupon.getId());
        tAuditRecord.setActivityName(tUserLargeCoupon.getName());
        tAuditRecord.setActivityType(4);
        tAuditRecord.setAuditTime(new Date());
        tAuditRecord.setAuditUserId(UserExt.getUser().getId());
        tAuditRecord.setRemark(remark);
        recordService.save(tAuditRecord);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除车辆类型管理
     */
    @RequestMapping(value = "/updateStatus")
    @ResponseBody
    public Object updateStatus(@RequestParam Integer tCarModelId) {
        activityClient.updateStatusFromId(tCarModelId);
        return SUCCESS_TIP;
    }
 
    @RequestMapping(value = "/updateTime")
    @ResponseBody
    public Object updateTime(@RequestParam String time) {
        String sTime=null;
        String eTime=null;
        if(time!=null && time !=""){
             sTime =time.split(" - ")[0];
             eTime =time.split(" - ")[1];
        }
//        List<Integer> collect = sysCouponRecordMapper.selectList(new LambdaQueryWrapper<SysCouponRecord>().eq(SysCouponRecord::getCouponType, 3)).stream().map(SysCouponRecord::getId).collect(Collectors.toList());
        List<Integer> ids  =activityClient.getLargeCouponIds();
        Map<String,Object> map = new HashMap<>();
        if(ids.size()>0){
            map = orderPrivateCarClient.tUserLargeAll(new LargerAllReq(ids,sTime,eTime));
        }else {
            map.put("allMoney",0);
            map.put("num",0);
            map.put("userNum",0);
            map.put("money",0);
        }
        return map;
    }
 
    /**
     * 修改车辆类型管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TCarModel tCarModel,Integer language) {
        tCarModel.setLanguage(language);
        return SUCCESS_TIP;
    }
 
}