TDeviceInfoController.java 4.54 KB
Newer Older
1 2 3 4 5
package com.zehong.web.controller.device;

import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
6
import com.zehong.common.core.page.TableDataInfo;
7
import com.zehong.common.enums.BusinessType;
8
import com.zehong.common.utils.poi.ExcelUtil;
9
import com.zehong.system.domain.TDeviceInfo;
王晓倩's avatar
王晓倩 committed
10
import com.zehong.system.domain.vo.DeviceInfoVo;
11
import com.zehong.system.service.ITDeviceInfoService;
12 13 14 15 16 17
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

/**
 * 设备信息Controller
 * 
 * @author zehong
 * @date 2021-07-09
 */
@RestController
@RequestMapping("/device/deviceInfo")
public class TDeviceInfoController extends BaseController
{
    @Autowired
    private ITDeviceInfoService tDeviceInfoService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDeviceInfo tDeviceInfo)
    {
        startPage();
王晓倩's avatar
王晓倩 committed
40
        List<DeviceInfoVo> list = tDeviceInfoService.selectTDeviceInfoList(tDeviceInfo);
41 42 43
        return getDataTable(list);
    }

44 45 46 47 48 49 50 51 52 53
    /**
     * 获取所有设备信息
     * @param tDeviceInfo
     * @return
     */
    @GetMapping("/deviceListInfo")
    public AjaxResult deviceListInfo(TDeviceInfo tDeviceInfo){
        return AjaxResult.success(tDeviceInfoService.selectTDeviceInfoList(tDeviceInfo));
    }

54 55 56 57
    /**
     * 获取设备下拉树列表
     */
    @PutMapping("/deviceTree")
58
    public AjaxResult deviceTree(@RequestBody Map<Object, List> param)
59
    {
60
        return AjaxResult.success(tDeviceInfoService.buildDeviceTreeSelect(param));
61 62
    }

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
    /**
     * 获取设备树
     */
    @GetMapping("/deviceNodeTree")
    public AjaxResult deviceNodeTree() throws Exception
    {
        List<Map<Object, Object>> list = null;
        try {
            list = tDeviceInfoService.buildDeviceTree();
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("获取设备列表失败");
        }

        return AjaxResult.success(list);
    }

80 81 82 83 84 85 86 87
    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDeviceInfo tDeviceInfo)
    {
王晓倩's avatar
王晓倩 committed
88 89
        List<DeviceInfoVo> list = tDeviceInfoService.selectTDeviceInfoList(tDeviceInfo);
        ExcelUtil<DeviceInfoVo> util = new ExcelUtil<DeviceInfoVo>(DeviceInfoVo.class);
90 91 92 93 94 95 96 97
        return util.exportExcel(list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:query')")
    @GetMapping(value = "/{deviceId}")
98
    public AjaxResult getInfo(@PathVariable("deviceId") int deviceId)
99 100 101 102 103 104 105 106 107 108 109 110
    {
        return AjaxResult.success(tDeviceInfoService.selectTDeviceInfoById(deviceId));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceInfo tDeviceInfo)
    {
111 112 113 114 115
        int result = tDeviceInfoService.insertTDeviceInfo(tDeviceInfo);
        if(result<=0){
            new Exception("设备信息插入失败");
        }
        return AjaxResult.success(tDeviceInfo.getDeviceId());
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceInfo tDeviceInfo)
    {
        return toAjax(tDeviceInfoService.updateTDeviceInfo(tDeviceInfo));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
135
    public AjaxResult remove(@PathVariable int[] deviceIds)
136 137 138
    {
        return toAjax(tDeviceInfoService.deleteTDeviceInfoByIds(deviceIds));
    }
139 140 141 142 143 144 145 146 147 148 149

    /**
     * 统计各设备类型的设备总数
     */
    @PreAuthorize("@ss.hasPermi('device:deviceInfo:countDeviceByType')")
    @GetMapping("/countDeviceByType")
    public AjaxResult countDeviceByType()
    {
        List<Map<Object, Object>> list = tDeviceInfoService.countDeviceByType();
        return AjaxResult.success(list);
    }
150
}