package com.ruoyi.web.controller.invest;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.enums.FileType;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.invest.domain.TProjectCompany;
import com.ruoyi.invest.service.ITProjectCompanyService;
import com.ruoyi.tool.domain.TUnifyFile;
import com.ruoyi.tool.service.ITUnifyFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 项目公司信息Controller
 * 
 * @author ruoyi
 * @date 2024-02-22
 */
@Api(tags = "项目公司信息")
@RestController
@RequestMapping("/invest/company")
public class TProjectCompanyController extends BaseController
{
    @Autowired
    private ITProjectCompanyService tProjectCompanyService;

    @Autowired
    private ITUnifyFileService tUnifyFileService;

    @Autowired
    private ServerConfig serverConfig;

    /**
     * 查询项目公司信息列表
     */
    @ApiOperation("查询项目公司信息列表")
    @PreAuthorize("@ss.hasPermi('invest:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(TProjectCompany tProjectCompany)
    {
        startPage();
        List<TProjectCompany> list = tProjectCompanyService.selectTProjectCompanyList(tProjectCompany);
        return getDataTable(list);
    }

    /**
     * 导出项目公司信息列表
     */
    @ApiOperation("导出项目公司信息列表")
    @PreAuthorize("@ss.hasPermi('invest:company:export')")
    @Log(title = "项目公司信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProjectCompany tProjectCompany)
    {
        List<TProjectCompany> list = tProjectCompanyService.selectTProjectCompanyList(tProjectCompany);
        ExcelUtil<TProjectCompany> util = new ExcelUtil<TProjectCompany>(TProjectCompany.class);
        util.exportExcel(response, list, "项目公司信息数据");
    }

    /**
     * 获取项目公司信息详细信息
     */
    @ApiOperation("获取项目公司信息详细信息")
    @PreAuthorize("@ss.hasPermi('invest:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tProjectCompanyService.selectTProjectCompanyById(id));
    }

    /**
     * 新增项目公司信息
     */
    @ApiOperation("新增项目公司信息")
    @PreAuthorize("@ss.hasPermi('invest:company:add')")
    @Log(title = "项目公司信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProjectCompany tProjectCompany)
    {
        tProjectCompany.setId(IdUtils.fastSimpleUUID());
        tProjectCompany.setCreateBy(getNickName());
        // todo 保存附件信息
        tUnifyFileService.insertTUnifyFileList(tProjectCompany.getListFile(),
                tProjectCompany.getProjectPoolId(),
                tProjectCompany.getId(),//公司ID
                String.valueOf(FileType.COMPANY.ordinal()),//文件类型:公司信息
                getNickName());

        return toAjax(tProjectCompanyService.insertTProjectCompany(tProjectCompany));
    }

    /**
     * 修改项目公司信息
     */
    @ApiOperation("修改项目公司信息")
    @PreAuthorize("@ss.hasPermi('invest:company:edit')")
    @Log(title = "项目公司信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProjectCompany tProjectCompany)
    {
        // todo 保存附件信息
        tUnifyFileService.insertTUnifyFileList(tProjectCompany.getListFile(),
                tProjectCompany.getProjectPoolId(),
                tProjectCompany.getId(),//公司ID
                String.valueOf(FileType.COMPANY.ordinal()),//文件类型:公司信息
                getNickName());
        return toAjax(tProjectCompanyService.updateTProjectCompany(tProjectCompany));
    }

    /**
     * 删除项目公司信息
     */
    @ApiOperation("删除项目公司信息")
    @PreAuthorize("@ss.hasPermi('invest:company:remove')")
    @Log(title = "项目公司信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tProjectCompanyService.updateTProjectCompanyByIds(ids));
    }
}
