package com.ruoyi.export.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.export.domain.vo.ExportContactVo;
import com.ruoyi.export.domain.bo.ExportContactBo;
import com.ruoyi.export.service.IExportContactService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联系方式
 *
 * @author ruoyi
 * @date 2025-07-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/export/contact")
public class ExportContactController extends BaseController {

    private final IExportContactService iExportContactService;

    /**
     * 查询联系方式列表
     */
    @GetMapping("/list")
    public TableDataInfo<ExportContactVo> list(ExportContactBo bo, PageQuery pageQuery) {
        return iExportContactService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出联系方式列表
     */
    @Log(title = "联系方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ExportContactBo bo, HttpServletResponse response) {
        List<ExportContactVo> list = iExportContactService.queryList(bo);
        ExcelUtil.exportExcel(list, "联系方式", ExportContactVo.class, response);
    }

    /**
     * 获取联系方式详细信息
     *
     * @param contactId 主键
     */
    @GetMapping("/{contactId}")
    public R<ExportContactVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long contactId) {
        return R.ok(iExportContactService.queryById(contactId));
    }

    /**
     * 新增联系方式
     */
    @Log(title = "联系方式", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ExportContactBo bo) {
        return toAjax(iExportContactService.insertByBo(bo));
    }

    /**
     * 修改联系方式
     */
    @Log(title = "联系方式", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ExportContactBo bo) {
        return toAjax(iExportContactService.updateByBo(bo));
    }

    /**
     * 删除联系方式
     *
     * @param contactIds 主键串
     */
    @Log(title = "联系方式", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contactIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] contactIds) {
        return toAjax(iExportContactService.deleteWithValidByIds(Arrays.asList(contactIds), true));
    }
}
