Commit facdeac3 authored by 赵啸非's avatar 赵啸非

修改设备新增

parent 55747c41
...@@ -123,3 +123,6 @@ INSERT INTO `mortals_xhx_param` VALUES (null, '日志类型,', 'DeviceLog', 'l ...@@ -123,3 +123,6 @@ INSERT INTO `mortals_xhx_param` VALUES (null, '日志类型,', 'DeviceLog', 'l
INSERT INTO `mortals_xhx_param` VALUES (null, '设备来源,为其它时候上线下线通过查询', 'Device', 'deviceSource', '0', '大厅', 1, 4, 0, 'deviceSource', NULL, NULL, NULL); INSERT INTO `mortals_xhx_param` VALUES (null, '设备来源,为其它时候上线下线通过查询', 'Device', 'deviceSource', '0', '大厅', 1, 4, 0, 'deviceSource', NULL, NULL, NULL);
INSERT INTO `mortals_xhx_param` VALUES (null, '设备来源,为其它时候上线下线通过查询', 'Device', 'deviceSource', '1', '其它', 1, 4, 0, 'deviceSource', NULL, NULL, NULL); INSERT INTO `mortals_xhx_param` VALUES (null, '设备来源,为其它时候上线下线通过查询', 'Device', 'deviceSource', '1', '其它', 1, 4, 0, 'deviceSource', NULL, NULL, NULL);
INSERT INTO `mortals_xhx_param` VALUES (null, '设备类型', 'Device', 'deviceType', '13', '无感一码通', 1, 4, 0, 'deviceType', NULL, NULL, NULL);
...@@ -34,12 +34,12 @@ export default { ...@@ -34,12 +34,12 @@ export default {
}, },
loginFail(error) { loginFail(error) {
this.$message.error(error.message || '请登录'); this.$message.error(error.message || '请登录');
// this.$router.replace({ this.$router.replace({
// path: '/login', path: '/login',
// query: { query: {
// redirect: this.redirect, redirect: this.redirect,
// } }
// }); });
}, },
getUrlKey (name) { getUrlKey (name) {
......
package com.mortals.xhx.base.system.param.service.impl; package com.mortals.xhx.base.system.param.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.code.YesNo;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.IParam; import com.mortals.framework.service.IParam;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils; import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.param.dao.ParamDao; import com.mortals.xhx.base.system.param.dao.ParamDao;
import com.mortals.xhx.base.system.param.model.ParamEntity; import com.mortals.xhx.base.system.param.model.ParamEntity;
import com.mortals.xhx.base.system.param.model.ParamQuery;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.Arrays;
...@@ -32,69 +27,43 @@ import java.util.stream.Collectors; ...@@ -32,69 +27,43 @@ import java.util.stream.Collectors;
@Service("paramService") @Service("paramService")
public class ParamServiceImpl extends AbstractCRUDCacheServiceImpl<ParamDao, ParamEntity, Long> public class ParamServiceImpl extends AbstractCRUDCacheServiceImpl<ParamDao, ParamEntity, Long>
implements ParamService { implements ParamService {
@Override
protected String getExtKey(ParamEntity data) {
return data.getParamKey();
}
@Override @Override
protected String getCacheName() { protected String getCacheName() {
return "ParamEntity.paramKey"; return "ParamEntity.paramKey";
} }
@Override
public void putCache(String key, ParamEntity data) {
cacheService.set(data.getParamKey(), data.getParamValue());
}
@Override
public void removeCache(String key) {
}
@Override
public int remove(Long[] ids, Context context) throws AppException {
// 先删缓存
for (Long id : ids) {
ParamEntity paramEntity = get(id, null);
cacheService.del(paramEntity.getParamKey());
}
removeBefore(ids, context);
int iRet = dao.delete(ids);
removeAfter(ids, context, iRet);
return iRet;
}
@Override @Override
public String getValueByKey(String key) { public String getValueByKey(String key) {
return cacheService.get(key); List<ParamEntity> list = this.getCacheList();
Map<String, String> keyValueMap = list.parallelStream().collect(Collectors.toMap(x -> x.getParamKey(), y -> y.getParamValue(), (o, n) -> n));
return keyValueMap.getOrDefault(key, "");
} }
@Override @Override
public Map<String, String> getParamByFirstOrganize(String firstOrganize, String... excludeParamKeys) { public Map<String, String> getParamByFirstOrganize(String firstOrganize, String... excludeParamKeys) {
ParamQuery query = new ParamQuery(); List<ParamEntity> list = this.getCacheList();
query.setFirstOrganize(firstOrganize); return list.stream()
List<ParamEntity> list = this.getDao().getList(query); .filter(f -> firstOrganize.equals(f.getFirstOrganize()))
return list.stream().filter(s -> { .filter(s ->
return !Arrays.asList(excludeParamKeys).contains(s.getParamKey()); !Arrays.asList(excludeParamKeys).contains(s.getParamKey())
}).collect(Collectors.toMap(ParamEntity::getParamKey, ParamEntity::getParamValue)); ).collect(Collectors.toMap(ParamEntity::getParamKey, ParamEntity::getParamValue, (o, n) -> n));
} }
public Map<String, String> getParamBySecondOrganize(String firstOrganize, String secondOrganize, String... excludeParamKeys) { public Map<String, String> getParamBySecondOrganize(String firstOrganize, String secondOrganize, String... excludeParamKeys) {
ParamQuery query = new ParamQuery(); List<ParamEntity> list = this.getCacheList();
query.setFirstOrganize(firstOrganize); return list.stream()
query.setSecondOrganize(secondOrganize); .filter(f -> firstOrganize.equals(f.getFirstOrganize()))
List<ParamEntity> list = this.getDao().getList(query); .filter(f -> secondOrganize.equals(f.getSecondOrganize()))
return list.stream().filter(s -> { .filter(s ->
return !Arrays.asList(excludeParamKeys).contains(s.getParamKey()); !Arrays.asList(excludeParamKeys).contains(s.getParamKey())
}).collect(Collectors.toMap(ParamEntity::getParamKey, ParamEntity::getParamValue)); ).collect(Collectors.toMap(ParamEntity::getParamKey, ParamEntity::getParamValue, (o, n) -> n));
} }
@Override @Override
public boolean needRefresh() { public boolean needRefresh() {
if (super.cacheService.isShareCache())//共享缓存,不需要实时刷新 if (super.cacheService.isShareCache()) {
{ //共享缓存如redis,不需要实时刷新
return false; return false;
} }
IParam param = this.findByKey(IParam.KEY_PARAM_REFRESH_COUNT); IParam param = this.findByKey(IParam.KEY_PARAM_REFRESH_COUNT);
...@@ -122,187 +91,91 @@ public class ParamServiceImpl extends AbstractCRUDCacheServiceImpl<ParamDao, Par ...@@ -122,187 +91,91 @@ public class ParamServiceImpl extends AbstractCRUDCacheServiceImpl<ParamDao, Par
@Override @Override
public IParam findByKey(String key) throws AppException { public IParam findByKey(String key) throws AppException {
ParamQuery params = new ParamQuery(); return this.getCacheList().stream().filter(f -> key.equals(f.getParamKey())).findFirst().orElseGet(() -> null);
params.setValidStatus(YesNo.YES.getValue());
params.setParamKey(key);
List<ParamEntity> list = super.find(params, null);
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
} }
@Override @Override
public List<? extends IParam> findAll() throws AppException { public List<? extends IParam> findAll() throws AppException {
ParamQuery params = new ParamQuery(); return this.getCacheList();
params.setValidStatus(YesNo.YES.getValue());
return super.find(params, null);
} }
@Override @Override
public boolean containsParamKey(String key) { public boolean containsParamKey(String key) {
return cacheService.hget(getCacheName(), key) != null; List<ParamEntity> list = this.getCacheList();
Map<String, String> keyValueMap = list.parallelStream().collect(Collectors.toMap(x -> x.getParamKey(), y -> y.getParamValue(), (o, n) -> n));
return keyValueMap.containsKey(key);
} }
@Override @Override
public IParam getParamByKey(String key) { public IParam getParamByKey(String key) {
return getExtCache(key); List<ParamEntity> list = this.getCacheList();
Map<String, IParam> keyValueMap = list.parallelStream().collect(Collectors.toMap(x -> x.getParamKey(), y -> y, (o, n) -> n));
return keyValueMap.get(key);
} }
@Override @Override
public String getParamValue(String key) { public String getParamValue(String key) {
String hget = cacheService.hget(getCacheName(), key); List<ParamEntity> list = this.getCacheList();
Map<String, String> keyValueMap = list.parallelStream().collect(Collectors.toMap(x -> x.getParamKey(), y -> y.getParamValue(), (o, n) -> n));
if (StringUtils.isEmpty(hget))return ""; return keyValueMap.getOrDefault(key, "");
IParam param = wrapParamObject(hget);
// IParam param = getExtCache(key);
if (param != null) {
return StringUtils.trim(param.getParamValue());
}
return "";
} }
private IParam wrapParamObject(String entityString) {
JSONObject jsonObject = JSON.parseObject(entityString);
ParamEntity param = new ParamEntity();
param.setCreateTime(jsonObject.getDate("createTime"));
param.setCreateUserId(jsonObject.getLong("createUserId"));
param.setDisplayType(jsonObject.getInteger("displayType"));
param.setFirstOrganize(jsonObject.getString("firstOrganize"));
param.setId(jsonObject.getLong("id"));
param.setModStatus(jsonObject.getInteger("modStatus"));
param.setName(jsonObject.getString("name"));
param.setParamKey(jsonObject.getString("paramKey"));
param.setParamValue(jsonObject.getString("paramValue"));
param.setValidStatus(jsonObject.getInteger("validStatus"));
return param;
}
@Override @Override
public String getParamValue(String key, String defaultValue) { public String getParamValue(String key, String defaultValue) {
if (containsParamKey(key)) { String value = getParamValue(key);
String value = getParamValue(key); if (StringUtils.isEmpty(value)) {
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
return value;
} else {
log.debug("cannot found key[" + key + "], use default value[" + defaultValue + "]");
return defaultValue; return defaultValue;
} }
return value;
} }
@Override @Override
public int getParamIntValue(String key) { public int getParamIntValue(String key) {
ParamEntity extCache = getExtCache(key); return DataUtil.converStr2Int(getParamValue(key), 0);
IParam param = extCache;
try {
if (param == null) {
return 0;
}
String value = param.getParamValue();
if (StringUtils.isEmpty(value)) {
return 0;
} else {
return Integer.parseInt(value);
}
} catch (Exception e) {
return 0;
}
} }
@Override @Override
public int getParamIntValue(String key, int defaultValue) { public int getParamIntValue(String key, int defaultValue) {
if (containsParamKey(key)) { return DataUtil.converStr2Int(getParamValue(key), defaultValue);
String value = getParamValue(key);
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
try {
return Integer.parseInt(value);
} catch (Exception e) {
log.debug("cannot conver key[" + key + "]'s value[" + value + "] to int, use default value[" + defaultValue + "]");
return defaultValue;
}
} else {
log.debug("cannot found key[" + key + "], use default value[" + defaultValue + "]");
return defaultValue;
}
} }
@Override @Override
public long getParamLongValue(String key) { public long getParamLongValue(String key) {
IParam param = getExtCache(key); return DataUtil.converStr2Long(getParamValue(key), 0L);
try {
if (param == null) {
return 0;
}
String value = param.getParamValue();
if (StringUtils.isEmpty(value)) {
return 0;
} else {
return Long.parseLong(value);
}
} catch (Exception e) {
return 0;
}
} }
@Override @Override
public long getParamLongValue(String key, long defaultValue) { public long getParamLongValue(String key, long defaultValue) {
if (containsParamKey(key)) { return DataUtil.converStr2Long(getParamValue(key), defaultValue);
String value = getParamValue(key);
if (StringUtils.isEmpty(value)) {
return defaultValue;
}
try {
return Long.parseLong(value);
} catch (Exception e) {
log.debug("cannot conver key[" + key + "]'s value[" + value + "] to long, use default value[" + defaultValue + "]");
return defaultValue;
}
} else {
log.debug("cannot found key[" + key + "], use default value[" + defaultValue + "]");
return defaultValue;
}
} }
@Override @Override
public boolean getParamBooleanValue(String key) { public boolean getParamBooleanValue(String key) {
IParam param = getExtCache(key); String value = getParamValue(key);
if (StringUtils.isEmpty(value)) {
return false;
}
try { try {
if (param == null) { return Boolean.parseBoolean(value);
return false;
}
String value = param.getParamValue();
if (StringUtils.isEmpty(value)) {
return false;
} else {
return Boolean.parseBoolean(value);
}
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
} }
@Override @Override
public boolean getParamBooleanValue(String key, boolean defaultValue) { public boolean getParamBooleanValue(String key, boolean defaultValue) {
if (containsParamKey(key)) { String value = getParamValue(key);
String value = getParamValue(key); if (StringUtils.isEmpty(value)) {
if (StringUtils.isEmpty(value)) { return defaultValue;
return defaultValue; }
} try {
try { return Boolean.parseBoolean(value);
return Boolean.parseBoolean(value); } catch (Exception e) {
} catch (Exception e) { log.debug("cannot conver key[" + key + "]'s value[" + value + "] to boolean, use default value[" + defaultValue + "]");
log.debug("cannot conver key[" + key + "]'s value[" + value + "] to boolean, use default value[" + defaultValue + "]");
return defaultValue;
}
} else {
log.debug("cannot found key[" + key + "], use default value[" + defaultValue + "]");
return defaultValue; return defaultValue;
} }
} }
} }
\ No newline at end of file
package com.mortals.xhx.base.system.param.web; package com.mortals.xhx.base.system.param.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.RepeatSubmit;
import com.mortals.framework.common.code.PageDisplayType; import com.mortals.framework.common.code.PageDisplayType;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.util.FileUtil; import com.mortals.framework.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.web.BaseCRUDJsonMappingController; import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.model.ParamEntity; import com.mortals.xhx.base.system.param.model.ParamEntity;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.DataSatusEnum; import com.mortals.xhx.common.code.DataSatusEnum;
import com.mortals.xhx.common.code.ModStatusEnum; import com.mortals.xhx.common.code.ModStatusEnum;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
......
...@@ -91,7 +91,7 @@ public class DeviceStatTaskImpl implements ITaskExcuteService { ...@@ -91,7 +91,7 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
* 定时清除设备日志 * 定时清除设备日志
*/ */
private void doDeviceLogDel() { private void doDeviceLogDel() {
//默认保存30天日志 //默认保存15天日志
int timeout = -GlobalSysInfo.getParamIntValue(ParamKey.SYS_PARAM_LOG_TIME, 15); int timeout = -GlobalSysInfo.getParamIntValue(ParamKey.SYS_PARAM_LOG_TIME, 15);
try { try {
DeviceLogQuery query = new DeviceLogQuery(); DeviceLogQuery query = new DeviceLogQuery();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment