瀏覽代碼

invw的redis修复

master
yangpeilai 2 月之前
父節點
當前提交
dc403436c1

+ 1
- 0
zhywpt-app-invw/build.gradle 查看文件

@@ -25,6 +25,7 @@ dependencies {
runtimeOnly 'com.oracle.database.jdbc:ojdbc8:19.10.0.0'
runtimeOnly 'cn.easyproject:orai18n:12.1.0.2.0'
implementation 'com.alibaba:easyexcel:3.2.1'
implementation "org.springframework.boot:spring-boot-starter-data-redis"

// 添加 MapStruct 核心库依赖
implementation 'org.mapstruct:mapstruct:1.5.5.Final'

+ 44
- 5
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/dto/warehouse/InvwWarehousePageResponseDTO.java 查看文件

@@ -1,13 +1,52 @@
package cn.com.taiji.invw.dto.warehouse;

import cn.com.taiji.core.entity.invw.InvwWarehouse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@ApiModel(description = "仓库分页响应")
public class InvwWarehousePageResponseDTO {
@ApiModelProperty(value = "仓库信息")
private InvwWarehouse warehouse;
@ApiModelProperty(value = "上级仓库信息")
private InvwWarehouse parentWarehouse;

@ApiModelProperty(value = "仓库ID")
private String id;

@ApiModelProperty(value = "仓库编号")
private String code;//仓库编号

@ApiModelProperty(value = "上级仓库ID")
private String parentId;//上级仓库ID

@ApiModelProperty(value = "仓库名称")
private String name;//仓库名称

@ApiModelProperty(value = "仓库层级")
private Integer warehouseLevel;//仓库层级1-3

@ApiModelProperty(value = "仓库状态 0-删除 1-正常")
private Integer status;//库存状态0-删除 1-正常

@ApiModelProperty(value = "更新时间")
private LocalDateTime updateTime;//更新时间

@ApiModelProperty(value = "创建时间")
private LocalDateTime insertTime;//创建时间

@ApiModelProperty(value = "渠道编号")
private String agencyId;//渠道编号

@ApiModelProperty(value = "网点编号")
private String channelId;//网点编号,三级有值

@ApiModelProperty(value = "库存校验 0-否 1-是")
private Integer isCheck;//库存校验,二级以上有值,0-否,1-是

@ApiModelProperty(value = "仓库编号")
private String parentCode;//仓库编号

@ApiModelProperty(value = "仓库名称")
private String parentName;//仓库名称

}

+ 216
- 0
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/manager/RedisWrapManager.java 查看文件

@@ -0,0 +1,216 @@
package cn.com.taiji.invw.manager;

import cn.com.taiji.common.entity.BaseEntity;
import cn.com.taiji.common.manager.AbstractManager;
import cn.com.taiji.common.model.dao.Pagination;
import cn.com.taiji.common.pub.StringTools;
import cn.com.taiji.common.pub.json.JsonTools;
import cn.com.taiji.core.manager.cache.RedisManager;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions.ScanOptionsBuilder;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

/**
* hash操作的方法以hash开头,如:hashGet<br>
*
* @author lijun <br>
* Create Time:2018年12月9日 下午1:43:54<br>
* mail:756915505@qq.com
* @since 1.0
* @version 1.0
*/
@Service
public class RedisWrapManager extends AbstractManager implements RedisManager {

@Autowired(required = false)
private RedisTemplate<String, String> redisTemplate;

public Set<String> key(String pattern) {
if ("*".equals(pattern)) {
throw new RuntimeException("禁止全扫描key");
}
return redisTemplate.keys(pattern);
}

public Boolean expire(String key, final long timeout, final TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}

public String get(String key) {
return redisTemplate.opsForValue().get(key);
}

public String getAndSet(String key, String value) {
return redisTemplate.opsForValue().getAndSet(key, value);
}

public void set(String key, String value, long timeout, TimeUnit unit) {
redisTemplate.opsForValue().set(key, value, timeout, unit);
}

public boolean setIfAbsent(String key, String value, long timeout, TimeUnit unit) {
return redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit);
}

public long increment(String key, long delta) {
return redisTemplate.opsForValue().increment(key, delta);
}

public Boolean delete(String key) {
return redisTemplate.delete(key);
}

public long listRightPush(String key, String value) {
return redisTemplate.opsForList().rightPush(key, value);
}

/**
* 返回存储在 key 的列表里指定范围内的元素。 start 和 end 偏移量都是基于0的下标,即list的第一个元素下标是0(list的表头),第二个元素下标是1,以此类推。
* 偏移量也可以是负数,表示偏移量是从list尾部开始计数。 例如, -1 表示列表的最后一个元素,-2 是倒数第二个,以此类推
*/
public List<String> listRange(String key, long start, long end) {
return redisTemplate.opsForList().range(key, start, end);
}

public Long listSize(String key) {
return redisTemplate.opsForList().size(key);
}

public Boolean hashHasKey(String key, Object hashKey) {
return opsForHash().hasKey(key, hashKey);
}

public boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}

