package com.muyu.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.security.annotation.InnerAuth;
import com.muyu.common.system.domain.SysFirm;
import com.muyu.common.system.domain.SysFirmDatasource;
import com.muyu.common.system.domain.resp.SysFirmResp;
import com.muyu.system.service.SysFirmDatasourceService;
import com.muyu.system.service.SysFirmService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 企业控制层
 * @Author：杨鹏
 * @Package：com.muyu.system.controller
 * @Project：cloud-vehicle
 * @name：SysFirmController
 * @Date：2024/10/8 19:41
 */
@RestController
@RequestMapping("/firm")
public class SysFirmController extends BaseController {

    @Resource
    private SysFirmService sysFirmService;
    @Resource
    private SysFirmDatasourceService sysFirmDatasourceService;

    /**
     * 企业下拉框列表
     * @return
     */
    @GetMapping("/firmList")
    public Result<List<SysFirm>> firmList(){
        return success(sysFirmService.list());
    }

    @GetMapping("/firmInnList")
    @InnerAuth
    public Result<List<SysFirmResp>> firmInnList(){
        LambdaQueryWrapper<SysFirm> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(SysFirm::getFirmId, 1);
        return success(sysFirmService.list(wrapper)
                .stream()
                .map(sysFirm ->
                     SysFirmResp.builder()
                            .sysFirm(sysFirm)
                            .sysFirmDatasource(
                                    sysFirmDatasourceService.getById(sysFirm.getDatasourceId())
                            )
                )
        );
    }



}
