package com.ruoyi.web.controller.fleet.basicData;

import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import com.ruoyi.basicData.domain.TCorps;
import com.ruoyi.basicData.service.ITCorpsService;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.basicData.domain.FleetCompanyMsg;
import com.ruoyi.basicData.service.IFleetCompanyMsgService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【车队】Controller
 * 
 * @author ruoyi
 * @date 2021-03-04
 */
@RestController
@RequestMapping("/fleet/companyMsg")
public class FleetCompanyMsgController extends BaseController
{
    @Autowired
    private ISysUserService userService;

    @Autowired
    private ITCorpsService tCorpsService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    @Autowired
    private IFleetCompanyMsgService fleetCompanyMsgService;

    /**
     * 下拉框查询【车队】id、name列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TCorps tCorps)
    {
        tCorps.setfTypeid("100");
        List<TCorps> list = tCorpsService.selectTCorpsList(tCorps);
        return getDataTable(list);
    }

    /**
     * 查询【车队】列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:query')")
    @GetMapping("/query")
    public TableDataInfo query(TCorps tCorps)
    {
        tCorps.setfTypeid("100");
        startPage();
        List<TCorps> list = tCorpsService.selectTCorpsList(tCorps);
        return getDataTable(list);
    }

    /**
     * 导出【车队】列表
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:export')")
    @Log(title = "【车队】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FleetCompanyMsg fleetCompanyMsg)
    {
        List<FleetCompanyMsg> list = fleetCompanyMsgService.selectFleetCompanyMsgList(fleetCompanyMsg);
        ExcelUtil<FleetCompanyMsg> util = new ExcelUtil<FleetCompanyMsg>(FleetCompanyMsg.class);
        return util.exportExcel(list, "msg");
    }

    /**
     * 获取【车队】详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fleetCompanyMsgService.selectFleetCompanyMsgById(id));
    }

    /**
     * 导入【车队】Excel
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:query')")
    @PostMapping(value = "/importCreate")
    public AjaxResult importCreateCompanyMsg(@RequestParam("file") MultipartFile file)
    {
        return fleetCompanyMsgService.importCreateCompanyMsg(file);
    }

    /**
     * 新增车队详情
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:add')")
    @Log(title = "客户详情", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    @RepeatSubmit
    public AjaxResult add(@RequestBody TCorps tCorps) {
        // 检验编号、名称、简称 唯一
        if (UserConstants.NOT_UNIQUE.equals(tCorpsService.checkUFNoUnique(tCorps))) {
            return AjaxResult.error("新增信息'" + tCorps.getfNo() + "'失败，编号已存在");
        } else if (UserConstants.NOT_UNIQUE.equals(tCorpsService.checkUFNnameUnique(tCorps))) {
            return AjaxResult.error("新增信息'" + tCorps.getfName() + "'失败，名称已存在");
        } else if (UserConstants.NOT_UNIQUE.equals(tCorpsService.checkUFCnameUnique(tCorps))) {
            return AjaxResult.error("新增信息'" + tCorps.getfCname() + "'失败，简称已存在");
        } else if (UserConstants.NOT_UNIQUE.equals(tCorpsService.checkULoginAccountUnique(tCorps))) {
            return AjaxResult.error("新增信息'" + tCorps.getfCname() + "'失败，登录账号已存在");
        }
        return fleetCompanyMsgService.insertFleetCompanyMsg(tCorps);
    }

    /**
     * 删除【车队】
     */
    @PreAuthorize("@ss.hasPermi('basicdata:corps:remove')")
    @Log(title = "【车队】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return fleetCompanyMsgService.deleteFleetCompanyMsgByIds(ids);
    }
}
