|
@@ -1,7 +1,10 @@
|
|
package com.rongwei.zhsw.system.utils;
|
|
package com.rongwei.zhsw.system.utils;
|
|
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
import com.rongwei.commonservice.service.RedisService;
|
|
|
|
+import com.rongwei.rwadmincommon.system.dao.SysDictDao;
|
|
|
|
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
import com.rongwei.rwadmincommon.system.domain.SysUserDo;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
import com.rongwei.rwcommon.base.BaseDo;
|
|
@@ -15,7 +18,12 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Random;
|
|
|
|
+import java.util.function.BiConsumer;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
/**
|
|
* CXCommonUtils class
|
|
* CXCommonUtils class
|
|
@@ -28,14 +36,17 @@ public class ZhswCommonUtils {
|
|
private static final Logger log = LoggerFactory.getLogger(ZhswCommonUtils.class.getName());
|
|
private static final Logger log = LoggerFactory.getLogger(ZhswCommonUtils.class.getName());
|
|
@Autowired
|
|
@Autowired
|
|
private RedisService autoRedisService;
|
|
private RedisService autoRedisService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysDictDao auoSysDictDao;
|
|
|
|
|
|
- private static RedisService redisService;
|
|
|
|
|
|
|
|
|
|
+ private static RedisService redisService;
|
|
|
|
+ private static SysDictDao sysDictDao;
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
public void info() {
|
|
public void info() {
|
|
redisService = autoRedisService;
|
|
redisService = autoRedisService;
|
|
-
|
|
|
|
|
|
+ sysDictDao=auoSysDictDao;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -61,15 +72,75 @@ public class ZhswCommonUtils {
|
|
userVo = getCurrentUser();
|
|
userVo = getCurrentUser();
|
|
}
|
|
}
|
|
t.setDeleted("0");
|
|
t.setDeleted("0");
|
|
|
|
+ t.setCreatedate(new Date());
|
|
|
|
+ t.setModifydate(new Date());
|
|
if(userVo==null){
|
|
if(userVo==null){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- t.setCreatedate(new Date());
|
|
|
|
- t.setModifydate(new Date());
|
|
|
|
t.setCreateuserid(userVo.getId());
|
|
t.setCreateuserid(userVo.getId());
|
|
t.setCreateusername(userVo.getName());
|
|
t.setCreateusername(userVo.getName());
|
|
t.setModifyuserid(userVo.getId());
|
|
t.setModifyuserid(userVo.getId());
|
|
t.setModifyusername(userVo.getName());
|
|
t.setModifyusername(userVo.getName());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 标识 用于业务系统的编号信息
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static String uniqueSign() {
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ Random random = new Random();
|
|
|
|
+ int randomNumber = random.nextInt(9999);
|
|
|
|
+ String dateString = sdf.format(new Date());
|
|
|
|
+ return dateString + String.format("%04d",randomNumber); // 将时间戳和随机数拼接成字符串
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * 数据字典替换方法
|
|
|
|
+ *
|
|
|
|
+ * @param dictType 数据字典类型
|
|
|
|
+ * @param pojos 实体List
|
|
|
|
+ * @param getPojoData 需要替换字段的get方
|
|
|
|
+ * @param setPojoData 需要替换字段的set方法
|
|
|
|
+ * @param <T>
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static <T> void replaceSysDictMethod(List<T> pojos,
|
|
|
|
+ Function<T, String> getPojoData, BiConsumer<T, String> setPojoData,
|
|
|
|
+ String dictType) {
|
|
|
|
+ if (org.apache.commons.lang.StringUtils.isBlank(dictType)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 报表类型
|
|
|
|
+ List<SysDictDo> sysDictDoList = sysDictDao.selectList(new LambdaQueryWrapper<SysDictDo>()
|
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
|
+ .eq(SysDictDo::getDicttype, dictType));
|
|
|
|
+ if (sysDictDoList.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 循环实体
|
|
|
|
+ pojos.forEach(pojo -> {
|
|
|
|
+ // 获取数字字典
|
|
|
|
+ SysDictDo sysDictDo = sysDictDoList.stream().filter(dict -> dict.getValue().equals(getPojoData.apply(pojo))).findFirst().orElse(null);
|
|
|
|
+ setPojoData.accept(pojo, sysDictDo == null ? getPojoData.apply(pojo) : sysDictDo.getName());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static <T> void replaceSysDictMethod(T pojo,
|
|
|
|
+ Function<T, String> getPojoData, BiConsumer<T, String> setPojoData,
|
|
|
|
+ String dictType) {
|
|
|
|
+ if (org.apache.commons.lang.StringUtils.isBlank(dictType)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 报表类型
|
|
|
|
+ List<SysDictDo> sysDictDoList = sysDictDao.selectList(new LambdaQueryWrapper<SysDictDo>()
|
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
|
+ .eq(SysDictDo::getDicttype, dictType));
|
|
|
|
+ if (sysDictDoList.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取数字字典
|
|
|
|
+ SysDictDo sysDictDo = sysDictDoList.stream().filter(dict -> dict.getValue().equals(getPojoData.apply(pojo))).findFirst().orElse(null);
|
|
|
|
+ setPojoData.accept(pojo, sysDictDo == null ? getPojoData.apply(pojo) : sysDictDo.getName());
|
|
|
|
+ }
|
|
}
|
|
}
|