package com.dayou.controller;

import com.dayou.annotation.DataPermission;
import com.dayou.annotation.OperLog;
import com.dayou.dto.DataPermissionCondition;
import com.dayou.vo.ItemLogCollectVO;
import com.dayou.vo.MarketLogVO;
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 org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IMarketLogService;
import com.dayou.entity.MarketLog;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;


import static com.dayou.common.Constants.MANAGER_OFFICE;

/**
 * 市场人员日志
 *
 * @author wucl
 * @since 2023-01-13
 */
@RestController
@RequestMapping("marketLog")
@Slf4j
public class MarketLogController extends BaseController {
    @Autowired
    private IMarketLogService marketLogService;

    /**
    * 市场人员日志列表
    */
    @GetMapping("")
    public RestResponse<Page<MarketLogVO>> page(MarketLog marketLog, Page page){
        Page<MarketLogVO> pages=marketLogService.selectPage(page,marketLog);
        return RestResponse.data(pages);
    }

    /**
     * 市场人员日志详情
     */
    @GetMapping("/{id}")
    public RestResponse<MarketLog> detail(@PathVariable Long id){
        MarketLog xMarketLog =marketLogService.detail(id);
        return RestResponse.data(xMarketLog);
     }

    /**
     * 市场人员日志新增
     */
    @OperLog(title = "新增市场人员日志")
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody MarketLog marketLog) {
        Boolean ret = marketLogService.add(marketLog);
        return RestResponse.data(ret);
    }

    /**
     * 市场人员日志更新
     */
    @OperLog(title = "更新市场人员日志")
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody MarketLog marketLog) {
        Boolean ret = marketLogService.update(marketLog);
        return RestResponse.data(ret);
    }

    /**
     * 市场人员日志删除
     */
    @OperLog(title = "删除市场人员日志")
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = marketLogService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 日志汇总列表
     * @return
     */
    @DataPermission(teamData = true,postChild = false,ignoreDepartment = {MANAGER_OFFICE})
    @GetMapping("/collect")
    public RestResponse<List<ItemLogCollectVO>> logCollect(DataPermissionCondition condition){
        List<ItemLogCollectVO> result = marketLogService.logCollect(condition);
        return RestResponse.data(result);
    }

}

