package com.zksy.controller.info;

import cn.hutool.core.date.DateTime;
import com.zksy.info.domain.EAdminLicenseInfo;
import com.zksy.info.domain.EContactManagement;
import com.zksy.info.service.EAdminLicenseInfoService;
import com.zksy.info.service.EContactManagementService;
import com.zksy.utils.AjaxResult;
import com.zksy.utils.ExcelExportUtil;
import com.zksy.utils.ExcelImportUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author Administrator
 * @version 1.0
 * @project enterprise-assets-service
 * @description 联系人管理控制层
 * @date 2025/6/24 14:33:13
 */
@RestController
@RequestMapping("/econtactManagement")
@Api(tags = "联系人管理信息",description = "联系人管理信息desc")
public class EContactManagementController {
    @Autowired
    private EContactManagementService service;
    @GetMapping("/findByPage")
    @ApiOperation(value = "联系人管理信息查询分页")
    public AjaxResult findByPage(long pageNum, long pageSize, String contactName,String contactDepartment,String contactMobile){
        return AjaxResult.success(service.findByPage(pageNum, pageSize, contactName,contactDepartment,contactMobile));
    }
    @GetMapping("/getEAdminLicenseInfoList")
    @ApiOperation(value = "联系人管理信息查询")
    public AjaxResult getEAdminLicenseInfoList(String contactName,String contactDepartment,String contactMobile){
        return AjaxResult.success(service.getEContactManagementList(contactName,contactDepartment,contactMobile));
    }
    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据Id查询联系人管理信息")
    public AjaxResult getById(@PathVariable String id){
        return AjaxResult.success(service.getById(id));
    }
    @PostMapping("/save")
    @ApiOperation(value = "联系人管理信息保存")
    public AjaxResult save(@RequestBody EContactManagement econtactManagement) {
        return service.save(econtactManagement) ? AjaxResult.success(econtactManagement) : AjaxResult.error("保存失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "联系人管理信息修改")
    public AjaxResult update(@RequestBody EContactManagement econtactManagement) {
        econtactManagement.setUpdateTime(LocalDateTime.now());
        return service.updateById(econtactManagement) ? AjaxResult.success(econtactManagement) : AjaxResult.error("更新失败");
    }
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "联系人管理信息删除")
    public AjaxResult delete(@RequestBody String[] ids) {
        return service.removeBatchByIds(Arrays.asList(ids)) ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
    }
    @PostMapping("/importData")
    @ApiOperation(value = "导入数据")
    public AjaxResult importData(MultipartFile file) {
        return AjaxResult.success(service.saveOrUpdateBatch(ExcelImportUtil.importExcel(file, EContactManagement.class)));
    }
    @GetMapping("/exportData")
    @ApiOperation(value = "导出数据")
    public void exportData(HttpServletResponse response,String contactName,String contactDepartment,String contactMobile) {
        ExcelExportUtil.exportExcel(response,service.getEContactManagementList(contactName,contactDepartment,contactMobile), EContactManagement.class, "联系人管理信息","联系人管理信息");
    }

}
