package com.bonus.material.equipment.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.InnerAuth;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.common.security.annotation.RequiresPermissionsOrInnerAuth;
import com.bonus.material.equipment.domain.DeptConfigRateSummary;
import com.bonus.material.equipment.domain.DeptConfigTypeSummary;
import com.bonus.material.equipment.domain.DeptEquipmentConfig;
import com.bonus.material.equipment.domain.EquipmentDetail;
import com.bonus.material.equipment.service.ISysDeptService;
import com.bonus.system.api.domain.SysDept;
import com.bonus.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/dept")
public class SysDeptController extends BaseController {

    @Autowired
    private ISysDeptService service;

    /**
     * 获取部门树列表
     */
    //@RequiresPermissionsOrInnerAuth(innerAuth = @InnerAuth, requiresPermissions = @RequiresPermissions("system:user:list"))
    @GetMapping("/deptTree")
    public AjaxResult deptTree(SysDept dept) {
        try {

            return success(service.selectDeptTreeList(dept));
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return error("系统异常,请联系管理员");
    }

    @GetMapping("/list")
    @SysLog(title = "装备列表", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "查询装备列表")
    public TableDataInfo list(DeptEquipmentConfig user) {
        try {
            startPage();
            List<SysUser> list = service.selectUserList(user);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }

    @GetMapping("/listRate")
    @SysLog(title = "装备列表", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "查询装备列表")
    public TableDataInfo listRate(DeptConfigRateSummary user) {
        try {
            List<DeptConfigRateSummary> list = service.selectDeptConfigRatePivot(user);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }


    @PostMapping("/selectConfigList")
    public AjaxResult selectConfigList(@RequestBody DeptEquipmentConfig user) {
        return service.selectConfigList(user);
    }
    //装备名称下拉框获取
    @PostMapping("/getTree")
    public AjaxResult getTree() {
        return service.getTree();
    }

    @GetMapping("/listConfigType")
    @SysLog(title = "装备列表", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "查询装备列表")
    public TableDataInfo listConfigType(DeptConfigTypeSummary user) {
        try {
            startPage();
            List<DeptConfigTypeSummary> list = service.selectDeptConfigTypeSummary(user);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }
    @PostMapping("/detailsInfo")
    @SysLog(title = "公司装备详情页面", businessType = OperaType.QUERY, logType = 0, module = "系统管理->装备列表", details = "公司装备详情页面")
    public TableDataInfo detailsInfo(@RequestBody EquipmentDetail equipmentDetail) {
        try {
            List<EquipmentDetail> list = service.detailsInfo(equipmentDetail);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }
 }
