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 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 result = new HashMap<>(); Integer count = departmentService.selectCountForExam(name); List data = departmentService.selectPageForExam(name, first, pageSize); result.put("count", count); result.put("data", data); return success(result); } @PostMapping("/departmentList") public Msg departmentList() { List list = departmentService.list(new LambdaQueryWrapper().eq(DepartmentInfo::getIsdel,0)); List 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 result = new HashMap<>(); Integer count = userService.selectCountForExam(name,idno,tel,department,company); List 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 result = new HashMap<>(); Integer count = roleService.selectCountForRole(name); List data = roleService.selectPageForRole(name, first, pageSize); result.put("count", count); result.put("data", data); return success(result); } }