|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.mixsmart.utils.FormulaUtils;
|
|
|
import com.mixsmart.utils.StringUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.manager.dto.FormulaOptionVo;
|
|
|
import org.springblade.manager.dto.RangeInfo;
|
|
@@ -106,45 +107,51 @@ public class FormulaOptionServiceImpl extends ServiceImpl<FormulaOptionMapper, F
|
|
|
|
|
|
@Override
|
|
|
public Object saveOrUpdateOption(RangeInfo rg,String[] dw,int start ) {
|
|
|
- RangeJson rj = new RangeJson(rg);
|
|
|
- rj.setStart(start);
|
|
|
- WbsTreeContract wbc = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, rg.getPkId()));
|
|
|
- WbsTreeContract parent= this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getParentId, wbc.getParentId()).eq(WbsTreeContract::getContractId, wbc.getContractId()));
|
|
|
- FormulaOption formulaOption = this.getById(parent.getPKeyId());
|
|
|
- JSONObject root;
|
|
|
- if (formulaOption == null) {
|
|
|
- formulaOption = new FormulaOption();
|
|
|
- formulaOption.setId(parent.getPKeyId());
|
|
|
- formulaOption.setParentId(wbc.getParentId());
|
|
|
- formulaOption.setContractId(Func.toLong(wbc.getContractId()));
|
|
|
- root = new JSONObject();
|
|
|
- } else {
|
|
|
- root = JSON.parseObject(formulaOption.getVal());
|
|
|
- }
|
|
|
- JSONObject table = (JSONObject) root.computeIfAbsent(wbc.getInitTableName(), (k) -> new JSONObject());
|
|
|
- JSONObject data = (JSONObject) table.computeIfAbsent(rg.getKey(), (k) -> new JSONObject());
|
|
|
- /*每个元素可以包含多个右键随机参数,只要范围不重叠都可以,具有重要参考意义但实际计算合格率和模仿数据的时候必须同时依赖实际元素数据*/
|
|
|
- /**/
|
|
|
- List<Map<String,Object>> listMaps=this.jdbcTemplate.queryForList("select p_key_id pkeyId from m_wbs_tree_contract where parent_id="+wbc.getParentId()+" and contract_id ="+wbc.getContractId()+" and is_deleted=0 and init_table_name='"+wbc.getInitTableName()+"' ORDER BY sort");
|
|
|
- if(listMaps.size()>0){
|
|
|
- List<Long> ids = listMaps.stream().map(m->Long.parseLong(m.get("pkeyId").toString())).collect(Collectors.toList());
|
|
|
- JSONArray rangeArr = (JSONArray) data.computeIfAbsent(RangeInfo.RG, (k) -> new JSONArray());
|
|
|
- if(ids.contains(rj.getPkeyId())){
|
|
|
- List<RangeJson> rjs= JSON.parseArray(rangeArr.toJSONString(),RangeJson.class);
|
|
|
- int head= (ids.indexOf(rj.getPkeyId()))*dw.length+start;
|
|
|
- int tail=head+Integer.parseInt(rj.getSize());
|
|
|
- rjs.removeIf(e->rangeCompare(ids,dw.length,e,head,tail));
|
|
|
- rjs.add(rj);
|
|
|
- rjs.sort(Comparator.comparingInt(e->ids.indexOf(e.getPkeyId())));
|
|
|
- rangeArr=JSONArray.parseArray(JSON.toJSONString(rjs));
|
|
|
- }else {
|
|
|
- rangeArr.add(rj);
|
|
|
+ try {
|
|
|
+
|
|
|
+ RangeJson rj = new RangeJson(rg);
|
|
|
+ rj.setStart(start);
|
|
|
+ WbsTreeContract wbc = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, rg.getPkId()));
|
|
|
+ WbsTreeContract parent = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getId, wbc.getParentId()).eq(WbsTreeContract::getContractId, wbc.getContractId()));
|
|
|
+ FormulaOption formulaOption = this.getById(parent.getPKeyId());
|
|
|
+ JSONObject root;
|
|
|
+ if (formulaOption == null) {
|
|
|
+ formulaOption = new FormulaOption();
|
|
|
+ formulaOption.setId(parent.getPKeyId());
|
|
|
+ formulaOption.setParentId(wbc.getParentId());
|
|
|
+ formulaOption.setContractId(Func.toLong(wbc.getContractId()));
|
|
|
+ root = new JSONObject();
|
|
|
+ } else {
|
|
|
+ root = JSON.parseObject(formulaOption.getVal());
|
|
|
+ }
|
|
|
+ JSONObject table = (JSONObject) root.computeIfAbsent(wbc.getInitTableName(), (k) -> new JSONObject());
|
|
|
+ JSONObject data = (JSONObject) table.computeIfAbsent(rg.getKey(), (k) -> new JSONObject());
|
|
|
+ /*每个元素可以包含多个右键随机参数,只要范围不重叠都可以,具有重要参考意义但实际计算合格率和模仿数据的时候必须同时依赖实际元素数据*/
|
|
|
+ /**/
|
|
|
+ List<Map<String, Object>> listMaps = this.jdbcTemplate.queryForList("select p_key_id pkeyId from m_wbs_tree_contract where parent_id=" + wbc.getParentId() + " and contract_id =" + wbc.getContractId() + " and is_deleted=0 and init_table_name='" + wbc.getInitTableName() + "' ORDER BY sort");
|
|
|
+ if (listMaps.size() > 0) {
|
|
|
+ List<Long> ids = listMaps.stream().map(m -> Long.parseLong(m.get("pkeyId").toString())).collect(Collectors.toList());
|
|
|
+ JSONArray rangeArr = (JSONArray) data.computeIfAbsent(RangeInfo.RG, (k) -> new JSONArray());
|
|
|
+ if (ids.contains(rj.getPkeyId())) {
|
|
|
+ List<RangeJson> rjs = JSON.parseArray(rangeArr.toJSONString(), RangeJson.class);
|
|
|
+ int head = (ids.indexOf(rj.getPkeyId())) * dw.length + start;
|
|
|
+ int tail = head + Integer.parseInt(rj.getSize());
|
|
|
+ rjs.removeIf(e -> rangeCompare(ids, dw.length, e, head, tail));
|
|
|
+ rjs.add(rj);
|
|
|
+ rjs.sort(Comparator.comparingInt(e -> ids.indexOf(e.getPkeyId())));
|
|
|
+ rangeArr = JSONArray.parseArray(JSON.toJSONString(rjs));
|
|
|
+ } else {
|
|
|
+ rangeArr.add(rj);
|
|
|
+ }
|
|
|
+ data.put(RangeInfo.RG, rangeArr);
|
|
|
}
|
|
|
- data.put(RangeInfo.RG, rangeArr);
|
|
|
+ formulaOption.setVal(root.toJSONString());
|
|
|
+ this.saveOrUpdate(formulaOption);
|
|
|
+ return data;
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.fail("保存失败");
|
|
|
}
|
|
|
- formulaOption.setVal(root.toJSONString());
|
|
|
- this.saveOrUpdate(formulaOption);
|
|
|
- return data;
|
|
|
}
|
|
|
|
|
|
public static Boolean rangeCompare(List<Long> ids,Integer len,RangeJson rj ,Integer head,Integer tail){
|