package com.reptileclient.jlifeapp.web;

import com.reptileclient.jlifeapp.result.ResponseInfoEnum;
import com.reptileclient.jlifeapp.result.ResultBody;
import com.reptileclient.jlifeapp.service.HmBookTradeOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
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 HmBookTradeOrderController {
    @Resource
    private HmBookTradeOrderService hmBookTradeOrderService;

    @ApiOperation(value = "通过预约人手机号同步盒马技师作业单")
    @GetMapping("syncHmBookTradeOrderByPhone")
    public ResultBody syncHmBookTradeOrderByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            return new ResultBody(ResponseInfoEnum.PHONE_IS_NULL);
        }
        int row = hmBookTradeOrderService.syncHmBookTradeOrderByPhone(phone);
        return new ResultBody(row);
    }

    @ApiOperation(value = "同步盒马技师作业单")
    @GetMapping("addHmBookTradeOrder")
    public ResultBody addHmBookOrder() {
        new Thread(() -> {
            hmBookTradeOrderService.addHmBookTradeList();
        }).start();

        return new ResultBody();
    }

    @ApiOperation(value = "更新盒马技师作业单")
    @GetMapping("updateHmBookTradeOrder")
    public ResultBody updateHmBookTradeOrder() {
        new Thread(() -> {
            try {
                hmBookTradeOrderService.updateHmBookTradeList();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        return new ResultBody();
    }
}
