package com.ruoyi.web.modules.industryservice.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.modules.industryservice.domain.BizYakAsset;
import com.ruoyi.web.modules.industryservice.service.IBizYakAssetService;

/**
 * 牦牛资产档案
 */
@RestController
@RequestMapping("/dataModel/yakAsset")
public class BizYakAssetController extends BaseController
{
    @Autowired
    private IBizYakAssetService bizYakAssetService;

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizYakAsset query)
    {
        startPage();
        List<BizYakAsset> list = bizYakAssetService.selectBizYakAssetList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:query')")
    @GetMapping("/byNo/{yakNo}")
    public AjaxResult getByYakNo(@PathVariable("yakNo") String yakNo)
    {
        return success(bizYakAssetService.selectDetailByYakNo(yakNo));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:query')")
    @GetMapping("/{id}/physioChart")
    public AjaxResult physioChart(@PathVariable("id") Long id, @RequestParam(value = "days", required = false) Integer days)
    {
        return success(bizYakAssetService.selectPhysioChart(id, days));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:query')")
    @GetMapping("/{id}/growthChart")
    public AjaxResult growthChart(@PathVariable("id") Long id,
            @RequestParam(value = "metric", required = false) String metric)
    {
        return success(bizYakAssetService.selectGrowthChart(id, metric));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizYakAssetService.selectDetailById(id));
    }

    @PreAuthorize("@ss.hasPermi('dataModel:yakAsset:sync')")
    @Log(title = "牦牛资产档案", businessType = BusinessType.OTHER)
    @PostMapping("/sync")
    public AjaxResult sync()
    {
        return success(bizYakAssetService.syncFromThirdParty());
    }
}
