package com.njcn.prepare.harmonic.controller.line;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.BizParamConstant;
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.common.utils.NjcnDateUtils;
import com.njcn.prepare.harmonic.pojo.param.LineParam;
import com.njcn.prepare.harmonic.service.mysql.line.PollutionService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 监测点污染指标
 *
 * @author xiaoyao
 * @version 1.0.0
 * @createTime 2022/10/18 8:54
 */

@Slf4j
@Api(tags = "监测点污染指标")
@RestController
@RequestMapping("/pollution")
@RequiredArgsConstructor
@Deprecated
public class PollutionController extends BaseController {

    private final PollutionService pollutionService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/processPollutionData")
    @ApiOperation("处理监测点污染指标")
    @ApiImplicitParam(name = "jobParam", value = "参数", required = true)
    public HttpResult<String> processPollutionData(@RequestBody @Validated LineParam jobParam){
        String methodDescribe = getMethodDescribe("processPollutionData");
        if (jobParam.getRepairFlag()&&Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(jobParam.getType())){
            List<String> timeRange = NjcnDateUtils.findEveryDay(jobParam.getBeginTime(),jobParam.getEndTime());
            for (String item : timeRange) {
                log.info(item+"-->开始执行");
                jobParam.setBeginTime(item+" "+"00:00:00");
                jobParam.setEndTime(item+" "+"23:59:59");
                System.out.println(jobParam);
                pollutionService.processPollutionData(jobParam);
            }
        } else {
            pollutionService.processPollutionData(jobParam);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

}
