| | |
| | | import com.taoke.autopay.entity.js2.OrderTaskExecutionDetail; |
| | | import com.taoke.autopay.factory.js2.OrderTaskExecutionDetailFactory; |
| | | import com.taoke.autopay.service.ClientAdditionalInfoService; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.js2.OrderTaskExecutionDetailService; |
| | | import com.taoke.autopay.service.js2.OrderTaskService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | |
| | | @Controller |
| | | @RequestMapping("api/client/js2/task") |
| | | public class OrderTaskController { |
| | | |
| | | private Logger loggerDoOrder = LoggerFactory.getLogger("doOrderLogger"); |
| | | |
| | | @Resource |
| | | private ClientAdditionalInfoService clientAdditionalInfoService; |
| | |
| | | @Resource |
| | | private OrderTaskService orderTaskService; |
| | | |
| | | @Resource |
| | | private ClientInfoService clientInfoService; |
| | | |
| | | /** |
| | | * 获取设备可执行的任务列表 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param page 页码 |
| | | * @param uid 客户端ID |
| | | * @param page 页码 |
| | | * @param pageSize 每页数量 |
| | | * @return 任务列表 |
| | | */ |
| | |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | | } |
| | | List<OrderTaskExecutionDetailVO> voList= new ArrayList<>(); |
| | | List<OrderTaskExecutionDetail> list = orderTaskExecutionDetailService.listCanExcuteTaskDetail(uid, (page-1)*pageSize,pageSize); |
| | | if(!list.isEmpty()){ |
| | | List<Long> taskIds=new ArrayList<>(); |
| | | clientInfoService.setActiveTime(uid, new Date()); |
| | | List<OrderTaskExecutionDetailVO> voList = new ArrayList<>(); |
| | | List<OrderTaskExecutionDetail> list = orderTaskExecutionDetailService.listCanExcuteTaskDetail(uid, (page - 1) * pageSize, pageSize); |
| | | if (!list.isEmpty()) { |
| | | List<Long> taskIds = new ArrayList<>(); |
| | | for (OrderTaskExecutionDetail detail : list) { |
| | | if(taskIds.contains(detail.getTaskId())){ |
| | | if (taskIds.contains(detail.getTaskId())) { |
| | | continue; |
| | | } |
| | | taskIds.add(detail.getTaskId()); |
| | | } |
| | | // 获取手机号与支付宝账号信息 |
| | | ClientAdditionalInfo clientAdditionalInfo = clientAdditionalInfoService.getClientAdditionalInfoByClientId(uid); |
| | | List<OrderTask> orderTaskList = orderTaskService.getOrderTaskByIds(taskIds); |
| | | Map<Long, OrderTask> orderTaskMap=new HashMap<>(); |
| | | for(OrderTask task:orderTaskList){ |
| | | orderTaskMap.put(task.getId(),task); |
| | | List<OrderTask> orderTaskList = orderTaskService.getOrderTaskByIds(taskIds); |
| | | Map<Long, OrderTask> orderTaskMap = new HashMap<>(); |
| | | for (OrderTask task : orderTaskList) { |
| | | orderTaskMap.put(task.getId(), task); |
| | | } |
| | | for(OrderTaskExecutionDetail detail:list){ |
| | | OrderTaskExecutionDetailVO vo = OrderTaskExecutionDetailFactory.createOrderTaskExecutionDetailVO(orderTaskMap.get(detail.getTaskId()),detail,clientAdditionalInfo); |
| | | for (OrderTaskExecutionDetail detail : list) { |
| | | OrderTaskExecutionDetailVO vo = OrderTaskExecutionDetailFactory.createOrderTaskExecutionDetailVO(orderTaskMap.get(detail.getTaskId()), detail, clientAdditionalInfo); |
| | | voList.add(vo); |
| | | } |
| | | } |
| | | voList.sort((o1, o2) -> (int) (o1.getCreateTime().getTime() - o2.getCreateTime().getTime())); |
| | | long count = orderTaskExecutionDetailService.countCanExcuteTaskDetail(uid); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("list", gson.toJson(voList)); |
| | | data.put("count", count); |
| | | return JsonUtil.loadTrueResult(data); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | loggerTask.error("获取任务列表失败: {}", e.getMessage(), e); |
| | | return JsonUtil.loadFalseResult("系统异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("canOrder") |
| | | public String canOrder(Long uid, String id) { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("任务ID不能为空"); |
| | | } |
| | | |
| | | OrderTaskExecutionDetail detail = orderTaskExecutionDetailService.getOrderTaskExecutionDetailByIdForUpdate(id); |
| | | if (detail == null || detail.getExecutionStatus() != OrderTaskExecutionDetail.STATUS_NOT_ORDERED) { |
| | | return JsonUtil.loadFalseResult("任务不存在或已执行"); |
| | | } |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | /** |
| | | * 下单成功 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param orderNo 订单号 |
| | | * @param uid 客户端ID |
| | | * @param id |
| | | * 任务执行详情ID |
| | | * @param orderNo 订单号 |
| | | * @param productTitle 商品标题 |
| | | * @param shopName 店铺名称 |
| | | * @param shopName 店铺名称 |
| | | * @param orderTimeStr 下单时间字符串 |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("orderSuccess") |
| | | public String orderSuccess(Long uid, String id, String orderNo, String productTitle, String shopName, String orderTimeStr) { |
| | | loggerTask.info("orderSuccess[{}]: {}-{}-{}-{}-{}", uid, id, orderNo, productTitle, shopName, orderTimeStr); |
| | | loggerDoOrder.info("下单成功[{}]: {}-{}-{}-{}-{}", uid, id, orderNo, productTitle, shopName, orderTimeStr); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | |
| | | if (StringUtil.isNullOrEmpty(orderNo)) { |
| | | return JsonUtil.loadFalseResult("订单号不能为空"); |
| | | } |
| | | |
| | | |
| | | orderNo = orderNo.split("订单编号")[1]; |
| | | |
| | | Date orderTime = null; |
| | | if (!StringUtil.isNullOrEmpty(orderTimeStr)) { |
| | |
| | | /** |
| | | * 下单失败,上传失败原因 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param failureReason 失败原因 |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("orderFailure") |
| | | public String orderFailure(Long uid, String id, String failureReason) { |
| | | loggerTask.info("orderFailure[{}]: {}-{}", uid, id, failureReason); |
| | | loggerDoOrder.info("下单失败[{}]: {}-{}", uid, id, failureReason); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | |
| | | /** |
| | | * 确认收货成功,上传券码 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param couponCode 券码 |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("confirmReceiptSuccess") |
| | | public String confirmReceiptSuccess(Long uid, String id, String couponCode) { |
| | | loggerTask.info("confirmReceiptSuccess[{}]: {}-{}", uid, id, couponCode); |
| | | loggerDoOrder.info("确认收货成功[{}]: {}-{}", uid, id, couponCode); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | |
| | | /** |
| | | * 确认收货失败,上传失败原因 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param reason 失败原因 |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("confirmReceiptFailure") |
| | | public String confirmReceiptFailure(Long uid, String id, String reason) { |
| | | loggerTask.info("confirmReceiptFailure[{}]: {}-{}", uid, id, reason); |
| | | loggerDoOrder.info("确认收货失败[{}]: {}-{}", uid, id, reason); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | |
| | | * 评价成功 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param id 任务执行详情ID |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("reviewSuccess") |
| | | public String reviewSuccess(Long uid, String id) { |
| | | loggerTask.info("reviewSuccess[{}]: {}", uid, id); |
| | | loggerDoOrder.info("评价成功[{}]: {}", uid, id); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |
| | |
| | | /** |
| | | * 评价失败,上传失败原因 |
| | | * |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param uid 客户端ID |
| | | * @param id 任务执行详情ID |
| | | * @param reason 失败原因 |
| | | * @return 操作结果 |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("reviewFailure") |
| | | public String reviewFailure(Long uid, String id, String reason) { |
| | | loggerTask.info("reviewFailure[{}]: {}-{}", uid, id, reason); |
| | | loggerDoOrder.info("评价失败[{}]: {}-{}", uid, id, reason); |
| | | try { |
| | | if (uid == null) { |
| | | return JsonUtil.loadFalseResult("客户端ID不能为空"); |