public Object hashGet(String key, Object hashKey) {
return opsForHash().get(key, hashKey);
}

public void hashPut(String key, Object hashKey, Object value) {
opsForHash().put(key, hashKey, value);
}

public Boolean hashPutIfAbsent(String key, Object hashKey, Object value) {
return opsForHash().putIfAbsent(key, hashKey, value);
}

public void hashPutAll(String key, Map<? extends Object, ? extends Object> m) {
opsForHash().putAll(key, m);
}

public Long hashIncrement(String key, Object hashKey, long delta) {
return opsForHash().increment(key, hashKey, delta);
}

public Long hashDelete(String key, Object... hashKeys) {
return opsForHash().delete(key, hashKeys);
}

public Map<Object, Object> hashScan(String key, String pattern) {
ScanOptionsBuilder b = new ScanOptionsBuilder();
Cursor<Entry<Object, Object>> s = opsForHash().scan(key, b.match(pattern).build());
Map<Object, Object> map = new HashMap<>();
s.forEachRemaining(e -> map.put(e.getKey(), e.getValue()));
return map;
}

public String findStr(String key, int timeout, Supplier<String> valueSupplier) {
String str = get(key);
if (!StringTools.hasText(str)) {
str = valueSupplier.get();
set(key, str, timeout);
}
return str;
}

