Merge branch 'master' into version_1.0
This commit is contained in:
commit
7929a5d312
75
src/main/java/com/lz/common/constant/CacheConstants.java
Normal file
75
src/main/java/com/lz/common/constant/CacheConstants.java
Normal file
@ -0,0 +1,75 @@
|
||||
package com.lz.common.constant;
|
||||
|
||||
/**
|
||||
* @author yuzhong
|
||||
* @date 2017-12-20 10:46 AM
|
||||
*/
|
||||
public enum CacheConstants {
|
||||
|
||||
KEY_SYS_CONFIG("sys_config_%s", CacheConstants.DEFAULT_EXPIRE_SECOND),
|
||||
KEY_QUOTA_MAX_CONFIG("quota_max_config_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_RULE_GROUP("rule_group_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_SCENE_OWN_TABLE("rule_scene_own_table_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_RULE_ENGINE_INFO("rule_engine_info_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_RULE_ENGINE_CONFIG("rule_engine_config_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_QUOTA_MODEL("quota_model_%s_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_QUOTA_BASE_CONFIG("quota_base_config_%s", CacheConstants.SECOND_OF_TEN_MINITS),
|
||||
KEY_FAMILY_USER_DIRECTORY("family_user_directory_%s", CacheConstants.SECOND_OF_TWO_DAY),
|
||||
KEY_EVENT_MANAGE_DTO("event_manage_%s", CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
HASH_KEY_RULE_RESULT("rule_result_%s", CacheConstants.SECOND_OF_ONE_WEEK),
|
||||
KEY_TEST_USER_STATUS("test_user_status_%s",CacheConstants.SECOND_OF_ONE_WEEK),
|
||||
KEY_PHONE_ADDR_BOOK("phone_addr_book_%s",CacheConstants.SECOND_OF_HALF_HOUR),
|
||||
KEY_USER_POOL_COUNT("user_pool_count",CacheConstants.SECOND_OF_AN_HOUR),//用户池用户数量
|
||||
KEY_FINAL_USER_POOL_COUNT("final_user_pool_count",CacheConstants.SECOND_OF_AN_HOUR),//最终用户池用户数量
|
||||
KEY_USER_POOL_COUNT_FOR_LIANTONG("user_pool_count_for_liantong",CacheConstants.SECOND_OF_AN_HOUR),//用户池用户数量(联通redis用)
|
||||
KEY_USER_POOL_COUNT_FOR_LZ("user_pool_count_for_linzi",CacheConstants.SECOND_OF_AN_HOUR),//用户池用户数量(LINZIredis用)
|
||||
KEY_FINAL_USER_POOL_COUNT_FOR_LZ("final_user_pool_count_for_linzi",CacheConstants.SECOND_OF_AN_HOUR),//最终用户池用户数量
|
||||
KEY_RULE_MODEL("rule_model_%s", CacheConstants.SECOND_OF_ONE_DAY),
|
||||
KEY_RULE_TREE("rule_tree_%s_%s", CacheConstants.SECOND_OF_ONE_DAY),
|
||||
KEY_XINSHEN_PERSON_TASK("xinshen_person_task_%s", CacheConstants.SECOND_OF_ONE_YEAR),
|
||||
KEY_XINSHEN_PERSON_COUNT("xinshen_person_count_%s", CacheConstants.SECOND_OF_ONE_YEAR),
|
||||
;
|
||||
|
||||
// 单位秒
|
||||
public static final long SECOND_OF_ONE_MINITS = 1 * 60l;
|
||||
public static final long SECOND_OF_ONE = 1L;
|
||||
public static final long FIVETY_MINITS = 1 * 50l;
|
||||
public static final long SECOND_OF_THREE_MINITS = 3 * 60l;
|
||||
public static final long SECOND_OF_TEN_MINITS = 10 * 60l;
|
||||
public static final long SECOND_OF_THREE = 30l;// 30秒
|
||||
public static final long SECOND_OF_HALF_HOUR = 30 * 60l;
|
||||
public static final long SECOND_OF_AN_HOUR = 60 * 60l;
|
||||
public static final long SECOND_OF_SIX_HOUR = 6 * 60 * 60l;
|
||||
public static final long SECOND_OF_ONE_DAY = 24 * 60 * 60l;
|
||||
public static final long SECOND_OF_TWO_DAY = 2 * 24 * 60 * 60l;
|
||||
public static final long SECOND_OF_ONE_WEEK = 7 * 24 * 60 * 60l;
|
||||
public static final long SECOND_OF_TWO_WEEK = 14 * 24 * 60 * 60l;
|
||||
public static final long SECOND_OF_ONE_MONTH = 30 * 24 * 60 * 60l;
|
||||
public static final long SECOND_OF_ONE_YEAR = 12 * 30 * 24 * 60 * 60l;
|
||||
public static final long DEFAULT_EXPIRE_SECOND = SECOND_OF_SIX_HOUR;
|
||||
|
||||
private String key;
|
||||
|
||||
private long expire;
|
||||
|
||||
private CacheConstants(String key, long expire) {
|
||||
this.key = key;
|
||||
this.expire = expire;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public long getExpire() {
|
||||
return expire;
|
||||
}
|
||||
|
||||
public void setExpire(long expire) {
|
||||
this.expire = expire;
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,12 @@ public class Constant {
|
||||
/**
|
||||
* 当前页码
|
||||
*/
|
||||
|
||||
public static final long SECOND_OF_5_MINITE = 5 * 60l;// 60秒
|
||||
|
||||
public static final String PAGE = "page";
|
||||
public static final long SECOND_OF_SIXTY = 60l;// 60秒
|
||||
|
||||
/**
|
||||
* 每页显示记录数
|
||||
*/
|
||||
@ -32,6 +37,7 @@ public class Constant {
|
||||
* 排序方式
|
||||
*/
|
||||
public static final String ORDER = "order";
|
||||
public static final long SECOND_OF_THREE = 30l;// 30秒
|
||||
/**
|
||||
* 升序
|
||||
*/
|
||||
|
||||
636
src/main/java/com/lz/common/utils/RedisCacheUtil.java
Normal file
636
src/main/java/com/lz/common/utils/RedisCacheUtil.java
Normal file
@ -0,0 +1,636 @@
|
||||
package com.lz.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.lz.common.constant.CacheConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* @author yuzhong
|
||||
* @date 2017-12-20 11:07 AM
|
||||
*/
|
||||
@Component("redisCacheUtil")
|
||||
public class RedisCacheUtil {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(RedisCacheUtil.class);
|
||||
|
||||
public static boolean RISK_CACHE_SWITCH = true;//风控缓存开关,true:打开(即使用缓存) false:关闭(即不使用缓存)
|
||||
|
||||
private static final String KEY_SEPARATOR = "_";
|
||||
|
||||
final Random random = new Random();
|
||||
|
||||
|
||||
enum KeyPre {
|
||||
|
||||
TABLE_KEY("table_"),
|
||||
TARGET_LT_KEY("target_lt_");
|
||||
|
||||
private String key;
|
||||
|
||||
KeyPre(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private ValueOperations<String, String> valueOperations;
|
||||
|
||||
@Autowired
|
||||
private HashOperations<String, String, Object> hashOperations;
|
||||
|
||||
@Autowired
|
||||
private ListOperations<String, Object> listOperations;
|
||||
|
||||
@Autowired
|
||||
private SetOperations<String, Object> setOperations;
|
||||
|
||||
@Autowired
|
||||
private ZSetOperations<String, Object> zSetOperations;
|
||||
|
||||
/**
|
||||
* 保存到缓存,过期时间为默认过期时间
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param obj 缓存数据
|
||||
*/
|
||||
public void saveObject(final String key, final Object obj) {
|
||||
this.saveObject(key, obj, CacheConstants.DEFAULT_EXPIRE_SECOND);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存到缓存,并设定过期时间
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param obj 缓存数据
|
||||
* @param expire 过期时间
|
||||
*/
|
||||
public void saveObject(final String key, final Object obj, final long expire) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key) || obj == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, obj, expire, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
logger.error("saveObject", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存到缓存,并设定过期时间
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param
|
||||
* @param expire 过期时间
|
||||
*/
|
||||
public void saveStr(final String key, final String str, final long expire) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key) || str == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, str, expire, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
logger.error("saveObject", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 调用set后的返回值
|
||||
*/
|
||||
public static final String OK = "OK";
|
||||
|
||||
public Object getHashValue(final String key, String hashKey) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isEmpty(key) || StringUtil.isEmpty(hashKey)) {
|
||||
return null;
|
||||
}
|
||||
return hashOperations.get(key, hashKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试 获取锁
|
||||
*
|
||||
* @param key
|
||||
* @param lockTime ,获得锁以后的锁定时间
|
||||
* @return
|
||||
*/
|
||||
public boolean lockTryTimes(final String key, final Long tryTimes, final Long lockTime) {
|
||||
final String value = "xx";
|
||||
boolean flag = false;
|
||||
try {
|
||||
// 请求锁超时时间,毫秒
|
||||
long timeout = tryTimes * 1000;
|
||||
// 系统当前时间,毫秒
|
||||
long nowTime = System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis() - nowTime) < timeout) {
|
||||
if (set(key, value)) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
// 每次请求等待一段时间
|
||||
seleep(10, 50000);
|
||||
}
|
||||
if (flag) {
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.expire(redisTemplate.getStringSerializer().serialize(key), lockTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
long a = System.currentTimeMillis();
|
||||
System.out.println(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param millis 毫秒
|
||||
* @param nanos 纳秒
|
||||
* @Title: seleep
|
||||
* @Description: 线程等待时间
|
||||
* @author yuhao.wang
|
||||
*/
|
||||
private void seleep(long millis, int nanos) {
|
||||
try {
|
||||
Thread.sleep(millis, random.nextInt(nanos));
|
||||
} catch (InterruptedException e) {
|
||||
logger.info("获取分布式锁休眠被中断:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 立即获取锁
|
||||
*
|
||||
* @param key
|
||||
* @param lockTime ,获得锁以后的锁定时间
|
||||
* @return
|
||||
*/
|
||||
public boolean lock(final String key, final Long lockTime) {
|
||||
final String value = "xx";
|
||||
try {
|
||||
Boolean flag = set(key, value);
|
||||
if (flag) {
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.expire(redisTemplate.getStringSerializer().serialize(key), lockTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Boolean set(String key, String value) {
|
||||
return (Boolean) redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.setNX(redisTemplate.getStringSerializer().serialize(key), value.getBytes());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 锁住某个key值30S,需要解锁时删除即可
|
||||
*
|
||||
* @param key
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public boolean lock30Second(final String key) {
|
||||
final String value = "xx";
|
||||
try {
|
||||
Boolean flag = set(key, value);
|
||||
if (flag) {
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.expire(redisTemplate.getStringSerializer().serialize(key), Constant.SECOND_OF_THREE);
|
||||
}
|
||||
});
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 锁住某个key值30S,需要解锁时删除即可
|
||||
*
|
||||
* @param key
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public boolean lock60Second(final String key) {
|
||||
final String value = "xx";
|
||||
try {
|
||||
Boolean flag = set(key, value);
|
||||
if (flag) {
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.expire(redisTemplate.getStringSerializer().serialize(key), Constant.SECOND_OF_SIXTY);
|
||||
}
|
||||
});
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 锁住某个key值30S,需要解锁时删除即可
|
||||
*
|
||||
* @param key
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public boolean lock5Minite(final String key) {
|
||||
final String value = "xx";
|
||||
try {
|
||||
Boolean flag = set(key, value);
|
||||
if (flag) {
|
||||
redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.expire(redisTemplate.getStringSerializer().serialize(key), Constant.SECOND_OF_5_MINITE);
|
||||
}
|
||||
});
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 锁住某个key值,需要解锁时删除即可
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public boolean getLock(final String key, final String value) {
|
||||
try {
|
||||
return (Boolean) redisTemplate.execute(new RedisCallback<Object>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.setNX(redisTemplate.getStringSerializer().serialize(key), value.getBytes());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("getLock error", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param key 需要删除缓存的id
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void unLock(final String key) {
|
||||
//如果为空
|
||||
if (StringUtil.isBlank(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.execute(new RedisCallback() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.del(redisTemplate.getStringSerializer().serialize(key));
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("delCache error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param key 需要删除缓存的id
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void delCache(final String key) {
|
||||
try {
|
||||
redisTemplate.execute(new RedisCallback() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) throws DataAccessException {
|
||||
return connection.del(redisTemplate.getStringSerializer().serialize(key));
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("delCache error", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveTableObjectViaHash(final String consumerNo, String table, Map<String, Object> tableFields) {
|
||||
if (StringUtil.isEmpty(consumerNo) || StringUtil.isEmpty(table)) {
|
||||
return;
|
||||
}
|
||||
String hashKey = KeyPre.TABLE_KEY.getKey() + consumerNo + KEY_SEPARATOR + table;
|
||||
hashOperations.putAll(hashKey, tableFields);
|
||||
hashOperations.getOperations().expire(hashKey, CacheConstants.SECOND_OF_ONE_WEEK, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void saveTargetValueViaHash(final String queryKey, Map<String, Object> targets) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isEmpty(queryKey) || targets == null) {
|
||||
return;
|
||||
}
|
||||
String hashKey = KeyPre.TARGET_LT_KEY.getKey() + queryKey;
|
||||
hashOperations.putAll(hashKey, targets);
|
||||
hashOperations.getOperations().expire(hashKey, CacheConstants.SECOND_OF_TWO_WEEK, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public Object getTargetValueViaHash(final String phone, final String targetCode) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(phone) || StringUtil.isBlank(targetCode)) {
|
||||
return null;
|
||||
}
|
||||
return hashOperations.get(KeyPre.TARGET_LT_KEY.getKey() + phone, targetCode);
|
||||
}
|
||||
|
||||
public Object getTableValueViaHash(final String consumerNo, final String table, final String column) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(consumerNo)) {
|
||||
return null;
|
||||
}
|
||||
return hashOperations.get(KeyPre.TABLE_KEY.getKey() + consumerNo + KEY_SEPARATOR + table, column);
|
||||
}
|
||||
|
||||
public Object getRuleResultValueViaHash(final String consumerNo, final String ruleId) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(consumerNo)) {
|
||||
return null;
|
||||
}
|
||||
String cacheKey = String.format(CacheConstants.HASH_KEY_RULE_RESULT.getKey(), consumerNo);
|
||||
return hashOperations.get(cacheKey, ruleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到缓存,永不过期
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param obj 缓存数据
|
||||
*/
|
||||
public void saveObjectForever(final String key, final Object obj) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key) || obj == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, obj);
|
||||
} catch (Exception e) {
|
||||
logger.error("saveObject", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存对象
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @return
|
||||
*/
|
||||
public <T> T getObject(final String key, Class<T> objClass) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (T) redisTemplate.opsForValue().get(key);
|
||||
} catch (Exception e) {
|
||||
logger.error("getObject error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存对象
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @return
|
||||
*/
|
||||
public Object getObject(final String key) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return redisTemplate.opsForValue().get(key);
|
||||
} catch (Exception e) {
|
||||
logger.error("getObject error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存对象
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param javaType Jackson JavaType
|
||||
* @return
|
||||
*/
|
||||
public <T> T getObject(final String key, JavaType javaType) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (T) redisTemplate.opsForValue().get(key);
|
||||
} catch (Exception e) {
|
||||
logger.error("getObject error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回int类型缓存值,null或者""则返回默认值
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param defaultValue 默认值
|
||||
* @return
|
||||
*/
|
||||
public int getInt(String key, int defaultValue) {
|
||||
String value = getObject(key, String.class);
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return NumberUtil.getInt(value.trim());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回double类型缓存值,null或者""则返回默认值
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param defaultValue 默认值
|
||||
* @return
|
||||
*/
|
||||
public double getDouble(String key, double defaultValue) {
|
||||
String value = getObject(key, String.class);
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return NumberUtil.getDouble(value.trim());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回String类型缓存值,null则返回默认值
|
||||
*
|
||||
* @param key 缓存key
|
||||
* @param defaultValue 默认值
|
||||
* @return
|
||||
*/
|
||||
public String getValue(String key, String defaultValue) {
|
||||
String value = getObject(key, String.class);
|
||||
if (StringUtil.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return StringUtil.isNull(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 缓存续期,单位秒,使用CacheConstants定义的时间
|
||||
*
|
||||
* @param key
|
||||
* @param expire
|
||||
*/
|
||||
public void expire(final String key, final long expire) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.expire(key, expire, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
logger.error("expire error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以key删除缓存
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public void delete(final String key) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(key)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.delete(key);
|
||||
} catch (Exception e) {
|
||||
logger.error("redis delete key error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户所有缓存
|
||||
*
|
||||
* @param consumerNo
|
||||
*/
|
||||
public void deleteByCNo(String consumerNo) {
|
||||
try {
|
||||
deleteByPrefix(KeyPre.TABLE_KEY.getKey() + consumerNo + KEY_SEPARATOR);
|
||||
deleteByPrefix(String.format(CacheConstants.HASH_KEY_RULE_RESULT.getKey(), consumerNo));
|
||||
logger.info("【删除redis缓存】consumerNo:" + consumerNo);
|
||||
} catch (Exception e) {
|
||||
logger.error("redis delete key, consumerNo:" + consumerNo + ",error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 以前缀删除缓存
|
||||
*
|
||||
* @param prefix
|
||||
*/
|
||||
public void deleteByPrefix(String prefix) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(prefix)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Set<String> keys = redisTemplate.keys(prefix + "*");
|
||||
redisTemplate.delete(keys);
|
||||
} catch (Exception e) {
|
||||
logger.error("redis delete prefix key error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以后缀删除缓存
|
||||
*
|
||||
* @param suffix
|
||||
*/
|
||||
public void deleteBySuffix(String suffix) {
|
||||
if (!RISK_CACHE_SWITCH || StringUtil.isBlank(suffix)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Set<String> keys = redisTemplate.keys("*" + suffix);
|
||||
redisTemplate.delete(keys);
|
||||
} catch (Exception e) {
|
||||
logger.error("redis delete suffix key error", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以keys删除缓存
|
||||
*
|
||||
* @param keys
|
||||
*/
|
||||
public void deleteByKeys(String... keys) {
|
||||
if (!RISK_CACHE_SWITCH || keys == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
redisTemplate.delete(Arrays.asList(keys));
|
||||
} catch (Exception e) {
|
||||
logger.error("redis delete keys error", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -356,23 +356,6 @@ public class StringUtil extends StringUtils {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
Set<String> set = new HashSet<>( );
|
||||
for(long i = 0 ;i < 2000000 ;i ++){
|
||||
String a = getThirdNo("jdk","2",i);
|
||||
set.add(a);
|
||||
}
|
||||
System.out.println(set.size());
|
||||
|
||||
|
||||
|
||||
}
|
||||
public static String removeDoubleChar(String str){
|
||||
if(str.indexOf("\"")==0) {
|
||||
str = str.substring(1, str.length()); //去掉第一个 "
|
||||
@ -650,4 +633,18 @@ public class StringUtil extends StringUtils {
|
||||
}
|
||||
return html.replaceAll("\\<.*?>","");
|
||||
}
|
||||
|
||||
public static String realNameTo2(String value) {
|
||||
if(StringUtil.isBlank(value)){
|
||||
return "";
|
||||
}
|
||||
if(value.length() > 2 ){
|
||||
return value.substring(value.length()-2);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
System.out.println(realNameTo2("xxxxx"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,10 +9,15 @@
|
||||
package com.lz.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
@ -22,20 +27,23 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
@Autowired
|
||||
private RedisConnectionFactory factory;
|
||||
@Value("${redis.cache.expiration:3600}")
|
||||
private Long expiration;
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, Object> redisTemplate() {
|
||||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||
redisTemplate.setConnectionFactory(factory);
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||
return redisTemplate.opsForHash();
|
||||
@ -60,4 +68,16 @@ public class RedisConfig {
|
||||
public ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {
|
||||
return redisTemplate.opsForZSet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示声明缓存key生成器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
|
||||
return new SimpleKeyGenerator();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,68 @@
|
||||
package com.lz.modules.app.controller;
|
||||
|
||||
import com.lz.common.utils.DateUtils;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
public class GetDateController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ResultRecordService resultRecordService;
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/get/date")
|
||||
public R getDate(ResultRecordReq req) throws Exception{
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordResultId());
|
||||
SimpleDateFormat myFmt2 = new SimpleDateFormat("yyyy-MM");
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
List<String> contains = new ArrayList<>();
|
||||
String value = myFmt2.format(resultRecord.getMonthTime());
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("value", value);
|
||||
list.add(map);
|
||||
contains.add(value);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String val = myFmt2.format(DateUtils.addDateMonths(new Date(), i));
|
||||
if (!contains.contains(val)) {
|
||||
contains.add(val);
|
||||
Map<String, String> mapValue = new HashMap<>();
|
||||
mapValue.put("value", val);
|
||||
list.add(mapValue);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 6; i++) {
|
||||
String val = myFmt2.format(DateUtils.addDateMonths(new Date(),-i));
|
||||
if(!contains.contains(val)){
|
||||
contains.add(val);
|
||||
Map<String,String> mapValue = new HashMap<>();
|
||||
mapValue.put("value",val);
|
||||
list.add(mapValue);
|
||||
}
|
||||
}
|
||||
return R.ok().put("list",list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/get/updateDate")
|
||||
public R updateDate(ResultRecordReq req) throws Exception {
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordResultId());
|
||||
SimpleDateFormat myFmt2 = new SimpleDateFormat("yyyy-MM");
|
||||
resultRecord.setMonthTime(myFmt2.parse(req.getMonthTime()));
|
||||
resultRecordService.updateResultRecordById(resultRecord);
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package com.lz.modules.app.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.*;
|
||||
import com.lz.modules.app.dto.DepartmentsDto;
|
||||
@ -9,6 +8,7 @@ import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.app.resp.ResultDetailResp;
|
||||
import com.lz.modules.app.resp.Step;
|
||||
import com.lz.modules.app.service.DepartmentsService;
|
||||
import com.lz.modules.app.service.DepartmentsStaffRelateService;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
@ -17,13 +17,11 @@ import com.lz.modules.flow.entity.RecordAuth;
|
||||
import com.lz.modules.flow.entity.RecordFile;
|
||||
import com.lz.modules.flow.entity.StaffRole;
|
||||
import com.lz.modules.flow.model.Auth;
|
||||
import com.lz.modules.flow.model.StaffRoleDto;
|
||||
import com.lz.modules.flow.req.ResultDetailReq;
|
||||
import com.lz.modules.flow.service.FlowRecordService;
|
||||
import com.lz.modules.flow.service.RecordAuthService;
|
||||
import com.lz.modules.flow.service.RecordFileService;
|
||||
import com.lz.modules.flow.service.StaffRoleService;
|
||||
import com.lz.modules.job.business.DingtalkBusiness;
|
||||
import com.lz.modules.sys.controller.AbstractController;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.app.ResultComment;
|
||||
@ -32,18 +30,17 @@ import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultCommentService;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -58,6 +55,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user/lzresultrecord")
|
||||
@Slf4j
|
||||
public class ResultRecordController extends AbstractController {
|
||||
@Autowired
|
||||
private ResultRecordService lzResultRecordService;
|
||||
@ -82,18 +80,15 @@ public class ResultRecordController extends AbstractController {
|
||||
@Autowired
|
||||
private RecordFileService recordFileService;
|
||||
|
||||
@Autowired
|
||||
private DingtalkBusiness dingtalkBusiness;
|
||||
|
||||
@Value("${dingtalk.appid}")
|
||||
private String appid;
|
||||
|
||||
@Value("${domain.main}")
|
||||
private String domain;
|
||||
|
||||
@Autowired
|
||||
private StaffRoleService staffRoleService;
|
||||
|
||||
@Autowired
|
||||
private RedisCacheUtil redisCacheUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ -137,6 +132,7 @@ public class ResultRecordController extends AbstractController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PageUtils page = lzResultRecordService.queryPage(req, user);
|
||||
return R.ok().put("page", page)
|
||||
.put("departmentList1", departmentList1)
|
||||
@ -189,8 +185,8 @@ public class ResultRecordController extends AbstractController {
|
||||
listAuth = recordAuthService.selectAuthInfo(staffRoleMap.get(getUserId()));
|
||||
auth = recordAuthService.getAuth(listAuth);
|
||||
}
|
||||
|
||||
List<ResultDetail> resultDetails = resultDetailService.selectByRecordId(resultRecord.getId());
|
||||
List<Step> stepList = resultDetailService.getStepList(resultRecord);
|
||||
BigDecimal sumWenHuaJiaZhiGuan = BigDecimal.ZERO;
|
||||
BigDecimal sumYeJi = BigDecimal.ZERO;
|
||||
if (CollectionUtils.isNotEmpty(resultDetails)) {
|
||||
@ -210,7 +206,7 @@ public class ResultRecordController extends AbstractController {
|
||||
ResultDetailResp resp = new ResultDetailResp();
|
||||
BeanUtils.copyProperties(resultDetail, resp);
|
||||
if (resultDetail.getType() == 1) {
|
||||
resp.setCheckRange("业绩");
|
||||
resp.setCheckRange("绩效");
|
||||
} else if (resultDetail.getType() == 2) {
|
||||
resp.setCheckRange("文化价值观");
|
||||
}
|
||||
@ -248,7 +244,6 @@ public class ResultRecordController extends AbstractController {
|
||||
list.add(resultDetailService.getWenHuaJiaZhiGuaResult1(sumWenHuaJiaZhiGuan));
|
||||
list.add(resultDetailService.getWenHuaJiaZhiGuaResult2());
|
||||
list.add(resultDetailService.getLastResult(resultRecord.getLastScore()));
|
||||
|
||||
List<ResultComment> comments = resultCommentService.selectByRecordId(resultRecord.getId());
|
||||
if (CollectionUtils.isNotEmpty(comments)) {
|
||||
ResultDetailResp header = new ResultDetailResp();
|
||||
@ -277,7 +272,7 @@ public class ResultRecordController extends AbstractController {
|
||||
.put("department1", departmentDto.getDepartment1())
|
||||
.put("department2", departmentDto.getDepartment2())
|
||||
.put("department3", departmentDto.getDepartment3())
|
||||
.put("checkMonth", sdf3.format(resultRecord == null ? new Date() : resultRecord.getGmtCreate()))
|
||||
.put("checkMonth", sdf3.format(resultRecord == null ? new Date() : resultRecord.getMonthTime()))
|
||||
.put("list", list)
|
||||
.put("auth", auth)
|
||||
.put("recordType", recordType)
|
||||
@ -288,85 +283,15 @@ public class ResultRecordController extends AbstractController {
|
||||
.put("commentNum", commentNum)
|
||||
.put("superStaff", superStaff)
|
||||
.put("fileCount",fileCount)
|
||||
.put("stepList",stepList)
|
||||
;
|
||||
}
|
||||
|
||||
@RequestMapping("/commitApproval")
|
||||
public R commitApproval(ResultRecordReq req) {
|
||||
R r = null;
|
||||
int status = 1;
|
||||
if (req.getStatus() == 2) {
|
||||
r = resultRecordService.approval(req.getRecordResultId(), getUserId());
|
||||
} else if (req.getStatus() == 3) { //侍提交
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordResultId());
|
||||
resultRecord.setStatus(Constant.STATUS_3);
|
||||
resultRecordService.updateResultRecordById(resultRecord);
|
||||
} else if (req.getStatus() == 5) { // 驳回
|
||||
status = 5;
|
||||
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByRecordId(req.getRecordResultId());
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordResultId());
|
||||
if (flowRecords.size() > 0 && req.getRollbackFlowId() > 0) {
|
||||
for (FlowRecord flowRecord : flowRecords) {
|
||||
if (flowRecord.getId().equals(req.getRollbackFlowId())) {
|
||||
resultRecord.setFlowStaffIdRole(flowRecord.getFlowStaffIdRole());
|
||||
resultRecord.setStatus(req.getStatus());
|
||||
flowRecord.getFlowStaffIdRole();
|
||||
List<StaffRoleDto> list = JSONObject.parseArray(resultRecord.getFlowStaffIdRole(), StaffRoleDto.class);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
StaffRoleDto staffRoleDto = list.get(0);
|
||||
StaffEntity approvalStaff = staffService.selectStaffById(staffRoleDto.getStaffId());
|
||||
resultRecord.setCurrentApprovalStaffId(approvalStaff != null ? approvalStaff.getId() : null);
|
||||
resultRecord.setCurrentApprovalStaffName(approvalStaff != null ? approvalStaff.getName() : null);
|
||||
}
|
||||
resultRecordService.updateResultRecordById(resultRecord);
|
||||
}
|
||||
if (flowRecord.getId() > req.getRollbackFlowId()) {
|
||||
flowRecord.setStatus(1);
|
||||
flowRecordService.updateFlowRecordById(flowRecord);
|
||||
}
|
||||
}
|
||||
StaffEntity mySelf = staffService.selectStaffById(resultRecord.getStaffId());
|
||||
r = R.ok("成功")
|
||||
.put("from", mySelf)
|
||||
.put("to", mySelf)
|
||||
.put("type", WorkMsgTypeEnum.REJECT);
|
||||
}
|
||||
}
|
||||
resultCommentService.addOrUpdateComment(req, getUserId(), status);
|
||||
|
||||
if(r != null){//下面推送消息
|
||||
if(r.isSuccess()){
|
||||
StaffEntity mySelf = (StaffEntity)r.get("from");
|
||||
StaffEntity toSelf = (StaffEntity)r.get("to");
|
||||
WorkMsgTypeEnum workMsgTypeEnum = (WorkMsgTypeEnum)r.get("type");
|
||||
sendWorkMSG(mySelf, toSelf, workMsgTypeEnum, req.getRecordResultId(), 1);
|
||||
return R.ok("成功");
|
||||
}
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
return R.ok("成功");
|
||||
//return r != null ? r : R.ok("成功");
|
||||
return resultRecordService.commitApproval(req, getUserId());
|
||||
}
|
||||
|
||||
private void sendWorkMSG(StaffEntity mySelf, StaffEntity toSelf, WorkMsgTypeEnum workMsgTypeEnum
|
||||
, Long recordResultId, int count){
|
||||
String url = domain + "/management/dingtalklogin?url=";//免登接口
|
||||
String jump;
|
||||
if(count == 1){//一个提交
|
||||
logger.info("单个提交推送消息");
|
||||
jump = domain + "/management/recorddetail?id=" + recordResultId
|
||||
+ "&recordType=3" ;//跳转接口
|
||||
}else{//批量提交
|
||||
logger.info("批量提交推送消息");
|
||||
jump = domain + "/management/result-record-lzresultrecordapp";//跳转接口
|
||||
}
|
||||
|
||||
jump = URLEncoder.encode(jump);
|
||||
String msg = dingtalkBusiness.sendWorkMSGByEntity(appid, mySelf, toSelf, workMsgTypeEnum, url + jump);
|
||||
logger.info("发送钉钉工作消息{}", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
@ -378,9 +303,6 @@ public class ResultRecordController extends AbstractController {
|
||||
return R.ok().put("lzResultRecord", lzResultRecord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@ -399,7 +321,7 @@ public class ResultRecordController extends AbstractController {
|
||||
if (resultComment == null || !getUserId().equals(resultComment.getStaffId())) {
|
||||
resultComment = new ResultComment();
|
||||
}
|
||||
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByResultRecordIdFlowId(recordId, 0l);
|
||||
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByResultRecordIdFlowId(recordId);
|
||||
if (flowRecords != null && flowRecords.size() > 0) {
|
||||
FlowRecord flowRecord = flowRecords.get(flowRecords.size()-1);
|
||||
if(flowRecord.getApprovalStaffId().equals(getUserId())){
|
||||
@ -454,12 +376,11 @@ public class ResultRecordController extends AbstractController {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
if (r != null && r.isSuccess()) {//批量提交
|
||||
StaffEntity mySelf = (StaffEntity) r.get("from");
|
||||
StaffEntity toSelf = (StaffEntity) r.get("to");
|
||||
WorkMsgTypeEnum workMsgTypeEnum = (WorkMsgTypeEnum) r.get("type");
|
||||
sendWorkMSG(mySelf, toSelf, workMsgTypeEnum, 0L, 2);
|
||||
resultRecordService.sendWorkMSG(mySelf, toSelf, workMsgTypeEnum, 0L, 2);
|
||||
}
|
||||
|
||||
return R.ok("批量提交成功");
|
||||
@ -546,6 +467,8 @@ public class ResultRecordController extends AbstractController {
|
||||
public R detailAddOrUpdate(ResultDetailReq req) {
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordId());
|
||||
req.setKeyResult(StringUtil.decodeBase64(req.getKeyResult()));
|
||||
req.setKeyResult35(StringUtil.decodeBase64(req.getKeyResult35()));
|
||||
req.setKeyResult37(StringUtil.decodeBase64(req.getKeyResult37()));
|
||||
req.setCheckResult(StringUtil.decodeBase64(req.getCheckResult()));
|
||||
req.setScoreComment(StringUtil.decodeBase64(req.getScoreComment()));
|
||||
ResultDetail old = resultDetailService.selectResultDetailById(req.getId());
|
||||
|
||||
@ -26,7 +26,7 @@ import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 业绩记录表
|
||||
* 绩效记录表
|
||||
*
|
||||
* @author zgh
|
||||
* @email zgh@ldxinyong.com
|
||||
|
||||
@ -39,5 +39,5 @@ public class ResultRecordReq {
|
||||
private String statusStr;
|
||||
private Long approvalStaffId;
|
||||
private int isChangeDepartmentrtment;
|
||||
|
||||
private String monthTime ;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ public class ResultDetailResp {
|
||||
private Date gmtCreate;
|
||||
//最后修改时间
|
||||
private Date gmtModified;
|
||||
//1,业绩,2文化价值观
|
||||
//1,绩效,2文化价值观
|
||||
private Integer type;
|
||||
//考核维度
|
||||
private String checkRange;
|
||||
@ -43,4 +43,9 @@ public class ResultDetailResp {
|
||||
private int isAdd;
|
||||
|
||||
private int isEdit;
|
||||
|
||||
private String keyResult35;
|
||||
//关键结果3.7分标准
|
||||
private String keyResult37;
|
||||
|
||||
}
|
||||
|
||||
@ -36,4 +36,11 @@ public class ResultRecordResp {
|
||||
|
||||
private Integer type ;
|
||||
|
||||
private String monthTimeStr;
|
||||
|
||||
//当前审批的员工 id
|
||||
private Long currentApprovalStaffId;
|
||||
//当前审批的员工名,以逗号隔开
|
||||
private String currentApprovalStaffName;
|
||||
|
||||
}
|
||||
|
||||
24
src/main/java/com/lz/modules/app/resp/Step.java
Normal file
24
src/main/java/com/lz/modules/app/resp/Step.java
Normal file
@ -0,0 +1,24 @@
|
||||
package com.lz.modules.app.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Step {
|
||||
private String name ;
|
||||
private String time ;
|
||||
private int status ;
|
||||
private String statusStr;
|
||||
public Step() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Step(String name, String time, int status, String statusStr) {
|
||||
this.name = name;
|
||||
this.time = time;
|
||||
this.status = status;
|
||||
this.statusStr = statusStr;
|
||||
}
|
||||
}
|
||||
@ -39,5 +39,7 @@ public interface FlowRecordMapper extends BaseMapper<FlowRecord> {
|
||||
|
||||
List<FlowRecord> selectFlowRecordByRecordId(@Param("recordId") Long recordId);
|
||||
|
||||
List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(@Param("recordId") Long recordId, @Param("rollbackFlowId") Long rollbackFlowId);
|
||||
List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(@Param("recordId") Long recordId);
|
||||
|
||||
List<FlowRecord> selectFlowRecordByFlowId(@Param("recordId") Long recordId);
|
||||
}
|
||||
@ -24,4 +24,6 @@ public class Auth {
|
||||
private int approvelCommit;
|
||||
private int uploadFile;
|
||||
private int downFile;
|
||||
private int keyResult35;
|
||||
private int keyResult37;
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ public class ResultDetailReq {
|
||||
private Date gmtCreate;
|
||||
//最后修改时间
|
||||
private Date gmtModified;
|
||||
//1,业绩,2文化价值观
|
||||
//1,绩效,2文化价值观
|
||||
private Integer type;
|
||||
//目标
|
||||
private String target;
|
||||
@ -42,4 +42,10 @@ public class ResultDetailReq {
|
||||
|
||||
private int page = 1;
|
||||
private int limit = 10 ;
|
||||
//关键结果_3.5标准
|
||||
private String keyResult35;
|
||||
//关键结果3.7分标准
|
||||
private String keyResult37;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -41,5 +41,7 @@ public interface FlowRecordService extends IService<FlowRecord> {
|
||||
|
||||
void initFlowRecord(ResultRecord resultRecord , Long roleId , Integer type , String name);
|
||||
|
||||
List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(Long recordResultId, Long rollbackFlowId);
|
||||
List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(Long recordResultId);
|
||||
|
||||
List<FlowRecord> selectFlowRecordByFlowId(Long recordId);
|
||||
}
|
||||
@ -106,8 +106,13 @@ public class FlowRecordServiceImpl extends ServiceImpl<FlowRecordMapper, FlowRec
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(Long recordResultId, Long rollbackFlowId) {
|
||||
return flowRecordMapper.selectFlowRecordByResultRecordIdFlowId(recordResultId, rollbackFlowId);
|
||||
public List<FlowRecord> selectFlowRecordByResultRecordIdFlowId(Long recordResultId) {
|
||||
return flowRecordMapper.selectFlowRecordByResultRecordIdFlowId(recordResultId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FlowRecord> selectFlowRecordByFlowId(Long recordId) {
|
||||
return flowRecordMapper.selectFlowRecordByFlowId(recordId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -123,7 +123,8 @@ public class RecordAuthServiceImpl extends ServiceImpl<RecordAuthMapper, RecordA
|
||||
auth.setWaitCommit(NumberUtil.objToIntDefault(map.get("waitCommit"), 0));
|
||||
auth.setApprovelCommit(NumberUtil.objToIntDefault(map.get("approvelCommit"), 0));
|
||||
auth.setUploadFile(NumberUtil.objToIntDefault(map.get("uploadFile"), 0));
|
||||
auth.setUploadFile(NumberUtil.objToIntDefault(map.get("uploadFile"), 0));
|
||||
auth.setKeyResult35(NumberUtil.objToIntDefault(map.get("keyResult35"), 0));
|
||||
auth.setKeyResult37(NumberUtil.objToIntDefault(map.get("keyResult37"), 0));
|
||||
return auth;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.lz.modules.sys.dao.app;
|
||||
/**
|
||||
* <p>
|
||||
* 业绩评论表 服务类
|
||||
* 绩效评论表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author quyixiao
|
||||
|
||||
@ -9,9 +9,9 @@ import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* 菜单权限表
|
||||
* </p>*业绩详情表
|
||||
* </p>*绩效详情表
|
||||
* @author quyixiao
|
||||
* @since 2020-08-13
|
||||
* @since 2020-08-28
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ -26,12 +26,16 @@ public class ResultDetail implements java.io.Serializable {
|
||||
private Date gmtCreate;
|
||||
//最后修改时间
|
||||
private Date gmtModified;
|
||||
//1,业绩,2文化价值观
|
||||
//1,绩效,2文化价值观
|
||||
private Integer type;
|
||||
//目标
|
||||
private String target;
|
||||
//关键结果
|
||||
private String keyResult;
|
||||
//关键结果_3.5标准
|
||||
private String keyResult35;
|
||||
//关键结果3.7分标准
|
||||
private String keyResult37;
|
||||
//考核权重
|
||||
private BigDecimal checkWeight;
|
||||
//考核结果
|
||||
@ -48,15 +52,6 @@ public class ResultDetail implements java.io.Serializable {
|
||||
private Long staffId;
|
||||
//优先级,从大到小
|
||||
private Integer priority;
|
||||
|
||||
public ResultDetail() {
|
||||
|
||||
}
|
||||
|
||||
public ResultDetail(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
@ -118,14 +113,14 @@ public class ResultDetail implements java.io.Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 1,业绩,2文化价值观
|
||||
* 1,绩效,2文化价值观
|
||||
* @return
|
||||
*/
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* 1,业绩,2文化价值观
|
||||
* 1,绩效,2文化价值观
|
||||
* @param type
|
||||
*/
|
||||
public void setType(Integer type) {
|
||||
@ -162,6 +157,36 @@ public class ResultDetail implements java.io.Serializable {
|
||||
this.keyResult = keyResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键结果_3.5标准
|
||||
* @return
|
||||
*/
|
||||
public String getKeyResult35() {
|
||||
return keyResult35;
|
||||
}
|
||||
/**
|
||||
* 关键结果_3.5标准
|
||||
* @param keyResult35
|
||||
*/
|
||||
public void setKeyResult35(String keyResult35) {
|
||||
this.keyResult35 = keyResult35;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键结果3.7分标准
|
||||
* @return
|
||||
*/
|
||||
public String getKeyResult37() {
|
||||
return keyResult37;
|
||||
}
|
||||
/**
|
||||
* 关键结果3.7分标准
|
||||
* @param keyResult37
|
||||
*/
|
||||
public void setKeyResult37(String keyResult37) {
|
||||
this.keyResult37 = keyResult37;
|
||||
}
|
||||
|
||||
/**
|
||||
* 考核权重
|
||||
* @return
|
||||
@ -292,6 +317,8 @@ public class ResultDetail implements java.io.Serializable {
|
||||
",type=" + type +
|
||||
",target=" + target +
|
||||
",keyResult=" + keyResult +
|
||||
",keyResult35=" + keyResult35 +
|
||||
",keyResult37=" + keyResult37 +
|
||||
",checkWeight=" + checkWeight +
|
||||
",checkResult=" + checkResult +
|
||||
",superScore=" + superScore +
|
||||
|
||||
@ -3,8 +3,10 @@ package com.lz.modules.sys.service.app;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.modules.app.resp.ResultDetailResp;
|
||||
import com.lz.modules.app.resp.Step;
|
||||
import com.lz.modules.flow.model.Auth;
|
||||
import com.lz.modules.sys.entity.app.ResultDetail;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@ -57,4 +59,6 @@ public interface ResultDetailService extends IService<ResultDetail> {
|
||||
void insertWenHuaJiaZhiGua(String s, Long id, Long userId);
|
||||
|
||||
String initRole(Long staffId, Long l);
|
||||
|
||||
List<Step> getStepList(ResultRecord resultRecord);
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
package com.lz.modules.sys.service.app;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.R;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.app.utils.t.TwoTuple;
|
||||
import com.lz.modules.flow.entity.Flow;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
|
||||
@ -57,4 +60,11 @@ public interface ResultRecordService extends IService<ResultRecord> {
|
||||
ResultRecord initResult(Long staffId ,Integer recordType,Long roleId) ;
|
||||
|
||||
R checkApproval(Long recordId);
|
||||
|
||||
int getDepartmentLevelIndex(List<Flow> list, int flowIndex);
|
||||
|
||||
R commitApproval(ResultRecordReq req,Long userId);
|
||||
|
||||
void sendWorkMSG(StaffEntity mySelf, StaffEntity toSelf, WorkMsgTypeEnum workMsgTypeEnum
|
||||
, Long recordResultId, int count);
|
||||
}
|
||||
@ -3,18 +3,31 @@ package com.lz.modules.sys.service.app.impl;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.common.utils.BigDecimalUtil;
|
||||
import com.lz.common.utils.StringUtil;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.resp.ResultDetailResp;
|
||||
import com.lz.modules.app.resp.Step;
|
||||
import com.lz.modules.app.service.DepartmentsService;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.app.utils.t.TwoTuple;
|
||||
import com.lz.modules.flow.entity.*;
|
||||
import com.lz.modules.flow.model.Auth;
|
||||
import com.lz.modules.flow.model.StaffRoleDto;
|
||||
import com.lz.modules.flow.service.*;
|
||||
import com.lz.modules.sys.dao.app.ResultDetailMapper;
|
||||
import com.lz.modules.sys.entity.app.ResultDetail;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -26,12 +39,24 @@ import java.util.List;
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, ResultDetail> implements ResultDetailService {
|
||||
|
||||
|
||||
@Autowired
|
||||
@Autowired
|
||||
private ResultDetailMapper resultDetailMapper;
|
||||
|
||||
@Autowired
|
||||
private StaffService staffService;
|
||||
|
||||
@Autowired
|
||||
private ResultRecordService resultRecordService;
|
||||
|
||||
@Autowired
|
||||
private FlowRelationService flowRelationService;
|
||||
|
||||
@Autowired
|
||||
private StaffRoleService staffRoleService;
|
||||
|
||||
|
||||
@Override
|
||||
@ -40,6 +65,18 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private StaffRoleDepartmentService staffRoleDepartmentService;
|
||||
|
||||
@Autowired
|
||||
private DepartmentsService departmentsService;
|
||||
|
||||
@Autowired
|
||||
private FlowService flowService;
|
||||
|
||||
@Autowired
|
||||
private FlowRecordService flowRecordService;
|
||||
|
||||
|
||||
@Override
|
||||
public Long insertResultDetail(ResultDetail resultDetail){
|
||||
@ -80,7 +117,7 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
|
||||
public ResultDetailResp getYeJi() {
|
||||
ResultDetailResp result = new ResultDetailResp();
|
||||
result.setCheckRange("业绩");
|
||||
result.setCheckRange("绩效");
|
||||
result.setCheckWeight(new BigDecimal(0.7));
|
||||
result.setIsAdd(1);
|
||||
result.setIsEdit(1);
|
||||
@ -90,7 +127,7 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
|
||||
public ResultDetailResp getYeJiKaoHe(BigDecimal acquireScore) {
|
||||
ResultDetailResp respHeader = new ResultDetailResp();
|
||||
respHeader.setKeyResult("业务考核结果");
|
||||
respHeader.setKeyResult("绩效考核结果");
|
||||
respHeader.setCheckWeight(new BigDecimal(0.7));
|
||||
respHeader.setSuperScore("/");
|
||||
respHeader.setAcquireScore(acquireScore);
|
||||
@ -135,7 +172,7 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
|
||||
public ResultDetailResp getWenHuaJiaZhiGuaResult2() {
|
||||
ResultDetailResp tail2 = new ResultDetailResp();
|
||||
tail2.setCheckRange("文化价值观考核结果");
|
||||
tail2.setCheckRange("最终绩效考核评分");
|
||||
tail2.setAcquireScore(BigDecimal.ZERO);
|
||||
tail2.setScoreComment("/");
|
||||
tail2.setIsAdd(-1);
|
||||
@ -173,4 +210,99 @@ public class ResultDetailServiceImpl extends ServiceImpl<ResultDetailMapper, Res
|
||||
return JSON.toJSONString(staffRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Step> getStepList(ResultRecord resultRecord) {
|
||||
Long staffId = resultRecord.getStaffId();
|
||||
int type = resultRecord.getType();
|
||||
String departmentId = resultRecord.getDepartmentId();
|
||||
List<Step> stepList = new ArrayList<>();
|
||||
|
||||
StaffEntity mySelf = staffService.selectStaffById(staffId);
|
||||
TwoTuple<Long, List<FlowDepartment>> flowInfo = resultRecordService.getFlowInfo(staffId, type);
|
||||
Long flowId = flowInfo.getFirst();
|
||||
List<FlowDepartment> list = flowInfo.getSecond();
|
||||
List<FlowRelation> flowRelations = flowRelationService.selectFlowRelationAll();
|
||||
Map<String, FlowDepartment> staffEntityMap = list.stream().collect(Collectors.toMap(FlowDepartment::getDepartmentLevel, p -> p));
|
||||
//approvalList = [ME,ONE_D,TWO_D,HR,BOSS]
|
||||
List<String> approvalList = new ArrayList<>();
|
||||
Map<String,String> roleNameMap = new HashMap<>();
|
||||
approvalList.add("ME");
|
||||
roleNameMap.put("ME",mySelf.getName());
|
||||
for (FlowRelation flowRelation : flowRelations) {
|
||||
FlowDepartment flowDepartment = staffEntityMap.get(flowRelation.getChild());
|
||||
if (flowDepartment != null || flowRelation.getCanReplace() == 0) {
|
||||
approvalList.add(flowRelation.getChild());
|
||||
String departmentLevel = flowRelation.getChild();
|
||||
if(flowDepartment != null ){
|
||||
StaffEntity flowStaff = staffService.selectStaffById(flowDepartment.getStaffId());
|
||||
roleNameMap.put(departmentLevel,flowStaff.getName());
|
||||
}else{
|
||||
List<StaffRole> staffRoles = staffRoleService.selectByRole(departmentLevel);
|
||||
Long approvalStaffId = 0l;
|
||||
for (StaffRole staffRole : staffRoles) {
|
||||
List<StaffRoleDepartment> staffRoleDepartments = staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
|
||||
Map<String, String> departmentIdMap = departmentsService.selectUserAllDepartmentIds(departmentId);
|
||||
for (StaffRoleDepartment staffRoleDepartment : staffRoleDepartments) {
|
||||
String value = departmentIdMap.get(staffRoleDepartment.getDepartmentId());
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
approvalStaffId =staffRole.getStaffId();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
StaffEntity flowStaff = staffService.selectStaffById(approvalStaffId);
|
||||
roleNameMap.put(departmentLevel,flowStaff.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("approvalList approval : " + Arrays.toString(approvalList.toArray()) + " roleNameMap : " + JSON.toJSONString(roleNameMap));
|
||||
List<Flow> flows = flowService.selectByFlowId(flowId);
|
||||
List<FlowRecord> flowRecordList = flowRecordService.selectFlowRecordByFlowId(resultRecord.getId());
|
||||
SimpleDateFormat myFmt2 = new SimpleDateFormat("MM-dd HH:mm");
|
||||
FlowRecord lastFlowRecord = null;
|
||||
if (CollectionUtils.isNotEmpty(flowRecordList)) {
|
||||
int index = 0;
|
||||
String lastStatusStr = "";
|
||||
for (FlowRecord flowRecord : flowRecordList) {
|
||||
String name = flowRecord.getApprovalStaffName();
|
||||
String time = myFmt2.format(flowRecord.getGmtCreate());
|
||||
String statusStr = "通过";
|
||||
if (flowRecord.getStatus().equals(0)) {
|
||||
lastFlowRecord = flowRecord;
|
||||
} else if (flowRecord.getStatus().equals(1)) {
|
||||
if (index + 1 <= flowRecordList.size() - 1) {
|
||||
FlowRecord flowRecord1 = flowRecordList.get(index + 1);
|
||||
if (flowRecord1.getStatus().equals(0)) {
|
||||
statusStr = "驳回";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(index ==0){
|
||||
stepList.add(new Step(name, time, 1, "提交"));
|
||||
}else if (index == flowRecordList.size() - 1) {
|
||||
if(resultRecord.getStatus() == 4 ){
|
||||
stepList.add(new Step(name, time, 1, "结束"));
|
||||
}else{
|
||||
stepList.add(new Step(name, time, 1, "驳回".equals(lastStatusStr) ? "确认" : "审批中"));
|
||||
}
|
||||
} else {
|
||||
stepList.add(new Step(name, time, 1, "驳回".equals(lastStatusStr) ? "确认" : statusStr));
|
||||
}
|
||||
lastStatusStr = statusStr;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
int flowIndex = lastFlowRecord != null ? lastFlowRecord.getFlowIndex() + 1 : 1;
|
||||
log.info("flowIndex = " + flowIndex);
|
||||
for (int i = flowIndex; i < flowIndex + 10; i++) {
|
||||
int index = resultRecordService.getDepartmentLevelIndex(flows, i);
|
||||
if (index < 0 || index >= approvalList.size()) {
|
||||
break;
|
||||
}
|
||||
String departmentLevel = approvalList.get(index);
|
||||
stepList.add(new Step(roleNameMap.get(departmentLevel), "", 0, ""));
|
||||
}
|
||||
return stepList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.lz.modules.sys.service.app.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.lz.common.emun.WorkMsgTypeEnum;
|
||||
import com.lz.common.utils.*;
|
||||
@ -21,18 +22,23 @@ import com.lz.modules.flow.model.StaffRoleDto;
|
||||
import com.lz.modules.flow.model.TypeFlowDto;
|
||||
import com.lz.modules.flow.model.TypeRoleDto;
|
||||
import com.lz.modules.flow.service.*;
|
||||
import com.lz.modules.job.business.DingtalkBusiness;
|
||||
import com.lz.modules.sys.dao.app.ResultRecordMapper;
|
||||
import com.lz.modules.sys.entity.SysUserEntity;
|
||||
import com.lz.modules.sys.entity.app.ResultDetail;
|
||||
import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultCommentService;
|
||||
import com.lz.modules.sys.service.app.ResultDetailService;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -99,6 +105,17 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
@Autowired
|
||||
private ResultDetailService resultDetailService;
|
||||
|
||||
@Autowired
|
||||
private ResultCommentService resultCommentService;
|
||||
|
||||
@Autowired
|
||||
private DingtalkBusiness dingtalkBusiness;
|
||||
|
||||
@Value("${dingtalk.appid}")
|
||||
private String appid;
|
||||
|
||||
@Value("${domain.main}")
|
||||
private String domain;
|
||||
|
||||
@Override
|
||||
public ResultRecord selectResultRecordById(Long id) {
|
||||
@ -167,6 +184,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
if("1,2,5".equals(params.getStatusStr())){
|
||||
params.setApprovalStaffId(user.getUserId());
|
||||
}
|
||||
|
||||
params.setDepartmentIds(departmentIds);
|
||||
String departmentLevel = Constant.ME;
|
||||
if (params.getIsSelf() != 1) { // 表示点击我们审批
|
||||
@ -184,6 +202,7 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
PageUtils pageUtils = PageUtils.startPage(params.getPage(), params.getLimit()).doSelect(
|
||||
page -> resultRecordMapper.selectByConditionByLeader(page, params)
|
||||
);
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
|
||||
List<ResultRecord> resultRecords = pageUtils.getList();
|
||||
if (CollectionUtils.isNotEmpty(resultRecords)) {
|
||||
List<ResultRecordResp> list = new ArrayList<>();
|
||||
@ -191,11 +210,10 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
ResultRecordResp resp = new ResultRecordResp();
|
||||
BeanUtils.copyProperties(resultRecord, resp);
|
||||
Map<Long, Long> staffRoleMap = recordAuthService.selectRoleIdByStaffRoleInfo(resultRecord.getFlowStaffIdRole());
|
||||
if (resp.getStatus().equals(1) && staffRoleMap.get(user.getUserId()) == null) {
|
||||
resp.setStatus(2); // 如果不是自己审批,说明自己己经审批完成
|
||||
} else if (resp.getStatus().equals(5) && staffRoleMap.get(user.getUserId()) == null) {
|
||||
if (resp.getStatus().equals(5) && staffRoleMap.get(user.getUserId()) == null) {
|
||||
resp.setStatus(1); // 如果不是自己审批,说明自己己经审批完成
|
||||
}
|
||||
resp.setMonthTimeStr(df.format(resultRecord.getMonthTime()));
|
||||
list.add(resp);
|
||||
}
|
||||
pageUtils.setList(list);
|
||||
@ -324,11 +342,11 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
public R checkApproval(Long recordId){
|
||||
List<ResultDetail> resultDetails = resultDetailService.selectByRecordId(recordId);
|
||||
if (CollectionUtils.isEmpty(resultDetails)) {
|
||||
return R.error("请先添加业绩。");
|
||||
return R.error("请先添加绩效。");
|
||||
}
|
||||
double sum = resultDetails.stream().filter(p -> p.getType() == 1).mapToDouble(p -> NumberUtil.objToDoubleWithDefault(p.getCheckWeight(), 0d)).sum();
|
||||
if (sum < 0.7) {
|
||||
return R.error("recordId为[" + recordId + "]业绩权重之和必需等于0.7。");
|
||||
return R.error("recordId为[" + recordId + "]绩效权重之和必需等于0.7。");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
@ -380,8 +398,6 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
flowRecord.setFlowIndex(flowIndex);
|
||||
flowRecord.setFlowId(flowId);
|
||||
String departmentLevel = approvalList.get(index);
|
||||
flowRecord.setDepartmentLevel(departmentLevel);
|
||||
|
||||
StaffEntity approvalStaff = null;
|
||||
List<StaffRoleDto> staffRoleDtos = new ArrayList<>();
|
||||
Long roleId = flows.get(flowIndex - 1).getRoleId();
|
||||
@ -392,33 +408,24 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
} else {
|
||||
FlowDepartment flowD = staffEntityMap.get(departmentLevel);
|
||||
if (flowD == null) {
|
||||
List<StaffRole> staffRoles = staffRoleService.selectByRole(departmentLevel);
|
||||
for (StaffRole staffRole : staffRoles) {
|
||||
List<StaffRoleDepartment> staffRoleDepartments = staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
|
||||
Map<String, String> departmentIdMap = departmentsService.selectUserAllDepartmentIds(resultRecord.getDepartmentId());
|
||||
for (StaffRoleDepartment staffRoleDepartment : staffRoleDepartments) {
|
||||
String value = departmentIdMap.get(staffRoleDepartment.getDepartmentId());
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
StaffRoleDto staffRoleDto = new StaffRoleDto(staffRole.getStaffId(), roleId != null && roleId > 0 ? roleId :
|
||||
TypeRoleDto.getRoleId(staffRole.getTypeRoleIds(), resultRecord.getType()));
|
||||
staffRoleDtos.add(staffRoleDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (staffRoleDtos.size() >= 1) { //表示只有一个审批的用户
|
||||
approvalStaff = staffService.selectStaffById(staffRoleDtos.get(0).getStaffId());
|
||||
}
|
||||
approvalStaff = getApprovalStaff(resultRecord, departmentLevel, approvalStaff, staffRoleDtos, roleId);
|
||||
} else {
|
||||
approvalStaff = staffService.selectStaffById(flowD.getStaffId());
|
||||
StaffRoleDto staffRoleDto = new StaffRoleDto(approvalStaff.getId(), roleId);
|
||||
staffRoleDtos.add(staffRoleDto);
|
||||
}
|
||||
}
|
||||
|
||||
flowRecord.setFlowName((approvalStaff != null ? approvalStaff.getName() + "-" : "") + flows.get(flowIndex - 1).getOptDesc());
|
||||
flowRecord.setApprovalStaffId(approvalStaff != null ? approvalStaff.getId() : null);
|
||||
flowRecord.setApprovalStaffName(approvalStaff != null ? approvalStaff.getName() : null);
|
||||
|
||||
// 如果用户有 HR 的权限,又在 flow_department 表中有记录,则记录为 HR
|
||||
if (approvalStaff != null) {
|
||||
StaffRole staffRole = staffRoleService.selectByStaffId(approvalStaff.getId());
|
||||
if (staffRole != null) {
|
||||
departmentLevel = staffRole.getDepartmentLevel();
|
||||
}
|
||||
}
|
||||
flowRecord.setDepartmentLevel(departmentLevel);
|
||||
String staffRoles = JSON.toJSONString(staffRoleDtos);
|
||||
flowRecord.setFlowStaffIdRole(staffRoles);
|
||||
flowRecordService.insertFlowRecord(flowRecord);
|
||||
@ -433,12 +440,34 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
.put("type", WorkMsgTypeEnum.SUBMIT);
|
||||
}
|
||||
|
||||
|
||||
private StaffEntity getApprovalStaff(ResultRecord resultRecord, String departmentLevel, StaffEntity approvalStaff, List<StaffRoleDto> staffRoleDtos, Long roleId) {
|
||||
List<StaffRole> staffRoles = staffRoleService.selectByRole(departmentLevel);
|
||||
for (StaffRole staffRole : staffRoles) {
|
||||
List<StaffRoleDepartment> staffRoleDepartments = staffRoleDepartmentService.selectStaffRoleDepartmentByStaffRoleId(staffRole.getId());
|
||||
Map<String, String> departmentIdMap = departmentsService.selectUserAllDepartmentIds(resultRecord.getDepartmentId());
|
||||
for (StaffRoleDepartment staffRoleDepartment : staffRoleDepartments) {
|
||||
String value = departmentIdMap.get(staffRoleDepartment.getDepartmentId());
|
||||
if (StringUtil.isNotBlank(value)) {
|
||||
StaffRoleDto staffRoleDto = new StaffRoleDto(staffRole.getStaffId(), roleId != null && roleId > 0 ? roleId :
|
||||
TypeRoleDto.getRoleId(staffRole.getTypeRoleIds(), resultRecord.getType()));
|
||||
staffRoleDtos.add(staffRoleDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (staffRoleDtos.size() >= 1) { //表示只有一个审批的用户
|
||||
approvalStaff = staffService.selectStaffById(staffRoleDtos.get(0).getStaffId());
|
||||
}
|
||||
return approvalStaff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResultRecord> selectResultRecordByIds(List<Long> recordIds) {
|
||||
return resultRecordMapper.selectResultRecordByIds(recordIds);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getDepartmentLevelIndex(List<Flow> list, int flowIndex) {
|
||||
if (flowIndex > list.size()) {
|
||||
return -1 ;
|
||||
@ -462,4 +491,82 @@ public class ResultRecordServiceImpl extends ServiceImpl<ResultRecordMapper, Res
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R commitApproval(ResultRecordReq req, Long userId) {
|
||||
ResultRecord resultRecord = resultRecordService.selectResultRecordById(req.getRecordResultId());
|
||||
if (resultRecord.getCurrentApprovalStaffId() !=null && !userId.equals(resultRecord.getCurrentApprovalStaffId())) {
|
||||
return R.error("请勿重复提交");
|
||||
}
|
||||
R r = null;
|
||||
int status = 1;
|
||||
if (req.getStatus() == 2) {
|
||||
r = resultRecordService.approval(req.getRecordResultId(), userId);
|
||||
} else if (req.getStatus() == 3) { //侍提交
|
||||
resultRecord.setStatus(Constant.STATUS_3);
|
||||
resultRecordService.updateResultRecordById(resultRecord);
|
||||
} else if (req.getStatus() == 5) { // 驳回
|
||||
status = 5;
|
||||
List<FlowRecord> flowRecords = flowRecordService.selectFlowRecordByResultRecordIdFlowId(req.getRecordResultId());
|
||||
if (flowRecords.size() >= 2) {
|
||||
FlowRecord secondFlowRecord = flowRecords.get(flowRecords.size() - 2);
|
||||
resultRecord.setFlowStaffIdRole(secondFlowRecord.getFlowStaffIdRole());
|
||||
resultRecord.setStatus(req.getStatus());
|
||||
List<StaffRoleDto> list = JSONObject.parseArray(resultRecord.getFlowStaffIdRole(), StaffRoleDto.class);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
StaffRoleDto staffRoleDto = list.get(0);
|
||||
StaffEntity approvalStaff = staffService.selectStaffById(staffRoleDto.getStaffId());
|
||||
resultRecord.setCurrentApprovalStaffId(approvalStaff != null ? approvalStaff.getId() : null);
|
||||
resultRecord.setCurrentApprovalStaffName(approvalStaff != null ? approvalStaff.getName() : null);
|
||||
}
|
||||
resultRecordService.updateResultRecordById(resultRecord);
|
||||
|
||||
FlowRecord lastFlowRecord = flowRecords.get(flowRecords.size() - 1);
|
||||
lastFlowRecord.setStatus(1);
|
||||
flowRecordService.updateFlowRecordById(lastFlowRecord);
|
||||
|
||||
// 可能会被删除
|
||||
FlowRecord lastUsedFlowRecord = flowRecordService.selectLastFlowRecordByRecordId(req.getRecordResultId());
|
||||
lastUsedFlowRecord.setId(null);
|
||||
lastUsedFlowRecord.setGmtCreate(new Date());
|
||||
lastUsedFlowRecord.setGmtModified(new Date());
|
||||
flowRecordService.insertFlowRecord(lastUsedFlowRecord);// 新插入一条提交记录
|
||||
|
||||
StaffEntity mySelf = staffService.selectStaffById(resultRecord.getStaffId());
|
||||
r = R.ok("成功")
|
||||
.put("from", mySelf)
|
||||
.put("to", mySelf)
|
||||
.put("type", WorkMsgTypeEnum.REJECT);
|
||||
}
|
||||
}
|
||||
resultCommentService.addOrUpdateComment(req, userId, status);
|
||||
if(r != null){//下面推送消息
|
||||
if(r.isSuccess()){
|
||||
StaffEntity mySelf = (StaffEntity)r.get("from");
|
||||
StaffEntity toSelf = (StaffEntity)r.get("to");
|
||||
WorkMsgTypeEnum workMsgTypeEnum = (WorkMsgTypeEnum)r.get("type");
|
||||
sendWorkMSG(mySelf, toSelf, workMsgTypeEnum, req.getRecordResultId(), 1);
|
||||
return R.ok("成功");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
return R.ok("成功");
|
||||
}
|
||||
|
||||
public void sendWorkMSG(StaffEntity mySelf, StaffEntity toSelf, WorkMsgTypeEnum workMsgTypeEnum
|
||||
, Long recordResultId, int count){
|
||||
String url = domain + "/management/dingtalklogin?url=";//免登接口
|
||||
String jump;
|
||||
if(count == 1){//一个提交
|
||||
log.info("单个提交推送消息");
|
||||
jump = domain + "/management/recorddetail?id=" + recordResultId
|
||||
+ "&recordType=3" ;//跳转接口
|
||||
}else{//批量提交
|
||||
log.info("批量提交推送消息");
|
||||
jump = domain + "/management/result-record-lzresultrecordapp";//跳转接口
|
||||
}
|
||||
|
||||
jump = URLEncoder.encode(jump);
|
||||
String msg = dingtalkBusiness.sendWorkMSGByEntity(appid, mySelf, toSelf, workMsgTypeEnum, url + jump);
|
||||
log.info("发送钉钉工作消息{}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@ dingtalk:
|
||||
domain:
|
||||
main: "http:/localhost"
|
||||
|
||||
|
||||
|
||||
##多数据源的配置
|
||||
#dynamic:
|
||||
# datasource:
|
||||
|
||||
@ -23,9 +23,8 @@ spring:
|
||||
max-request-size: 100MB
|
||||
enabled: true
|
||||
redis:
|
||||
open: false # 是否开启redis缓存 true开启 false关闭
|
||||
database: 0
|
||||
host: localhost
|
||||
host: 172.16.157.239
|
||||
port: 6379
|
||||
password: # 密码(默认为空)
|
||||
timeout: 6000ms # 连接超时时长(毫秒)
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
<result column="type" property="type"/>
|
||||
<result column="target" property="target"/>
|
||||
<result column="key_result" property="keyResult"/>
|
||||
<result column="key_result_3_5" property="keyResult35"/>
|
||||
<result column="key_result_3_7" property="keyResult37"/>
|
||||
<result column="check_weight" property="checkWeight"/>
|
||||
<result column="check_result" property="checkResult"/>
|
||||
<result column="super_score" property="superScore"/>
|
||||
@ -24,7 +26,7 @@
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, type AS type, target AS target, key_result AS keyResult, check_weight AS checkWeight, check_result AS checkResult, super_score AS superScore, acquire_score AS acquireScore, score_comment AS scoreComment, record_id AS recordId, staff_id AS staffId, priority AS priority
|
||||
id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, type AS type, target AS target, key_result AS keyResult, key_result_3_5 AS keyResult35, key_result_3_7 AS keyResult37, check_weight AS checkWeight, check_result AS checkResult, super_score AS superScore, acquire_score AS acquireScore, score_comment AS scoreComment, record_id AS recordId, staff_id AS staffId, priority AS priority
|
||||
</sql>
|
||||
|
||||
|
||||
@ -40,6 +42,8 @@
|
||||
<if test="type != null">type, </if>
|
||||
<if test="target != null">target, </if>
|
||||
<if test="keyResult != null">key_result, </if>
|
||||
<if test="keyResult35 != null">key_result_3_5, </if>
|
||||
<if test="keyResult37 != null">key_result_3_7, </if>
|
||||
<if test="checkWeight != null">check_weight, </if>
|
||||
<if test="checkResult != null">check_result, </if>
|
||||
<if test="superScore != null">super_score, </if>
|
||||
@ -55,6 +59,8 @@
|
||||
<if test="type != null">#{ type}, </if>
|
||||
<if test="target != null">#{ target}, </if>
|
||||
<if test="keyResult != null">#{ keyResult}, </if>
|
||||
<if test="keyResult35 != null">#{ keyResult35}, </if>
|
||||
<if test="keyResult37 != null">#{ keyResult37}, </if>
|
||||
<if test="checkWeight != null">#{ checkWeight}, </if>
|
||||
<if test="checkResult != null">#{ checkResult}, </if>
|
||||
<if test="superScore != null">#{ superScore}, </if>
|
||||
@ -79,6 +85,8 @@
|
||||
<if test="type != null">type = #{type},</if>
|
||||
<if test="target != null">target = #{target},</if>
|
||||
<if test="keyResult != null">key_result = #{keyResult},</if>
|
||||
<if test="keyResult35 != null">key_result_3_5 = #{keyResult35},</if>
|
||||
<if test="keyResult37 != null">key_result_3_7 = #{keyResult37},</if>
|
||||
<if test="checkWeight != null">check_weight = #{checkWeight},</if>
|
||||
<if test="checkResult != null">check_result = #{checkResult},</if>
|
||||
<if test="superScore != null">super_score = #{superScore},</if>
|
||||
@ -102,6 +110,8 @@
|
||||
type = #{type},
|
||||
target = #{target},
|
||||
key_result = #{keyResult},
|
||||
key_result_3_5 = #{keyResult35},
|
||||
key_result_3_7 = #{keyResult37},
|
||||
check_weight = #{checkWeight},
|
||||
check_result = #{checkResult},
|
||||
super_score = #{superScore},
|
||||
@ -120,6 +130,7 @@
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
<select id="selectByRecordId" resultType="com.lz.modules.sys.entity.app.ResultDetail">
|
||||
select * from lz_result_detail where record_id=#{recordResultId} and is_delete = 0 order by type asc ,priority desc
|
||||
</select>
|
||||
|
||||
@ -134,5 +134,10 @@
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectFlowRecordByFlowId" resultType="com.lz.modules.flow.entity.FlowRecord">
|
||||
select * from lz_flow_record where is_delete = 0 and record_id = #{recordId}
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ public class MysqlMain {
|
||||
}
|
||||
List<TablesBean> list = new ArrayList<TablesBean>();
|
||||
|
||||
list.add(new TablesBean("lz_result_record"));
|
||||
list.add(new TablesBean("lz_result_detail"));
|
||||
|
||||
List<TablesBean> list2 = new ArrayList<TablesBean>();
|
||||
Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user