Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-dataup / src / main / java / com / newfiber / termite / controller / DeviceInfoController.java
@xiongkai xiongkai on 9 Jul 5 KB 图片添加水印
package com.newfiber.termite.controller;

import com.newfiber.common.core.exception.ServiceException;
import com.newfiber.common.core.utils.poi.ExcelUtil;
import com.newfiber.common.core.web.controller.BaseController;
import com.newfiber.common.core.web.domain.Result;
import com.newfiber.common.core.web.page.PageResult;
import com.newfiber.common.log.annotation.Log;
import com.newfiber.common.log.enums.BusinessType;
import com.newfiber.termite.domain.DeviceInfo;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoBatchSaveRequest;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoImportRequest;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoQueryRequest;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoSaveRequest;
import com.newfiber.termite.domain.request.deviceInfo.DeviceInfoUpdateRequest;
import com.newfiber.termite.service.IDeviceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 设备信息Controller
 * 
 * @author X.K
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/deviceInfo")
@Api(value = "设备信息", tags = "设备信息")
public class DeviceInfoController extends BaseController {

    @Resource
    private IDeviceInfoService deviceInfoService;

    /**
     * 新增设备信息
     */
    @PostMapping("add")
    @ApiOperation(value = "新增设备信息", position = 10)
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    public Result<Long> add(@Valid @RequestBody DeviceInfoSaveRequest request) {
        return success(deviceInfoService.insert(request));
    }

    /**
     * 新增设备信息
     */
    @PostMapping("addBatch")
    @ApiOperation(value = "批量新增设备信息", position = 10)
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    public Result<String> addBatch(@Valid @RequestBody DeviceInfoBatchSaveRequest request) {
        deviceInfoService.insert(request);
        return success();
    }

    @PostMapping("/parseExcel")
    public Result<List<DeviceInfoImportRequest>> parseExcel(MultipartFile file) throws Exception{
        ExcelUtil<DeviceInfoImportRequest> util = new ExcelUtil<>(DeviceInfoImportRequest.class);
        List<DeviceInfoImportRequest> deviceInfoImportRequestList = util.importExcel(file.getInputStream());
        return success(deviceInfoImportRequestList);
    }

    @PostMapping("/importExcel")
    public Result<List<DeviceInfo>> importExcel(MultipartFile file, String projectCode) throws Exception{
        if(null == file){
            throw new ServiceException("请上传文件");
        }
        ExcelUtil<DeviceInfoImportRequest> util = new ExcelUtil<>(DeviceInfoImportRequest.class);
        List<DeviceInfoImportRequest> deviceInfoImportRequestList = util.importExcel(file.getInputStream());
        DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList);
        return success(deviceInfoService.insert(batchSaveRequest));
    }

    /**
     * 修改设备信息
     */
    @PutMapping("edit")
    @ApiOperation(value = "修改设备信息", position = 20)
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    public Result<Object> edit(@Valid @RequestBody DeviceInfoUpdateRequest request) {
        return success(deviceInfoService.update(request));
    }

    /**
     * 删除设备信息
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除设备信息", notes = "传入ids(,隔开)", position = 30)
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
    public Result<Object> remove(@PathVariable String ids) {
        return success(deviceInfoService.delete(ids));
    }

    /**
     * 详细查询设备信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详细查询设备信息", position = 40)
    public Result<DeviceInfo> detail(@PathVariable("id") Long id) {
        return success(deviceInfoService.selectDetail(id));
    }

    /**
     * 分页查询设备信息
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询设备信息", position = 50)
    public PageResult<List<DeviceInfo>> page(DeviceInfoQueryRequest request) {
        startPage();
        List<DeviceInfo> list = deviceInfoService.selectPage(request);
        return pageResult(list);
    }

    /**
     * 列表查询设备信息
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表查询设备信息", position = 60)
    public Result<List<DeviceInfo>> list(DeviceInfoQueryRequest request) {
        List<DeviceInfo> list = deviceInfoService.selectList(request);
        return success(list);
    }

}