liujie
2023-10-15 871efa21e6c95520e9825ae1f2338c9a919fdd5d
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
package com.stylefeng.guns.modular.system.controller;
 
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.model.dto.UserAddInfoDto;
import com.stylefeng.guns.modular.system.service.ITOrderService;
import com.stylefeng.guns.modular.system.service.ITPriceService;
import com.stylefeng.guns.modular.system.service.ITUserAddressService;
import com.stylefeng.guns.modular.system.service.ITUserService;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2022-12-28 09:33:09
 */
@Controller
@Api(tags = "用户端 -- 主页")
@RequestMapping("/api/index")
public class IndexController extends BaseController {
 
    @Autowired
    private ITOrderService orderService;
 
    @Resource
    private ITUserService userService;
 
    @Resource
    private ITUserAddressService userAddressService;
 
    @Autowired
    private ITPriceService priceService;
    /**
     * 完善信息
     */
    @ApiOperation(value = "用户-完善信息",notes="用户-完善信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/addInfo")
    @ResponseBody
    public Object addInfo(@RequestBody UserAddInfoDto userAddInfoDto) {
        TUser tUser = userService.selectById(userAddInfoDto.getUserId());
        tUser.setPhone(userAddInfoDto.getPhone());
        tUser.setContactName(userAddInfoDto.getContactName());
        tUser.setContactEmail(userAddInfoDto.getContactEmail());
        tUser.setContactPhone(userAddInfoDto.getContactPhone());
        tUser.setLogisticsContactName(userAddInfoDto.getLogisticsContactName());
        tUser.setLogisticsContactEmail(userAddInfoDto.getLogisticsContactEmail());
        tUser.setLogisticsContactPhone(userAddInfoDto.getLogisticsContactPhone());
        tUser.setEmail(userAddInfoDto.getEmail());
        tUser.setCompanyName(userAddInfoDto.getCompanyName());
        tUser.setHeadImg(userAddInfoDto.getImg());
//        TUserAddress tUserAddress = new TUserAddress();
//        tUserAddress.setAddress(userAddInfoDto.getAddress());
//        tUserAddress.setUserId(userAddInfoDto.getUserId());
        userService.updateById(tUser);
//        userAddressService.insert(tUserAddress);
        return new SuccessTip();
    }
 
 
    /**
     * 完善信息
     */
    @ApiOperation(value = "用户-完善信息--获取信息",notes="用户-完善信息--获取信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int"),
    })
    @PostMapping(value = "/getInfo")
    @ResponseBody
    public Object getInfo( int id) {
        TUser tUser = userService.selectById(id);
//        userAddressService.insert(tUserAddress);
        return new SuccessTip(tUser);
    }
 
    /**
     * 获取首页信息
     */
    @ApiOperation(value = "用户端-首页信息",notes="用户端-首页信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "time", value = "2000-01-01 - 2000-11-11", required = false, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "1all 2this year 3this quarter 4自定义时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
    })
    @GetMapping(value = "/index")
    @ResponseBody
    public Object list(String time,int type,int userId) {
        TUser tUser = userService.selectById(userId);
        IndexInfo indexInfo = new IndexInfo();
        int numberOfOrder = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).ne("status",17));
        int dispatching = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).eq("status",0));
        int pendingPickup = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).eq("status",2));
        int inTransit = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).eq("status",7));
        int toBeUnloaded = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).eq("status",8));
        int unloaded = orderService.selectCount(new EntityWrapper<TOrder>().eq("user_id", userId).eq("status",9));
        List<TOrder> orders = orderService.selectList(new EntityWrapper<TOrder>().eq("user_id", userId).isNull("pay_time").ne("status",17));
        BigDecimal bigDecimal = new BigDecimal(0);
        for (TOrder order : orders) {
            List<TPrice> prices = priceService.selectList(new EntityWrapper<TPrice>().eq("order_id", order.getId()));
            BigDecimal reduce = prices.stream().map(TPrice::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
            bigDecimal = bigDecimal.add(reduce);
        }
        indexInfo.setNumberOfOrder(numberOfOrder);
        indexInfo.setDispatching(dispatching);
        indexInfo.setPendingPickup(pendingPickup);
        indexInfo.setInTransit(inTransit);
        indexInfo.setToBeUnloaded(toBeUnloaded);
        indexInfo.setUnloaded(unloaded);
        indexInfo.setUnpaidBills(bigDecimal);
        indexInfo.setAllQuota(tUser.getReditLimit());
        indexInfo.setResidueQuota(tUser.getResidueLimit());
        indexInfo.setPaymentDay(Integer.valueOf(tUser.getPaymentDays()));
 
        if(type==1){
            List<IndexMonth> list = orderService.index(userId);
            indexInfo.setList(list);
        }else if(type==2){
            int i = DateUtil.thisYear();
            List<IndexMonth> list = orderService.indexYear(i,userId);
            indexInfo.setList(list);
        }else if(type==3){
            String sTime = DateUtil.beginOfQuarter(new Date()).toString();
            String eTime = DateUtil.endOfQuarter(new Date()).toString();
            List<IndexMonth> list = orderService.indexTime(sTime,eTime,userId);
            indexInfo.setList(list);
        }else {
            String sTime =time.split(" - ")[0]+" 00:00:00";
            String eTime =time.split(" - ")[1]+" 23:59:59";
            List<IndexMonth> list = orderService.indexTime(sTime,eTime,userId);
            indexInfo.setList(list);
        }
        return new SuccessTip(indexInfo);
    }
 
    public static void main(String[] args) {
        DateTime dateTime = DateUtil.beginOfQuarter(new Date());
        System.out.println(dateTime);
        String s = dateTime.toString();
        System.out.println(s);
    }
 
}