文件上传、token过期监控修改、养生区成品区代码修改、easyExcel

This commit is contained in:
lyd
2022-10-27 20:31:07 +08:00
parent 113a5186e6
commit 36be12ba96
15 changed files with 712 additions and 164 deletions

View File

@@ -176,6 +176,16 @@
</dependency>
<!-- excel工具 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>

View File

@@ -7,7 +7,7 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
/**
* @author: lyd
* @description:
* @description: redis监听配置
* @Date: 2022/10/8
*/
@Configuration

View File

@@ -1,7 +1,9 @@
package org.nl.modules.security.satoken;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.mnt.websocket.MsgType;
import org.nl.modules.mnt.websocket.SocketMsg;
import org.nl.modules.mnt.websocket.WebSocketServer;
@@ -13,11 +15,10 @@ import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* @author: lyd
* @description:
* @description: redis过期key监听器
* @Date: 2022/10/8
*/
@Slf4j
@@ -32,20 +33,13 @@ public class TokenKeyExpirationListener extends KeyExpirationEventMessageListene
@Override
public void onMessage(Message message, byte[] pattern) {
// 监听过期的key
String expireKey = new String(message.getBody(), StandardCharsets.UTF_8);
//获取key原本的value 获取不到 是null
String expireKeyValue = redisTemplate.opsForValue().get("my-satoken");
//我是根据tokenvalues作为主键ID的
String[] split = expireKey.split(":");
String s = split[split.length - 1];
try {
WebSocketServer.sendInfo(new SocketMsg("token会话过期", MsgType.INFO), "exp-token");
if (ObjectUtil.isEmpty(expireKeyValue))
WebSocketServer.sendInfo(new SocketMsg("token会话过期", MsgType.INFO), "exp-token");
} catch (IOException e) {
log.error(e.getMessage(), e);
}
log.info("expireKey---"+expireKey);
log.info("expireKeyValue---"+expireKeyValue);
}
}

View File

@@ -1,35 +0,0 @@
package org.nl.modules.security.satoken.utils;
import cn.dev33.satoken.stp.StpUtil;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.utils.dto.CurrentUser;
import org.nl.modules.system.service.dto.UserDto;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author: lyd
* @description: 当用户信息改变时候需要刷新session
* @Date: 2022/9/23
*/
@Component
@RequiredArgsConstructor
public class FlushSessionUtil {
/**
* 更新session数据 - Session TokenSession
* @param userDto
* @param permissionList
*/
public void flushSessionInfo(UserDto userDto, List<String> permissionList) {
StpUtil.getSession().set("UserDto", userDto);
// 获取权限列表 - 登录查找权限
CurrentUser user = new CurrentUser();
user.setId(userDto.getId());
user.setUsername(userDto.getUsername());
user.setUser(userDto);
user.setPermissions(permissionList);
StpUtil.getTokenSession().set("userInfo", user);
}
}

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,39 @@ 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");
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 unit_code = String.valueOf(map.get(1));
String unit_name = String.valueOf(map.get(2));
JSONObject unit = new JSONObject();
unit.put("measure_unit_id", IdUtil.getSnowflake(1, 1).nextId());
unit.put("unit_code", unit_code);
unit.put("unit_name", unit_name);
unit.put("qty_precision", 2);
unit.put("is_used", 1);
unit.put("is_delete", 0);
unit.put("create_id", currentUserId);
unit.put("create_name", nickName);
unit.put("create_time", now);
unit.put("update_optid", currentUserId);
unit.put("update_optname", nickName);
unit.put("update_time", now);
measureunitTab.insert(unit);
}
}
}

View File

