add:增加物料导入;
This commit is contained in:
@@ -24,10 +24,8 @@ import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.nl.common.utils.IPUtil;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.common.utils.RequestHolder;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.config.lucene.LuceneAppender;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -108,12 +106,17 @@ public class LogAspect {
|
||||
List<Object> argList = new ArrayList<>();
|
||||
Parameter[] parameters = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
//将RequestBody注解修饰的参数作为请求参数
|
||||
Object value = args[i];
|
||||
// 跳过 MultipartFile 和 Servlet 类型参数
|
||||
if (value instanceof org.springframework.web.multipart.MultipartFile ||
|
||||
value instanceof javax.servlet.http.HttpServletRequest ||
|
||||
value instanceof javax.servlet.http.HttpServletResponse) {
|
||||
continue;
|
||||
}
|
||||
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
|
||||
if (requestBody != null) {
|
||||
argList.add(args[i]);
|
||||
argList.add(value);
|
||||
}
|
||||
//将RequestParam注解修饰的参数作为请求参数
|
||||
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
|
||||
if (requestParam != null) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@@ -121,16 +124,28 @@ public class LogAspect {
|
||||
if (!StrUtil.isEmpty(requestParam.value())) {
|
||||
key = requestParam.value();
|
||||
}
|
||||
map.put(key, args[i]);
|
||||
// 若是 MultipartFile,则只记录文件名与大小
|
||||
if (value instanceof org.springframework.web.multipart.MultipartFile) {
|
||||
org.springframework.web.multipart.MultipartFile file = (org.springframework.web.multipart.MultipartFile) value;
|
||||
map.put(key, file.getOriginalFilename() + " (" + file.getSize() + " bytes)");
|
||||
} else {
|
||||
map.put(key, value);
|
||||
}
|
||||
argList.add(map);
|
||||
}
|
||||
}
|
||||
if (argList.size() == 0) {
|
||||
if (argList.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return JSON.toJSONString(argList);
|
||||
try {
|
||||
return JSON.toJSONString(argList);
|
||||
} catch (Exception e) {
|
||||
log.warn("请求参数序列化失败:{}", e.getMessage());
|
||||
return "[参数序列化失败]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getUsername() {
|
||||
try {
|
||||
return SecurityUtils.getCurrentUsername();
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.wms.basedata_manage.service.IMdMeMaterialbaseService;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -14,7 +15,10 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -48,6 +52,14 @@ public class MaterialbaseController {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PostMapping("/excelImport")
|
||||
public ResponseEntity<Object> excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
|
||||
RedissonUtils.lock(() -> {
|
||||
iMdMeMaterialbaseService.excelImport(file, request, response);
|
||||
}, "信息导入", null);
|
||||
return new ResponseEntity<>(TableDataInfo.build(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改物料")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody MdMeMaterialbase dto) {
|
||||
|
||||
@@ -5,7 +5,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.wms.basedata_manage.service.dao.MdMeMaterialbase;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -31,6 +34,13 @@ public interface IMdMeMaterialbaseService extends IService<MdMeMaterialbase> {
|
||||
* @param dto 物料实体类
|
||||
*/
|
||||
void create(MdMeMaterialbase dto);
|
||||
/**
|
||||
* 导入物料
|
||||
* @param file
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 修改物料
|
||||
|
||||
@@ -3,12 +3,15 @@ package org.nl.wms.basedata_manage.service.impl;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
@@ -20,7 +23,11 @@ import org.nl.wms.ext.service.WmsToErpService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -84,6 +91,55 @@ public class MdMeMaterialbaseServiceImpl extends ServiceImpl<MdMeMaterialbaseMap
|
||||
this.save(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
ExcelReader excelReader = ExcelUtil.getReader(inputStream);
|
||||
List<List<Object>> read = excelReader.read();
|
||||
if (read.size() > 1) {
|
||||
List<MdMeMaterialbase> materialList = new ArrayList<>();
|
||||
for (int i = 1; i < read.size(); i++) {
|
||||
List<Object> list = read.get(i);
|
||||
String m1 = String.valueOf(list.get(0));
|
||||
String m2 = String.valueOf(list.get(1));
|
||||
String m3 = ObjectUtil.isEmpty(list.get(2))?null:String.valueOf(list.get(2));
|
||||
String m4 = ObjectUtil.isEmpty(list.get(3))?null:String.valueOf(list.get(3));
|
||||
String m5 = ObjectUtil.isEmpty(list.get(4))?null:String.valueOf(list.get(4));
|
||||
// 根据物料编码查询是否有相同物料编码的物料
|
||||
MdMeMaterialbase mdMeMaterialbase = this.baseMapper.selectOne(
|
||||
new QueryWrapper<MdMeMaterialbase>().lambda()
|
||||
.eq(MdMeMaterialbase::getMaterial_code, m1)
|
||||
);
|
||||
if (ObjectUtil.isNotEmpty(mdMeMaterialbase)) {
|
||||
continue;
|
||||
}
|
||||
MdMeMaterialbase dao = new MdMeMaterialbase();
|
||||
dao.setMaterial_id(IdUtil.getStringId());
|
||||
dao.setMaterial_code(m1);
|
||||
dao.setMaterial_name(m2);
|
||||
dao.setMaterial_spec(m3);
|
||||
dao.setMaterial_model(m4);
|
||||
dao.setBase_unit_id(m5);
|
||||
dao.setIs_used("1");
|
||||
dao.setIs_delete("0");
|
||||
dao.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
dao.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
dao.setCreate_time(DateUtil.now());
|
||||
dao.setUpdate_optid(SecurityUtils.getCurrentUserId());
|
||||
dao.setUpdate_optname(SecurityUtils.getCurrentNickName());
|
||||
dao.setUpdate_time(DateUtil.now());
|
||||
materialList.add(dao);
|
||||
}
|
||||
this.saveBatch(materialList);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new BadRequestException("导入失败" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void update(MdMeMaterialbase dto) {
|
||||
|
||||
Reference in New Issue
Block a user