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("/api/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().eq("userId", uid).eq("phone", frequentPassengers.getPhone()).eq("status", 1)); // if(null != frequentPassengers1){ // return ResultUtil.error("该手机号已被使用"); // } FrequentPassengers frequentPassengers1 = frequentPassengersService.selectOne(new EntityWrapper().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> queryFrequentPassengersList(HttpServletRequest request){ try { Integer uid = userInfoService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } List frequentPassengers = frequentPassengersService.selectList(new EntityWrapper().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().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(); } } }