|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.StopWatch;
|
|
|
import cn.hutool.log.StaticLog;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
@@ -33,9 +34,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
-
|
|
|
-import javax.script.ScriptEngine;
|
|
|
-import javax.script.ScriptEngineManager;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -99,7 +97,6 @@ public class WbsParamController {
|
|
|
this.elementFormulaMappingService.update(Wrappers.<ElementFormulaMapping>lambdaUpdate().set(ElementFormulaMapping::getIsDeleted, 1).in(ElementFormulaMapping::getParamId, pb.getDelIds()));
|
|
|
}
|
|
|
}
|
|
|
- /*应该检查接触关联的参数公式还是否存在引用,不存在的情况也要删去*/
|
|
|
}
|
|
|
if (CollectionUtil.isNotEmpty(wps)) {
|
|
|
Map<Boolean, List<WbsParamBean>> map = wps.stream().peek(w -> w.setType(pb.getType())).collect(Collectors.partitioningBy(e -> e.getId() != null));
|
|
@@ -108,6 +105,7 @@ public class WbsParamController {
|
|
|
if (CollectionUtil.isNotEmpty(saveList)) {
|
|
|
List<WbsParam> entityList = BeanUtil.copy(saveList, WbsParam.class);
|
|
|
this.service.saveBatch(entityList);
|
|
|
+ Map<String, Object> tmpMap = new HashMap<>();
|
|
|
if (!pb.isCommon()) {
|
|
|
/*新建的时候需要初始化绑定表单元素*/
|
|
|
List<Map<String, Object>> elementMap = new ArrayList<>();
|
|
@@ -127,38 +125,53 @@ public class WbsParamController {
|
|
|
"where b.project_id=" + pb.getProjectId() + " and a.p_key_id=" + pb.getNodeId() + " and b.is_deleted=0 and c.is_deleted=0 ");
|
|
|
}
|
|
|
if (!elementMap.isEmpty()) {
|
|
|
- Map<String, Object> tmpMap = new HashMap<>();
|
|
|
List<Map<String, Object>> finalElementMap = elementMap;
|
|
|
+ // List<Map<String,Object>> formulaIdAndKmaps=this.jdbcTemplate.queryForList("select a.id,b.k from m_formula a join m_wbs_param b on a.param_id=b.id where b.k in ("+entityList.stream().map(WbsParam::getK).collect(Collectors.joining("','","'","'"))+") AND b.type=0");
|
|
|
+ Map<String,Long> fkMap=this.service.formulaIdKeyMap(entityList.stream().map(WbsParam::getK).collect(Collectors.toList()));
|
|
|
entityList.forEach(e -> {
|
|
|
- Formula formula = new Formula();
|
|
|
- formula.setOutm(Formula.FULL);
|
|
|
- formula.setParamId(e.getId());
|
|
|
- Map<String, String> keyMap = new HashMap<>();
|
|
|
- keyMap.put("name", e.getName());
|
|
|
- keyMap.put("id", e.getId().toString());
|
|
|
- tmpMap.put(e.getK(), keyMap);
|
|
|
- if (RegexUtil.match(ParamElements.LEVEL_REG, e.getV().trim())) {
|
|
|
- /*取层级*/
|
|
|
- formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
- } else {
|
|
|
- /*直接取数*/
|
|
|
- formula.setFormula("WP[" + e.getK() + "]");
|
|
|
- }
|
|
|
- formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
- this.formulaService.save(formula);
|
|
|
- tmpMap.clear();
|
|
|
+// Formula formula = new Formula();
|
|
|
+// formula.setOutm(Formula.FULL);
|
|
|
+// formula.setParamId(e.getId());
|
|
|
+// Map<String, String> keyMap = new HashMap<>();
|
|
|
+// keyMap.put("name", e.getName());
|
|
|
+// keyMap.put("id", e.getId().toString());
|
|
|
+// tmpMap.put(e.getK(), keyMap);
|
|
|
+// if (RegexUtil.match(ParamElements.LEVEL_REG, e.getV().trim())) {
|
|
|
+// /*取层级*/
|
|
|
+// formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
+// } else {
|
|
|
+// /*直接取数*/
|
|
|
+// formula.setFormula("WP[" + e.getK() + "]");
|
|
|
+// }
|
|
|
+// formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+// this.formulaService.save(formula);
|
|
|
+// tmpMap.clear();
|
|
|
finalElementMap.forEach(m -> {
|
|
|
if (StringUtils.handleNull(m.get("name")).contains(e.getName())) {
|
|
|
ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
efm.setScope(FormulaBean.PARAM);
|
|
|
efm.setParamId(e.getId());
|
|
|
efm.setElementId(Long.parseLong(m.get("id").toString()));
|
|
|
- efm.setFormulaId(formula.getId());
|
|
|
+ efm.setFormulaId(fkMap.get(e.getK()));
|
|
|
this.elementFormulaMappingService.save(efm);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+ }else{
|
|
|
+ entityList.forEach(e -> {
|
|
|
+ Formula formula = new Formula();
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
+ formula.setParamId(e.getId());
|
|
|
+ Map<String, String> keyMap = new HashMap<>();
|
|
|
+ keyMap.put("name", e.getName());
|
|
|
+ keyMap.put("id", e.getId().toString());
|
|
|
+ tmpMap.put(e.getK(), keyMap);
|
|
|
+ formula.setFormula("FC.tree(trees,WP[" + e.getK().replaceAll("[\\s]+","") + "])");
|
|
|
+ formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+ this.formulaService.save(formula);
|
|
|
+ tmpMap.clear();
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtil.isNotEmpty(updateList)) {
|
|
@@ -166,8 +179,17 @@ public class WbsParamController {
|
|
|
for (WbsParamBean b : updateList) {
|
|
|
WbsParam old = this.service.getById(b.getId());
|
|
|
if (pb.isCommon()) {
|
|
|
- if (old != null && (StringUtils.isNotEquals(old.getK(),b.getK())||StringUtils.isNotEquals(old.getRemark(),b.getRemark()))) {
|
|
|
+ if (old != null && (StringUtils.isNotEquals(old.getName(),b.getName())||StringUtils.isNotEquals(old.getK(),b.getK())||StringUtils.isNotEquals(old.getRemark(),b.getRemark()))) {
|
|
|
/*只有公式内容变化的时候才需要更新*/
|
|
|
+ if(StringUtils.isNotEquals(old.getK(),b.getK())||StringUtils.isNotEquals(old.getName(),b.getName())){
|
|
|
+ LambdaUpdateWrapper<WbsParam> wrapper=Wrappers.<WbsParam>lambdaUpdate().set(WbsParam::getName,b.getName()).set(WbsParam::getK,b.getK()).eq(WbsParam::getType,1).eq(WbsParam::getK,old.getK());
|
|
|
+ this.service.update(wrapper);
|
|
|
+ if(StringUtils.isNotEquals(old.getK(),b.getK())) {
|
|
|
+ Formula formula = this.formulaService.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getParamId, old.getId()));
|
|
|
+ formula.setFormula("FC.tree(trees,WP[" + b.getK() + "])");
|
|
|
+ this.formulaService.saveOrUpdate(formula);
|
|
|
+ }
|
|
|
+ }
|
|
|
old.setIsDeleted(0);
|
|
|
BeanUtils.copyProperties(b, old);
|
|
|
ul.add(old);
|
|
@@ -244,7 +266,7 @@ public class WbsParamController {
|
|
|
@ApiOperation(value = "获取名称字典", notes = "获取名称字典")
|
|
|
@GetMapping("/keymap")
|
|
|
public R<List<WbsParamBean>> list2() {
|
|
|
- LambdaQueryWrapper<WbsParam> queryWrapper = Wrappers.<WbsParam>query().lambda().eq(WbsParam::getType, 0);
|
|
|
+ LambdaQueryWrapper<WbsParam> queryWrapper = Wrappers.<WbsParam>query().lambda().eq(WbsParam::getType, 0).orderByDesc(WbsParam::getCreateTime);
|
|
|
List<WbsParamBean> list = new ArrayList<>();
|
|
|
List<WbsParam> data = this.service.list(queryWrapper);
|
|
|
if (CollectionUtil.isNotEmpty(data)) {
|
|
@@ -263,6 +285,11 @@ public class WbsParamController {
|
|
|
.eq(WbsParam::getNodeId, wbsId)
|
|
|
.eq(WbsParam::getType, 1));
|
|
|
if (data.size() > 0) {
|
|
|
+ List<Map<String,Object>> statistics=jdbcTemplate.queryForList("select count(*) sum,param_id id from m_element_formula_mapping a join m_wbs_param b on a.param_id= b.id where b.node_id="+wbsId+" and b.is_deleted=0 GROUP BY a.param_id");
|
|
|
+ Map<Long,Integer> mapSum=statistics.stream().collect(Collectors.toMap(m->Long.parseLong(m.get("id").toString()),m-> Integer.parseInt(m.get("sum").toString()),(v1,v2)->v2));
|
|
|
+ if(statistics.size()>1){
|
|
|
+ data.sort(Comparator.comparingInt((WbsParam d)->mapSum.getOrDefault(d.getId(),0)).reversed());
|
|
|
+ }
|
|
|
return R.data(BeanUtil.copyProperties(data, WbsParamBean.class));
|
|
|
}
|
|
|
return R.data(null);
|
|
@@ -315,35 +342,42 @@ public class WbsParamController {
|
|
|
public R<Boolean> specified(@ApiParam(value = "关联id", required = true) Long paramId, Long elementId) {
|
|
|
/*先删旧关联,检查是否存在公式,没有就新增 再增新关联*/
|
|
|
this.jdbcTemplate.execute("update m_element_formula_mapping set is_deleted=1 where element_id=" + elementId + " and param_id=" + paramId);
|
|
|
- Formula formula = this.formulaService.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getParamId, paramId));
|
|
|
- if (formula == null) {
|
|
|
- Map<String, Object> tmpMap = new HashMap<>();
|
|
|
- formula = new Formula();
|
|
|
- WbsParam param = this.service.getById(paramId);
|
|
|
- formula.setOutm(Formula.FULL);
|
|
|
- formula.setParamId(param.getId());
|
|
|
- Map<String, String> keyMap = new HashMap<>();
|
|
|
- keyMap.put("name", param.getName());
|
|
|
- keyMap.put("id", param.getId().toString());
|
|
|
- tmpMap.put(param.getK(), keyMap);
|
|
|
- if (RegexUtil.match(ParamElements.LEVEL_REG, param.getV().trim())) {
|
|
|
- /*取层级*/
|
|
|
- formula.setFormula("FC.tree(trees,WP[" + param.getK() + "])");
|
|
|
- } else {
|
|
|
- /*直接取数*/
|
|
|
- formula.setFormula("WP[" + param.getK() + "]");
|
|
|
- }
|
|
|
- formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
- this.formulaService.save(formula);
|
|
|
+// Formula formula = this.formulaService.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getParamId, paramId));
|
|
|
+// if (formula == null) {
|
|
|
+// Map<String, Object> tmpMap = new HashMap<>();
|
|
|
+// formula = new Formula();
|
|
|
+// WbsParam param = this.service.getById(paramId);
|
|
|
+// formula.setOutm(Formula.FULL);
|
|
|
+// formula.setParamId(param.getId());
|
|
|
+// Map<String, String> keyMap = new HashMap<>();
|
|
|
+// keyMap.put("name", param.getName());
|
|
|
+// keyMap.put("id", param.getId().toString());
|
|
|
+// tmpMap.put(param.getK(), keyMap);
|
|
|
+// if (RegexUtil.match(ParamElements.LEVEL_REG, param.getV().trim())) {
|
|
|
+// /*取层级*/
|
|
|
+// formula.setFormula("FC.tree(trees,WP[" + param.getK() + "])");
|
|
|
+// } else {
|
|
|
+// /*直接取数*/
|
|
|
+// formula.setFormula("WP[" + param.getK() + "]");
|
|
|
+// }
|
|
|
+// formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+// this.formulaService.save(formula);
|
|
|
+// }
|
|
|
+ WbsParam wbsParam=this.service.getById(paramId);
|
|
|
+ Long formulaId=this.service.formulaId(wbsParam.getK());
|
|
|
+ if(formulaId==null){
|
|
|
+ R.fail("公式不存在");
|
|
|
}
|
|
|
ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
efm.setScope(FormulaBean.PARAM);
|
|
|
efm.setParamId(paramId);
|
|
|
efm.setElementId(elementId);
|
|
|
- efm.setFormulaId(formula.getId());
|
|
|
+ efm.setFormulaId(formulaId);
|
|
|
return R.status(this.elementFormulaMappingService.save(efm));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/refresh")
|
|
|
@ApiOperationSupport(order = 1)
|
|
|
@ApiOperation(value = "刷新当前节点的节点参数", notes = "刷新当前节点的节点参数")
|
|
@@ -374,31 +408,32 @@ public class WbsParamController {
|
|
|
|
|
|
List<Long> longList = this.jdbcTemplate.queryForList("select element_id from m_element_formula_mapping where is_deleted=0 and scope=35 and param_id in(" + paramList.stream().map(WbsParam::getId).map(String::valueOf).collect(Collectors.joining(",")) + ")", Long.class);
|
|
|
if (Func.isNotEmpty(elementMap)) {
|
|
|
- Map<String, Object> tmpMap = new HashMap<>();
|
|
|
+// Map<String, Object> tmpMap = new HashMap<>();
|
|
|
List<Map<String, Object>> finalElementMap = elementMap;
|
|
|
+ Map<String,Long> fkMap = this.service.formulaIdKeyMap(paramList.stream().map(WbsParam::getK).collect(Collectors.toList()));
|
|
|
paramList.forEach(e -> {
|
|
|
/*复用节点参数公式,只要公式脚本一样就直接引用*/
|
|
|
- Formula formula = this.formulaService.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getParamId, e.getId()));
|
|
|
- if (formula == null) {
|
|
|
- formula = new Formula();
|
|
|
- formula.setOutm(Formula.FULL);
|
|
|
- formula.setParamId(e.getId());
|
|
|
- Map<String, String> keyMap = new HashMap<>();
|
|
|
- keyMap.put("name", e.getName());
|
|
|
- keyMap.put("id", e.getId().toString());
|
|
|
- tmpMap.put(e.getK(), keyMap);
|
|
|
- if (RegexUtil.match(ParamElements.LEVEL_REG, e.getV().trim())) {
|
|
|
- /*取层级*/
|
|
|
- formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
- } else {
|
|
|
- /*直接取数*/
|
|
|
- formula.setFormula("WP[" + e.getK() + "]");
|
|
|
- }
|
|
|
- formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
- this.formulaService.save(formula);
|
|
|
- tmpMap.clear();
|
|
|
- }
|
|
|
- Formula finalFormula = formula;
|
|
|
+// Formula formula = this.formulaService.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getParamId, e.getId()));
|
|
|
+// if (formula == null) {
|
|
|
+// formula = new Formula();
|
|
|
+// formula.setOutm(Formula.FULL);
|
|
|
+// formula.setParamId(e.getId());
|
|
|
+// Map<String, String> keyMap = new HashMap<>();
|
|
|
+// keyMap.put("name", e.getName());
|
|
|
+// keyMap.put("id", e.getId().toString());
|
|
|
+// tmpMap.put(e.getK(), keyMap);
|
|
|
+// if (RegexUtil.match(ParamElements.LEVEL_REG, e.getV().trim())) {
|
|
|
+// /*取层级*/
|
|
|
+// formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
+// } else {
|
|
|
+// /*直接取数*/
|
|
|
+// formula.setFormula("WP[" + e.getK() + "]");
|
|
|
+// }
|
|
|
+// formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+// this.formulaService.save(formula);
|
|
|
+// tmpMap.clear();
|
|
|
+// }
|
|
|
+// Formula finalFormula = formula;
|
|
|
String name = e.getName().replace("【水】", "").trim();
|
|
|
finalElementMap.forEach(m -> {
|
|
|
if (StringUtils.handleNull(m.get("name")).contains(name)) {
|
|
@@ -408,7 +443,7 @@ public class WbsParamController {
|
|
|
efm.setScope(FormulaBean.PARAM);
|
|
|
efm.setParamId(e.getId());
|
|
|
efm.setElementId(Long.parseLong(m.get("id").toString()));
|
|
|
- efm.setFormulaId(finalFormula.getId());
|
|
|
+ efm.setFormulaId(fkMap.get(e.getK()));
|
|
|
this.elementFormulaMappingService.save(efm);
|
|
|
}
|
|
|
}
|
|
@@ -425,6 +460,22 @@ public class WbsParamController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**节点公式创建*/
|
|
|
+ private Formula createFormula(WbsParam e){
|
|
|
+ Formula formula = new Formula();
|
|
|
+ Map<String, Object> tmpMap = new HashMap<>();
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
+ formula.setParamId(e.getId());
|
|
|
+ Map<String, String> keyMap = new HashMap<>();
|
|
|
+ keyMap.put("name", e.getName());
|
|
|
+ keyMap.put("id", e.getId().toString());
|
|
|
+ tmpMap.put(e.getK(), keyMap);
|
|
|
+ formula.setFormula("FC.tree(trees,WP[" + e.getK() + "])");
|
|
|
+ formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+ this.formulaService.save(formula);
|
|
|
+ return formula;
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/del-duplicate")
|
|
|
public R<Object> duplicate() {
|
|
|
try {
|
|
@@ -485,6 +536,46 @@ public class WbsParamController {
|
|
|
|
|
|
@GetMapping("/test")
|
|
|
public R<Object> test() {
|
|
|
- return R.fail("失败");
|
|
|
+ /*刷模版公式*/
|
|
|
+ List<WbsParam> list =service.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getType,0));
|
|
|
+ Map<String, Object> tmpMap = new HashMap<>();
|
|
|
+ list.forEach(e->{
|
|
|
+ Formula formula = new Formula();
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
+ formula.setParamId(e.getId());
|
|
|
+ Map<String, String> keyMap = new HashMap<>();
|
|
|
+ keyMap.put("name", e.getName());
|
|
|
+ keyMap.put("id", e.getId().toString());
|
|
|
+ tmpMap.put(e.getK(), keyMap);
|
|
|
+ formula.setFormula("FC.tree(trees,WP[" + e.getK().replaceAll("[\\s]+","") + "])");
|
|
|
+ formula.setMap(JSON.toJSONString(tmpMap));
|
|
|
+ this.formulaService.save(formula);
|
|
|
+ tmpMap.clear();
|
|
|
+ });
|
|
|
+ return R.success("完成");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/lack")
|
|
|
+ public R<Object> lack(String name) {
|
|
|
+ String tamplate="CREATE TABLE `"+name+"` (\n" +
|
|
|
+ " `id` bigint(20) NOT NULL COMMENT '主键id',\n" +
|
|
|
+ " `p_key_id` bigint(20) DEFAULT NULL COMMENT '合同段wbs树表单的p_key_id',\n" +
|
|
|
+ " `group_id` bigint(20) DEFAULT NULL COMMENT '分组id',\n" +
|
|
|
+ " #REPLACE\n" +
|
|
|
+ " PRIMARY KEY (`id`) USING BTREE\n" +
|
|
|
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8";
|
|
|
+ List<Map<String,Object>> listMap= this.jdbcTemplate.queryForList("select a.tab_ch_name tabName,a.tab_en_name initTableName,b.e_name eName,b.id elementId,b.e_key eKey ,CONCAT(a.tab_en_name,':',b.e_key) code from m_table_info a join m_wbs_form_element b on b.f_id=a.id where a.tab_en_name in ('"+name+"') and b.is_deleted=0");
|
|
|
+ if(listMap.size()>0){
|
|
|
+ List<String> keys = listMap.stream().map(m-> Func.toStr(m.get("ekey"))).collect(Collectors.toList());
|
|
|
+ String target = keys.stream().distinct().filter(Func::isNotBlank).map(s-> "`"+s+"` varchar(80) DEFAULT NULL,").collect(Collectors.joining("\n"));
|
|
|
+ tamplate=tamplate.replace("#REPLACE",target);
|
|
|
+ System.out.println(tamplate);
|
|
|
+ this.jdbcTemplate.execute(tamplate);
|
|
|
+ return R.success("完成");
|
|
|
+ }
|
|
|
+ return R.fail("创建失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|