package com.dsk.web.controller.business;

import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.core.domain.entity.BusinessInfo;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.system.domain.BusinessAddDto;
import com.dsk.system.domain.BusinessListDto;
import com.dsk.system.domain.vo.BusinessListVo;
import com.dsk.system.service.IBusinessInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 项目详情Controller
 *
 * @author lxl
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/business/info")
public class BusinessInfoController extends BaseController
{
    @Autowired
    private IBusinessInfoService businessInfoService;

    /**
     * 项目批量导入
     */
    @PostMapping("/upload")
//    public AjaxResult batchUpload(@RequestPart("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response){
    public AjaxResult batchUpload(@RequestPart("file") MultipartFile file){
         return businessInfoService.batchUpload(file);
    }

    /**
     * 查询所有项目名称(支持模糊查询)
     */
    @PostMapping("/query/project")
    public AjaxResult queryprojectName(@RequestBody BusinessListDto dto){
        return AjaxResult.success(businessInfoService.selectProjectName(dto));
    }

    /**
     * 分页查询项目列表
     */
//    @PreAuthorize("@ss.hasPermi('system:business:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessListDto dto)
    {
        startPage();
        List<BusinessListVo> list = businessInfoService.selectBusinessInfoList(dto);
        return getDataTable(list);
    }

    /**
     * 查询项目速览
     */
//    @PreAuthorize("@ss.hasPermi('system:business:query')")
    @GetMapping("/browse/{businessId}")
    public AjaxResult browse(@PathVariable("businessId") Integer businessId)
    {
        return success(businessInfoService.browse(businessId));
    }

    /**
     * 获取项目建设内容
     */
//    @PreAuthorize("@ss.hasPermi('system:business:query')")
    @GetMapping(value = "/construction/{id}")
    public AjaxResult getConstruction(@PathVariable("id") Integer id)
    {
        return success(businessInfoService.getConstruction(id));
    }

    /**
     * 删除项目列表
     */
//    @PreAuthorize("@ss.hasPermi('system:business:remove')")
//    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable(value = "ids",required=false) Long[] ids)
    {
        return toAjax(businessInfoService.deleteBusinessInfoByIds(ids));
    }

    /**
     * 新增项目详情
     */
//    @PreAuthorize("@ss.hasPermi('system:business:add')")
//    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BusinessAddDto dto)
    {
        return businessInfoService.insertBusinessInfo(dto);
    }

    /**
     * 修改项目详情
     */
//    @PreAuthorize("@ss.hasPermi('system:business:edit')")
//    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BusinessInfo businessInfo)
    {
        return toAjax(businessInfoService.updateBusinessInfo(businessInfo));
    }

//    /**
//     * 获取项目详情详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:info:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Integer id)
//    {
//        return success(businessInfoService.selectBusinessInfoById(id));
//    }

//    /**
//     * 导出项目详情列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:info:export')")
//    @Log(title = "项目详情", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, BusinessInfo businessInfo)
//    {
//        List<BusinessInfo> list = businessInfoService.selectBusinessInfoList(businessInfo);
//        ExcelUtil<BusinessInfo> util = new ExcelUtil<BusinessInfo>(BusinessInfo.class);
//        util.exportExcel(response, list, "项目详情数据");
//    }

}
