package com.reptileclient.jlifeapp.web;

import com.reptileclient.jlifeapp.result.ResponseInfoEnum;
import com.reptileclient.jlifeapp.result.ResultBody;
import com.reptileclient.jlifeapp.schedule.HmBookOrderTask;
import com.reptileclient.jlifeapp.service.HmBookOrderService;
import com.reptileclient.jlifeapp.service.HmPaymentOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author fuxubing
 */
@RestController
@Api(value = "服务单管理", description = "服务单管理")
public class HmBookOrderController {
    @Resource
    private HmBookOrderService hmBookOrderService;
    @Resource
    private HmPaymentOrderService hmPaymentOrderService;

    @Autowired
    HmBookOrderTask hmBookOrderTask;

    @ApiOperation(value = "通过预约人手机号同步盒马服务单")
    @GetMapping("syncHmBookOrderByPhone")
    public ResultBody syncHmBookOrderByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            return new ResultBody(ResponseInfoEnum.PHONE_IS_NULL);
        }
        int row = hmBookOrderService.syncHmBookOrderByPhone(phone);
        return new ResultBody(row);
    }

    @ApiOperation(value = "同步盒马服务单")
    @GetMapping("addHmBookOrder")
    public ResultBody addHmBookOrder() {
        new Thread(() -> {
            hmBookOrderService.addBookOrderList();
        }).start();
        return new ResultBody();
    }

    @ApiOperation(value = "更新盒马服务单")
    @GetMapping("updateHmBookOrder")
    public ResultBody updateHmBookOrder() {
        new Thread(() -> {
            hmBookOrderService.updateBookOrder();
        }).start();
        return new ResultBody();
    }


    @ApiOperation(value = "测试更新盒马服务单HmBookOrderTask.runTask")
    @GetMapping("runTask")
    public ResultBody runTask() {
        new Thread(() -> {
            hmBookOrderTask.runTask();
        }).start();
        return new ResultBody();
    }

    @ApiOperation(value = "将作业单匹配到的预约单、支付单进行状态同步")
    @GetMapping("runUpdateTask")
    public ResultBody runUpdateTask() {
        new Thread(() -> {
            hmBookOrderTask.runUpdateTask();
        }).start();
        return new ResultBody();
    }
}
