/**
 * @Author: Kane Wang <wangkane@qq.com>
 * @Date: 2025-12-26 17:16:22
 * @LastEditors: Kane Wang
 * @LastModified: 2025-12-26 17:16:22
 * @FilePath: src/main/java/com/cpic/xim/web/controllers/regulatory/AddNewRegulatoryController.java
 * @Description: 新增制度的控制器
 *
 *               Copyright (c) 2025 by Kane All rights reserved
 */
package com.cpic.xim.web.controllers.regulatory;

import java.io.File;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cpic.xim.utils.files.UploadedFile;

@Controller
@RequestMapping( "/regulatory" )
public class AddNewRegulatoryController
{
    // 制度库文件的基础目录
    private static final String baseDirectory = "D:/制度库/";
    
    @RequestMapping( path = "/add-new-regulatory.do", method = RequestMethod.POST )
    @ResponseBody
    public static AddNewRegulatoryResponse addNewRegulatory( @RequestBody AddNewRegulatoryRequest request )
    {
        AddNewRegulatoryResponse response = new AddNewRegulatoryResponse();
        
        // 验证文件是否存在，并判断目睹路径是否有同名文件存在
        for ( UploadedFile file : request.getRegulatoryFiles() )
        {
            String destFilePath = baseDirectory + "/" + request.getRegulatoryName() + "/" + file.getFileName();
            File   uploadFile   = new File( file.getAbsoluteFilePath() );
            File   dest         = new File( destFilePath );
            
            if ( uploadFile.exists() == false )
            {
                response.setSuccess( false );
                response.setMessage( "文件" + file.getAbsoluteFilePath() + "不存在！" );
                
                return response;
            }
            
            // 判断目的路径是否有同名文件
            if ( dest.exists() == true )
            {
                response.setSuccess( false );
                response.setMessage( "文件" + file.getAbsoluteFilePath() + "存在同名文件！" );
                
                return response;
            }
        }
        
        // 复制文件
        for ( UploadedFile file : request.getRegulatoryFiles() )
        {
            File uploadFile = new File( file.getAbsoluteFilePath() );
            
        }
        
        return response;
    }
}
