package com.bonus.material.equipment.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.basic.domain.BmCompanyAddress;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import com.bonus.material.device.domain.vo.DevInfoVo;
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.IDeptEquipmentConfigService;
import com.bonus.material.equipment.service.ISysDeptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/equipmentConfig")

public class DeptEquipmentConfigController extends BaseController {

    @Autowired
    private IDeptEquipmentConfigService service;

    @Autowired
    private ISysDeptService isyservice;
    @GetMapping("/{deptId}")
    public AjaxResult getConfigByDept(@PathVariable Long deptId) {
        return AjaxResult.success(service.selectByDeptId(deptId));
    }

    @PostMapping("/saveEquitConfig")
    public AjaxResult save(@RequestBody DeptEquipmentConfig configList) {
        int i = service.saveBatch(configList);
        if (i > 0){
            return AjaxResult.success("操作成功");
        }else {
            return AjaxResult.error("操作失败");
        }
    }
    /**
     * 导出企业信息列表
     */
    @ApiOperation(value = "导出机械化施工装备配置率")
    @PreventRepeatSubmit
    @SysLog(title = "机械化施工装备配置率信息", businessType = OperaType.EXPORT, logType = 1,module = "出租方管理->机械化施工装备配置率信息")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody EquipmentDetail equipmentDetail) {
        try {
            List<EquipmentDetail> list = isyservice.detailsInfo(equipmentDetail);
            ExcelUtil<EquipmentDetail> util = new ExcelUtil<EquipmentDetail>(EquipmentDetail.class);
            util.exportExcel(response, list, "装备详情数据");
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }

    }

    /**
     *
     * 查询机械化施工装备
     *
     * 自有装备数据的数量
     * @param devInfoVo
     * @return
     */
    @PostMapping("/getdeviceInfo")
    public AjaxResult getdeviceInfo( @RequestBody DevInfoVo devInfoVo) {
        List<DevInfoVo> list = service.selectDevInfoLists(devInfoVo);
        return AjaxResult.success(list);
    }

}
