package com.dayou.controller;

import com.dayou.annotation.OperLog;
import com.dayou.vo.ItemLogCollectVO;
import com.dayou.vo.ItemUserLogVO;
import com.dayou.vo.LogEcharsVO;
import com.dayou.vo.LogStatVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IItemUserLogService;
import com.dayou.entity.ItemUserLog;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 项目用户日志
 *
 * @author wucl
 * @since 2022-12-08
 */
@RestController
@RequestMapping("itemUserLog")
@Slf4j
public class ItemUserLogController extends BaseController {
    @Autowired
    private IItemUserLogService itemUserLogService;

    /**
    * 项目用户日志列表
    */
    @GetMapping("")
    public RestResponse<Page<ItemUserLogVO>> page(ItemUserLogVO itemUserLogVO, Page page){
        Page<ItemUserLogVO> pages=itemUserLogService.selectPage(page,itemUserLogVO);
        return RestResponse.data(pages);
    }

    /**
     * 项目用户日志详情
     */
    @GetMapping("/{id}")
    public RestResponse<ItemUserLogVO> detail(@PathVariable Long id){
        ItemUserLogVO xItemUserLog =itemUserLogService.detail(id);
        return RestResponse.data(xItemUserLog);
     }

    /**
     * 项目用户日志新增
     */
    @OperLog(title = "新增项目用户日志")
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ItemUserLog itemUserLog) {
        Boolean ret = itemUserLogService.add(itemUserLog);
        return RestResponse.data(ret);
    }

    /**
     * 项目用户日志更新
     */
    @OperLog(title = "更新项目用户日志")
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ItemUserLog itemUserLog) {
        Boolean ret = itemUserLogService.update(itemUserLog);
        return RestResponse.data(ret);
    }

    /**
     * 项目用户日志删除
     */
    @OperLog(title = "删除项目用户日志")
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = itemUserLogService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 日志汇总列表
     * @param departmentId 部门id
     * @param scope 范围
     * @return
     */
    @GetMapping("/collect")
    public RestResponse<List<ItemLogCollectVO>> logCollect(Long departmentId, Boolean scope, Long itemId, LocalDate startDate,LocalDate endDate){
        List<ItemLogCollectVO> result = itemUserLogService.logCollect(departmentId,scope,itemId,startDate,endDate);
        return RestResponse.data(result);
    }

    /**
     * 获取日志echars数据
     * @return
     */
    @GetMapping("/logEchars")
    public RestResponse<LogEcharsVO> getLogEchars(){
        LogEcharsVO logEcharsVO  = itemUserLogService.getLogEchars();
        return RestResponse.data(logEcharsVO);
    }

    /**
     * 获取日志首页统计数据
     * @return
     */
    @GetMapping("/stat")
    public RestResponse<LogStatVO> logStat(){
        LogStatVO logStatVO = itemUserLogService.logStat();
        return RestResponse.data(logStatVO);
    }
}

