package com.liangjian.dataplatform.member.controller;

import com.liangjian.dataplatform.member.entity.response.ResultObject;
import com.liangjian.dataplatform.member.service.IMemberOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 黄树文
 * @date 2020/4/18 10:25
 */
@RestController
@RequestMapping("/memberOrder")
@Api(value = "会员订单控制器", tags = "会员订单控制器")
public class MemberOrderController {


    @Autowired
    private IMemberOrderService iMemberOrderService;


    /**
     * 根据用户加密手机号查询购药订单
     * @param secretPhone
     * @param start
     * @param end
     * @param orderCode
     * @return
     * @throws SQLException
     */
    @PostMapping("/findOrderBySecretPhone")
    @ApiOperation(value = "根据用户加密手机号查询购药订单")
    public ResultObject<List<JSONObject>> findOrgerBySecretPhone(@ApiParam(value = "用户加密手机号", required = true) @RequestParam String secretPhone,
                                                                 @ApiParam(value = "开始日期", required = false) @RequestParam String start,
                                                                 @ApiParam(value = "截止日期", required = false) @RequestParam String end,
                                                                 @ApiParam(value = "订单编号", required = false) @RequestParam String orderCode) throws SQLException {


        List<JSONObject> result = iMemberOrderService.findOrderBySecretPhone(secretPhone, start, end, orderCode);

        return ResultObject.success(result);
    }

    /**
     * 根据用户手机号查询购药订单
     * @param phone
     * @param start
     * @param end
     * @param orderCode
     * @return
     * @throws SQLException
     */
    @PostMapping("/findOrderByPhone")
    @ApiOperation(value = "根据用户手机号查询购药订单")
    public ResultObject<List<JSONObject>> findOrgerByPhone(@ApiParam(value = "用户手机号", required = true) @RequestParam String phone,
                                                                 @ApiParam(value = "开始日期", required = false) @RequestParam String start,
                                                                 @ApiParam(value = "截止日期", required = false) @RequestParam String end,
                                                                 @ApiParam(value = "订单编号", required = false) @RequestParam String orderCode) throws SQLException {


        List<JSONObject> result = iMemberOrderService.findOrderByPhone(phone, start, end, orderCode);

        return ResultObject.success(result);
    }


}
