2023-05-12 11:23:36 完成设备管理的导出、模板下载、导入接口!

master
魔神煜修罗皇 2 years ago
parent 5daa9451f0
commit e725765030
  1. 8
      psdc-admin/src/main/java/com/psdc/PsdcApplication.java
  2. 2
      psdc-business/src/main/java/com/psdc/service/IPsdcDeviceService.java
  3. 18
      psdc-business/src/main/java/com/psdc/service/impl/PsdcDeviceServiceImpl.java
  4. 7
      psdc-web/src/main/java/com/psdc/controller/manager/PsdcDeviceController.java
  5. BIN
      psdc-web/src/main/resources/template/AllDevicesData.xlsx

@ -2,13 +2,13 @@ package com.psdc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication()
public class PsdcApplication
{
public static void main(String[] args)
{
@EnableTransactionManagement
public class PsdcApplication {
public static void main(String[] args) {
SpringApplication.run(PsdcApplication.class, args);
System.out.println("《= = = 系统启动成功 = = =》");
}

@ -64,7 +64,7 @@ public interface IPsdcDeviceService {
*/
boolean deleteById(Long[] deviceIds);
boolean daoruDevicesData(MultipartFile file);
boolean daoruDevicesData(MultipartFile file, String cjr);
/**
* 更新设备状态

@ -9,6 +9,7 @@ import com.psdc.mapper.PsdcControlLogMapper;
import com.psdc.mapper.PsdcDeviceMapper;
import com.psdc.service.IPsdcDeviceService;
import com.psdc.utils.SecurityUtils;
import com.psdc.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -114,11 +116,23 @@ public class PsdcDeviceServiceImpl implements IPsdcDeviceService {
@Override
@Transactional(propagation = REQUIRES_NEW)
public boolean daoruDevicesData(MultipartFile file) {
public boolean daoruDevicesData(MultipartFile file, String cjr) {
try {
// 需要将上传文件转成Stream流
InputStream in = file.getInputStream();
// EasyExcel.read(in, PsdcDevice.class, new DevicesDataListener(psdcDeviceMapper)).sheet().sheetNo(0).doRead();
ExcelUtil<PsdcDevice> util = new ExcelUtil<>(PsdcDevice.class);
List<PsdcDevice> devices = util.importExcel(in);
for (PsdcDevice pd : devices){
pd.setCreateBy(cjr);
pd.setCreateTime(new Date());
pd.setDeviceType(Integer.parseInt(pd.getDevType()));
// 新导入的设备默认状态为: 未激活
// 新导入的设备默认启动时间为null,请在设备激活后手动修改!
pd.setDeviceStatus(1);
// 新导入的设备默认运行状态为: 关闭
pd.setDeviceRunstatus(2);
}
psdcDeviceMapper.saveDevicesData(devices);
return true;
} catch (Exception e) {
e.printStackTrace();

@ -162,10 +162,13 @@ public class PsdcDeviceController extends BaseController {
excel文件的读取
*/
@RequestMapping("/daoruDevData")
@PreAuthorize("hasAuthority('addevice')")
@PreAuthorize("@ss.hasPermi('manager:device:list')")
@Log(title = "设备管理", businessType = BusinessType.IMPORT)
@Transactional(rollbackFor = Exception.class)
public AjaxResult daoruDevData(@RequestPart("file") MultipartFile file) {
return toAjax(psdcDeviceService.daoruDevicesData(file));
long userId = SecurityUtils.getUserId();
String cjr = sysUserService.selectUserById(userId).getUserName();
return toAjax(psdcDeviceService.daoruDevicesData(file, cjr));
}
}

Loading…
Cancel
Save