完善优化代码(可能出错)
parent
88e5b9ad2c
commit
c73812a09f
@ -1,3 +1,3 @@
|
||||
/target/
|
||||
target
|
||||
/.idea/
|
||||
power.iml
|
||||
*.iml
|
@ -1,65 +0,0 @@
|
||||
package com.manage.interfaces.cache;
|
||||
|
||||
/**
|
||||
* @Description 缓存DTO
|
||||
* @Date 2019/7/2 11:41
|
||||
* @Created by ljx
|
||||
*/
|
||||
public class Cache {
|
||||
private String key;//缓存ID
|
||||
private Object value;//缓存数据
|
||||
private long timeOut;//更新时间
|
||||
private boolean expired; //是否终止
|
||||
public Cache() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Cache(String key, Object value, long timeOut, boolean expired) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.timeOut = timeOut;
|
||||
this.expired = expired;
|
||||
}
|
||||
|
||||
public Cache(String key, Object value, long timeOut) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.timeOut = timeOut;
|
||||
}
|
||||
public Cache(String key, Object value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getTimeOut() {
|
||||
return timeOut;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setKey(String string) {
|
||||
key = string;
|
||||
}
|
||||
|
||||
public void setTimeOut(long l) {
|
||||
timeOut = l;
|
||||
}
|
||||
|
||||
public void setValue(Object object) {
|
||||
value = object;
|
||||
}
|
||||
|
||||
public boolean isExpired() {
|
||||
return expired;
|
||||
}
|
||||
|
||||
public void setExpired(boolean b) {
|
||||
expired = b;
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
package com.manage.interfaces.cache;
|
||||
|
||||
import com.manage.vo.Power_UserVo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class CacheManager {
|
||||
private static HashMap cacheMap = new HashMap();
|
||||
|
||||
private CacheManager() {
|
||||
super();
|
||||
}
|
||||
public static boolean getSimpleFlag(String key){
|
||||
try{
|
||||
return (Boolean) cacheMap.get(key);
|
||||
}catch(NullPointerException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static long getServerStartdt(String key){
|
||||
try {
|
||||
return (Long)cacheMap.get(key);
|
||||
} catch (Exception ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public synchronized static boolean setSimpleFlag(String key,boolean flag){
|
||||
if (flag && getSimpleFlag(key)) {
|
||||
return false;
|
||||
}else{
|
||||
cacheMap.put(key, flag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public synchronized static boolean setSimpleFlag(String key,long serverbegrundt){
|
||||
if (cacheMap.get(key) == null) {
|
||||
cacheMap.put(key,serverbegrundt);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized static Cache getCache(String key) {
|
||||
return (Cache) cacheMap.get(key);
|
||||
}
|
||||
|
||||
private synchronized static boolean hasCache(String key) {
|
||||
return cacheMap.containsKey(key);
|
||||
}
|
||||
|
||||
public synchronized static void clearAll() {
|
||||
cacheMap.clear();
|
||||
}
|
||||
|
||||
public synchronized static void clearAll(String type) {
|
||||
Iterator i = cacheMap.entrySet().iterator();
|
||||
String key;
|
||||
ArrayList<String> arr = new ArrayList<String>();
|
||||
try {
|
||||
while (i.hasNext()) {
|
||||
java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
|
||||
key = (String) entry.getKey();
|
||||
if (key.startsWith(type)) {
|
||||
arr.add(key);
|
||||
}
|
||||
}
|
||||
for (int k = 0; k < arr.size(); k++) {
|
||||
clearOnly(arr.get(k));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static void clearOnly(String key) {
|
||||
cacheMap.remove(key);
|
||||
}
|
||||
|
||||
public synchronized static void putCache(String key, Cache obj) {
|
||||
cacheMap.put(key, obj);
|
||||
}
|
||||
|
||||
public static Cache getCacheInfo(String key) {
|
||||
|
||||
if (hasCache(key)) {
|
||||
Cache cache = getCache(key);
|
||||
if (cacheExpired(cache)) {
|
||||
cache.setExpired(true);
|
||||
}
|
||||
return cache;
|
||||
}else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void putCacheInfo(String key, Cache obj, long dt,boolean expired) {
|
||||
Cache cache = new Cache();
|
||||
cache.setKey(key);
|
||||
cache.setTimeOut(dt + System.currentTimeMillis());
|
||||
cache.setValue(obj);
|
||||
cache.setExpired(expired);
|
||||
cacheMap.put(key, cache);
|
||||
}
|
||||
public static void putCacheInfo(String key,Cache obj,long dt){
|
||||
Cache cache = new Cache();
|
||||
cache.setKey(key);
|
||||
cache.setTimeOut(dt+System.currentTimeMillis());
|
||||
cache.setValue(obj);
|
||||
cache.setExpired(false);
|
||||
cacheMap.put(key,cache);
|
||||
}
|
||||
|
||||
public static boolean cacheExpired(Cache cache) {
|
||||
if (null == cache) {
|
||||
return false;
|
||||
}
|
||||
long nowDt = System.currentTimeMillis();
|
||||
long cacheDt = cache.getTimeOut();
|
||||
if (cacheDt <= 0||cacheDt>nowDt) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCacheSize() {
|
||||
return cacheMap.size();
|
||||
}
|
||||
|
||||
public static int getCacheSize(String type) {
|
||||
int k = 0;
|
||||
Iterator i = cacheMap.entrySet().iterator();
|
||||
String key;
|
||||
try {
|
||||
while (i.hasNext()) {
|
||||
java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
|
||||
key = (String) entry.getKey();
|
||||
if (key.indexOf(type) != -1) {
|
||||
k++;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getCacheAllkey() {
|
||||
ArrayList a = new ArrayList();
|
||||
try {
|
||||
Iterator i = cacheMap.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
|
||||
a.add((String) entry.getKey());
|
||||
}
|
||||
} catch (Exception ex) {} finally {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> getCacheListkey(String type) {
|
||||
ArrayList a = new ArrayList();
|
||||
String key;
|
||||
try {
|
||||
Iterator i = cacheMap.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
java.util.Map.Entry entry = (java.util.Map.Entry) i.next();
|
||||
key = (String) entry.getKey();
|
||||
if (key.indexOf(type) != -1) {
|
||||
a.add(key);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {} finally {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static void removeCacheByObject(Power_UserVo obj) {
|
||||
ArrayList a = new ArrayList();
|
||||
Object key;
|
||||
ArrayList<String> arr = new ArrayList<String>();
|
||||
try {
|
||||
Iterator i = cacheMap.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) i.next();
|
||||
Cache cache = CacheManager.getCacheInfo((String)entry.getKey());
|
||||
Power_UserVo o = (Power_UserVo)cache.getValue();
|
||||
if (obj.getUserName().equals(o.getUserName())) {
|
||||
arr.add((String)entry.getKey());
|
||||
}
|
||||
}
|
||||
if(null != arr && !arr.isEmpty()){
|
||||
for (int k = 0; k < arr.size(); k++) {
|
||||
clearOnly(arr.get(k));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {}
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.manage.interfaces.webservice;
|
||||
|
||||
|
||||
import com.manage.vo.PowerTree;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebService;
|
||||
import java.util.List;
|
||||
|
||||
@WebService
|
||||
public interface RoleAndUserTreeWebService {
|
||||
@WebMethod()
|
||||
List<PowerTree> getRolePowerTree();
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.manage;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @ProjectName:
|
||||
* @Description:
|
||||
* @Param 传输参数
|
||||
* @Return
|
||||
* @Author: 曾文和
|
||||
* @CreateDate: 2019/11/28 11:42
|
||||
* @UpdateUser: 曾文和
|
||||
* @UpdateDate: 2019/11/28 11:42
|
||||
* @UpdateRemark: 更新说明
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class test {
|
||||
public static void main(String[] args) throws Exception{
|
||||
String str = "temperature_stat.htm";
|
||||
readfile(str);
|
||||
}
|
||||
public static String readfile(String filePath){
|
||||
File file = new File(filePath);
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = new FileInputStream(file);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
byte[] bytes = new byte[1024];
|
||||
try {
|
||||
for(int n ; (n = input.read(bytes))!=-1 ; ){
|
||||
buffer.append(new String(bytes,0,n,"GBK"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int i = buffer.toString().lastIndexOf("</TD>");
|
||||
String substring = buffer.substring(0, i);
|
||||
String substring1 = substring.substring(substring.length() - 4, substring.length());
|
||||
Float f = Float.valueOf(substring1);
|
||||
Math.round(f);
|
||||
System.out.println(substring1);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String getBody(String val) {
|
||||
String start = "<body>";
|
||||
String end = "</body>";
|
||||
int s = val.indexOf(start) + start.length();
|
||||
int e = val.indexOf(end);
|
||||
return val.substring(s, e);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
log4j.logger.myLog=debug,myLog
|
||||
log4j.appender.myLog=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.myLog.File=D:\\logs\\power\\info\\info_log
|
||||
log4j.appender.myLog.DatePattern=-yyyy-MM-dd'.log'
|
||||
log4j.appender.myLog.Append = true
|
||||
log4j.appender.myLog.Threshold = INFO
|
||||
log4j.appender.myLog.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.myLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
|
||||
|
||||
log4j.logger.errorMsg=error,errorMsg
|
||||
log4j.appender.errorMsg=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.errorMsg.File=D:\\logs\\power\\error\\error_log
|
||||
log4j.appender.errorMsg.DatePattern=-yyyy-MM-dd'.log'
|
||||
log4j.appender.errorMsg.Append = true
|
||||
log4j.appender.errorMsg.Threshold = error
|
||||
log4j.appender.errorMsg.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.errorMsg.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:%m%n
|
||||
|
@ -1,48 +0,0 @@
|
||||
package com.manage;
|
||||
|
||||
import com.manage.dao.Power_MenuMapper;
|
||||
import com.manage.dao.T_MenuMapper;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
public class MapperTest {
|
||||
/**
|
||||
* 测试角色mapper
|
||||
*/
|
||||
public static void main(String[] arg){
|
||||
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
|
||||
Client client = dcf.createClient("http://192.168.1.3:8081/WebService/PowerWebService?wsdl");
|
||||
Object[] objects = new Object[0];
|
||||
String error = null;
|
||||
try {
|
||||
// invoke("方法名",参数1,参数2,参数3....);
|
||||
objects = client.invoke("getInfosByUserId",token,"0");
|
||||
Result result = JSON.parseObject(objects[0].toString()
|
||||
, new TypeReference<Result>() {});
|
||||
String permStrs = "";
|
||||
if(null != result.getPowerMenuList() && !result.getPowerMenuList().isEmpty()){
|
||||
for (Power_Menu p: result.getPowerMenuList()) {
|
||||
if(StringUtils.isNoneBlank(p.getMenuName())){
|
||||
permStrs+=p.getMenuName() + ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
Power_User powerUser = result.getPowerUser();
|
||||
if(powerUser != null){
|
||||
Power_User admin = (Power_User)SecurityUtils.getSubject().getPrincipal();
|
||||
UserToken userToken = new UserToken(powerUser.getUserName(),powerUser.getUserPwd(),true,powerUser.getRoleId(),permStrs);
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
subject.login(userToken);
|
||||
}
|
||||
String msg = "";
|
||||
if (error != null) {//出错了,返回登录页面
|
||||
return "redirect://http:192.168.1.3:8080/login";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
CREATE VIEW power_user_dict AS
|
||||
SELECT
|
||||
`power_user`.`user_id` AS `user_id`,
|
||||
`power_dept`.`dict_id` AS `dict_id`
|
||||
FROM
|
||||
((
|
||||
`power_user`
|
||||
JOIN `mysql`.`help_topic` `b` ON ((
|
||||
`b`.`help_topic_id` < (( length( `power_user`.`dept_id` ) - length( REPLACE ( `power_user`.`dept_id`, _latin1 ',', _latin1 '' ))) + 1 ))))
|
||||
LEFT JOIN `power_dept` ON ((
|
||||
`power_dept`.`dept_id` = `power_user`.`dept_id`
|
||||
)))
|
||||
GROUP BY
|
||||
`power_user`.`user_id`
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@
|
||||
package com.manage.util;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* @ProjectName:
|
||||
* @Description:
|
||||
* @Param 传输参数
|
||||
* @Return
|
||||
* @Author: 曾文和
|
||||
* @CreateDate: 2020/8/4 14:18
|
||||
* @UpdateUser: 曾文和
|
||||
* @UpdateDate: 2020/8/4 14:18
|
||||
* @UpdateRemark: 更新说明
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ExceptionPrintUtil {
|
||||
private static Logger log = Logger.getLogger("errorMsg");
|
||||
public static void printException(Exception e){
|
||||
//方法名
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
e.printStackTrace(new PrintStream(baos));
|
||||
String exception = baos.toString();
|
||||
log.error(exception);
|
||||
try {
|
||||
baos.flush();
|
||||
baos.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.manage;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
System.out.println( "Hello World!" );
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue