package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.dto.AppendixCalDto;
import com.huatek.busi.dto.ArresterCalDto;
import com.huatek.busi.entity.AppendixAssessmentResult;
import com.huatek.busi.entity.ArresterAssessmentResult;
import com.huatek.busi.entity.TransformerLoadRate;
import com.huatek.busi.service.*;
import com.huatek.busi.vo.AppendixAssessmentResultVo;
import com.huatek.busi.vo.ArresterAssessmentResultVo;
import com.huatek.busi.vo.BusiOfflineTransformerBrandVo;
import com.huatek.busi.vo.BusiTreeNodeVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Api(tags = {"附件评估"})
@RestController
@RequestMapping("/api/AppendixAssess")
public class AppendixAssessController {

    @Reference(check = false)
    private AppendixAssessService appendixAssessService;

    @Reference(check = false)
    private BusiSiteTreeService busiSiteTreeService;

    @Reference(check = false)
    private AppendixAssessmentResultService appendixAssessmentResultService;



    /**
     * 手动计算
     * @param
     * @return
     */
    @PostMapping(value = "/getAppendixAssessmentResult")
    public Map<String, Object>  getAppendixAssessmentResult(@RequestBody AppendixCalDto appendixCalDto) {

        AppendixAssessmentResult appendixAssessmentResult =  appendixAssessService.assessmentForAppendixHandMovement(appendixCalDto,"1");
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", appendixAssessmentResult);
    }

    /**
     * 查询附件评估
     * @param
     * @return
     */
   @ApiOperation(value ="查询附件评估", response = ArresterAssessmentResultVo.class)
   @GetMapping(value="/queryAppendixAssessmentResultVo", produces = {"application/json;charset=utf-8"})
   public Map<String, Object> queryArresterAssessmentResultVo(@RequestParam ("siteId") String siteId,
                                                         @RequestParam ("mainTreeId") String mainTreeId,
                                                         @RequestParam(value = "page", required = false) Integer page,
                                                         @RequestParam(value = "limit", required = false) Integer limit,
                                                         @RequestParam(value = "startTime", required = false) String startTime,
                                                         @RequestParam(value = "endTime", required = false) String endTime,
                                                         @RequestParam(value = "type", required = false) String type) {
       DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
       LocalDate start = null;
       LocalDate end = null;


       if (StringUtils.isNotBlank(startTime)) {
           start = LocalDate.parse(startTime, df);
       }

       if (StringUtils.isNotBlank(endTime)) {
           end = LocalDate.parse(endTime, df).plusDays(1);
       }
	   PageInfo<AppendixAssessmentResultVo> appendixAssessmentResultVo = appendixAssessmentResultService.findAppendixAssessmentByMainTreeId(siteId, mainTreeId, page, limit, start, end, type);
       return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, appendixAssessmentResultVo.getTotal(), "", appendixAssessmentResultVo.getList());
   }



    /**
     * 结果追溯
     * @param
     * @return
     */
    @ApiOperation(value ="结果追溯")
    @GetMapping(value="/findCalculateStep", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findCalculateStep(@RequestParam ("pid") String pid){
        return appendixAssessmentResultService.findCalculateStep(pid);
    }

}
