package com.ruoyi.web.controller.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.clean.domain.CleanQuery;
import com.ruoyi.ss.clean.domain.CleanVO;
import com.ruoyi.ss.clean.service.ICleanService;
import com.ruoyi.ss.store.domain.StoreQuery;
import com.ruoyi.ss.store.domain.StoreVO;
import com.ruoyi.ss.store.service.IStoreAssembler;
import com.ruoyi.ss.store.service.IStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 保洁记录Controller
 *
 * @author qzz
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/app/clean")
public class AppCleanController extends BaseController
{
    @Autowired
    private ICleanService cleanService;

    @Autowired
    private IStoreService storeService;

    @Autowired
    private IStoreAssembler storeAssembler;

    /**
     * 查询保洁记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CleanQuery query)
    {
        startPage();
        startOrderBy();
        StoreQuery store = new StoreQuery();
        store.setMerchantId(getUserId());
        List<StoreVO> storeList =  storeService.selectEStoreList(store);
        // 拼接归属店铺
        storeAssembler.assembleBelongStore(storeList,getUserId());
        if(!storeList.isEmpty()){
            StoreVO storeVO = storeList.get(0);
            query.setStoreId(storeVO.getStoreId());
        }
        List<CleanVO> list = cleanService.selectECleanList(query);
        return getDataTable(list);
    }


    /**
     * 获取保洁记录详细信息
     */
    @GetMapping(value = "/{cleanId}")
    public AjaxResult getInfo(@PathVariable("cleanId") Long cleanId)
    {
        return success(cleanService.selectECleanByCleanId(cleanId));
    }

    /**
     * 完成保洁
     */
    @Log(title = "完成保洁", businessType = BusinessType.COMPLETECLEANING)
    @GetMapping("/completeCleaning")
    public AjaxResult completeCleaning(Long cleanId)
    {
        if (cleanId == null) {
            return error("cleanId不能为空");
        }
        return success(cleanService.completeCleaning(cleanId));
    }

}
