package com.cool.store.controller.webc;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.PartnerUserHolder;
import com.cool.store.dto.pre.fry.*;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PreFryRecordsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2025/6/23 19:00
 * @Version 1.0
 */
@Slf4j
@Api(tags = "预炸-预炸记录")
@RestController
@RequestMapping("/mini/pre/record/")
public class PreFryRecordsController {


    @Resource
    PreFryRecordsService preFryRecordsService;

    @ApiOperation("预炸记录-按日期查询是否有预炸记录")
    @GetMapping("/queryByStoreCode")
    public ResponseResult<List<DailyFryCountDTO>> queryByStoreCode(@RequestParam(required = true, value = "storeCode") String storeCode,
                                                                   @RequestParam(required = true, value = "time") Long time) {
        log.info("预炸记录-按日期查询是否有预炸记录：{}", JSONObject.toJSONString(storeCode));
        return ResponseResult.success(preFryRecordsService.queryByStoreCode(storeCode,time));
    }

    @ApiOperation("预炸记录详情列表")
    @GetMapping("/queryById")
    public ResponseResult<PreFryRecordsDetailDTO> queryById(@RequestParam(required = true, value = "id") Long id) {
        log.info("预炸记录详情：{}", JSONObject.toJSONString(id));
        return ResponseResult.success(preFryRecordsService.getById(id));
    }
    @ApiOperation("销售完成")
    @GetMapping("/salesCompleted")
    public ResponseResult<Boolean> salesCompleted(@RequestParam(required = true, value = "id") Long id) {
        log.info("预炸记录详情：{}", JSONObject.toJSONString(id));
        return ResponseResult.success(preFryRecordsService.salesCompleted(id, PartnerUserHolder.getUser()));
    }

    @ApiOperation("预炸批量新增")
    @PostMapping("/batchAdd")
    public ResponseResult<Boolean> batchInsert(@RequestBody @Validated AddPreFryRecordsDTO dto) {
        log.info("批量新增：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryRecordsService.batchInsert(dto, PartnerUserHolder.getUser()));
    }

    @ApiOperation("预炸列表 根据门店编码与日期查询")
    @PostMapping("/ListByStoreCodeAndDate")
    public ResponseResult<PageInfo<PreFryRecordsDetailDTO>> ListByStoreCodeAndDate(@RequestBody @Validated FryRecordsQueryDTO dto) {
        log.info("预炸列表 根据门店编码与日期查询：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFryRecordsService.ListByStoreCodeAndDate(dto));
    }

}
