package com.yijia.station.controller;

import java.util.Arrays;
import java.util.List;

import com.yijia.common.core.domain.entity.SysDept;
import com.yijia.common.core.domain.model.LoginUser;
import com.yijia.common.utils.SecurityUtils;
import com.yijia.system.service.ISysDeptService;
import com.yijia.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.station.domain.StationInfo;
import com.yijia.station.service.IStationInfoService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 油站信息Controller
 * 
 * @author yijia
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/station/info")
public class StationInfoController extends BaseController
{
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysDeptService sysDeptService;
    /**
     * 查询油站信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDept sysDept)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            sysDept.setDeptIdList(list);
            sysDept.setDeptId(null);
        }
        startPage();
        sysDept.setJiBie(Integer.valueOf("2"));
        List<SysDept> deptList = sysDeptService.selectDeptList(sysDept);
        return getDataTable(deptList);
    }

    @GetMapping("/selectStationInfo")
    public TableDataInfo selectStationInfo(SysDept sysDept)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = sysDeptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            sysDept.setDeptIdList(list);
            sysDept.setDeptId(null);
        }
        sysDept.setJiBie(Integer.valueOf("2"));
        List<SysDept> deptList = sysDeptService.selectDeptList(sysDept);
        return getTable(deptList);
    }

    /**
     * 获取油站信息详细信息
     */
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(sysDeptService.selectDeptById(deptId));
    }

    /**
     * 修改油站信息
     */
    @Log(title = "油站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDept sysDept)
    {
        return toAjax(sysDeptService.updateDept(sysDept));
    }

}
