package com.persagy.adm.server.custom.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.persagy.adm.server.custom.entity.CadFileQueryParam;
import com.persagy.adm.server.custom.entity.db.AdmCad;
import com.persagy.adm.server.custom.service.IAdmCadService;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ADM文件服务
 * @author yanguofeng
 * @since 2022-01-10
 */
@RestController
@RequestMapping("/adm/adm-file")
public class AdmFileController {

    @Autowired
    IAdmCadService iAdmCadService;

    /**
     * CAD文件查询接口
     */

    @PostMapping("/queryCadFiles")
    public CommonResult<List<AdmCad>> queryCadFiles(@RequestBody CadFileQueryParam queryParam){
        Wrapper<AdmCad> eq = new LambdaQueryWrapper<AdmCad>()
                .eq(StringUtils.isNotBlank(queryParam.getProjectId()), AdmCad::getProjectId, queryParam.getProjectId())
                .eq(StringUtils.isNotBlank(queryParam.getBuildingId()),AdmCad::getBuildingId,queryParam.getBuildingId())
                .eq(StringUtils.isNotBlank(queryParam.getFloorId()),AdmCad::getFloorId,queryParam.getFloorId())
                .eq(StringUtils.isNotBlank(queryParam.getFileKey()),AdmCad::getFileKey,queryParam.getFileKey())
                .eq(StringUtils.isNotBlank(queryParam.getMajorCode()),AdmCad::getMajorCode,queryParam.getMajorCode());
        return ResultHelper.multi(iAdmCadService.list(eq));
    }

    /**
     * 保存CAD文件信息
     */
    @PostMapping("/saveCadFileInfo")
    public CommonResult<Void> saveCadFileInfo(@RequestBody List<AdmCad> admFiles){
        iAdmCadService.saveOrUpdateBatch(admFiles);
        return ResultHelper.success();
    }

    /**
     * 删除CAD文件信息
     * @param id 文件信息表主键ID
     */
    @PostMapping("/delete")
    public CommonResult<Void> delete(@RequestParam("id") String id){
        iAdmCadService.removeById(id);
        return ResultHelper.success();
    }
}
