五、核心代码
5.1 查询车辆档案
@RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "查询车辆") public Result<IPage<Vehicle>> getByPage(@ModelAttribute Vehicle vehicle ,@ModelAttribute PageVo page){ QueryWrapper<Vehicle> qw = new QueryWrapper<>(); if(!ZwzNullUtils.isNull(vehicle.getUserName())) { qw.like("user_name",vehicle.getUserName()); } if(!ZwzNullUtils.isNull(vehicle.getCarNumber())) { qw.like("car_number",vehicle.getCarNumber()); } if(!ZwzNullUtils.isNull(vehicle.getStatus())) { qw.like("status",vehicle.getStatus()); } IPage<Vehicle> data = iVehicleService.page(PageUtil.initMpPage(page),qw); return new ResultUtil<IPage<Vehicle>>().setData(data); }
5.2 申请车辆理赔
@RequestMapping(value = "/addOne", method = RequestMethod.GET) @ApiOperation(value = "小程序申请理赔") public Result<Object> addOne(@RequestParam String carId,@RequestParam String reason,@RequestParam String money,@RequestParam String image){ Vehicle v = iVehicleService.getById(carId); if(v == null) { return ResultUtil.error("车辆不存在"); } VehicleClaim vc = new VehicleClaim(); vc.setVehicleId(v.getId()); vc.setUserId(v.getUserId()); vc.setUserName(v.getUserName()); vc.setMobile(v.getMobile()); vc.setCarNumber(v.getCarNumber()); vc.setImage(v.getImage()); vc.setBrand(v.getBrand()); vc.setClaimReason(reason); vc.setClaimTime1(DateUtil.now()); vc.setClaimTime2(""); vc.setClaimStatus("未审核"); vc.setClaimUser(""); try { vc.setClaimMoney(BigDecimal.valueOf(Long.parseLong(money))); } catch (Exception e) { vc.setClaimMoney(BigDecimal.ZERO); } iVehicleClaimService.saveOrUpdate(vc); User currUser = securityUtil.getCurrUser(); String[] imageList = image.split(","); for (String vo : imageList) { VehicleImage vi = new VehicleImage(); vi.setClaimId(vc.getId()); vi.setImage(vo); vi.setUploadTime(DateUtil.now()); vi.setUploadUser(currUser.getNickname()); iVehicleImageService.saveOrUpdate(vi); } return ResultUtil.success(); }
5.3 上传理赔照片
@RequestMapping(value = "/addOne", method = RequestMethod.GET) @ApiOperation(value = "新增照片") public Result<VehicleImage> addOne(@RequestParam String id,@RequestParam String image){ User currUser = securityUtil.getCurrUser(); String[] imageList = image.split(","); for (String vo : imageList) { VehicleImage vi = new VehicleImage(); vi.setClaimId(id); vi.setImage(vo); vi.setUploadTime(DateUtil.now()); vi.setUploadUser(currUser.getNickname()); iVehicleImageService.saveOrUpdate(vi); } return ResultUtil.success(); }
5.4 小程序登录
@RequestMapping(value = "/loginOnWeb", method = RequestMethod.GET) @ApiOperation(value = "小程序登陆") public Result<String> loginOnWeb(@RequestParam String userName, @RequestParam String password){ QueryWrapper<User> qw = new QueryWrapper<>(); qw.eq("username",userName); List<User> userList = iUserService.list(qw); if(userList.size() < 1) { User u = new User(); u.setUsername(userName); u.setNickname(userName); u.setMobile(userName); u.setEmail(u.getMobile() + "@qq.com"); String encryptPass = new BCryptPasswordEncoder().encode(password); u.setPassword(encryptPass).setType(0); iUserService.saveOrUpdate(u); QueryWrapper<Role> roleQw = new QueryWrapper<>(); roleQw.eq("default_role",true); List<Role> roleList = iRoleService.list(roleQw); if(roleList.size() > 0){ for(Role role : roleList) { iUserRoleService.saveOrUpdate(new UserRole().setUserId(u.getId()).setRoleId(role.getId())); } } String accessToken = securityUtil.getToken(u.getUsername(), true); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(new SecurityUserDetails(u), null, null); SecurityContextHolder.getContext().setAuthentication(authentication); return new ResultUtil<String>().setData(accessToken); } User user = userList.get(0); if(!new BCryptPasswordEncoder().matches(password, user.getPassword())){ return ResultUtil.error("密码不正确"); } String accessToken = securityUtil.getToken(user.getUsername(), true); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(new SecurityUserDetails(user), null, null); SecurityContextHolder.getContext().setAuthentication(authentication); return new ResultUtil<String>().setData(accessToken); }
5.5 修改个人昵称
@RequestMapping(value = "/changeName", method = RequestMethod.GET) @ApiOperation(value = "修改昵称") public Result<User> changeName(@RequestParam String nickname){ User user = iUserService.getById(securityUtil.getCurrUser().getId()); if(user == null) { return ResultUtil.error("用户不存在"); } user.setNickname(nickname); iUserService.saveOrUpdate(user); return new ResultUtil<User>().setData(user); }
六、免责说明
- 本项目仅供个人学习使用,商用授权请联系博主,否则后果自负。
- 博主拥有本软件构建后的应用系统全部内容所有权及独立的知识产权,拥有最终解释权。
- 如有问题,欢迎在仓库 Issue 留言,看到后会第一时间回复,相关意见会酌情考虑,但没有一定被采纳的承诺或保证。
下载本系统代码或使用本系统的用户,必须同意以下内容,否则请勿下载!
- 出于自愿而使用/开发本软件,了解使用本软件的风险,且同意自己承担使用本软件的风险。
- 利用本软件构建的网站的任何信息内容以及导致的任何版权纠纷和法律争议及后果和博主无关,博主对此不承担任何责任。
- 在任何情况下,对于因使用或无法使用本软件而导致的任何难以合理预估的损失(包括但不仅限于商业利润损失、业务中断与业务信息丢失),博主概不承担任何责任。
- 必须了解使用本软件的风险,博主不承诺提供一对一的技术支持、使用担保,也不承担任何因本软件而产生的难以预料的问题的相关责任。