package com.reptileclient.jlifeapp.web;

import com.reptileclient.jlifeapp.result.ResponseInfoEnum;
import com.reptileclient.jlifeapp.result.ResultBody;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

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

    @ApiOperation(value = "通过用户手机号同步盒马服务付款单")
    @GetMapping("syncHmPaymentOrderByPhone")
    public ResultBody syncHmPaymentOrderByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            return new ResultBody(ResponseInfoEnum.PHONE_IS_NULL);
        }
        int row = hmPaymentOrderService.syncHmPaymentOrderByPhone(phone);
        return new ResultBody(row);
    }

    @ApiOperation(value = "同步盒马服务付款单")
    @GetMapping("addHmPaymentOrder")
    public ResultBody addHmPaymentOrder() {
        new Thread(() -> {
            hmPaymentOrderService.addPaymentOrderList();
        }).start();
        return new ResultBody();
    }

    @ApiOperation(value = "更新盒马服务付款单")
    @GetMapping("updateHmPaymentOrder")
    public ResultBody updateHmPaymentOrder() {
        new Thread(() -> {
            hmPaymentOrderService.updatePaymentOrderList();
        }).start();
        return new ResultBody();
    }
}
