liujie
2023-05-26 786466f6accfe836160342c56cdf3415e09bcb38
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
package com.stylefeng.guns.modular.system.controller;
 
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.model.vo.CompanyInfoVo;
import com.stylefeng.guns.modular.system.model.vo.MeInfoVo;
import com.stylefeng.guns.modular.system.model.vo.MeWalletVo;
import com.stylefeng.guns.modular.system.model.vo.WalletInfo;
import com.stylefeng.guns.modular.system.service.ITCompanyService;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.stylefeng.guns.modular.system.service.TCarriersService;
import com.stylefeng.guns.modular.system.utils.UserInfoUtil;
import com.stylefeng.guns.modular.system.utils.tips.ErrorTip;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
@Controller
@Api(tags = "我的信息")
@RequestMapping("/api/me")
public class MeController {
 
    @Resource
    private ITDriverService driverService;
 
 
    @Resource
    private ITCompanyService companyService;
 
 
    @Resource
    private TCarriersService carriersService;
 
    @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"),
    })
    @GetMapping(value = "/getMeInfo")
    @ResponseBody
    public Object getMeInfo(int id){
        TDriver driver = driverService.selectById(id);
        MeInfoVo meInfoVo = new MeInfoVo();
        meInfoVo.setAddress(driver.getAddress());
        meInfoVo.setContactNumber(driver.getContactNumber());
        meInfoVo.setDateOfBrith(driver.getDateOfBrith());
        meInfoVo.setDriverEmployeeNumber(driver.getDriverNumber());
        meInfoVo.setDriverName(driver.getDriverName());
        meInfoVo.setDriverType(driver.getDriverType());
        meInfoVo.setId(driver.getId());
        meInfoVo.setNotes(driver.getStatusRemark());
        meInfoVo.setStatus(driver.getStatus());
        return new SuccessTip(meInfoVo);
    }
 
 
 
    @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"),
    })
    @GetMapping(value = "/getMeCompanyInfo")
    @ResponseBody
    public Object getMeCompanyInfo(int id){
        TDriver driver = driverService.selectById(id);
        Integer companyId = driver.getCompanyId();
        TCompany company = companyService.selectById(companyId);
        CompanyInfoVo companyInfoVo = new CompanyInfoVo();
        companyInfoVo.setAddress(company.getAddress());
        companyInfoVo.setCompanyName(company.getName());
        companyInfoVo.setContactEmail(company.getContactEmail());
        companyInfoVo.setContactPhone(company.getContactPhone());
        companyInfoVo.setScacCode(company.getScacCode());
        companyInfoVo.setSetUpTheTime(company.getSetUpTheTime());
        return new SuccessTip(companyInfoVo);
    }
 
    @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"),
    })
    @GetMapping(value = "/getMeWallet")
    @ResponseBody
    public Object getMeWallet(int id){
        try {
            MeWalletVo meWalletVo = new MeWalletVo();
 
            ArrayList<WalletInfo> walletInfos = new ArrayList<>();
            TDriver driver = driverService.selectById(id);
            // 获取承运商
            Integer carriersId = driver.getCarriersId();
 
            TCarriers tCarriers = carriersService.selectById(carriersId);
            meWalletVo.setBillNumber(tCarriers.getBillNumber());
 
            BigDecimal unpaid = new BigDecimal(0);
            BigDecimal paid = new BigDecimal(0);
 
            List<TOrder> orders = driverService.getOrderInfo(id);
            for (TOrder e : orders) {
                WalletInfo walletInfo = new WalletInfo();
                walletInfo.setShipmentId(e.getId());
                BigDecimal payMoney = e.getPayMoney();
                double v = tCarriers.getCommission() / 100;
                // 承运商应得金额
                BigDecimal multiply = payMoney.multiply(new BigDecimal(v));
                walletInfo.setMoney(multiply);
                walletInfo.setPayStatus(e.getCarriersPayStatus());
                // TODO 时间
                if(e.getCarriersPayStatus()==0){
                    unpaid = unpaid.add(multiply);
                }else {
                    paid=paid.add(multiply);
                }
                walletInfos.add(walletInfo);
            }
            meWalletVo.setAllTotal(unpaid.add(paid));
            meWalletVo.setUnpaid(unpaid);
            meWalletVo.setPaid(paid);
            meWalletVo.setList(walletInfos);
            return new SuccessTip(meWalletVo);
        }catch (Exception e){
            e.printStackTrace();
            return new ErrorTip(500,"ERROR");
        }
 
    }
 
 
}