package cn.exrick.xboot.your.controller; import cn.exrick.xboot.core.common.utils.PageUtil; import cn.exrick.xboot.core.common.utils.ResultUtil; import cn.exrick.xboot.core.common.utils.SecurityUtil; import cn.exrick.xboot.core.common.vo.PageVo; import cn.exrick.xboot.core.common.vo.Result; import cn.exrick.xboot.core.entity.User; import cn.exrick.xboot.core.service.UserService; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; /** * @author Exrick */ @Slf4j @RestController @Api(tags = "指纹管理接口") @RequestMapping("/xboot/fingerprint") @Transactional public class FingerprintController { @Autowired private IFingerprintService iFingerprintService; @Autowired private UserService userService; @Autowired private ICustomerReceiveService iCustomerReceiveService; @Autowired private ICustomerService iCustomerService; @Autowired private IAreaService iAreaService; @Autowired private ICarService iCarService; @Autowired private SecurityUtil securityUtil; @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) @ApiOperation(value = "通过id获取") public Result get(@PathVariable String id) { Fingerprint fingerprint = iFingerprintService.getById(id); return new ResultUtil().setData(fingerprint); } @RequestMapping(value = "/getAreaIdByToken", method = RequestMethod.GET) @ApiOperation(value = "根据token获取区域id") public Result getAreaIdByToken() { Area area = getArea(securityUtil.getCurrUser().getId()); return new ResultUtil().setData(area); } @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "获取全部司机和配送员指纹数据") public Result> getAll() { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.select(" id,code,file_id,user_id "); wrapper.isNotNull("user_id"); wrapper.isNotNull("file_id"); List list = iFingerprintService.list(wrapper); return new ResultUtil>().setData(list); } @RequestMapping(value = "/getAllByAreaId", method = RequestMethod.GET) @ApiOperation(value = "获取全部片区内指纹数据") public Result> getAllByAreaId() { Area area = getArea(securityUtil.getCurrUser().getId()); if(area==null){ return ResultUtil.error("该用户还未绑定片区"); } QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("area_id",area.getId()); List list = iFingerprintService.list(wrapper); return new ResultUtil>().setData(list); } // public Area getArea(String userId){ // QueryWrapper wrapper = new QueryWrapper(); // wrapper.eq("user_id",userId); // Area area = iAreaService.getOne(wrapper); // if(area==null){ // QueryWrapper carQueryWrapper = new QueryWrapper(); // carQueryWrapper.eq("user_id",userId); // Car one = iCarService.getOne(carQueryWrapper); // // QueryWrapper wrapper3 = new QueryWrapper(); // wrapper3.eq("user_id",one.getFollowUserId()); // area = iAreaService.getOne(wrapper3); // return area; // } // return area; // } public Area getArea(String userId){ QueryWrapper carQueryWrapper = new QueryWrapper(); carQueryWrapper.eq("user_id",userId).or().eq("follow_user_id",userId); Car one = iCarService.getOne(carQueryWrapper); if(one==null){ return null; }else{ QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("car_id",one.getId()); Area area = iAreaService.getOne(wrapper); return area; } } @RequestMapping(value = "/getCount", method = RequestMethod.GET) @ApiOperation(value = "获取用户指纹数") public Result getCount() { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.isNotNull("user_id"); int a = iFingerprintService.count(wrapper); return new ResultUtil().setData(a); } @RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "分页获取") public Result> getByPage(PageVo page) { IPage data = iFingerprintService.page(PageUtil.initMpPage(page)); return new ResultUtil>().setData(data); } @RequestMapping(value = "/getUserByCode", method = RequestMethod.GET) @ApiOperation(value = "用指纹编号司机或配送员的登录名和密码") public Result getUserByCode(String code) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("code",code); wrapper.isNotNull("user_id"); Fingerprint one = iFingerprintService.getOne(wrapper); User user = userService.findByUsername(one.getUsername()); if(user==null){ return ResultUtil.error("用户已删除"); }else{ one.setPassword(Base64.getEncoder().encodeToString(user.getDescription().getBytes(StandardCharsets.UTF_8))); } return new ResultUtil().setData(one); } @RequestMapping(value = "/getCustomerByCode", method = RequestMethod.GET) @ApiOperation(value = "用指纹编号和商户id获取接货人信息") public Result getCustomerByCode(String code,String customerId) { Customer c = iCustomerService.getById(customerId); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("code",code); wrapper.eq("area_id",c.getAreaId()); wrapper.eq("customer_id",customerId); Fingerprint one = iFingerprintService.getOne(wrapper); if(one==null){ QueryWrapper wrapper2 = new QueryWrapper<>(); wrapper2.eq("code",code); wrapper2.eq("area_id",c.getAreaId()); Fingerprint one2 = iFingerprintService.getOne(wrapper2); if(one2!=null){ c.setLikeCusotmerId(one2.getCustomerId()); iCustomerService.saveOrUpdate(c); } return ResultUtil.error("指纹与商户不匹配"); } CustomerReceive customerReceive = iCustomerReceiveService.getById(one.getCustomerReceiveId()); return new ResultUtil().setData(customerReceive); } @RequestMapping(value = "/getCode2", method = RequestMethod.GET) @ApiOperation(value = "根据商户id获取接货人编号") public Result getCode2(String customerId) { Customer c = iCustomerService.getById(customerId); int code = iFingerprintService.maxCode2(c.getAreaId()); return new ResultUtil().setData(code); } @RequestMapping(value = "/getCode", method = RequestMethod.GET) @ApiOperation(value = "获取司机或配送员指纹编号") public Result getCode() { User currUser = securityUtil.getCurrUser(); String userId = currUser.getId(); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("user_id",userId); wrapper.isNull("file_id"); Fingerprint one = iFingerprintService.getOne(wrapper); if(one!=null){ return new ResultUtil().setData(one.getCode()); }else{ int code = iFingerprintService.maxCode(); Fingerprint fingerprint = new Fingerprint(); fingerprint.setUserId(userId); fingerprint.setType(currUser.getType2()); fingerprint.setCode(code); fingerprint.setUsername(currUser.getUsername()); fingerprint.setPassword(currUser.getDescription()); iFingerprintService.saveOrUpdate(fingerprint); return new ResultUtil().setData(code); } } @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST) @ApiOperation(value = "编辑或更新数据") public Result saveOrUpdate(Fingerprint fingerprint) { if(StrUtil.isEmpty(fingerprint.getFileId())){ return ResultUtil.error("fileId不能为空"); } if(StrUtil.isNotEmpty(fingerprint.getUserId())){ QueryWrapper wp = new QueryWrapper(); wp.eq("code",fingerprint.getCode()); wp.isNotNull("user_id"); List f = iFingerprintService.list(wp); if(f.size()>1){ return ResultUtil.error("code重复,请重新获取code并录入指纹"); } QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("code",fingerprint.getCode()); wrapper.eq("user_id",fingerprint.getUserId()); Fingerprint one = iFingerprintService.getOne(wrapper); if(one!=null){ one.setFileId(fingerprint.getFileId()); // User user = userService.get(fingerprint.getUserId()); // one.setUsername(user.getUsername()); // one.setPassword(user.getDescription()); // one.setType(user.getType2()); iFingerprintService.saveOrUpdate(one); }else{ return ResultUtil.error("未找到需要更新的指纹"); } } if(StrUtil.isNotEmpty(fingerprint.getCustomerId())){ Customer byId = iCustomerService.getById(fingerprint.getCustomerId()); fingerprint.setAreaId(byId.getAreaId()); QueryWrapper wrapper = new QueryWrapper(); wrapper.eq("code",fingerprint.getCode()); wrapper.eq("area_id",byId.getAreaId()); wrapper.isNotNull("customer_id"); Fingerprint one = iFingerprintService.getOne(wrapper); if(one!=null){ return ResultUtil.error("code重复了,请重新获取"); } }else{ return ResultUtil.error("customerId不能为空"); } if(StrUtil.isNotEmpty(fingerprint.getCustomerReceiveId())){ CustomerReceive byId = iCustomerReceiveService.getById(fingerprint.getCustomerReceiveId()); byId.setFstatus(1); iCustomerReceiveService.saveOrUpdate(byId); if (iFingerprintService.saveOrUpdate(fingerprint)) { return new ResultUtil().setData(fingerprint); } } return new ResultUtil().setErrorMsg("操作失败"); } @RequestMapping(value = "/delByIds", method = RequestMethod.POST) @ApiOperation(value = "批量通过id删除") public Result delAllByIds(@RequestParam String[] ids) { for (String id : ids) { iFingerprintService.removeById(id); } return ResultUtil.success("批量通过id删除数据成功"); } }