@@ -71,5 +71,13 @@ public class StructivtController {
structivtService.outInventory(jsonArray);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PostMapping("/batchEdit")
@Log("批量修改")
@ApiOperation("批量修改")
public ResponseEntity<Object> batchEdit(@RequestBody JSONArray datas){
structivtService.batchEdit(datas);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

View File

@@ -68,5 +68,11 @@ public interface StructivtService {
* @param jsonArray
*/
void outInventory(JSONArray jsonArray);
/**
* 批量修改
* @param datas
*/
void batchEdit(JSONArray datas);
}

View File

@@ -43,12 +43,15 @@ public class StructivtServiceImpl implements StructivtService {
@Override
public Map<String,Object> queryAll(Map whereJson, Pageable page){
JSONObject map = new JSONObject();
JSONObject map = new JSONObject();
map.put("flag", "1");
map.put("region_code", "(" + whereJson.get("region_code") + ")");
if (!ObjectUtil.isNull(whereJson.get("point_code"))) {
map.put("point_code", "%" + whereJson.get("point_code") + "%");
}
if (!ObjectUtil.isNull(whereJson.get("material_code"))) {
map.put("material_code", "%" + whereJson.get("material_code") + "%");
}
map.put("layer_num", whereJson.get("layer_num"));
map.put("row_num", whereJson.get("row_num"));
map.put("col_num", whereJson.get("col_num"));
@@ -71,6 +74,16 @@ public class StructivtServiceImpl implements StructivtService {
statusMap.put(status[0], status[1]);
}
cppEntry.put("point_status_name", statusMap.getString(cppEntry.getString("point_status")));
// 获取物料信息
String materialId = cppEntry.getString("material_id");
if (ObjectUtil.isNotEmpty(materialId)) {
WQLObject md_me_materialBase = WQLObject.getWQLObject("MD_ME_MaterialBase");
JSONObject jsonObject = md_me_materialBase.query("material_id = '" + materialId + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonObject)) {
cppEntry.put("material_code", jsonObject.getString("material_code"));
cppEntry.put("material_name", jsonObject.getString("material_name"));
}
}
res.add(cppEntry);
}
json.put("content", res);
@@ -274,4 +287,68 @@ public class StructivtServiceImpl implements StructivtService {
}
}
/**
* 批量修改
*
* @param datas
*/
@Override
public void batchEdit(JSONArray datas) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
System.out.println(datas);
WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point");
WQLObject structIvtTab = WQLObject.getWQLObject("ST_IVT_StructIvt");
WQLObject materialBaseTab = WQLObject.getWQLObject("MD_ME_MaterialBase");
for ( int i = 0; i < datas.size(); i++ ) {
JSONObject object = datas.getJSONObject(i);
// 根据物料material_code查找物料信息
String material_id = null;
String material_code = object.getString("material_code");
if (ObjectUtil.isNotEmpty(material_code)) {
JSONObject materialObj = materialBaseTab.query("material_code = '" + material_code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(materialObj)) {
material_id = materialObj.getString("material_id");
} else {
throw new BadRequestException("物料编码出错");
}
}
JSONObject points = pointTab.query("point_id = '" + object.getString("point_id") + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(points)) {
points.put("point_status", object.getString("point_status"));
points.put("lock_type", object.getString("lock_type"));
points.put("vehicle_type", object.getString("vehicle_type"));
points.put("is_used", object.getString("is_used"));
points.put("update_optid", currentUserId);
points.put("update_optname", nickName);
points.put("update_time", now);
points.put("material_id", material_id);
pointTab.update(points);
}
// 修改/新增 仓位库存表【ST_IVT_StructIvt】
String stockrecordId = object.getString("stockrecord_id");
if (ObjectUtil.isNotEmpty(stockrecordId)) {
// 修改
JSONObject strObject = structIvtTab.query("stockrecord_id = '" + stockrecordId + "'").uniqueResult(0);
strObject.put("ivt_qty", object.getString("ivt_qty"));
strObject.put("material_id", points.getString("material_id"));
structIvtTab.update(strObject);
} else {
// 新增
JSONObject str = new JSONObject();
str.put("stockrecord_id", IdUtil.getSnowflake(1, 1).nextId());
str.put("point_id", points.getString("point_id"));
str.put("point_code", points.getString("point_code"));
str.put("point_name", points.getString("point_name"));
str.put("region_id", points.getString("region_id"));
str.put("region_code", points.getString("region_code"));
str.put("region_name", points.getString("region_name"));
str.put("material_id", points.getString("material_id"));
str.put("ivt_qty", object.getString("ivt_qty"));
structIvtTab.insert(str);
}
}
}
}

View File

@@ -22,6 +22,10 @@
输入.bill_status TYPEAS s_string
输入.io_type TYPEAS s_string
输入.lock_type TYPEAS s_string
输入.material_code TYPEAS s_string
输入.point_status TYPEAS s_string
输入.vehicle_type TYPEAS s_string
输入.is_used TYPEAS s_string
[临时表]
@@ -48,17 +52,16 @@
IF 输入.flag = "1"
PAGEQUERY
SELECT
str.*,
point.vehicle_type,
point.layer_num,
point.row_num,
point.col_num,
point.is_used,
point.lock_type,
point.point_status
point.*,
str.stockrecord_id,
str.pcsn,
str.ivt_qty,
str.qty_unit_id,
str.instorage_time,
str.standing_time
FROM
st_ivt_structivt str
LEFT JOIN sch_base_point point ON str.point_id = point.point_id
sch_base_point point
LEFT JOIN st_ivt_structivt str ON str.point_id = point.point_id
WHERE
point.region_code IN 输入.region_code
OPTION 输入.point_code <> ""
@@ -70,6 +73,11 @@
OPTION 输入.vehicle_type <> ""
point.vehicle_type = 输入.vehicle_type
ENDOPTION
OPTION 输入.material_code <> ""
point.material_id IN (
SELECT material_code FROM md_me_materialbase WHERE material_code LIKE 输入.material_code
)
ENDOPTION
OPTION 输入.layer_num <> ""
point.layer_num = 输入.layer_num
ENDOPTION