|
@@ -11,6 +11,7 @@ import com.mixsmart.utils.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.tool.api.R;
|
|
@@ -19,7 +20,9 @@ import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.RegexUtil;
|
|
|
import org.springblade.core.tool.utils.StringPool;
|
|
|
import org.springblade.manager.dto.*;
|
|
|
+import org.springblade.manager.entity.ElementFormulaMapping;
|
|
|
import org.springblade.manager.entity.Formula;
|
|
|
+import org.springblade.manager.service.IElementFormulaMappingService;
|
|
|
import org.springblade.manager.service.IExcelTabService;
|
|
|
import org.springblade.manager.service.impl.FormulaServiceImpl;
|
|
|
import org.springblade.manager.wrapper.FormulaWrapper;
|
|
@@ -45,51 +48,58 @@ import java.util.stream.Collectors;
|
|
|
public class FormulaController {
|
|
|
private final FormulaServiceImpl service;
|
|
|
private final IExcelTabService tabService;
|
|
|
+ private final IElementFormulaMappingService elementFormulaMappingService;
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
/**
|
|
|
* 新增或修改
|
|
|
*/
|
|
|
@PostMapping("/save")
|
|
|
- @ApiOperationSupport(order = 4)
|
|
|
- @ApiOperation(value = "新增或修改", notes = "传入")
|
|
|
- public R save(@RequestBody Formula f) {
|
|
|
- f.setFormula(StringUtils.escapeFormula(f.getFormula()));
|
|
|
- if(this.service.count(Wrappers.<Formula>query().lambda().eq(Formula::getElementId,f.getElementId()))>0){
|
|
|
- return R.status(false);
|
|
|
- }
|
|
|
- this.service.relyParse(f);
|
|
|
- service.save(f);
|
|
|
- return R.data(f.getId());
|
|
|
+ @Deprecated
|
|
|
+ public R save(@RequestBody FormulaBean f) {
|
|
|
+ return saveOrUpdate(f);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 修改
|
|
|
*/
|
|
|
@PostMapping("/update")
|
|
|
- @ApiOperationSupport(order = 5)
|
|
|
- @ApiOperation(value = "修改", notes = "传入脚本")
|
|
|
+ @Deprecated
|
|
|
public R update( @RequestBody FormulaBean f) {
|
|
|
- f.setFormula(StringUtils.escapeFormula(f.getFormula()));
|
|
|
- if(f.getId()!=null){
|
|
|
- Formula old = this.service.getById(f.getId());
|
|
|
- if(old!=null){
|
|
|
- BeanUtils.copyProperties(f,old);
|
|
|
- this.service.relyParse(old);
|
|
|
- return R.status(service.updateById(old));
|
|
|
- }
|
|
|
- }
|
|
|
- return R.status(false);
|
|
|
+ return saveOrUpdate(f);
|
|
|
}
|
|
|
|
|
|
@PostMapping("/saveOrUpdate")
|
|
|
@ApiOperationSupport(order = 5)
|
|
|
@ApiOperation(value = "保存或修改公式脚本", notes = "保存或修改公式脚本")
|
|
|
- public R saveOrUpdate( @RequestBody Formula f) {
|
|
|
- if(f.getId()==null){
|
|
|
- return save(f);
|
|
|
- }else{
|
|
|
- return update(Objects.requireNonNull(BeanUtil.copy(f, FormulaBean.class)));
|
|
|
- }
|
|
|
+ public R saveOrUpdate( @RequestBody FormulaBean f) {
|
|
|
+ if(f.verify()){
|
|
|
+ Formula fa =f.toFormula();
|
|
|
+ fa.setFormula(StringUtils.escapeFormula(f.getFormula()));
|
|
|
+ this.service.relyParse(fa);
|
|
|
+ if(f.isNewOne()){
|
|
|
+ if(f.isPart()){
|
|
|
+ if(f.getNodeId()!=null){
|
|
|
+ fa.setId(SnowFlakeUtil.getId());
|
|
|
+ this.service.save(fa);
|
|
|
+ ElementFormulaMapping efm = new ElementFormulaMapping();
|
|
|
+ efm.setFormulaId(fa.getId());
|
|
|
+ efm.setNodeId(f.getNodeId());
|
|
|
+ efm.setElementId(f.getElementId());
|
|
|
+ this.elementFormulaMappingService.save(efm);
|
|
|
+ return R.success("新增成功");
|
|
|
+ }else{
|
|
|
+ R.fail("保存不成功,请检查nodeId字段是否为空") ;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ R.status(this.service.save(fa));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ R.status(this.service.updateById(fa));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.fail("保存不成功,请检查elementId、formula、scope字段是否为空");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -99,7 +109,12 @@ public class FormulaController {
|
|
|
@ApiOperationSupport(order = 6)
|
|
|
@ApiOperation(value = "删除", notes = "传入id集合")
|
|
|
public R remove(@RequestParam String ids) {
|
|
|
- return R.status(this.service.deleteLogic(Func.toLongList(ids)));
|
|
|
+ if(StringUtils.isNotEmpty(ids)) {
|
|
|
+ List<Long> ids_d=Func.toLongList(ids);
|
|
|
+ this.elementFormulaMappingService.update(Wrappers.<ElementFormulaMapping>lambdaUpdate().set(ElementFormulaMapping::getIsDeleted, 1).in(ElementFormulaMapping::getFormulaId,ids_d));
|
|
|
+ return R.status(this.service.deleteLogic(ids_d));
|
|
|
+ }
|
|
|
+ return R.fail("无效id");
|
|
|
}
|
|
|
/**
|
|
|
* 查询单条
|
|
@@ -107,11 +122,23 @@ public class FormulaController {
|
|
|
@ApiOperationSupport(order =7)
|
|
|
@ApiOperation(value = "查看详情", notes = "传入id")
|
|
|
@GetMapping("/detail")
|
|
|
- public R<FormulaBean> detail(Formula f) {
|
|
|
- Formula detail = service.getOne(Condition.getQueryWrapper(f));
|
|
|
- if(detail!=null){
|
|
|
- return R.data(BeanUtil.copy(detail,FormulaBean.class));
|
|
|
- }
|
|
|
+ public R<FormulaBean> detail(FormulaBean f) {
|
|
|
+ Formula data = null;
|
|
|
+ if(f.isGlobal()){
|
|
|
+ if(f.getElementId()!=null) {
|
|
|
+ data = this.service.getOne(Wrappers.<Formula>lambdaQuery().eq(Formula::getElementId, f.getElementId()));
|
|
|
+ }
|
|
|
+ }else if(f.isPart()){
|
|
|
+ if(f.getElementId()!=null&&f.getNodeId()!=null) {
|
|
|
+ ElementFormulaMapping efm = this.elementFormulaMappingService.getOne(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getElementId, f.getElementId()).eq(ElementFormulaMapping::getNodeId, f.getNodeId()));
|
|
|
+ if(efm!=null){
|
|
|
+ data=this.service.getById(efm.getFormulaId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(data!=null){
|
|
|
+ return R.data(BeanUtil.copy(data,FormulaBean.class));
|
|
|
+ }
|
|
|
return R.success("无数据");
|
|
|
}
|
|
|
|
|
@@ -120,8 +147,8 @@ public class FormulaController {
|
|
|
@GetMapping("/page")
|
|
|
public IPage<FormulaBean> userSearch(@ApiIgnore FormulaBean param, @ApiIgnore Query query) {
|
|
|
LambdaQueryWrapper<Formula> queryWrapper = Wrappers.<Formula>query().lambda();
|
|
|
- if(Func.isNotEmpty(param.getWbsId())){
|
|
|
- queryWrapper.eq(Formula::getWbsId,param.getWbsId());
|
|
|
+ if(Func.isNotEmpty(param.getNodeId())){
|
|
|
+ queryWrapper.eq(Formula::getNodeId,param.getNodeId());
|
|
|
}
|
|
|
if(Func.isNotEmpty(param.getFormula())){
|
|
|
queryWrapper.like(Formula::getFormula,param.getFormula());
|
|
@@ -145,8 +172,8 @@ public class FormulaController {
|
|
|
elementIds.forEach(e->{
|
|
|
Formula formula = new Formula();
|
|
|
formula.setElementId(e);
|
|
|
- formula.setWbsId(bean.getNodeId());
|
|
|
- formula.setOut(Formula.FULL);
|
|
|
+ formula.setNodeId(bean.getNodeId());
|
|
|
+ formula.setOutm(Formula.FULL);
|
|
|
Map<String,String> m= new HashMap<>();
|
|
|
m.put("name",bean.getName());
|
|
|
m.put("id",bean.getParamId().toString());
|
|
@@ -207,7 +234,7 @@ public class FormulaController {
|
|
|
}
|
|
|
List<Object> data = CustomFunction.b445random(info.getSize(),info.getDesign(),info.getDev(),info.getFail(),1);
|
|
|
String[] dw = keymap.get(info.getKey()).split(StringPool.SEMICOLON);
|
|
|
- Map<String,Object> result = new HashMap<>();
|
|
|
+ Map<String,Object> result = new HashMap<>(dw.length*2);
|
|
|
if(dw.length==1){
|
|
|
result.put(info.getKey()+"__"+dw[0],data.stream().filter(StringUtils::isNotEmpty).map(Func::toStr).collect(Collectors.joining("、")));
|
|
|
}else{
|