package com.zd.laboratory.controller;

import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.security.service.TokenService;
import com.zd.laboratory.domain.vo.*;
import com.zd.laboratory.service.ILabMessageUserService;
import com.zd.system.api.laboratory.domain.LabMessageUser;
import com.zd.laboratory.domain.LabSubjectAccessRecord;
import com.zd.laboratory.domain.LabViolation;
import com.zd.laboratory.service.ILabSubjectService;
import com.zd.laboratory.service.ILabViolationService;
import com.zd.laboratory.service.ILabWorkBenchService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * 工作台Controller
 *
 * @author cyl
 * @date 2021-09-13
 */

@RestController
@RequestMapping("/workbench")
public class LabWorkBenchController extends BaseController {
    @Autowired
    private TokenService tokenService;

    @Autowired
    private ILabWorkBenchService labWorkBenchService;

    @Autowired
    private ILabSubjectService labSubjectService;

    @Autowired
    private ILabViolationService labViolationService;

    @Autowired
    private ILabMessageUserService messageUserService;

    /**
     * 未读消息统计列表
     */
    @GetMapping("/unreadmessage")
    public AjaxResult unreadMessage() {
        LabMessageUser messageUser = new LabMessageUser();
        messageUser.setUserId(tokenService.getLoginUser().getUserid());
        messageUser.setIsRead(false);
        int count = labWorkBenchService.unreadMessage(messageUser);
        return AjaxResult.success(count);
    }

    /**
     * 实验室进出记录前五条
     */
    @GetMapping("/inoutfirstfive")
    public AjaxResult inoutFirstFive() {
        LabSubjectAccessRecord access = new LabSubjectAccessRecord();

        List<LabSubjectAccessRecordVo> accessList = labWorkBenchService.inoutFirstFive(access);
        return AjaxResult.success(accessList);
    }


    /**
     * 工作台实验室风险统计
     */
    @GetMapping("/riskStatistics")
    public AjaxResult riskStatistics() {
        LabWorkBenchVO workBench = labWorkBenchService.riskStatistics();
        return AjaxResult.success(workBench);
    }


    /**
     * 我的实验室列表
     */
    @RequestMapping("/mySubjectList")
    public AjaxResult mySubjectList(@RequestBody LabSubjectVO labSubjectVo)
    {
        List<LabSubjectVO> list = labSubjectService.mySubjectList(labSubjectVo);
        return AjaxResult.success(list);
    }

    /**
     * 小程序工作台，查询违规记录统计
     */
    @RequestMapping("/myViolationCount")
    public AjaxResult myViolationCount(@RequestBody LabViolation labViolation) {
        Map<String, Object> map = labViolationService.myViolationCount(labViolation);
        return AjaxResult.success(map);
    }

    /**
     * 待办事项
     */
    @ApiOperation("待办事项")
    @GetMapping("/dowords/{size}")
    public ResultData<List<ToDoWork>> doworks(@PathVariable("size") Long size) {
        List<ToDoWork> list = labWorkBenchService.queryDoWork(size);
        return ResultData.success(list);
    }


}
