package com.yiqi.admin.controller.app;

import java.util.List;

import com.yiqi.app.domain.dto.AppDeliveryManDTO;
import com.yiqi.app.domain.dto.AppDeliveryManListQueryDTO;
import com.yiqi.app.domain.vo.AppDeliveryManListVO;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.core.page.TableDataInfo;
import com.yiqi.order.domain.vo.OrderClothRecordVO;
import com.yiqi.order.service.IOrderClothService;
import com.yiqi.system.domain.SysStore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.app.domain.AppDeliveryMan;
import com.yiqi.app.service.IAppDeliveryManService;

/**
 * 配送员Controller
 *
 * @author ruoyi
 * @date 2023-11-07
 */
@Api(tags = "管理后台 - 配送员")
@RestController
@RequestMapping(UrlConstants.managerApi + "/app/delivery")
public class AppDeliveryManController extends BaseController {
    @Autowired
    private IAppDeliveryManService appDeliveryManService;

    @Autowired
    private IOrderClothService orderClothService;

    /**
     * 查询配送员列表
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询配送员列表")
    public R<List<AppDeliveryManListVO>> list(AppDeliveryManListQueryDTO appDeliveryManListQueryDTO) {
        return R.ok(appDeliveryManService.selectAppDeliveryManList(appDeliveryManListQueryDTO));
    }

    /**
     * 查询配送员列表
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:list')")
    @GetMapping("/page")
    @ApiOperation(value = "查询配送员列表(分页)")
    public TableDataInfo listPage(AppDeliveryManListQueryDTO appDeliveryManListQueryDTO) {
        startPage();
        List<AppDeliveryManListVO> list = appDeliveryManService.selectAppDeliveryManList(appDeliveryManListQueryDTO);
        return getDataTable(list);
    }

    /**
     * 获取配送员详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取配送员详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appDeliveryManService.selectAppDeliveryManById(id));
    }

    /**
     * 新增配送员
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:add')")
    @Log(title = "配送员", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增配送员")
    public AjaxResult add(@RequestBody AppDeliveryManDTO appDeliveryManDTO) {
        return toAjax(appDeliveryManService.insertAppDeliveryMan(appDeliveryManDTO));
    }

    /**
     * 修改配送员
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:edit')")
    @Log(title = "配送员", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改配送员")
    public AjaxResult edit(@RequestBody AppDeliveryManDTO appDeliveryManDTO) {
        return toAjax(appDeliveryManService.updateAppDeliveryMan(appDeliveryManDTO));
    }

    /**
     * 删除配送员
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:remove')")
    @Log(title = "配送员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除配送员")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appDeliveryManService.deleteAppDeliveryManByIds(ids));
    }

    /**
     * 修改配送员状态
     */
    @PreAuthorize("@ss.hasPermi('app:delivery:edit')")
    @Log(title = "配送员", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改配送员状态")
    public AjaxResult updateAppDeliveryManStatus(@RequestBody AppDeliveryMan appDeliveryMan) {
        return toAjax(appDeliveryManService.updateAppDeliveryManStatus(appDeliveryMan));
    }

    /**
     * 查询配送员接单记录列表
     */
    @GetMapping("/getDeliveryOrderRecordList")
    @ApiOperation(value = "查询配送员接单记录列表")
    public TableDataInfo getDeliveryOrderRecordList(AppDeliveryManListQueryDTO appDeliveryManListQueryDTO) {
        startPage();
        List<OrderClothRecordVO> orderRecordList = orderClothService.getDeliveryOrderRecordList(appDeliveryManListQueryDTO);
        return getDataTable(orderRecordList);
    }

    /**
     * 预约订单列表，查询配送员
     */
    @GetMapping("/getDeliveryManListByOrg")
    @ApiOperation(value = "查询配送员列表")
    public R<List<AppDeliveryManListVO>> getDeliveryManListByOrg() {
        return R.ok(appDeliveryManService.getDeliveryManListByOrg());
    }


    /**
     * 查看配送员列表
     */
    @GetMapping("/store/list")
    @ApiOperation(value = "查询配送员绑定的门店列表")
    public R<List<SysStore>> getStoreList(Long deliveryId) {
        return R.ok(appDeliveryManService.getStoreList(deliveryId));
    }
}
