luodangjia
2024-12-10 31ce6be2d56798d9509e6d90335999064351f7f3
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
package com.stylefeng.guns.modular.api;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.FrequentPassengers;
import com.stylefeng.guns.modular.system.service.IFrequentPassengersService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.util.JuHeUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
 
/**
 * 常用乘车人
 */
@RestController
@RequestMapping("/base/frequentPassengers")
public class FrequentPassengersController {
 
    @Autowired
    private IFrequentPassengersService frequentPassengersService;
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private JuHeUtil juHeUtil;
 
 
 
    @ResponseBody
    @RequestMapping(value = "/saveFrequentPassengers", method = RequestMethod.POST)
    @ApiOperation(value = "添加/编辑 常用乘车人【新】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil saveFrequentPassengers(FrequentPassengers frequentPassengers, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            //开始校验身份真实
            boolean b = juHeUtil.idcard(frequentPassengers.getName(), frequentPassengers.getIdcode());
            if(!b){
                return ResultUtil.error("身份校验不通过");
            }
//            FrequentPassengers frequentPassengers1 = frequentPassengersService.selectOne(new EntityWrapper<FrequentPassengers>().eq("userId", uid).eq("phone", frequentPassengers.getPhone()).eq("status", 1));
//            if(null != frequentPassengers1){
//                return ResultUtil.error("该手机号已被使用");
//            }
            FrequentPassengers frequentPassengers1 = frequentPassengersService.selectOne(new EntityWrapper<FrequentPassengers>().eq("userId", uid).eq("idcode", frequentPassengers.getIdcode()).eq("status", 1));
            if(null != frequentPassengers1){
                if(null == frequentPassengers.getId()){
                    return ResultUtil.error("该身份证号已被使用");
                }
                if(null != frequentPassengers.getId() && frequentPassengers1.getId().compareTo(frequentPassengers.getId()) != 0){
                    return ResultUtil.error("该身份证号已被使用");
                }
            }
 
            frequentPassengers.setUserId(uid);
            frequentPassengers.setStatus(1);
            frequentPassengers.setCreateTime(new Date());
            if(null == frequentPassengers.getId()){
                frequentPassengersService.insert(frequentPassengers);
            }else{
                frequentPassengersService.updateById(frequentPassengers);
            }
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
    @ResponseBody
    @RequestMapping(value = "/queryFrequentPassengersList", method = RequestMethod.POST)
    @ApiOperation(value = "获取常用乘车人列表【新】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<FrequentPassengers>> queryFrequentPassengersList(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<FrequentPassengers> frequentPassengers = frequentPassengersService.selectList(new EntityWrapper<FrequentPassengers>().eq("userId", uid).eq("status", 1));
            return ResultUtil.success(frequentPassengers);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @RequestMapping(value = "/delFrequentPassengers", method = RequestMethod.POST)
    @ApiOperation(value = "删除常用乘车人列表【新】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数据id", name = "id", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil delFrequentPassengers(Integer id, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            FrequentPassengers frequentPassengers = frequentPassengersService.selectOne(new EntityWrapper<FrequentPassengers>().eq("id", id).eq("userId", uid));
            if(null == frequentPassengers){
                return ResultUtil.error("无效的数据");
            }
            frequentPassengers.setStatus(3);
            frequentPassengersService.updateById(frequentPassengers);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}