代码更新

This commit is contained in:
lyd
2022-10-28 13:38:26 +08:00
parent db1baf70a7
commit e752d45e1e
14 changed files with 720 additions and 8 deletions

View File

@@ -16,6 +16,7 @@
package org.nl.modules.tools.rest;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -97,4 +98,12 @@ public class LocalStorageController {
localStorageService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@ApiOperation("导入数据")
@PostMapping("/importExcel")
@SaIgnore
public ResponseEntity<Object> importExcel(@RequestBody String path) {
localStorageService.importExcel(path);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -81,4 +81,10 @@ public interface LocalStorageService {
* @throws IOException /
*/
void download(List<LocalStorageDto> localStorageDtos, HttpServletResponse response) throws IOException;
/**
* 导入数据
* @param path
*/
void importExcel(String path);
}

View File

@@ -15,21 +15,23 @@
*/
package org.nl.modules.tools.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.config.FileProperties;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.common.utils.PageUtil;
import org.nl.modules.common.utils.QueryHelp;
import org.nl.modules.common.utils.ValidationUtil;
import org.nl.modules.common.utils.*;
import org.nl.modules.tools.domain.LocalStorage;
import org.nl.modules.tools.repository.LocalStorageRepository;
import org.nl.modules.tools.service.LocalStorageService;
import org.nl.modules.tools.service.dto.LocalStorageDto;
import org.nl.modules.tools.service.dto.LocalStorageQueryCriteria;
import org.nl.modules.tools.service.mapstruct.LocalStorageMapper;
import org.nl.modules.wql.core.bean.WQLObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -135,4 +137,43 @@ public class LocalStorageServiceImpl implements LocalStorageService {
}
FileUtil.downloadExcel(list, response);
}
/**
* 导入数据
*
* @param path
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void importExcel(String path) {
WQLObject measureunitTab = WQLObject.getWQLObject("md_pb_measureunit");
WQLObject materialbaseTab = WQLObject.getWQLObject("md_me_materialbase");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
List<Map<String, Object>> listMap = EasyExcel.read(path).sheet().doReadSync();
// listMap.remove(0);
for (int i = 0; i < listMap.size(); i++) {
Map<String, Object> map = listMap.get(i);
String material_code = String.valueOf(map.get(5));
String material_name = String.valueOf(map.get(6));
String unit_code = String.valueOf(map.get(7));
JSONObject object = measureunitTab.query("unit_code = '" + unit_code + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(object)) throw new BadRequestException("" + unit_code);
JSONObject material = new JSONObject();
material.put("material_id", IdUtil.getSnowflake(1, 1).nextId());
material.put("material_code", material_code);
material.put("material_name", material_name);
material.put("base_unit_id", object.getString("measure_unit_id"));
material.put("is_used", 1);
material.put("is_delete", 0);
material.put("create_id", currentUserId);
material.put("create_name", nickName);
material.put("create_time", now);
material.put("update_optid", currentUserId);
material.put("update_optname", nickName);
material.put("update_time", now);
materialbaseTab.insert(material);
}
}
}