package com.gree.mall.manager.controller.comlist;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.es.CommonListES;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.comlist.WorkerComListLogic;
import com.gree.mall.manager.plus.entity.WorkerComList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Slf4j
@RestController
@Api(value = "师傅-文件下发", tags ={"师傅-文件下发"} )
@RequestMapping(value = "/worker/comlist", produces = "application/json; charset=utf-8")
public class WorkerComListController {

    @Autowired
    WorkerComListLogic workerComListLogic;

    @GetMapping("/list")
    @ApiOperation(value = "万能通用附件列表")
    public ResponseHelper<IPage<WorkerComList>> list(
            @ApiParam(required = false, value = "师傅编号") @RequestParam(required = false) String workerNumber,
            @ApiParam(required = false, value = "标题") @RequestParam(required = false) String title,
            @ApiParam(required = false, value = "备注") @RequestParam(required = false) String remark,
            @ApiParam(required = false, value = "状态 true=显示 false=隐藏") @RequestParam(required = false) Boolean status,
            @ApiParam(required = true, value = "页号") @RequestParam(required = true) Integer pageNum,
            @ApiParam(required = true, value = "页大小") @RequestParam(required = true) Integer pageSize

    ){
        IPage<WorkerComList> list = workerComListLogic.list(workerNumber,title, status, remark, pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除万能通用附件")
    public ResponseHelper list(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id
    ){
        workerComListLogic.delete(id);
        return ResponseHelper.success();
    }

    @PostMapping("/updateStatus")
    @ApiOperation(value = "修改状态")
    public ResponseHelper list(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id,
            @ApiParam(required = true, value = "true=正常 false=隐藏") @RequestParam(required = true) Boolean status
    ){
        workerComListLogic.updateStatus(id,status);
        return ResponseHelper.success();
    }


    @PostMapping("/save")
    @ApiOperation(value = "上传万能通用列表附件")
    public ResponseHelper save(
            @ApiParam(required = true, value = "标题") @RequestParam(required = true) String title,
            @ApiParam(required = false, value = "备注") @RequestParam(required = false) String remark,
            @ApiParam(required = true, value = "fileUrl") @RequestParam(required = true) String file
    ) throws Exception {
        workerComListLogic.save(title,remark,file);
        return ResponseHelper.success();
    }

    @GetMapping("/record")
    @ApiOperation(value = "通用列表-明细")
    public ResponseHelper<List<CommonListES>> record(
            @ApiParam(required = true, value = "列表id") @RequestParam(required = true) String comListId,
            @ApiParam(required = true, value = "师傅编号") @RequestParam(required = true) String workerNumber
    ) throws Exception {
        List<CommonListES> record = workerComListLogic.record(comListId, workerNumber);
        return ResponseHelper.success(record);
    }

    @GetMapping("/download")
    @ApiOperation(value = "下载万能通用列表附件")
    public void down(
            @ApiParam(required = true, value = "comListId") @RequestParam(required = true) String comListId,
            @ApiParam(required = false, value = "websitNumber") @RequestParam(required = false) String websitNumber,
            HttpServletRequest request, HttpServletResponse response
    ) throws Exception {
        workerComListLogic.download(comListId,websitNumber, request, response);
    }


}
