package com.shzg.project.worn.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shzg.project.worn.domain.dto.FileUrlDTO;
import com.shzg.project.worn.service.impl.WornTechnicalAppraisalFileServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shzg.framework.aspectj.lang.annotation.Log;
import com.shzg.framework.aspectj.lang.enums.BusinessType;
import com.shzg.project.worn.domain.WornTechnicalAppraisalFile;
import com.shzg.project.worn.service.IWornTechnicalAppraisalFileService;
import com.shzg.framework.web.controller.BaseController;
import com.shzg.framework.web.domain.AjaxResult;
import com.shzg.common.utils.poi.ExcelUtil;
import com.shzg.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 技术鉴定附件Controller
 * 
 * @author shzg
 * @date 2026-04-10
 */
@RestController
@RequestMapping("/worn/technicalFile")
public class WornTechnicalAppraisalFileController extends BaseController
{
    @Autowired
    private IWornTechnicalAppraisalFileService wornTechnicalAppraisalFileService;
    private static final Logger log = LoggerFactory.getLogger(WornTechnicalAppraisalFileServiceImpl.class);

    /**
     * 查询技术鉴定附件列表
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(WornTechnicalAppraisalFile wornTechnicalAppraisalFile)
    {
        startPage();
        List<WornTechnicalAppraisalFile> list = wornTechnicalAppraisalFileService.selectWornTechnicalAppraisalFileList(wornTechnicalAppraisalFile);
        return getDataTable(list);
    }

    /**
     * 导出技术鉴定附件列表
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:export')")
    @Log(title = "技术鉴定附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WornTechnicalAppraisalFile wornTechnicalAppraisalFile)
    {
        List<WornTechnicalAppraisalFile> list = wornTechnicalAppraisalFileService.selectWornTechnicalAppraisalFileList(wornTechnicalAppraisalFile);
        ExcelUtil<WornTechnicalAppraisalFile> util = new ExcelUtil<WornTechnicalAppraisalFile>(WornTechnicalAppraisalFile.class);
        util.exportExcel(response, list, "技术鉴定附件数据");
    }

    /**
     * 获取技术鉴定附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wornTechnicalAppraisalFileService.selectWornTechnicalAppraisalFileById(id));
    }

    /**
     * 新增技术鉴定附件
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:add')")
    @Log(title = "技术鉴定附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WornTechnicalAppraisalFile wornTechnicalAppraisalFile)
    {
        return toAjax(wornTechnicalAppraisalFileService.insertWornTechnicalAppraisalFile(wornTechnicalAppraisalFile));
    }

    /**
     * 修改技术鉴定附件
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:edit')")
    @Log(title = "技术鉴定附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WornTechnicalAppraisalFile wornTechnicalAppraisalFile)
    {
        return toAjax(wornTechnicalAppraisalFileService.updateWornTechnicalAppraisalFile(wornTechnicalAppraisalFile));
    }

    /**
     * 删除技术鉴定附件
     */
    @PreAuthorize("@ss.hasPermi('worn:technicalFile:remove')")
    @Log(title = "技术鉴定附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wornTechnicalAppraisalFileService.deleteWornTechnicalAppraisalFileByIds(ids));
    }
    /**
     * 多张图片上传
     * 前端参数：
     * file: 多个同名文件字段
     * scene: 场景
     * bizType: 业务类型
     */
    @Log(title = "技术鉴定附件上传", businessType = BusinessType.OTHER)
    @PostMapping(value = "/upload", consumes = "multipart/form-data")
    public AjaxResult uploadBatch(@RequestParam("file") MultipartFile[] files,
                                  @RequestParam("scene") String scene,
                                  @RequestParam("bizType") String bizType,
                                  HttpServletRequest request)
    {
        try
        {
            List<FileUrlDTO> list = wornTechnicalAppraisalFileService.uploadBatch(files, scene, bizType, request);

            Map<String, Object> result = new HashMap<>();
            result.put("fileUrlList", list);

            return AjaxResult.success(result);
        }
        catch (Exception e)
        {
            logger.error("技术鉴定附件批量上传失败", e);
            return AjaxResult.error("上传失败：" + e.getMessage());
        }
    }
}
