|
@@ -31,6 +31,7 @@ import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.node.ForestNodeMerger;
|
|
|
+import org.springblade.core.tool.support.Try;
|
|
|
import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.manager.bean.NodeVO;
|
|
|
import org.springblade.manager.dto.TableSortDTO;
|
|
@@ -50,6 +51,7 @@ import org.springblade.manager.vo.*;
|
|
|
import org.springblade.system.cache.ParamCache;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
+import org.springframework.jdbc.BadSqlGrammarException;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -2409,4 +2411,58 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
|
|
|
throw new ServiceException("请传入ids");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void resetTableDate(Long projectId) {
|
|
|
+ //1 获取项目下所有节点
|
|
|
+ List<WbsTreeContract> allTable = baseMapper.projectAllTable(projectId);
|
|
|
+ //2 获取所有的m表,存入set集合中
|
|
|
+ Set<String> tables = allTable.stream().filter(l->StringUtils.isNotBlank(l.getInitTableName())).map(l->l.getInitTableName()).collect(Collectors.toSet());
|
|
|
+ List<String> updateSql = new ArrayList<>();
|
|
|
+ //3 循环m表,判断是否存在,存在则查询所有数据,按照map格式
|
|
|
+ for (String table : tables) {
|
|
|
+ String isExitSql = " select * from " + table;
|
|
|
+ List<Map<String, Object>> tabList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ tabList = jdbcTemplate.queryForList(isExitSql);
|
|
|
+ }catch (BadSqlGrammarException e){
|
|
|
+ System.out.println("表单不存在"+table);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (CollectionUtil.isNotEmpty(tabList)) {
|
|
|
+ //4 循环数据,正则表达式匹配,匹配成功就拼接sql,存入集合
|
|
|
+ for (Map<String, Object> map : tabList) {
|
|
|
+ Object id = map.get("id");
|
|
|
+ for (String s : map.keySet()) {
|
|
|
+ Object object = map.get(s);
|
|
|
+ if (org.springblade.core.tool.utils.ObjectUtil.isNotEmpty(object) && !object.toString().contains("[") && object.toString().contains(",")){
|
|
|
+ // 定义日期格式的正则表达式
|
|
|
+ String regex = "\\d{4}年\\d{1,2}月\\d{1,2}日";
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
+ Matcher matcher = pattern.matcher(object.toString());
|
|
|
+ // 使用计数器来跟踪匹配到的日期数量
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ while (matcher.find()) {
|
|
|
+ list.add(matcher.group());
|
|
|
+ }
|
|
|
+ if (list.size() == 2) {
|
|
|
+ System.out.println(object);
|
|
|
+ //分割尾缀
|
|
|
+ String[] split = object.toString().split("_\\^_",2);
|
|
|
+ String newDate = "["+list.get(0)+", "+list.get(1)+"]"+"_^_"+split[1];
|
|
|
+ String sql = " UPDATE "+table + " set "+s +"= '"+newDate+"' WHERE id = "+id;
|
|
|
+ updateSql.add(sql);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //5 执行sql,批量修改
|
|
|
+ List<List<String>> lists = CommonUtil.splitList(updateSql, 1000);
|
|
|
+ for (List<String> list : lists) {
|
|
|
+ baseMapper.batchUpdateTable(list);
|
|
|
+ }
|
|
|
+ System.out.println("66666666666");
|
|
|
+ }
|
|
|
}
|