package com.yiqi.api.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.PageVO;
import com.yiqi.common.core.domain.R;
import com.yiqi.system.domain.SysOrg;
import com.yiqi.system.domain.SysStore;
import com.yiqi.system.domain.dto.weapp.WeAppOrgInfoQueryDTO;
import com.yiqi.system.domain.dto.weapp.WeAppOrgQueryDTO;
import com.yiqi.system.domain.vo.OrgVO;
import com.yiqi.system.domain.vo.SysStoreVo;
import com.yiqi.system.service.ISysOrgService;
import com.yiqi.system.service.ISysStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author xiaohei
 * @date 2023/10/4
 */
@Api(tags = "门店")
@RestController
@RequestMapping(value = UrlConstants.wxappApi + "/store")
public class WeAppStoreController {

    @Autowired
    private ISysStoreService sysStoreService;
    @Autowired
    private ISysOrgService sysOrgService;

    @ApiOperation("获取门店列表")
    @PostMapping(value = "list")
    public R<List<SysStoreVo>> list(@RequestBody WeAppOrgQueryDTO weAppOrgQueryDTO) throws Exception{
        return R.ok(sysStoreService.findStoreByDistance(weAppOrgQueryDTO));
    }

    @ApiOperation("获取门店详情")
    @GetMapping(value = "getInfo")
    public R<SysStore> getInfo(@RequestParam Long storeId) throws Exception{
        return R.ok(sysStoreService.getOne(new QueryWrapper<SysStore>().lambda().eq(SysStore::getId,storeId)));
    }

    @ApiOperation("查询所有门店工厂列表")
    @GetMapping("/allOrg")
    public R<List<SysOrg>> allOrg(@RequestParam @ApiParam("来源类型,01=工厂，02=门店") String sourceType){
        return R.ok(sysOrgService.list(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getSourceType,sourceType)));
    }

//    @ApiOperation("获取门店详情")
//    @PostMapping(value = "getStoreInfo")
//    public R<List<OrgVO>> getStoreInfo(@RequestBody WeAppOrgInfoQueryDTO weAppOrgInfoQueryDTO) throws Exception{
//        return R.ok(sysOrgService.getStoreInfo(weAppOrgInfoQueryDTO));
//    }
}
