package com.dsk.biz.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.dsk.biz.domain.BusinessInfo;
import com.dsk.biz.domain.bo.BusinessAddDto;
import com.dsk.biz.domain.bo.BusinessListDto;
import com.dsk.biz.domain.vo.BusinessBrowseVo;
import com.dsk.biz.domain.vo.BusinessLikeProjectNameListVo;
import com.dsk.biz.domain.vo.BusinessListVo;
import com.dsk.biz.service.IBusinessInfoService;
import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.domain.R;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.enums.BusinessType;
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.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 R<List<BusinessLikeProjectNameListVo>> queryprojectName(@RequestBody BusinessListDto dto,@RequestBody PageQuery pageQuery){
        return R.ok(businessInfoService.selectProjectName(dto,pageQuery));
    }

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

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

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

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

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

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

}
