package com.zd.app.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zd.common.core.domain.R;
import com.zd.common.security.service.TokenService;
import com.zd.system.api.domain.AppSubQuery;
import com.zd.system.api.domain.SubQueryConfig;
import com.zd.system.api.domain.SysDept;
import com.zd.system.api.laboratory.RemoteSubQueryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 实验室相关Controller
 *
 * @author cyl
 * @date 2021/9/15
 */
@RestController
@RequestMapping("/laboratory")
@Api(tags = {"实验室相关"})
public class LaboratoryApi {

    @Autowired
    RemoteSubQueryService remoteSubQueryService;

    @Autowired
    private TokenService tokenService;


    /**
     * 预警 ：实验室详情
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("实验室详情")
    public R querySub(@PathVariable("id") Long id)
    {
        return remoteSubQueryService.getSafeWarnCount(id,SubQueryConfig.subQueryConfigWran);
    }

    /**
     * 实验室列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("实验室列表")
    public R querySubCListVO( AppSubQuery appSubQuery)
    {
        String s = JSON.toJSONString(appSubQuery);
        Map<String,Object>  map= (Map<String,Object>)JSON.parse(s);

        try {
            SysDept dept = tokenService.getLoginUser().getSysUser().getDept();
            // 只查询所属部门的实验室，没有部门则无数据
            if(dept == null){
                return R.ok();
            }else if(dept.getParentId() == 100){
                map.put("deptId", dept.getDeptId());
            }else if(dept.getParentId() != 0){
                return R.ok();
            }
        }catch (Exception e){}

        return remoteSubQueryService.querySubCListVO(map);
    }


}
