From 734414f3ba3557f05fb153600c3c530c663cbc7f Mon Sep 17 00:00:00 2001 From: bgy <1322446236@qq.com> Date: Fri, 13 Sep 2024 19:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E5=9E=8B=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E3=80=82=E4=BC=98=E5=8C=96=E6=88=90=E6=9C=AC=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppSceneCostModelController.java | 62 +++++++++-- .../cost/manage/entity/AppSceneCostModel.java | 103 ++++++++++-------- .../manage/enums/CostModelStatusEnum.java | 65 +++++++++++ .../manage/plugin/StandardCostService.java | 2 +- .../cost/manage/vo/CostModelDefinitionVO.java | 45 ++++++++ 5 files changed, 223 insertions(+), 54 deletions(-) create mode 100644 qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostModelStatusEnum.java create mode 100644 qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/CostModelDefinitionVO.java diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostModelController.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostModelController.java index fc5d5e4..1018688 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostModelController.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/controller/AppSceneCostModelController.java @@ -5,12 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zzsmart.qomo.dao.entity.FlowDefinition; +import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostCount; +import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostModel; +import com.zzsmart.qomo.kn.cost.manage.enums.CostModelStatusEnum; +import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostCountMapper; +import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostModelMapper; import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostModelService; +import com.zzsmart.qomo.kn.cost.manage.vo.CostModelDefinitionVO; import com.zzsmart.qomo.service.IDataFlowDefinitionService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.authz.annotation.RequiresPermissions; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.system.query.QueryGenerator; @@ -20,6 +25,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; +import java.util.Random; /** * @Description: app_scene_cost_model @@ -36,7 +42,10 @@ public class AppSceneCostModelController { private IAppSceneCostModelService appSceneCostModelService; @Autowired private IDataFlowDefinitionService flowDefinitionService; - + @Autowired + private AppSceneCostCountMapper appSceneCostCountMapper; + @Autowired + private AppSceneCostModelMapper costModelMapper; /** * 标准成本模型分页列表查询 * @@ -71,17 +80,41 @@ public class AppSceneCostModelController { /** * 添加标准成本模型 * - * @param flowDefinition + * @param modelDefinitionVO * @return */ @AutoLog(value = "app_scene_cost_model-添加") @ApiOperation(value = "app_scene_cost_model-添加", notes = "app_scene_cost_model-添加") @PostMapping(value = "/add") - public Result add(@RequestBody FlowDefinition flowDefinition) { - flowDefinition.setCreateTime(new Date()); - flowDefinition.setUpdateTime(new Date()); - FlowDefinition definition = flowDefinitionService.add(flowDefinition); - return Result.OK(definition); + public Result add(@RequestBody CostModelDefinitionVO modelDefinitionVO) { + try { + FlowDefinition flowDefinition = new FlowDefinition(); + //TODO 新增平台层模型定义记录 + String flowCode = "FLOW_" + System.currentTimeMillis() + new Random(10000).nextInt(); + flowDefinition.setUpdateTime(new Date()); + flowDefinition.setCreateTime(new Date()); + flowDefinition.setCode(flowCode); + flowDefinition.setProjectId(modelDefinitionVO.getProjectId()); + flowDefinition.setUserId("1744546658109349889"); + flowDefinition.setUserName("系统管理员"); + flowDefinition.setTenantId(-1); + flowDefinition.setEnvironmentId(1); + flowDefinition.setName(modelDefinitionVO.getModelName()); + FlowDefinition definition = flowDefinitionService.add(flowDefinition); + AppSceneCostModel forecastModel = new AppSceneCostModel(); + forecastModel.setModelType(modelDefinitionVO.getModelType()); + forecastModel.setModelName(modelDefinitionVO.getModelName()); + forecastModel.setStatus(CostModelStatusEnum.Draft.getCode()); + //2.新模型记录 + forecastModel.setFlowDefinitionId(definition.getId()); + forecastModel.setUpdateTime(new Date()); + forecastModel.setCreateTime(new Date()); + costModelMapper.insert(forecastModel); + + } catch (Exception e) { + return Result.error("新增失败"); + } + return Result.OK("新增成功"); } /** @@ -108,6 +141,19 @@ public class AppSceneCostModelController { @ApiOperation(value = "app_scene_cost_model-通过id删除", notes = "app_scene_cost_model-通过id删除") @DeleteMapping(value = "/delete") public Result delete(@RequestParam(name = "id", required = true) Integer id) { + //检查模型是否被引用或挂载 + if (id != null) { + FlowDefinition flowDefinition = flowDefinitionService.getById(id); + if (flowDefinition != null) { + Integer id1 = flowDefinition.getId(); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("flow_definition_id", id1); + Long aLong = appSceneCostCountMapper.selectCount(queryWrapper); + if (aLong > 0) { + return Result.error("该模型正在被引用,无法删除!"); + } + } + } flowDefinitionService.delete(id); return Result.OK("删除成功!"); } diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostModel.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostModel.java index a80a2fd..50700f6 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostModel.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/entity/AppSceneCostModel.java @@ -1,75 +1,88 @@ package com.zzsmart.qomo.kn.cost.manage.entity; -import java.io.Serializable; -import java.io.UnsupportedEncodingException; -import java.util.Date; -import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.annotation.TableLogic; -import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; -import org.springframework.format.annotation.DateTimeFormat; -import org.jeecgframework.poi.excel.annotation.Excel; -import org.jeecg.common.aspect.annotation.Dict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import lombok.EqualsAndHashCode; +import lombok.*; import lombok.experimental.Accessors; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; /** * @Description: app_scene_cost_model * @Author: jeecg-boot - * @Date: 2024-07-29 + * @Date: 2024-09-09 * @Version: V1.0 */ @Data +@Builder +@AllArgsConstructor +@NoArgsConstructor @TableName("app_scene_cost_model") @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) -@ApiModel(value="app_scene_cost_model对象", description="app_scene_cost_model") +@ApiModel(value = "app_scene_cost_model对象", description = "app_scene_cost_model") public class AppSceneCostModel implements Serializable { private static final long serialVersionUID = 1L; - /**主键*/ - @TableId(type = IdType.ASSIGN_ID) + /** + * 主键 + */ + @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键") private Integer id; - /**物料编号*/ - @Excel(name = "物料编号", width = 15) - @ApiModelProperty(value = "物料编号") - private String materialNo; - /**图号*/ - @Excel(name = "图号", width = 15) - @ApiModelProperty(value = "图号") - private String drawingNo; - /**标准成本计算流程id*/ - @Excel(name = "标准成本计算流程id", width = 15) - @ApiModelProperty(value = "标准成本计算流程id") + /** + * 模型名称 + */ + @Excel(name = "模型名称", width = 15) + @ApiModelProperty(value = "模型名称") + private String modelName; + /** + * 模型类型(标准成本、成本挖掘) + */ + @Excel(name = "模型类型(标准成本、成本挖掘)", width = 15) + @ApiModelProperty(value = "模型类型(标准成本、成本挖掘)") + private String modelType; + /** + * 模型定义id + */ + @Excel(name = "模型定义id", width = 15) + @ApiModelProperty(value = "模型定义id") private Integer flowDefinitionId; - /**状态*/ - @Excel(name = "状态", width = 15) - @ApiModelProperty(value = "状态") - private Integer status; - /**模型版本*/ - @Excel(name = "模型版本", width = 15) - @ApiModelProperty(value = "模型版本") - private String modelVersion; - /**创建人*/ - @ApiModelProperty(value = "创建人") - private Integer createBy; - /**创建时间*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 状态(草稿、已发布、已作废) + */ + @Excel(name = "状态(草稿、已发布、已作废)", width = 15) + @ApiModelProperty(value = "状态(草稿、已发布、已作废)") + private String status; + /** + * 创建时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "创建时间") private Date createTime; - /**更新人*/ - @ApiModelProperty(value = "更新人") - private Integer updateBy; - /**更新时间*/ - @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") - @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + /** + * 创建人 + */ + @ApiModelProperty(value = "创建人") + private String createBy; + /** + * 更新时间 + */ + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "更新时间") private Date updateTime; + /** + * 更新人 + */ + @ApiModelProperty(value = "更新人") + private String updateBy; } diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostModelStatusEnum.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostModelStatusEnum.java new file mode 100644 index 0000000..08609fa --- /dev/null +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/enums/CostModelStatusEnum.java @@ -0,0 +1,65 @@ +package com.zzsmart.qomo.kn.cost.manage.enums; + +/** + * 预测模型状态枚举 + */ +public enum CostModelStatusEnum { + /** + * 草稿 + */ + Draft("Draft", "草稿"), + /** + * 已删除 + */ + Delete("Deleted", "已删除"), + /** + * 已发布 + */ + Published("Published", "已发布"); + + private final String code; + private final String name; + + CostModelStatusEnum(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public String getName() { + return name; + } + + /** + * 根据code获取text + * + * @param codeNo + * @return + */ + public static String getTextByCode(String codeNo) { + for (CostModelStatusEnum value : CostModelStatusEnum.values()) { + if (value.getCode().equals(codeNo)) { + return value.name(); + } + } + return codeNo.toString(); + } + + /** + * 根据text获取code + * + * @param name + * @return + */ + public static String getCodeByName(String name) { + for (CostModelStatusEnum value : CostModelStatusEnum.values()) { + if (value.name().equals(name)) { + return value.name(); + } + } + return name; + } +} diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java index 33673e8..1f5fd9a 100644 --- a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/plugin/StandardCostService.java @@ -478,7 +478,7 @@ public class StandardCostService { //获取最上层的物料号 String topMaterialCode = flowTaskInfoVO.getTopMaterialCode(); //获取任务类型 - String taskType = parameters.getTaskType(); + String taskType = parameters.getTaksType(); //获取任务代码 String taskCode = flowTaskInfoVO.getTaskCode(); //获取流程id diff --git a/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/CostModelDefinitionVO.java b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/CostModelDefinitionVO.java new file mode 100644 index 0000000..35bf7b9 --- /dev/null +++ b/qomo-kn-cost-manage/src/main/java/com/zzsmart/qomo/kn/cost/manage/vo/CostModelDefinitionVO.java @@ -0,0 +1,45 @@ +package com.zzsmart.qomo.kn.cost.manage.vo; + +import com.zzsmart.qomo.common.enums.ReleaseState; +import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 模型信息封装 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CostModelDefinitionVO extends AppSceneCostModel { + @ApiModelProperty("encoding") + private String code; + @ApiModelProperty("flow definition name") + private String name; + @ApiModelProperty("flow definition version") + private Integer version; + @ApiModelProperty("flow definition release state: 0:offline,1:online") + private ReleaseState releaseState; + @ApiModelProperty("定时调度表达式") + private String scheduleCron; + @ApiModelProperty("任务调度模式(1任务队列领取模式(推荐) 2所有集群服务器均可同时运行 3只有主服务器可运行(主服务器失败时其他服务器接管) 4由调度服务器统一调度)") + private Integer scheduleMode; + @ApiModelProperty("依赖周期(分钟)") + private Integer dependencyCycle; + @ApiModelProperty("在任务队列模式下可以根据任务重要性来领取任务(10为最高)") + private Integer taskImportance; + @ApiModelProperty("运行方式(0 禁用 1手动触发 2定时自动调度 3依赖上级流程)") + private Integer runMode; + @ApiModelProperty("project id") + private Integer projectId; + @ApiModelProperty("project code") + private String projectCode; + @ApiModelProperty("环境配置ID") + private Integer environmentId; + @ApiModelProperty("租户ID") + private Integer tenantId; +}