package com.sckw.order.controller;

import com.sckw.core.annotation.Log;
import com.sckw.core.web.response.HttpResult;
import com.sckw.order.model.vo.req.AddWantBuyParam;
import com.sckw.order.model.vo.req.UpdateWantBuyParam;
import com.sckw.order.model.vo.req.WantBuyDels;
import com.sckw.order.model.vo.req.WantBuySelectParam;
import com.sckw.order.serivce.KwpWantBuyService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @desc: 求购controller
 * @author: yzc
 * @date: 2023-07-24 14:44
 */
@RestController
@RequestMapping(value = "/kwoWantBuy")
@RequiredArgsConstructor
public class KwpWantBuyController {

    private final KwpWantBuyService kwpWantBuyService;

    /**
     * @desc: 求购分页查询
     * @author lt
     * @Date 15:34 2023/7/26 0026
    **/
    @PostMapping(value = "/select", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购分页查询")
    public HttpResult select(@RequestBody WantBuySelectParam wantBuySelectParam) {
        return HttpResult.ok(kwpWantBuyService.select(wantBuySelectParam));
    }

    /**
     * @desc: 求购大厅
     * @author lt
     * @Date 15:34 2023/7/26 0026
    **/
    @PostMapping(value = "/buyHallList", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购大厅")
    public HttpResult buyHallList(@RequestBody WantBuySelectParam wantBuySelectParam) {
        return HttpResult.ok(kwpWantBuyService.buyHallList(wantBuySelectParam));
    }

    /**
     * @desc: 新增求购草稿
     * @author: yzc
     * @date: 2023-07-24 16:42
     * @Param addWantBuyParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/addDraft", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "新增求购草稿")
    public HttpResult addDraft(@RequestBody AddWantBuyParam addWantBuyParam) {
        kwpWantBuyService.addDraft(addWantBuyParam);
        return HttpResult.ok("新增求购草稿成功");
    }

    /**
     * @desc: 新增求购上架
     * @author: yzc
     * @date: 2023-07-24 16:43
     * @Param addWantBuyParam:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @PostMapping(value = "/addShelves", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "新增求购上架")
    public HttpResult addShelves(@RequestBody @Validated AddWantBuyParam addWantBuyParam) {
        kwpWantBuyService.addShelves(addWantBuyParam);
        return HttpResult.ok("新增求购上架成功");
    }

    /**
     * @desc: 求购上架
     * @Author: lt
     * @Date: 13:39 2023/7/25 0025
    **/
    @GetMapping(value = "/putOnShelves", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购上架")
    public HttpResult putOnShelves(@RequestParam Long id) {
        kwpWantBuyService.putOnShelves(id);
        return HttpResult.ok("求购上架成功");
    }

    /**
     * @desc: 求购批量下架
     * @Author: lt
     * @Date: 13:39 2023/7/25 0025
    **/
    @PostMapping(value = "/batchTakeOffShelves", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购批量下架")
    public HttpResult batchTakeOffShelves(@RequestBody WantBuyDels ids) {
        kwpWantBuyService.batchTakeOffShelves(ids);
        return HttpResult.ok("批量下架成功");
    }

    /**
     * @desc: 求购批量删除
     * @Author: lt
     * @Date: 13:39 2023/7/25 0025
    **/
    @DeleteMapping(value = "/dels", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购批量删除")
    public HttpResult dels(@RequestBody WantBuyDels ids) {
        kwpWantBuyService.dels(ids);
        return HttpResult.ok("批量删除成功");
    }

    /**
     * @desc: 求购详情
     * @author: yzc
     * @date: 2023-07-24 16:45
     * @Param id:
     * @return: com.sckw.core.web.response.HttpResult
     */
    @GetMapping("/detail")
    @Log(description = "求购详情")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(kwpWantBuyService.detail(id));
    }

    /**
     * @desc: 求购编辑
     * @author lt
     * @Date 15:22 2023/7/26 0026
    **/
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购编辑")
    public HttpResult update(@RequestBody @Validated UpdateWantBuyParam updateWantBuyParam) {
        kwpWantBuyService.update(updateWantBuyParam);
        return HttpResult.ok("求购修改成功!");
    }

    /**
     * @desc 求购角标统计
     * @author lt
     * @Date 15:23 2023/7/26 0026
    **/
    @PostMapping(value = "/statistic", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(description = "求购统计")
    public HttpResult statistic(@RequestBody WantBuySelectParam params)
    {
        return HttpResult.ok(kwpWantBuyService.statistic(params));
    }
}
