package com.ruoyi.project.aspen.controller;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import com.ruoyi.project.production.domain.TDailyProductionReport;
import com.ruoyi.project.production.mapper.TDailyProductionReportMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.aspen.domain.TDashboarddata;
import com.ruoyi.project.aspen.service.ITDashboarddataService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * dashboard抓取数据Controller
 *
 * @author ruoyi
 * @date 2022-01-06
 */
@RestController
@RequestMapping("/aspen/dashboarddata")
public class TDashboarddataController extends BaseController
{
    @Autowired
    private ITDashboarddataService tDashboarddataService;
    @Resource
    private TDailyProductionReportMapper tDailyProductionReportMapper;
    /**
     * 查询dashboard抓取数据列表
     */
    @GetMapping("/list")
    public List<TDashboarddata> list(TDashboarddata tDashboarddata)
    {
        List<TDashboarddata> list = tDashboarddataService.selectTDashboarddataList(tDashboarddata);
        return list;
    }

    /**
     * 查询最后一条dashboard抓取数据
     */
    @GetMapping("/selectLast")
    public AjaxResult selectLast(TDashboarddata tDashboarddata)
    {
        TDailyProductionReport report = tDailyProductionReportMapper.selectTDailyProductionReportByMaxDate();
        TDashboarddata dashboarddata = tDashboarddataService.selectLast(tDashboarddata);
        //石脑油储罐
        dashboarddata.setNapOne(new BigDecimal(report.getSctfStorageCltf1621()).divide(new BigDecimal("33000"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setNapTwo(new BigDecimal(report.getSctfStorageCltf1622()).divide(new BigDecimal("33000"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setNapThree(new BigDecimal(report.getSctfStorageCltf1623()).divide(new BigDecimal("33000"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        //乙烯储罐
        dashboarddata.setEhtOne(new BigDecimal(report.getSctfStorageTk1061()).divide(new BigDecimal("517"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setEhtTwo(new BigDecimal(report.getSctfStorageTk1062()).divide(new BigDecimal("517"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setEhtThree(new BigDecimal(report.getSctfStorageTk1063()).divide(new BigDecimal("517"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setEhtFour(new BigDecimal(report.getSctfStorageTk1064()).divide(new BigDecimal("517"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setEhtFive(new BigDecimal(report.getSctfStorageTk1065Off()).divide(new BigDecimal("517"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        //芳烃储罐
        dashboarddata.setProOne(new BigDecimal(report.getSctfStorageTk1510B()).divide(new BigDecimal("3900"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setProTwo(new BigDecimal(report.getSctfStorageTk1520Rpg()).divide(new BigDecimal("13500"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setProThree(new BigDecimal(report.getSctfStorageTk1360T()).divide(new BigDecimal("3800"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        dashboarddata.setProFour(new BigDecimal(report.getSctfStorageTk1410X()).divide(new BigDecimal("1560"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString());
        //丙烯储罐
        dashboarddata.setAcrOne(new BigDecimal(report.getSctfStorageTk1011()).divide(new BigDecimal("1200"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString().toString());
        dashboarddata.setAcrTwo(new BigDecimal(report.getSctfStorageTk1012()).divide(new BigDecimal("1200"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString().toString());
        dashboarddata.setAcrThree(new BigDecimal(report.getSctfStorageTk1013()).divide(new BigDecimal("1200"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString().toString());
        dashboarddata.setAcrFour(new BigDecimal(report.getSctfStorageTk1014()).divide(new BigDecimal("1200"), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(1, RoundingMode.HALF_UP).toString().toString());

        return AjaxResult.success(dashboarddata);
    }

    /**
     * 导出dashboard抓取数据列表
     */
    @Log(title = "dashboard抓取数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDashboarddata tDashboarddata)
    {
        List<TDashboarddata> list = tDashboarddataService.selectTDashboarddataList(tDashboarddata);
        ExcelUtil<TDashboarddata> util = new ExcelUtil<TDashboarddata>(TDashboarddata.class);
        return util.exportExcel(list, "dashboarddata");
    }

    /**
     * 获取dashboard抓取数据详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDashboarddataService.selectTDashboarddataById(id));
    }

    /**
     * 新增dashboard抓取数据
     */
    @Log(title = "dashboard抓取数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDashboarddata tDashboarddata)
    {
        return toAjax(tDashboarddataService.insertTDashboarddata(tDashboarddata));
    }

    /**
     * 修改dashboard抓取数据
     */
    @Log(title = "dashboard抓取数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDashboarddata tDashboarddata)
    {
        return toAjax(tDashboarddataService.updateTDashboarddata(tDashboarddata));
    }

    /**
     * 删除dashboard抓取数据
     */
    @Log(title = "dashboard抓取数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDashboarddataService.deleteTDashboarddataByIds(ids));
    }
}
