package com.njcn.advance.controller.govern.harmonic;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.advance.pojo.po.govern.harmonic.SgHarmonicFile;
import com.njcn.advance.service.govern.harmonic.ISgHarmonicFileService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.utils.FileStorageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.njcn.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2024-04-17
 */
@Slf4j
@RestController
@RequestMapping("/sgHarmonic")
@Api(tags = "暂降治理评估控制器")
@RequiredArgsConstructor
public class SgHarmonicFileController extends BaseController {

    private final FileStorageUtil fileStorageUtil;
    private final ISgHarmonicFileService harmonicFileService;

    @PostMapping(value = "/importHarmonicData")
    @ApiOperation("上传谐波数据文件")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    public HttpResult<String> importHarmonicData(@RequestParam("file") MultipartFile file, @RequestParam("name") String name) {
        String methodDescribe = getMethodDescribe("importHarmonicData");
        String filePath = fileStorageUtil.uploadMultipart(file, OssPath.GOVERN_HARMONIC_FILE);
        SgHarmonicFile sgHarmonicFile = new SgHarmonicFile();
        sgHarmonicFile.setDataName(name);
        sgHarmonicFile.setDataPath(filePath);
        sgHarmonicFile.setState(DataStateEnum.ENABLE.getCode());
        harmonicFileService.save(sgHarmonicFile);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


    @PostMapping(value = "/listHarmonicData")
    @ApiOperation("获取谐波数据数据")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    public HttpResult<List<SgHarmonicFile>> listHarmonicData() {
        String methodDescribe = getMethodDescribe("listHarmonicData");
        LambdaQueryWrapper<SgHarmonicFile> sgHarmonicFileLambdaQueryWrapper = new LambdaQueryWrapper<>();
        sgHarmonicFileLambdaQueryWrapper.eq(SgHarmonicFile::getState,DataStateEnum.ENABLE.getCode());
        List<SgHarmonicFile> files = harmonicFileService.list(sgHarmonicFileLambdaQueryWrapper);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, files, methodDescribe);
    }

}

