package com.care.keeper.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.care.common.exception.BDException; import com.care.common.service.FileUploadService; import com.care.common.util.PageResult; import com.care.common.util.Result; import com.care.common.vo.PageReqVO; import com.care.common.vo.order.*; import com.care.keeper.service.KeeperApiService; import com.care.keeper.service.KeeperPassportService; import com.care.keeper.vo.HouseContactVO; import com.care.keeper.vo.KeeperInfoVO; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Author: lilt * @Date: 2021/5/26 * @Desc: */ @RestController @Api(value = "EventHandleController") @Slf4j @RequestMapping("/keeper/api/event") public class KeeperEventApiController { @Resource private KeeperApiService keeperApiService; @Resource private KeeperPassportService keeperPassportService; @Resource private FileUploadService fileUploadService; @GetMapping("/queryTodoList") @ApiOperation(tags = {"我的"},value = "未处理事件 分页") public PageResult> queryTodoList(@RequestHeader String token,PageReqVO pageReqVo){ try { KeeperInfoVO current = this.keeperPassportService.checkToken(token); IPage pageResponse = this.keeperApiService.queryTodoEventByChambId(pageReqVo,current.getId()); return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal()); }catch (BDException e) { log.error("我的未处理事件 分页列表出现异常",e); return PageResult.error(e.getMessage()); } catch (Exception e) { log.error("我的事件处理: 未处理事件查询出现异常",e); return PageResult.error( "获取列表失败"); } } @GetMapping("/queryDoingList") @ApiOperation(tags = {"我的"},value = "处理中事件 分页") public PageResult> queryDoingList(@RequestHeader String token,PageReqVO pageReqVo){ try { KeeperInfoVO current = this.keeperPassportService.checkToken(token); IPage pageResponse = this.keeperApiService.queryDoingEventByChambId(pageReqVo,current.getId()); return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal()); }catch (BDException e) { log.error("我的处理中事件 分页列表出现异常",e); return PageResult.error(e.getMessage()); } catch (Exception e) { log.error("我的事件处理: 处理中事件查询出现异常",e); return PageResult.error( "获取列表失败"); } } @GetMapping("/queryDoneList") @ApiOperation(tags = {"我的"},value = "已完成事件 分页") public PageResult> queryDoneList(@RequestHeader String token,PageReqVO pageReqVo){ try { KeeperInfoVO current = this.keeperPassportService.checkToken(token); IPage pageResponse = this.keeperApiService.queryDoneEventByChambId(pageReqVo,current.getId()); return PageResult.success(pageResponse.getRecords(),pageResponse.getCurrent(),pageResponse.getSize(),pageResponse.getTotal()); }catch (BDException e) { log.error("我的已完成事件 分页列表出现异常",e); return PageResult.error(e.getMessage()); } catch (Exception e) { log.error("我的已完成事件: 分页列表出现异常",e); return PageResult.error( "获取列表失败"); } } @GetMapping("/getEventInfo") @ApiOperation(tags = {"事件处理"},value = "事件处理或者详情") public Result> getEventInfo(@RequestParam("orderId") Long orderId){ EventOrderVO eventOrderVO = this.keeperApiService.getEventInfo(orderId); List olderVOList = this.keeperApiService.queryOrderOlderList(orderId); List houseContactVOList = this.keeperApiService.queryContactByOrderId(orderId); Map data = new HashMap<>(3); //订单信息 data.put("info",eventOrderVO); //老人 data.put("older",olderVOList); // 联系人 data.put("contact",houseContactVOList); return Result.success("查询成功!",data); } @GetMapping("/getApplyKeyInfo") @ApiOperation(tags = {"事件处理"},value = "获取钥匙信息,data如果为NULL,需要进行申请") public Result getApplyKeyInfo(@RequestHeader("token") String token, @RequestParam("orderId") Long orderId){ KeeperInfoVO current = this.keeperPassportService.checkToken(token); OrderKeyApplyVO orderKeyApplyVO = this.keeperApiService.getApplyKeyInfo(orderId,current.getId()); return Result.success("查询成功!",orderKeyApplyVO); } @GetMapping("/toApplyKey") @ApiOperation(tags = {"事件处理"},value = "申请钥匙") public Result> toApplyKey(@RequestHeader("token") String token, @RequestParam("orderId") Long orderId){ KeeperInfoVO current = this.keeperPassportService.checkToken(token); this.keeperApiService.applyKey(orderId,current); return Result.success("申请成功!"); } @PostMapping("/daoda") @ApiOperation(tags = {"事件处理"},value = "到达确认") public Result daoDaConfirm(@RequestParam("chambOrderId") Long chambOrderId){ if (this.keeperApiService.daoDaConfirm(chambOrderId)){ return Result.success("到达确认成功!"); }else{ return Result.error("操作失败!"); } } @PostMapping("/likai") @ApiOperation(tags = {"事件处理"},value = "离开确认") public Result liKaiConfirm(@RequestParam("chambOrderId") Long chambOrderId,@RequestParam("remark") String remark,@RequestParam("scenePic") String scenePic){ if (this.keeperApiService.liKaiConfirm(chambOrderId,remark,scenePic)){ return Result.success("离开确认成功!"); }else{ return Result.error("操作失败!"); } } @GetMapping("/queryDoHis") @ApiOperation(tags = {"事件处理"},value = "处理日志") public Result> queryDoHis(@RequestParam("orderId") Long orderId){ return Result.success("查询成功!",this.keeperApiService.queryOrderHandleHis(orderId)); } @ApiOperation(tags = {"APP-图片上传"},value = "图片上传接口", notes = "图片上传接口") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "放在请求头中的令牌", dataType = "String", paramType = "header", required = true) }) @CrossOrigin @PostMapping(value = "/img/upload", headers="content-type=multipart/form-data",produces = "application/json;charset=UTF-8") public Result imgUpload( @ApiParam(value="图片",required=true) MultipartFile file, @RequestHeader(name = "token") String token) { KeeperInfoVO current = this.keeperPassportService.checkToken(token); String url = fileUploadService.upload(file,"order"); return Result.success("上传成功!",url); } @GetMapping("/getKeeperStatus") @ApiOperation(tags = {"事件处理"},value = "获取管家当前的状态 0:未到达 1 到达、服务中 2 离开") public Result getKeeperStatus(@RequestParam("chambOrderId") Long chambOrderId){ Integer status = 0; ChambEventOrderVO orderVO = this.keeperApiService.getChambOrder(chambOrderId); if (orderVO!=null ){ if (orderVO.getDaodaTime()!=null && orderVO.getLikaiTime()==null){ status = 1; }else if (orderVO.getDaodaTime()!=null && orderVO.getLikaiTime()!=null){ status = 2 ; } } return Result.success("查询成功!",status); } @GetMapping("/getFuwuCount") @ApiOperation(tags = {"首页"},value = "获取管家的服务人数") public Result getFuwuCount( @RequestHeader(name = "token") String token){ KeeperInfoVO current = this.keeperPassportService.checkToken(token); return Result.success("查询成功!",this.keeperApiService.queryOlderCount(current)); } @GetMapping("/myOrderStat") @ApiOperation(tags = {"我的"},value = "工单统计") public Result myOrderStat( @RequestHeader(name = "token") String token){ KeeperInfoVO current = this.keeperPassportService.checkToken(token); return Result.success("查询成功!",this.keeperApiService.getOrderCountByChambId(current.getId())); } }