package com.ruoyi.project.business.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.annotation.DataUpdateCheck;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.domain.TpElevatorModel;
import com.ruoyi.project.business.domain.vo.paramSelectItem.TpElevatorModelVo;
import com.ruoyi.project.business.domain.vo.quotation.EleconfigVO;
import com.ruoyi.project.business.dto.TpElevatorModelDto;
import com.ruoyi.project.business.service.ITpElevatorModelService;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/business/elevator")
public class TpElevatorModelController extends BaseController {

    @Resource
    private ITpElevatorModelService tpElevatorModelService;

    /**
     * 查询【请填写功能名称】列表
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:list')")
    @GetMapping("/list")
    public TableDataInfo list(TpElevatorModel tpElevatorModel) {
        startPage();
        List<TpElevatorModel> list = tpElevatorModelService.selectTpElevatorModelList(tpElevatorModel);
        return getDataTable(list);
    }

    @GetMapping("/listNew")
    public TableDataInfo listNew(TpElevatorModelVo tpElevatorModel) {
        startPage();
        List<TpElevatorModel> list = tpElevatorModelService.selectTpElevatorModelListNew(tpElevatorModel);
        return getDataTable(list);
    }

    @GetMapping("/listNewAll")
    public TableDataInfo listNewAll(TpElevatorModelVo tpElevatorModel) {
        List<TpElevatorModel> list = tpElevatorModelService.listNewAll(tpElevatorModel);
        return getDataTable(list);
    }

    @GetMapping("/listNewAllParam/{id}")
    public AjaxResult listNewAllParam(@PathVariable("id") Long id,
        @RequestParam("quotationFlag") boolean quotationFlag) {
        EleconfigVO eleconfigVO = tpElevatorModelService.selectTpElevatorModelParamOption(id, quotationFlag);
        return success(eleconfigVO);
    }

    @GetMapping("/listElevatorParam/{id}")
    public AjaxResult listElevatorParam(@PathVariable("id") Long id,
        @RequestParam("quotationFlag") boolean quotationFlag) {
        EleconfigVO eleconfigVO = tpElevatorModelService.listElevatorParam(id, quotationFlag);
        return success(eleconfigVO);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TpElevatorModel tpElevatorModel) {
        List<TpElevatorModel> list = tpElevatorModelService.selectTpElevatorModelList(tpElevatorModel);
        ExcelUtil<TpElevatorModel> util = new ExcelUtil<TpElevatorModel>(TpElevatorModel.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tpElevatorModelService.selectTpElevatorModelById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TpElevatorModel tpElevatorModel) {
        return toAjax(tpElevatorModelService.insertTpElevatorModel(tpElevatorModel));
    }

    /**
     * 修改【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    @DataUpdateCheck(key = "id", tableName = "tp_elevator_model")
    public AjaxResult edit(@RequestBody TpElevatorModel tpElevatorModel) {
        return toAjax(tpElevatorModelService.updateTpElevatorModel(tpElevatorModel));
    }

    /**
     * 删除【请填写功能名称】
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tpElevatorModelService.deleteTpElevatorModelByIds(ids));
    }

    /**
     * 删除参数
     */
    @Log(title = "参数", businessType = BusinessType.DELETE)
    @DataUpdateCheck(key = "id", tableName ="tp_elevator_model")
    @PostMapping("/delete")
    public AjaxResult removecheck(@RequestBody List<TpElevatorModel> tpElevatorModels) {
        if(ObjectUtils.isEmpty(tpElevatorModels)){
            return AjaxResult.error("未填入删除数据！");
        }
        List<Long> idList = tpElevatorModels.stream().map(TpElevatorModel::getId).collect(Collectors.toList());
        Long[] ids = idList.toArray(new Long[idList.size()]);
        return toAjax(tpElevatorModelService.deleteTpElevatorModelByIds(ids));
    }


    /**
     * 状态修改
     */
    @Log(title = "参数", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    //验证时间判断是否修改
    @DataUpdateCheck(key = "id", tableName = "tp_elevator_model")
    public AjaxResult changeStatus(@RequestBody TpElevatorModel tpElevatorModel) {
        return toAjax(tpElevatorModelService.updateParaStatus(tpElevatorModel));
    }

    /**
     * 获取电梯参数配置信息
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:paramInfo')")
    @GetMapping(value = "/paramInfo/{id}")
    public AjaxResult getParamInfo(@PathVariable("id") Long id) {
        return success(tpElevatorModelService.selectTpElevatorModelParamById(id));
    }

    /**
     * 获取电梯参数选项配置信息
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:getParamItemInfo')")
    @GetMapping(value = "/itemInfo/{id}")
    public AjaxResult getParamItemInfo(@PathVariable("id") Long id) {
        return success(tpElevatorModelService.selectTpElevatorModelParamSelectItemById(id));
    }

    /**
     * 获取电梯参数选项配置信息
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:getParamStandInfo')")
    @GetMapping(value = "/itemStandInfo/{id}")
    public AjaxResult getParamItemStandInfo(@PathVariable("id") Long id) {
        return success(tpElevatorModelService.selectTpElevatorModelParamStantById(id));
    }


    /**
     * description: listForComponents 服务于共同组件的查询
     *
     * @param tpElevatorModel: 前端查询参数
     * @return java.util.List<com.ruoyi.project.business.dto.TpElevatorModelDto>
     * @author jubs 😀
     * @date 2024/4/29 14:06
     */
    @GetMapping("/listForComponents")
    public TableDataInfo listForComponents(TpElevatorModelDto tpElevatorModel) {
        startPage();
        List<TpElevatorModelDto> list = tpElevatorModelService.listForComponents(tpElevatorModel);
        return getDataTable(list);
    }

    /**
     * 获取电梯参数选项配置信息
     */
    // @PreAuthorize("@ss.hasPermi('business:elevator:modelJGBInfo')")
    @GetMapping(value = "/modelJGBInfo/{id}")
    public AjaxResult modelJGBInfo(@PathVariable("id") Long id) {
        return success(tpElevatorModelService.selectTpElevatorModelJGBById(id));
    }


}
