package com.yijia.station.controller;
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.StationClassesSummary;
import com.yijia.station.service.IStationClassesSummaryService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 班结汇总Controller
 * 
 * @author yijia
 * @date 2020-12-28
 */
@RestController
@RequestMapping("/station/summary")
public class StationClassesSummaryController extends BaseController
{
    @Autowired
    private IStationClassesSummaryService stationClassesSummaryService;
    @Autowired
    private ISysDeptService deptService;
    /**
     * 查询班结汇总列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StationClassesSummary stationClassesSummary)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            stationClassesSummary.setStationIdList(list);
            stationClassesSummary.setStationId(null);
        }
        startPage();
        List<StationClassesSummary> summaryList = stationClassesSummaryService.selectStationClassesSummaryList(stationClassesSummary);
        return getDataTable(summaryList);
    }

    /**
     * 导出班结汇总列表
     */
    @Log(title = "班结汇总", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StationClassesSummary stationClassesSummary)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            stationClassesSummary.setStationIdList(list);
            stationClassesSummary.setStationId(null);
        }
        List<StationClassesSummary> summaryList = stationClassesSummaryService.selectStationClassesSummaryList(stationClassesSummary);
        ExcelUtil<StationClassesSummary> util = new ExcelUtil<StationClassesSummary>(StationClassesSummary.class);
        return util.exportExcel(summaryList, "summary");
    }

    /**
     * 获取班结汇总详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stationClassesSummaryService.selectStationClassesSummaryById(id));
    }

    /**
     * 新增班结汇总
     */
    @Log(title = "班结汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StationClassesSummary stationClassesSummary)
    {
        return toAjax(stationClassesSummaryService.insertStationClassesSummary(stationClassesSummary));
    }

    /**
     * 修改班结汇总
     */
    @Log(title = "班结汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StationClassesSummary stationClassesSummary)
    {
        return toAjax(stationClassesSummaryService.updateStationClassesSummary(stationClassesSummary));
    }

    /**
     * 删除班结汇总
     */
    @Log(title = "班结汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stationClassesSummaryService.deleteStationClassesSummaryByIds(ids));
    }
}
