diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/epdc/esua/epdc.gitkeep b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/epdc/esua/epdc.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiFormulaDTO.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiFormulaDTO.java new file mode 100644 index 000000000..91ddc77b0 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-client/src/main/java/com/elink/esua/epdc/dto/KpiFormulaDTO.java @@ -0,0 +1,102 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.dto; + + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Data +public class KpiFormulaDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 公式编码 + */ + private String code; + + /** + * 公式名称 + */ + private String name; + + /** + * 公式运行方法(Javascript) + */ + private String formula; + + /** + * 公式参数数量 + */ + private Integer paramAmount; + + /** + * 公式描述 + */ + private String description; + + /** + * 备注 + */ + private String remark; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * 删除标记 + */ + private String delFlag; + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/KpiApplication.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/KpiApplication.java similarity index 95% rename from esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/KpiApplication.java rename to esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/KpiApplication.java index 8032f1958..0d003f3dc 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/KpiApplication.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/KpiApplication.java @@ -6,7 +6,7 @@ * 版权所有,侵权必究! */ -package com.elink.epdc.esua; +package com.elink.esua.epdc; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/config/ModuleConfigImpl.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java similarity index 93% rename from esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/config/ModuleConfigImpl.java rename to esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java index 3dd8672dc..6bd7a2a81 100644 --- a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/epdc/esua/config/ModuleConfigImpl.java +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/config/ModuleConfigImpl.java @@ -6,7 +6,7 @@ * 版权所有,侵权必究! */ -package com.elink.epdc.esua.config; +package com.elink.esua.epdc.config; import com.elink.esua.epdc.commons.tools.config.ModuleConfig; import org.springframework.stereotype.Service; diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/controller/KpiFormulaController.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/controller/KpiFormulaController.java new file mode 100644 index 000000000..45f0ea8e2 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/controller/KpiFormulaController.java @@ -0,0 +1,93 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.controller; + +import com.elink.esua.epdc.dto.KpiFormulaDTO; +import com.elink.esua.epdc.excel.KpiFormulaExcel; +import com.elink.esua.epdc.service.KpiFormulaService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@RestController +@RequestMapping("kpiformula") +public class KpiFormulaController { + + @Autowired + private KpiFormulaService kpiFormulaService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = kpiFormulaService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + KpiFormulaDTO data = kpiFormulaService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody KpiFormulaDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + //kpiFormulaService.save(dto); + return kpiFormulaService.saveKpiFormula(dto); + } + + @PutMapping + public Result update(@RequestBody KpiFormulaDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + return kpiFormulaService.update(dto); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + kpiFormulaService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = kpiFormulaService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, KpiFormulaExcel.class); + } + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiFormulaDao.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiFormulaDao.java new file mode 100644 index 000000000..9aa5512f0 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/dao/KpiFormulaDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.dao; + +import com.elink.esua.epdc.entity.KpiFormulaEntity; +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import org.apache.ibatis.annotations.Mapper; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Mapper +public interface KpiFormulaDao extends BaseDao { + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiFormulaEntity.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiFormulaEntity.java new file mode 100644 index 000000000..b4b4fd98b --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/entity/KpiFormulaEntity.java @@ -0,0 +1,71 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_kpi_formula") +public class KpiFormulaEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 公式编码 + */ + private String code; + + /** + * 公式名称 + */ + private String name; + + /** + * 公式运行方法(Javascript) + */ + private String formula; + + /** + * 公式参数数量 + */ + private Integer paramAmount; + + /** + * 公式描述 + */ + private String description; + + /** + * 备注 + */ + private String remark; + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/excel/KpiFormulaExcel.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/excel/KpiFormulaExcel.java new file mode 100644 index 000000000..033374b7c --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/excel/KpiFormulaExcel.java @@ -0,0 +1,74 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Data +public class KpiFormulaExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "公式编码") + private String code; + + @Excel(name = "公式名称") + private String name; + + @Excel(name = "公式运行方法(Javascript)") + private String formula; + + @Excel(name = "公式参数数量") + private Integer paramAmount; + + @Excel(name = "公式描述") + private String desc; + + @Excel(name = "备注") + private String remark; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + @Excel(name = "删除标记") + private String delFlag; + + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/redis/KpiFormulaRedis.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/redis/KpiFormulaRedis.java new file mode 100644 index 000000000..74a3ca3ee --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/redis/KpiFormulaRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Component +public class KpiFormulaRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/KpiFormulaService.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/KpiFormulaService.java new file mode 100644 index 000000000..f354275eb --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/KpiFormulaService.java @@ -0,0 +1,106 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service; + + +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.KpiFormulaDTO; +import com.elink.esua.epdc.entity.KpiFormulaEntity; +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; + +import java.util.List; +import java.util.Map; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +public interface KpiFormulaService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2019-11-26 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2019-11-26 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return KpiFormulaDTO + * @author generator + * @date 2019-11-26 + */ + KpiFormulaDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2019-11-26 + */ + void save(KpiFormulaDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2019-11-26 + */ + Result update(KpiFormulaDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2019-11-26 + */ + void delete(String[] ids); + + /** + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 新增 + * @Date 2019/11/26 17:14 + **/ + Result saveKpiFormula(KpiFormulaDTO dto); +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiFormulaServiceImpl.java b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiFormulaServiceImpl.java new file mode 100644 index 000000000..529fffdcd --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/java/com/elink/esua/epdc/service/impl/KpiFormulaServiceImpl.java @@ -0,0 +1,165 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dao.KpiFormulaDao; +import com.elink.esua.epdc.dto.KpiFormulaDTO; +import com.elink.esua.epdc.entity.KpiFormulaEntity; +import com.elink.esua.epdc.redis.KpiFormulaRedis; +import com.elink.esua.epdc.service.KpiFormulaService; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 绩效考核公式 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-11-26 + */ +@Service +public class KpiFormulaServiceImpl extends BaseServiceImpl implements KpiFormulaService { + + @Autowired + private KpiFormulaRedis kpiFormulaRedis; + + @Override + public PageData page(Map params) { + QueryWrapper wrapper=new QueryWrapper<>(); + String name =(String)params.get(FieldConstant.NAME_HUMP); + wrapper.like(StringUtils.isNotBlank(name),FieldConstant.NAME,name); + + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + wrapper + ); + return getPageData(page, KpiFormulaDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, KpiFormulaDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + return wrapper; + } + + @Override + public KpiFormulaDTO get(String id) { + KpiFormulaEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, KpiFormulaDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(KpiFormulaDTO dto) { + KpiFormulaEntity entity = ConvertUtils.sourceToTarget(dto, KpiFormulaEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result update(KpiFormulaDTO dto) { + try{ + if(StringUtils.isNotBlank(dto.getFormula())){ + //获得一个javascipt的执行引擎 + ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); + //执行js代码 + engine.eval(dto.getFormula()); + //是否可调用方法 + boolean flag=engine instanceof Invocable; + if(!flag){ + return new Result().error("运行方法异常"); + } +// else{ +// Invocable in = (Invocable)engine; +// //执行js中的函数 +// Double result=(Double) in.invokeFunction(dto.getCode(), 5,2); +// //打印出调用方法的结果: +// System.out.println("的运算结果是:"+result); +// } + } + }catch(Exception e){ + e.printStackTrace(); + return new Result().error("运行方法异常"+e.getMessage()); + } + KpiFormulaEntity entity = ConvertUtils.sourceToTarget(dto, KpiFormulaEntity.class); + updateById(entity); + return new Result(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + /** + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author yinzuomei + * @Description 新增 + * @Date 2019/11/26 17:14 + **/ + @Override + @Transactional(rollbackFor = Exception.class) + public Result saveKpiFormula(KpiFormulaDTO dto) { + try{ + if(StringUtils.isNotBlank(dto.getFormula())){ + //获得一个javascipt的执行引擎 + ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript"); + //执行js代码 + engine.eval(dto.getFormula()); + //是否可调用方法 + boolean flag=engine instanceof Invocable; + if(!flag){ + return new Result().error("运行方法异常"); + } + } + }catch(Exception e){ + return new Result().error("运行方法异常"+e.getMessage()); + } + KpiFormulaEntity entity = ConvertUtils.sourceToTarget(dto, KpiFormulaEntity.class); + insert(entity); + return new Result(); + } + +} diff --git a/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiFormulaDao.xml b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiFormulaDao.xml new file mode 100644 index 000000000..48b67a1b4 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-kpi/epdc-kpi-server/src/main/resources/mapper/KpiFormulaDao.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +