das接口修改

This commit is contained in:
chenhaojie 2024-07-15 17:11:19 +08:00
parent 4af603d7c1
commit 5a03ca40a8
5 changed files with 17 additions and 8 deletions

View File

@ -51,6 +51,7 @@ public class HuExcelUtils {
ServletOutputStream out = null;
try {
response.setContentType("application/vnd.ms-excel");
//attachment 弹出下载对话框 inline 则会使用默认浏览器打开文件不出现弹框在线预览
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment;filename=%s", URLEncoder.encode(fileName + ".xls", StandardCharsets.UTF_8)));
out = response.getOutputStream();

View File

@ -103,8 +103,9 @@ public class LoginServiceImpl implements LoginService {
@Override
public void logout(HttpServletRequest request) {
String token = request.getHeader("token");
adminRedisTemplate.del(token);
StpUtil.logoutByTokenValue(token);
if (adminRedisTemplate.del(token)) {
StpUtil.logoutByTokenValue(token);
}
}
@Override

View File

@ -132,7 +132,10 @@ public class EquipmentController {
/** 设备导出 */
@PostMapping("/import")
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException, ParseException {
sysEquipmentService.importSysEquipment(id, file);
return R.success();
boolean result = sysEquipmentService.importSysEquipment(id, file);
if (result) {
return R.success("导出成功");
}
return R.success("导出失败");
}
}

View File

@ -26,6 +26,6 @@ public interface SysEquipmentService {
void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response);
void importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException, ParseException;
boolean importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException, ParseException;
}

View File

@ -151,7 +151,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
// 一次性写出内容使用默认样式强制输出标题
writer.write(sysEquipmentList, true);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("application/octet-stream");
response.setContentType("application/vnd.ms-excel");
ServletOutputStream out = null;
try {
// 设置请求头属性
@ -169,7 +169,8 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
}
@Override
public void importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException, ParseException {
public boolean importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException, ParseException {
boolean flag = false;
// 通过文件获取输入流
InputStream is = file.getInputStream();
// 借助hutool读取
@ -218,7 +219,10 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
field.setUpdatedBy(StpUtil.getLoginIdAsString());
sysEquipmentList.add(field);
}
sysEquipmentMapper.insertBatch(sysEquipmentList);
if(sysEquipmentMapper.insertBatch(sysEquipmentList)){
flag = true;
}
return flag;
}
}