public <T extends BaseEntity> T findObj(Class<T> clazz, String key, int timeout, Supplier<T> valueSupplier) {
String jsonStr = (String)get(key);
try {
if (!StringTools.hasText(jsonStr)) {
T obj = valueSupplier.get();
jsonStr = JsonTools.toJsonStr(obj);
set(key, jsonStr, timeout);
}
return JsonTools.json2Object(jsonStr, clazz);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

public <T extends BaseEntity> T findObj(Class<T> clazz, String key) {
String jsonStr = redisTemplate.opsForValue().get(key);
try {
return JsonTools.json2Object(jsonStr, clazz);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

public <T> Map<String, T> findMap(Class<T> clazz, String key, int timeout, Supplier<Map<String, T>> valueSupplier) {
String jsonStr = get(key);
try {
if (!StringTools.hasText(jsonStr)) {
Map<String, T> map = valueSupplier.get();
jsonStr = JsonTools.toJsonStr(map);
set(key, jsonStr, timeout);
}
return JsonTools.json2Map(jsonStr, String.class, clazz);
} catch (IOException e) {
e.printStackTrace();
return new HashedMap<>();
}
}

public <T> List<T> findList(Class<T> clazz, String key, int timeout, Supplier<Collection<T>> valueSupplier) {
String jsonStr = get(key);
try {
if (!StringTools.hasText(jsonStr)) {
Collection<T> c = valueSupplier.get();
jsonStr = JsonTools.toJsonStr(c);
set(key, jsonStr, timeout);
}
return JsonTools.json2List(jsonStr, clazz);
} catch (IOException e) {
e.printStackTrace();
return new ArrayList<>();
}
}

public <T extends BaseEntity> Pagination findPagn(Class<T> clazz, String key, int timeout,
Supplier<Pagination> valueSupplier) {
String jsonStr = get(key);
try {
if (!StringTools.hasText(jsonStr)) {
Pagination c = valueSupplier.get();
jsonStr = JsonTools.toJsonStr(c);
set(key, jsonStr, timeout);
}
return JsonTools.json2Pagn(jsonStr, clazz);
} catch (IOException e) {
e.printStackTrace();
return new Pagination().setResult(new ArrayList<>());
}
}

private <HK, HV> HashOperations<String, HK, HV> opsForHash() {
return redisTemplate.opsForHash();
}

private void set(String key, String value, int timeout) {
redisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
}
}

+ 42
- 37
zhywpt-app-invw/src/main/java/cn/com/taiji/invw/manager/warehouse/InvwWarehouseManagerImpl.java 查看文件

@@ -267,44 +267,46 @@ public class InvwWarehouseManagerImpl extends AbstractInvwManager implements Inv
} else {
warehouseList = warehouseRepo.findAllByStatus(1);
}
switch (req.getType()) {
case "1":
warehouseList = warehouseRepo.findParByParentIdAndStatus(req.getId(), 1);
break;
case "2":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findBroByParentIdAndStatus(warehouse.getParentId(), 1);
if(StringTools.hasText(req.getType())) {
switch (req.getType()) {
case "1":
warehouseList = warehouseRepo.findParByParentIdAndStatus(req.getId(), 1);
break;
case "2":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findBroByParentIdAndStatus(warehouse.getParentId(), 1);
}
}
}
break;
case "3":
warehouseList = warehouseRepo.findChiByIdAndStatus(req.getId(), 1);
break;
case "4":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findParBroByParentId(warehouse.getParentId(), 1);
break;
case "3":
warehouseList = warehouseRepo.findChiByIdAndStatus(req.getId(), 1);
break;
case "4":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findParBroByParentId(warehouse.getParentId(), 1);
}
}
}
break;
case "5":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findBroChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
break;
case "5":
if (warehouse != null) {
if (StringTools.hasText(warehouse.getParentId())) {
warehouseList = warehouseRepo.findBroChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
}
}
}
break;
case "6":
if (warehouse != null) {
warehouseList = warehouseRepo.findParChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
}
break;
case "7":
if (warehouse != null) {
warehouseList = warehouseRepo.findParBroChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
}
break;
break;
case "6":
if (warehouse != null) {
warehouseList = warehouseRepo.findParChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
}
break;
case "7":
if (warehouse != null) {
warehouseList = warehouseRepo.findParBroChiByParentIdOrId(warehouse.getParentId(), warehouse.getId(), 1);
}
break;
}
}
if (!isEmpty(warehouseList)) {
for (InvwWarehouse invwWarehouse : warehouseList) {
@@ -331,12 +333,15 @@ public class InvwWarehouseManagerImpl extends AbstractInvwManager implements Inv

public InvwWarehousePageResponseDTO convert(InvwWarehouse warehouse) {
InvwWarehousePageResponseDTO response = new InvwWarehousePageResponseDTO();
response.setWarehouse(warehouse);
BeanUtils.copyProperties(warehouse, response);
String parentId = warehouse.getParentId();
// 查询父级仓库
if (StringTools.hasText(parentId)) {
InvwWarehouse parentWarehouse = warehouseRepo.findById(parentId).orElse(null);
response.setParentWarehouse(parentWarehouse);
if(parentWarehouse != null){
response.setParentCode(parentWarehouse.getCode());
response.setParentName(parentWarehouse.getName());
}
}
return response;
}

+ 2
- 0
zhywpt-app-invw/src/main/resources/bootstrap.yml 查看文件

@@ -33,6 +33,8 @@ spring:
refresh: true
- data-id: minio-client.yaml
refresh: true
- data-id: redis.yaml
refresh: true
server:
port: 9085
servlet:

Loading…
取消
儲存