郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Api;
 
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.DepartmentInfo;
import com.gk.hotwork.Domain.ExamScoreInfo;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.RoleInfo;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.BeanUtils;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.dto.DepartmentDTO;
import com.gk.hotwork.Domain.dto.UserDTO;
import com.gk.hotwork.Service.DepartmentService;
import com.gk.hotwork.Service.ExamScoreService;
import com.gk.hotwork.Service.RoleService;
import com.gk.hotwork.Service.UserService;
import com.sun.org.apache.bcel.internal.generic.I2F;
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.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@Api(tags = "Api接口数据接口")
@RestController
@RequestMapping("/api")
public class ApiController extends BaseController {
    @Value("${filePath}")
    private String filePath; //配置文件配置的物理保存地址
    @Value("${fileurl}")
    private String fileurl;
    @Autowired
    ExamScoreService examscoreService;
    @Autowired
    UserService userService;
    @Autowired
    DepartmentService departmentService;
    @Autowired
    private RoleService roleService;
 
    @PostMapping("/addExam")
    @ApiOperation(value = "添加合格成绩", notes = "添加合格成绩", response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "realname",value = "真实姓名"),
            @ApiImplicitParam(name = "mobile",value = "手机号"),
            @ApiImplicitParam(name = "idcard",value = "身份证"),
            @ApiImplicitParam(name = "examtype",value = "考试类型"),
            @ApiImplicitParam(name = "score",value = "分数"),
            @ApiImplicitParam(name = "starttime",value = "有效期开始时间"),
            @ApiImplicitParam(name = "endtime",value = "有效期结束时间"),
    })
    public Msg addExam(@RequestBody JSONArray jsonArray){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            ExamScoreInfo examScoreInfo = new ExamScoreInfo();
            examScoreInfo.setRealname(jsonObject.getString("realname"));
            examScoreInfo.setMobile(jsonObject.getString("mobile"));
            examScoreInfo.setIdcard(jsonObject.getString("idcard"));
            examScoreInfo.setExamtype(jsonObject.getString("examtype"));
            examScoreInfo.setScore(jsonObject.getInteger("score"));
            examScoreInfo.setStarttime(jsonObject.getDate("starttime"));
            examScoreInfo.setEndtime(jsonObject.getDate("endtime"));
            examScoreInfo.setCreatetime(new Date());
            ExamScoreInfo examScoreExist = examscoreService.selectByMobile(jsonObject.getString("examtype"),jsonObject.getString("mobile"));
            if (examScoreExist != null){
                examScoreInfo.setId(examScoreExist.getId());
                examscoreService.updateById(examScoreInfo);
            }else {
                examscoreService.save(examScoreInfo);
            }
        }
 
        return msg;
    }
 
    /**
    * @Description: 众泰考试api
    * @date 2022/4/26 16:34
    */
 
    @PostMapping("/exam/foreground/login")
    public Msg examLogin(@RequestBody JSONObject loginFormData) {
        //手机号
        String username = loginFormData.getString("telIdNo");
        String password = loginFormData.getString("password");
        UserInfo userInfo = userService.examForegroundLogin(username, password);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(userInfo,userDTO);
        if (userDTO.getId() != null) {
            List<RoleInfo> roleInfos = roleService.selectRoleByUser(userDTO.getId());
            if (roleInfos.size() == 1)
            userDTO.setRoleId(roleInfos.get(0).getId());
            userDTO.setRoleName(roleInfos.get(0).getName());
        }
 
        return success(userDTO);
    }
 
    @PostMapping("/exam/background/login")
    public Msg examBackgroundLogin(@RequestBody JSONObject loginFormData) {
 
        String username = loginFormData.getString("username");
        String password = loginFormData.getString("password");
        UserInfo userInfo = userService.examBackgroundLogin(username, password);
        return success(userInfo);
    }
 
    @PostMapping("/departmentPage")
    public Msg departmentPage(@RequestBody JSONObject jsonObject) {
        String name = jsonObject.getString("name");
        Integer first = jsonObject.getInteger("first");
        Integer pageSize = jsonObject.getInteger("pageSize");
        Map<String, Object> result = new HashMap<>();
        Integer count = departmentService.selectCountForExam(name);
        List<DepartmentInfo> data =  departmentService.selectPageForExam(name, first, pageSize);
        result.put("count", count);
        result.put("data", data);
        return success(result);
    }
 
    @PostMapping("/departmentList")
    public Msg departmentList() {
        List<DepartmentInfo> list = departmentService.list(new LambdaQueryWrapper<DepartmentInfo>().eq(DepartmentInfo::getIsdel,0));
        List<DepartmentDTO> res = new ArrayList<>();
        DepartmentDTO departmentDTO;
        for (DepartmentInfo dep : list) {
            departmentDTO = new DepartmentDTO();
            departmentDTO.setId(dep.getId());
            departmentDTO.setName(dep.getDepartment());
            res.add(departmentDTO);
        }
 
        return success(res);
    }
 
    @PostMapping("/personPage")
    public Msg personPage(@RequestBody JSONObject jsonObject) {
        String name = jsonObject.getString("name");
        String idno = jsonObject.getString("idno");
        String tel = jsonObject.getString("tel");
        String department = jsonObject.getString("department");
        String company = jsonObject.getString("company");
        Integer first = jsonObject.getInteger("first");
        Integer pageSize = jsonObject.getInteger("pageSize");
        Map<String, Object> result = new HashMap<>();
        Integer count = userService.selectCountForExam(name,idno,tel,department,company);
        List<UserInfo> data =  userService.selectPageForExam(name,idno,tel,department,company, first, pageSize);
        result.put("count", count);
        result.put("data", data);
        return success(result);
    }
 
 
    @PostMapping("/rolePage")
    public Msg rolePage(@RequestBody JSONObject jsonObject) {
        String name = jsonObject.getString("name");
        Integer first = jsonObject.getInteger("first");
        Integer pageSize = jsonObject.getInteger("pageSize");
        Map<String, Object> result = new HashMap<>();
        Integer count = roleService.selectCountForRole(name);
        List<RoleInfo> data =  roleService.selectPageForRole(name, first, pageSize);
        result.put("count", count);
        result.put("data", data);
        return success(result);
    }
}