From c542bc64636b92d3abc266c6ad513ec9861322ec Mon Sep 17 00:00:00 2001
From: 935090232@qq.com <ak473600000>
Date: Mon, 02 May 2022 09:34:30 +0800
Subject: [PATCH] fead:缓存存储到数据库,合并本店产品与总部产品
---
zq-erp/src/main/java/com/matrix/system/common/interceptor/HostInterceptor.java | 3
zq-erp/src/main/java/com/matrix/system/common/dao/SysCacheValueDao.java | 14 ++
zq-erp/src/main/resources/config/application-local.properties | 9 +
zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java | 183 ++++++++++++++++++++++++------
zq-erp/src/main/java/com/matrix/system/hive/action/ProjUseController.java | 6
zq-erp/pom.xml | 5
zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java | 13 +-
zq-erp/src/main/java/com/matrix/system/hive/dao/ShoppingGoodsDao.java | 2
zq-erp/src/main/resources/config/application.properties | 2
zq-erp/src/main/resources/mybatis/mapper/hive/SysShopInfoDao.xml | 7 +
zq-erp/src/main/java/com/matrix/system/common/bean/SysCacheValue.java | 39 ++++++
zq-erp/src/main/java/com/matrix/system/hive/action/ServiceRecordController.java | 2
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java | 31 +++-
zq-erp/src/main/resources/templates/views/admin/hive/products/shoppinggoods-zb-list.html | 20 ++-
zq-erp/src/main/java/com/matrix/system/hive/dao/SysShopInfoDao.java | 3
zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java | 9
16 files changed, 273 insertions(+), 75 deletions(-)
diff --git a/zq-erp/pom.xml b/zq-erp/pom.xml
index faef2a9..e080c3f 100644
--- a/zq-erp/pom.xml
+++ b/zq-erp/pom.xml
@@ -100,6 +100,11 @@
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
+ <groupId>com.sun.mail</groupId>
+ <artifactId>javax.mail</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
diff --git a/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java b/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java
index fb84dee..d2cb915 100644
--- a/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java
+++ b/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java
@@ -1,6 +1,9 @@
package com.matrix.system.app.authority;
import cn.hutool.crypto.SecureUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.StringUtils;
@@ -100,10 +103,8 @@
String redisKey = USER_POWER_REDISKEY_APP + SecureUtil.md5(user.getSuId()+"");
Map<String, Object> cachePowerMap = LocalCache.get(redisKey);
if (Objects.nonNull(cachePowerMap)) {
-
- userFunction = (Map<String, SysFunction>) cachePowerMap.get(USERFUNCTION);
-
- userUrlMapping = (List<String>) cachePowerMap.get(USER_URL_MAPPING);
+ userFunction = JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USERFUNCTION)), new TypeReference<Map<String, SysFunction>>(){});
+ userUrlMapping =JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USER_URL_MAPPING)) , new TypeReference<List<String>>(){});
} else {
// 获取用户所有权限
diff --git a/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java b/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java
index 381b643..656e646 100644
--- a/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java
+++ b/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java
@@ -1,6 +1,9 @@
package com.matrix.system.common.authority;
import cn.hutool.crypto.SecureUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.StringUtils;
@@ -13,6 +16,7 @@
import com.matrix.system.common.init.LocalCache;
import com.matrix.system.common.service.SysFunctionService;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -154,12 +158,9 @@
Map<String, Object> cachePowerMap = LocalCache.get(redisKey);
if (Objects.nonNull(cachePowerMap)) {
-
- userFunction = (Map<String, SysFunction>) cachePowerMap.get(USERFUNCTION);
-
- menuFunction = (List<SysFunction>) cachePowerMap.get(MENUSFUNCTION);
-
- userUrlMapping = (List<String>) cachePowerMap.get(USER_URL_MAPPING);
+ userFunction = JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USERFUNCTION)), new TypeReference<Map<String, SysFunction>>(){});
+ menuFunction = JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(MENUSFUNCTION)) ,new TypeReference<List<SysFunction>>(){});
+ userUrlMapping =JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USER_URL_MAPPING)) , new TypeReference<List<String>>(){});
} else {
// 获取用户所有权限
diff --git a/zq-erp/src/main/java/com/matrix/system/common/bean/SysCacheValue.java b/zq-erp/src/main/java/com/matrix/system/common/bean/SysCacheValue.java
new file mode 100644
index 0000000..5a4e8cc
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/common/bean/SysCacheValue.java
@@ -0,0 +1,39 @@
+package com.matrix.system.common.bean;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+
+/**
+ * 缓存对象
+ */
+@Data
+public class SysCacheValue {
+
+
+ @TableId(type= IdType.AUTO)
+ private Long id;
+ /**
+ * 缓存key
+ */
+ private String cacheKey;
+ /**
+ * 过期时间,0 表示不过期,单位毫秒
+ */
+ private Long timeOut ;
+ /**
+ * 缓存值
+ */
+ private String cacheValue;
+ /**
+ * 类型名称
+ */
+ private String className;
+
+ /**
+ * 缓存创建时间
+ */
+ private Long createTime;
+}
diff --git a/zq-erp/src/main/java/com/matrix/system/common/dao/SysCacheValueDao.java b/zq-erp/src/main/java/com/matrix/system/common/dao/SysCacheValueDao.java
new file mode 100644
index 0000000..b6b4bbd
--- /dev/null
+++ b/zq-erp/src/main/java/com/matrix/system/common/dao/SysCacheValueDao.java
@@ -0,0 +1,14 @@
+package com.matrix.system.common.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.matrix.system.common.bean.SysCacheValue;
+import com.matrix.system.fenxiao.entity.ShopSalemanSettlement;
+
+/**
+ * @description 缓存对象
+ * @author jyy
+ * @date 2021-03-10 15:22
+ */
+public interface SysCacheValueDao extends BaseMapper<SysCacheValue> {
+
+}
\ No newline at end of file
diff --git a/zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java b/zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java
index ed624c2..6e52c98 100644
--- a/zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java
+++ b/zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java
@@ -1,26 +1,64 @@
package com.matrix.system.common.init;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
+import com.matrix.system.common.bean.SysCacheValue;
+import com.matrix.system.common.dao.SysCacheValueDao;
import lombok.Data;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
+import java.lang.reflect.Type;
+import java.util.*;
import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
-public class LocalCache {
+@Component
+public class LocalCache implements ApplicationRunner {
/*
* 清理线程运行状态 0 未启动,1 已启动
*/
private static int CLEAR_THREAD_STATUS = 0;
- private static ConcurrentMap<String, Value> localCache = new ConcurrentHashMap(60);
+
+ private static ConcurrentMap<String, CacheValue> localCache = new ConcurrentHashMap(60);
+
+ private static ConcurrentLinkedQueue<Long> deadCache = new ConcurrentLinkedQueue<>();
+
+ @Autowired
+ private SysCacheValueDao sysCacheValueDao;
+
+ @Override
+ public void run(ApplicationArguments args) {
+ //初始化缓存
+ List<SysCacheValue> sysCacheValues = sysCacheValueDao.selectByMap(null);
+ if(CollUtil.isNotEmpty(sysCacheValues)){
+ LogUtil.debug("初始化缓存");
+ localCache.putAll(buildValues(sysCacheValues));
+ }
+ startClearThread();
+ startSaveStoreThread();
+ }
+
+ private Map<String,CacheValue> buildValues(List<SysCacheValue> sysCacheValues) {
+ Map<String,CacheValue> storeCache=new HashMap<>();
+ sysCacheValues.forEach(e->{
+ CacheValue cacheValue=new CacheValue();
+ BeanUtil.copyProperties(e,cacheValue);
+ storeCache.put(cacheValue.getCacheKey(),cacheValue);
+ });
+ return storeCache;
+ }
/**
* 根据key匹配多个缓存值
@@ -33,8 +71,8 @@
return localCache.entrySet().stream()
.filter(item -> StringUtils.isMatch(key, item.getKey()))
.map(Map.Entry::getValue)
- .filter(item -> Objects.nonNull(item.value))
- .collect(Collectors.toMap(Value::getKey, item -> (T) item.value));
+ .filter(item -> Objects.nonNull(item.cacheValue))
+ .collect(Collectors.toMap(CacheValue::getCacheKey, item -> JSONObject.parseObject(item.cacheValue, new TypeReference<T>(){})));
}
/**
@@ -45,9 +83,24 @@
* @return
*/
public static <T> T get(String key) {
- Value value = localCache.get(key);
+ CacheValue value = localCache.get(key);
if (Objects.nonNull(value)) {
- return (T) value.value;
+ return JSONObject.parseObject(value.cacheValue, new TypeReference<T>(){});
+ }
+ return null;
+ }
+
+ /**
+ * 获取本地缓存,如果需要转换为List,Map类型的具体泛型使用本方法
+ * @param key
+ * @param typeReference
+ * @param <T>
+ * @return
+ */
+ public static <T> T get(String key,TypeReference typeReference) {
+ CacheValue value = localCache.get(key);
+ if (Objects.nonNull(value)) {
+ return (T)JSONObject.parseObject(value.cacheValue, typeReference);
}
return null;
}
@@ -60,9 +113,10 @@
* @return
*/
public static <T> T remove(String key) {
- Value value = localCache.remove(key);
+ CacheValue value = localCache.get(key);
if (Objects.nonNull(value)) {
- return (T) value.value;
+ deadCache.add(value.getId());
+ return (T) value.cacheValue;
}
return null;
}
@@ -75,10 +129,10 @@
*/
public static int batchRemove(String key) {
int count = 0;
- Set<Map.Entry<String, Value>> entries = localCache.entrySet();
- Iterator<Map.Entry<String, Value>> iterator = entries.iterator();
+ Set<Map.Entry<String, CacheValue>> entries = localCache.entrySet();
+ Iterator<Map.Entry<String, CacheValue>> iterator = entries.iterator();
while (iterator.hasNext()) {
- Map.Entry<String, Value> next = iterator.next();
+ Map.Entry<String, CacheValue> next = iterator.next();
if (StringUtils.isMatch(key, next.getKey())) {
remove(next.getKey());
count++;
@@ -110,25 +164,26 @@
if (null != localCache.put(key, buildValue(key, value, timeOut))) {
LogUtil.debug("覆盖原有缓存{}", key);
}
- startClearThread();
+
}
/**
* 重置缓存失效时间
+ *
* @param key
*/
public static void resetExpire(String key) {
Objects.requireNonNull(key);
- Value value = localCache.get(key);
- if(Objects.nonNull(value)){
- value.getCreateTime().set(System.currentTimeMillis());
+ CacheValue value = localCache.get(key);
+ if (Objects.nonNull(value)) {
+ value.setCreateTime(System.currentTimeMillis());
}
}
/**
* 清理过期对象
*/
- private synchronized static void startClearThread() {
+ private synchronized void startClearThread() {
if (CLEAR_THREAD_STATUS == 0) {
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("demo-pool-%d").build();
@@ -139,10 +194,10 @@
CLEAR_THREAD_STATUS = 1;
while (true) {
try {
- Set<Map.Entry<String, Value>> entries = localCache.entrySet();
- Iterator<Map.Entry<String, Value>> iterator = entries.iterator();
+ Set<Map.Entry<String, CacheValue>> entries = localCache.entrySet();
+ Iterator<Map.Entry<String, CacheValue>> iterator = entries.iterator();
while (iterator.hasNext()) {
- Map.Entry<String, Value> next = iterator.next();
+ Map.Entry<String, CacheValue> next = iterator.next();
if (next.getValue().timeOut == 0) {
continue;
@@ -150,9 +205,14 @@
boolean isTimeOut = (System.currentTimeMillis() - next.getValue().getCreateTime().longValue()) > next.getValue().timeOut;
if (isTimeOut) {
- Value removed = localCache.remove(next.getKey());
- LogUtil.debug("清除过期对象:{}", removed.value);
+ CacheValue removed = remove(next.getKey());
+ LogUtil.debug("清除过期对象:{}", removed.cacheValue);
}
+ }
+ if(CollUtil.isNotEmpty(deadCache)){
+ LogUtil.debug("删除数据库中的缓存:{}",deadCache);
+ sysCacheValueDao.deleteBatchIds(deadCache);
+ deadCache.clear();
}
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -166,49 +226,94 @@
}
}
+ /**
+ * 缓存对象写入磁盘
+ */
+ private synchronized void startSaveStoreThread() {
- private static Value buildValue(String key, Object value) {
+ ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
+ .setNameFormat("startSaveStoreThread-pool-%d").build();
+ ExecutorService singleThreadPool = new ThreadPoolExecutor(1, 1,
+ 0L, TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<Runnable>(1), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
+ singleThreadPool.execute(() -> {
+ try {
+ while (true){
+ Collection<CacheValue> values = localCache.values();
+ List<CacheValue> notSavedList = values.stream().filter(v -> !v.saved).collect(Collectors.toList());
+ if(CollUtil.isNotEmpty(notSavedList)){
+ List<String> collect = notSavedList.stream().map(e -> e.getCacheKey()).collect(Collectors.toList());
+ sysCacheValueDao.delete(new LambdaQueryWrapper<SysCacheValue>().in(SysCacheValue::getCacheKey,collect));
+ notSavedList.forEach(e->{
+ e.setSaved(true);
+ SysCacheValue sysCacheValue = buildSysCacheValue(e);
+ sysCacheValueDao.insert(sysCacheValue);
+ e.setId(sysCacheValue.getId());
+ LogUtil.debug("持久化缓存对象:{}",e.getCacheKey());
+ });
+ }
+ Thread.sleep(1000);
+ }
+ } catch (Exception e) {
+ LogUtil.error("存储缓存对象线程异常停止", e);
+ }
+ });
+
+
+ }
+
+ private SysCacheValue buildSysCacheValue(CacheValue e) {
+ SysCacheValue cacheValue=new SysCacheValue();
+ BeanUtil.copyProperties(e,cacheValue);
+ return cacheValue;
+ }
+
+
+ private static CacheValue buildValue(String key, Object value) {
return buildValue(key, value, 0);
}
- private static Value buildValue(String key, Object value, long timeOut) {
- Value instances = new Value();
- instances.createTime = new AtomicLong(System.currentTimeMillis());
- instances.key = key;
- instances.value = value;
+ private static CacheValue buildValue(String key, Object value, long timeOut) {
+ CacheValue instances = new CacheValue();
+ instances.createTime = System.currentTimeMillis();
+ instances.cacheKey = key;
+ instances.cacheValue = JSON.toJSONString(value);
instances.timeOut = timeOut;
return instances;
}
-
-
/**
* 缓存对象
*/
@Data
- static class Value {
+ static class CacheValue {
+
+ private Long id ;
/**
* 过期时间,0 表示不过期,单位毫秒
*/
- private long timeOut = 0;
+ private Long timeOut = 0L;
+
/**
* 缓存key
*/
- private String key;
+ private String cacheKey;
/**
* 缓存值
*/
- private Object value;
+ private String cacheValue;
/**
* 缓存创建时间
*/
- private AtomicLong createTime;
+ private Long createTime;
+ private boolean saved=false;
+ private boolean live=true;
}
diff --git a/zq-erp/src/main/java/com/matrix/system/common/interceptor/HostInterceptor.java b/zq-erp/src/main/java/com/matrix/system/common/interceptor/HostInterceptor.java
index 7effc67..c4694a2 100644
--- a/zq-erp/src/main/java/com/matrix/system/common/interceptor/HostInterceptor.java
+++ b/zq-erp/src/main/java/com/matrix/system/common/interceptor/HostInterceptor.java
@@ -1,5 +1,6 @@
package com.matrix.system.common.interceptor;
+import com.alibaba.fastjson.TypeReference;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
@@ -47,7 +48,7 @@
return false;
}
- Map<String, SysCompany> companyMap = LocalCache.get("companyMap");
+ Map<String, SysCompany> companyMap = LocalCache.get("companyMap",new TypeReference<Map<String, SysCompany>>(){});
SysCompany company=companyMap.get(host);
if(Objects.nonNull(company)){
// 查到公司后存到sesssion中
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/action/ProjUseController.java b/zq-erp/src/main/java/com/matrix/system/hive/action/ProjUseController.java
index a3883d9..6921eb5 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/action/ProjUseController.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/action/ProjUseController.java
@@ -1,5 +1,6 @@
package com.matrix.system.hive.action;
+import cn.hutool.core.util.StrUtil;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
@@ -19,6 +20,7 @@
import com.matrix.system.hive.service.MoneyCardUseService;
import com.matrix.system.hive.service.SysProjUseService;
import com.matrix.system.hive.service.SysProjuseFreezeService;
+import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
@@ -328,7 +330,7 @@
Object tel = objects.get(1);
if (tel != null) {
String telStr = tel.toString();
- SysVipInfo vipInfo = vipInfoDao.selectByPhone(telStr,sysUsers.getCompanyId());
+ SysVipInfo vipInfo = vipInfoDao.selectByPhone(StrUtil.trim(telStr),sysUsers.getCompanyId());
if (vipInfo == null) {
vipInfo = new SysVipInfo();
vipInfo.setShopId(sysUsers.getShopId());
@@ -385,7 +387,7 @@
Object tel = objects.get(1);
if (tel != null) {
String telStr = tel.toString();
- SysVipInfo vipInfo = vipInfoDao.selectByPhone(telStr,sysUsers.getCompanyId());
+ SysVipInfo vipInfo = vipInfoDao.selectByPhone(StrUtil.trim(telStr),sysUsers.getCompanyId());
if (vipInfo == null) {
vipInfo = new SysVipInfo();
vipInfo.setShopId(sysUsers.getShopId());
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/action/ServiceRecordController.java b/zq-erp/src/main/java/com/matrix/system/hive/action/ServiceRecordController.java
index 0e45975..0dd9357 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/action/ServiceRecordController.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/action/ServiceRecordController.java
@@ -32,7 +32,7 @@
@RequestMapping(value = "/showAllList")
public @ResponseBody
- AjaxResult showAllList(ServiceRecord serviceRecord, PaginationVO pageVo) {
+ AjaxResult showAllList(ServiceRecord serviceRecord, PaginationVO pageVo) {
if (!getMe().getShopRole().equals(Dictionary.FLAG_YES_Y)) {
serviceRecord.setShopId(getMe().getShopId());
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/dao/ShoppingGoodsDao.java b/zq-erp/src/main/java/com/matrix/system/hive/dao/ShoppingGoodsDao.java
index cc06823..4116c43 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/dao/ShoppingGoodsDao.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/dao/ShoppingGoodsDao.java
@@ -90,7 +90,7 @@
int selectShopppingGoodsAipTotal(@Param("record") ShoppingGoodsListDto shoppingGoodsListDto);
- public List<ShoppingGoods> selectByIds(@Param("ids")List<Integer> ids);
+ public List<ShoppingGoods> selectByIds(@Param("ids")List<Long> ids);
int updateInvalidProduct();
}
\ No newline at end of file
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/dao/SysShopInfoDao.java b/zq-erp/src/main/java/com/matrix/system/hive/dao/SysShopInfoDao.java
index f2e7153..448fab0 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/dao/SysShopInfoDao.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/dao/SysShopInfoDao.java
@@ -30,7 +30,8 @@
public int selectTotalRecord(@Param("record") SysShopInfo sysShopInfo);
public SysShopInfo selectById(Long id);
-
+
+
public SysShopInfo selectByShopName(@Param("shopName") String shopName);
public List<SysShopInfo> selectShopInfo(Long companyId);
diff --git a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
index e13f1f9..a9adf31 100644
--- a/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
@@ -1,5 +1,6 @@
package com.matrix.system.hive.service.imp;
+import cn.hutool.core.collection.CollUtil;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
@@ -33,6 +34,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
/**
@@ -59,16 +62,11 @@
-
-
-
-
@Override
@Transactional(rollbackFor = Exception.class)
public int add(ShoppingGoods shoppingGoods) {
SysUsers sysUsers = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
SysShopInfo shopInfo = shopInfoDao.selectById(sysUsers.getShopId());
-
if(shopInfo.getShopType()==SysShopInfo.SHOP_TYPE_ZONGBU){
@@ -78,10 +76,14 @@
}
shoppingGoods.setShopId(sysUsers.getShopId());
- // 校验去重
- if (serviceUtil.addCheckRepeatTowColumn("shopping_goods",
- "code", shoppingGoods.getCode(),
- "company_id", shoppingGoods.getCompanyId())) {
+
+ //去重查询
+ ShoppingGoods queryGoods=new ShoppingGoods();
+ queryGoods.setCompanyId(shoppingGoods.getCompanyId());
+ queryGoods.setCode(shoppingGoods.getCode());
+ queryGoods.setIsDel(ShoppingGoods.NORMAL);
+ List<ShoppingGoods> oldGoods=shoppingGoodsDao.selectByModel(queryGoods);
+ if(CollUtil.isNotEmpty(oldGoods)){
throw new GlobleException("编号" + shoppingGoods.getCode() + "重复");
}
@@ -242,6 +244,17 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int remove(List<Long> list) {
+ SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
+ SysShopInfo zbShop = shopInfoDao.selectZbShop(user.getCompanyId());
+ //非总部员工只能删除自己门店的产品
+ if(user.getShopId()!=zbShop.getId()){
+ //校验是否可以删除
+ List<ShoppingGoods> dataList = shoppingGoodsDao.selectByIds(list);
+ List<ShoppingGoods> collect = dataList.stream().filter(goods -> !Objects.equals(user.getShopId(), goods.getShopId())).collect(Collectors.toList());
+ if(CollUtil.isNotEmpty(collect)){
+ throw new GlobleException("非总部员工只能删除自己门店的产品");
+ }
+ }
return shoppingGoodsDao.deleteByIds(list);
}
diff --git a/zq-erp/src/main/resources/config/application-local.properties b/zq-erp/src/main/resources/config/application-local.properties
index 20398bb..79bc8fe 100644
--- a/zq-erp/src/main/resources/config/application-local.properties
+++ b/zq-erp/src/main/resources/config/application-local.properties
@@ -1,8 +1,8 @@
#数据库链接
-spring.datasource.username=ct_test
-spring.datasource.password=123456
-spring.datasource.url=jdbc:mysql://120.27.238.55:3306/hive_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
+spring.datasource.username=root
+spring.datasource.password=root
+spring.datasource.url=jdbc:mysql://127.0.0.1:3306/md_test_local?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
#是否启用debug模式
@@ -15,6 +15,9 @@
#文件保存地址
file_storage_path= D:\\webresources\\uploadeFile\\
+local.cache.path= D:\\webresources\\uploadeFile\\
+
+
#微信支付调试开关
wx_pay_debug_onoff = false
diff --git a/zq-erp/src/main/resources/config/application.properties b/zq-erp/src/main/resources/config/application.properties
index 7ab9f40..af40963 100644
--- a/zq-erp/src/main/resources/config/application.properties
+++ b/zq-erp/src/main/resources/config/application.properties
@@ -1,5 +1,5 @@
-spring.profiles.active=meidu
+spring.profiles.active=local
evn=dev
server.port=8080
diff --git a/zq-erp/src/main/resources/mybatis/mapper/hive/SysShopInfoDao.xml b/zq-erp/src/main/resources/mybatis/mapper/hive/SysShopInfoDao.xml
index a5cb67d..3cf87c3 100644
--- a/zq-erp/src/main/resources/mybatis/mapper/hive/SysShopInfoDao.xml
+++ b/zq-erp/src/main/resources/mybatis/mapper/hive/SysShopInfoDao.xml
@@ -310,5 +310,12 @@
<select id="selectZbShop" resultMap="SysShopInfoMap">
select * from sys_shop_info where shop_type=1 and company_id=#{companyId}
</select>
+ <select id="selectByIds" resultType="com.matrix.system.hive.bean.SysShopInfo">
+ select * from sys_shop_info where ID in
+ <foreach collection="list" index="index" item="item" open="("
+ separator="," close=")">
+ #{item}
+ </foreach>
+ </select>
</mapper>
\ No newline at end of file
diff --git a/zq-erp/src/main/resources/templates/views/admin/hive/products/shoppinggoods-zb-list.html b/zq-erp/src/main/resources/templates/views/admin/hive/products/shoppinggoods-zb-list.html
index a9e5af4..f25d4f5 100644
--- a/zq-erp/src/main/resources/templates/views/admin/hive/products/shoppinggoods-zb-list.html
+++ b/zq-erp/src/main/resources/templates/views/admin/hive/products/shoppinggoods-zb-list.html
@@ -17,17 +17,11 @@
<body class=" container-fluid">
<div class="pd-10">
- <div class="row" >
- <a th:href="@{/admin/redirect/hive/products/shoppinggoods-zb-list}" class="btn btn-info " type="button"></i>总部产品</a>
- <a th:href="@{/admin/redirect/hive/products/shoppinggoods-md-list}" class="btn btn-default " type="button"></i>本店产品</a>
-
- </div>
<!-- 搜索框部分start -->
<div class="row form-head">
<form class="form-inline" id="serchform">
<input autocomplete="off" type="hidden" name="salePlatform" value="线下">
- <input autocomplete="off" type="hidden" name="headquarters" value="1">
<div class="form-group mr-20">
<label for="name">商品名称</label>
<input class="form-control " name="name" id="name">
@@ -83,6 +77,15 @@
</select>
</div>
+ <div class="form-group mr-20">
+ <label for=" ">是否总部产品</label>
+ <select class="form-control" name="headquarters" id=" ">
+ <option value=''>--请选择--</option>
+ <option value='1'>是</option>
+ <option value='2'>否</option>
+ </select>
+ </div>
+
<div class="form-group mr-20">
<label>商品创建日期</label>
@@ -103,6 +106,9 @@
<div class="row mt-10">
<div id="option-bar">
<button matrix:btn="shoppinggoods1-add" onclick="openEdit()" type="button" class="btn btn-info btn-sm"><i class="fa fa-eye" ></i> 查看</button>
+ <button matrix:btn="shoppinggoods1-add" onclick="openAdd()" type="button" class="btn btn-info btn-sm"><i class="fa fa-plus" ></i> 新增</button>
+ <button matrix:btn="shoppinggoods1-edit" onclick="openEdit()" type="button" class="btn btn-info btn-sm"><i class="fa fa-edit" ></i> 编辑</button>
+ <button matrix:btn="shoppinggoods1-dels" onclick="myGrid.delItems()" type="button" class="btn btn-danger btn-sm"><i class="fa fa-trash" ></i>批量删除</button>
<button matrix:btn="shoppinggoods1-add" onclick="exportExcel()" type="button" class="btn btn-default btn-sm"><i class="fa fa-download"></i>导出 </button>
</div>
<!-- 数据表格部分 -->
@@ -120,7 +126,7 @@
<th data-field="isPresent">是否赠送</th>
<th data-field="goodType" data-sortable="true">类型</th>
<th data-field="cateName" >分类</th>
- <th data-field="achieveRuleName" >业绩规则</th>
+ <th data-field="shopName" >创建门店</th>
<th data-field="createTime" data-sortable="true" data-formatter="MGrid.getTime">创建时间</th>
</tr>
</thead>
--
Gitblit v1.9.1