package com.simuwang.manage.api.company;


import com.simuwang.base.common.page.TableDataInfo;
import com.simuwang.base.common.support.MybatisPage;
import com.simuwang.base.pojo.dto.query.CompanyEmailHistoryPageQuery;
import com.simuwang.base.pojo.dto.query.CompanyEmailPageQuery;
import com.simuwang.base.pojo.vo.*;
import com.simuwang.manage.api.base.BaseController;
import com.simuwang.manage.service.CompanyEmailConfigService;
import com.simuwang.manage.service.CompanyEmailSendHistoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 公司邮箱配置管理
 * Author:   chenjianhua
 * Date:     2024/9/6 15:25
 * Description: ${DESCRIPTION}
 */
@RestController
@RequestMapping("/v1/company")
public class CompanyEmailSendHistoryController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(CompanyEmailSendHistoryController.class);
    @Autowired
    private CompanyEmailSendHistoryService companyEmailSendHistoryService;

    @Autowired
    private CompanyEmailConfigService companyEmailConfigService;

    /**
     * 公司邮箱页面展示查询
     * @param companyEmailPageQuery
     * @return
     */
    @RequestMapping("search-company-email")
    public MybatisPage<CompanyEmailSendHistoryVO> searchCompanyEmail(CompanyEmailPageQuery companyEmailPageQuery){
        MybatisPage<CompanyEmailSendHistoryVO> result = companyEmailSendHistoryService.searchCompanyEmail(companyEmailPageQuery);
        return result;
    }

    /**
     * 根据公司ID查询邮箱发送历史
     * @param  companyEmailHistoryPageQuery
     * @return
     */
    @RequestMapping("search-email-history")
    public MybatisPage<CompanyEmailSendHistoryVO> searchEmailHistory(CompanyEmailHistoryPageQuery companyEmailHistoryPageQuery){
        MybatisPage<CompanyEmailSendHistoryVO> result = companyEmailSendHistoryService.searchEmailHistory(companyEmailHistoryPageQuery);
        return result;
    }


    /**
     * 根据公司ID查询邮箱配置信息
     * @param companyEmailHistoryPageQuery 公司ID
     * @return
     */
    @RequestMapping("search-email-config")
    public MybatisPage<CompanyEmailConfigVO> searchEmailConfig(CompanyEmailHistoryPageQuery companyEmailHistoryPageQuery){
        MybatisPage<CompanyEmailConfigVO> result = companyEmailSendHistoryService.searchEmailConfig(companyEmailHistoryPageQuery);
        return result;
    }

    /**
     * 根据公司ID批量删除邮箱配置
     * @param comyanyEmailIdVO
     * @return
     */
    @PostMapping("delete-company-email")
    public boolean deleteEmail(@RequestBody CompanyIdListVO comyanyEmailIdVO){
        companyEmailSendHistoryService.deleteEmail(comyanyEmailIdVO.getCompanyIdList());
        return true;
    }

    /**
     * 根据ID批量删除邮箱发送历史数据
     * @param comyanyEmailIdVO 已选行的idList
     * @return
     */
    @PostMapping("delete-email-history")
    public boolean deleteEmailHistory(@RequestBody IdListVO comyanyEmailIdVO){
        companyEmailSendHistoryService.deleteEmailHistory(comyanyEmailIdVO.getIdList());
        return true;
    }

    /**
     * 保存邮箱配置
     * @param companyEmailConfigVOList
     * @return
     */
    @PostMapping("save-email-config")
    public boolean saveCompanyEmailConfig(@RequestBody List<CompanyEmailConfigVO> companyEmailConfigVOList){
        companyEmailConfigService.saveCompanyEmailConfig(companyEmailConfigVOList);
        return true;
    }

    /**
     * 修改邮箱配置
     * @param companyEmailConfigVO
     * @return
     */
    @PostMapping("update-email-config")
    public boolean updateCompanyEmailConfig(@RequestBody CompanyEmailConfigVO companyEmailConfigVO){
        companyEmailConfigService.updateCompanyEmailConfig(companyEmailConfigVO);
        return true;
    }

    /**
     * 根据ID删除邮箱配置
     * @param comyanyEmailIdVO --id
     * @return
     */
    @PostMapping("delete-email-config")
    public boolean deleteCompanyEmailConfig(@RequestBody IdVO comyanyEmailIdVO){
        companyEmailConfigService.deleteCompanyEmailConfig(comyanyEmailIdVO.getId());
        return true;
    }


    /**
     * 根据companyIdList发送数据缺失邮件
     * @param comyanyEmailIdVO  已选行的companyIdList
     * @return
     */
    @PostMapping("send-company-email")
    public boolean sendCompanyEmail(@RequestBody CompanyIdListVO comyanyEmailIdVO){
        companyEmailConfigService.sendCompanyEmail(comyanyEmailIdVO.getCompanyIdList());
        return true;
    }
}
