新增:机型常用参数增删改
This commit is contained in:
parent
abd03dd5a5
commit
d984933dd3
@ -1,8 +1,8 @@
|
||||
package com.xdap.self_development.controller;
|
||||
|
||||
import com.definesys.mpaas.common.http.Response;
|
||||
import com.xdap.self_development.controller.form.ModelCommonItem;
|
||||
import com.xdap.self_development.controller.form.ModelCommonParameterForm;
|
||||
import com.xdap.self_development.controller.form.ModelCommon;
|
||||
import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm;
|
||||
import com.xdap.self_development.service.CommonParameterService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -20,26 +20,26 @@ public class CommonParameterController {
|
||||
// 查询机型参数常用
|
||||
@GetMapping("/getModelCommon")
|
||||
public Response getModelCommonParameter(
|
||||
@NotBlank @RequestParam String modelCommonId
|
||||
@NotBlank @RequestParam String userId
|
||||
) {
|
||||
List<ModelCommonItem> list = commonParameterService.getModelCommonParameter(modelCommonId);
|
||||
List<ModelCommon> list = commonParameterService.getModelCommonParameter(userId);
|
||||
return Response.ok().data(list);
|
||||
}
|
||||
// 新增机型参数常用
|
||||
@PostMapping("/insertModelCommon")
|
||||
public Response insertModelCommonParameter(
|
||||
@Valid @RequestBody ModelCommonParameterForm form
|
||||
@Valid @RequestBody ModelCommonParameterInsertForm form
|
||||
) {
|
||||
|
||||
return Response.ok();
|
||||
commonParameterService.insertModelCommonParameter(form);
|
||||
return Response.ok().setMessage("新增成功");
|
||||
}
|
||||
// 修改机型参数常用
|
||||
@PostMapping("/updateModelCommon")
|
||||
public Response updateModelCommonParameter(
|
||||
@Valid @RequestBody ModelCommonParameterForm form
|
||||
@Valid @RequestBody ModelCommonParameterInsertForm form
|
||||
) {
|
||||
|
||||
return Response.ok();
|
||||
commonParameterService.updateModelCommonParameter(form);
|
||||
return Response.ok().setMessage("修改成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,12 +6,17 @@ import com.xdap.self_development.controller.request.ModelRolesRequest;
|
||||
import com.xdap.self_development.pojo.ModelRolesPojo;
|
||||
import com.xdap.self_development.pojo.dto.PageResultDTO;
|
||||
import com.xdap.self_development.pojo.view.MenuListView;
|
||||
import com.xdap.self_development.pojo.view.ParametersView;
|
||||
import com.xdap.self_development.service.ModelMenuPermissionService;
|
||||
import com.xdap.self_development.service.ModelRoleService;
|
||||
import com.xdap.self_development.service.ParameterService;
|
||||
import com.xdap.self_development.service.TemplateService;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -22,6 +27,9 @@ public class PermissionController {
|
||||
ModelRoleService modelRoleService;
|
||||
@Autowired
|
||||
ModelMenuPermissionService modelMenuPermissionService;
|
||||
@Resource
|
||||
private ParameterService parameterService;
|
||||
|
||||
//添加角色
|
||||
@PostMapping("/addRoles")
|
||||
Response addRoles(ModelRolesRequest request){
|
||||
@ -61,6 +69,12 @@ public class PermissionController {
|
||||
|
||||
|
||||
//参数查询
|
||||
|
||||
@GetMapping("/getAllParameters")
|
||||
public Response getAllParameters(
|
||||
@NotBlank String subsystem
|
||||
) {
|
||||
List<ParametersView> list = parameterService.getAllParameters(subsystem);
|
||||
return Response.ok().data(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ModelCommonParameterForm {
|
||||
private String userId;
|
||||
public class ModelCommon {
|
||||
private String commonName;
|
||||
private List<ModelCommonItem> subsystems;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package com.xdap.self_development.controller.form;
|
||||
|
||||
import com.xdap.self_development.pojo.view.ParametersView;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@ -7,5 +8,5 @@ import java.util.List;
|
||||
@Data
|
||||
public class ModelCommonItem {
|
||||
private String subsystem;
|
||||
List<String> parameterId;
|
||||
List<ParametersView> parameters;
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.xdap.self_development.controller.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class ModelCommonParameterInsertForm {
|
||||
@NotBlank(message = "创建者不能为空")
|
||||
private String userId;
|
||||
@NotNull(message = "常用不能为空")
|
||||
private ModelCommon common;
|
||||
}
|
||||
@ -1,12 +1,14 @@
|
||||
package com.xdap.self_development.pojo;
|
||||
|
||||
import com.definesys.mpaas.query.annotation.RowID;
|
||||
import com.definesys.mpaas.query.annotation.RowIDType;
|
||||
import com.definesys.mpaas.query.annotation.Table;
|
||||
import com.definesys.mpaas.query.annotation.*;
|
||||
import com.definesys.mpaas.query.model.MpaasBasePojo;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@SQLQuery(value = {
|
||||
@SQL(view = "getCommonById",
|
||||
sql = "SELECT ymcp.*, ymp.parameter_name as 'parameterName' FROM yfsjglpt_model_common_parameters ymcp LEFT JOIN yfsjglpt_model_parameter ymp ON ymcp.parameter_id = ymp.id WHERE ymcp.user_id = #userId")
|
||||
})
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Table("yfsjglpt_model_common_parameters")
|
||||
@ -16,4 +18,9 @@ public class ModelCommonParameters extends MpaasBasePojo {
|
||||
private String subsystem;
|
||||
private String parameterId;
|
||||
private String userId;
|
||||
// 唯一性
|
||||
private String commonName;
|
||||
|
||||
@Column(type = ColumnType.CALCULATE)
|
||||
private String parameterName;
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package com.xdap.self_development.pojo.view;
|
||||
|
||||
import com.definesys.mpaas.query.annotation.SQL;
|
||||
import com.definesys.mpaas.query.annotation.SQLQuery;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@SQLQuery(value = {
|
||||
@SQL(view = "getAllParameters",
|
||||
sql = "SELECT DISTINCT mp.parameter_name as 'parameterName', mp.id as 'parameterId' FROM yfsjglpt_model_parameter mp INNER JOIN yfsjglpt_model_parameter_and_template mpat ON mp.id = mpat.parameter_id INNER JOIN yfsjglpt_model_template mt ON mpat.template_id = mt.id INNER JOIN ( SELECT template_name, MAX(version) AS max_version FROM yfsjglpt_model_template WHERE status = 'COMPLETE' GROUP BY template_name ) latest ON mt.template_name = latest.template_name AND mt.version = latest.max_version WHERE mt.status = 'COMPLETE' ORDER BY mp.parameter_name where mp.subsystem_name = #subsystem")
|
||||
})
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ParametersView {
|
||||
private String parameterId;
|
||||
private String parameterName;
|
||||
}
|
||||
@ -1,10 +1,16 @@
|
||||
package com.xdap.self_development.service;
|
||||
|
||||
import com.xdap.self_development.controller.form.ModelCommonItem;
|
||||
import com.xdap.self_development.controller.form.ModelCommon;
|
||||
import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
public interface CommonParameterService {
|
||||
List<ModelCommonItem> getModelCommonParameter(@NotBlank String modelCommonId);
|
||||
List<ModelCommon> getModelCommonParameter(@NotBlank String userId);
|
||||
|
||||
void insertModelCommonParameter(@Valid ModelCommonParameterInsertForm form);
|
||||
|
||||
void updateModelCommonParameter(@Valid ModelCommonParameterInsertForm form);
|
||||
}
|
||||
|
||||
@ -4,11 +4,15 @@ import com.definesys.mpaas.query.db.PageQueryResult;
|
||||
import com.xdap.self_development.controller.form.ParameterPageForm;
|
||||
import com.xdap.self_development.controller.form.UpdateParameterForm;
|
||||
import com.xdap.self_development.pojo.Parameter;
|
||||
import com.xdap.self_development.pojo.view.ParametersView;
|
||||
import com.xdap.self_development.pojo.view.TemplateInfoView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterService {
|
||||
PageQueryResult<Parameter> getParameterByCondition(ParameterPageForm form);
|
||||
|
||||
TemplateInfoView maintenanceParameters(UpdateParameterForm form);
|
||||
|
||||
List<ParametersView> getAllParameters(String subsystem);
|
||||
}
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
package com.xdap.self_development.service.impl;
|
||||
|
||||
import com.xdap.self_development.config.BusinessDatabase;
|
||||
import com.xdap.self_development.controller.form.ModelCommon;
|
||||
import com.xdap.self_development.controller.form.ModelCommonItem;
|
||||
import com.xdap.self_development.controller.form.ModelCommonParameterInsertForm;
|
||||
import com.xdap.self_development.exception.CommonException;
|
||||
import com.xdap.self_development.pojo.ModelCommonParameters;
|
||||
import com.xdap.self_development.pojo.view.ParametersView;
|
||||
import com.xdap.self_development.service.CommonParameterService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CommonParameterServiceImpl implements CommonParameterService {
|
||||
@ -16,11 +23,87 @@ public class CommonParameterServiceImpl implements CommonParameterService {
|
||||
private BusinessDatabase bd;
|
||||
|
||||
@Override
|
||||
public List<ModelCommonItem> getModelCommonParameter(String modelCommonId) {
|
||||
public List<ModelCommon> getModelCommonParameter(String userId) {
|
||||
List<ModelCommonParameters> modelCommonParameters = bd.getBusinessDatabase()
|
||||
.eq("id", modelCommonId)
|
||||
.viewQueryMode(true)
|
||||
.view("getCommonById")
|
||||
.setVar("userId", userId)
|
||||
.doQuery(ModelCommonParameters.class);
|
||||
return convertToModelCommonList(modelCommonParameters);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
@Override
|
||||
@Transactional(rollbackFor = CommonException.class)
|
||||
public void insertModelCommonParameter(ModelCommonParameterInsertForm form) {
|
||||
// 检查名字是否重复
|
||||
List<ModelCommonParameters> modelCommonParameters = convertToModelCommonParameters(form.getCommon(), form.getUserId());
|
||||
bd.getBusinessDatabase().doBatchInsert(modelCommonParameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = CommonException.class)
|
||||
public void updateModelCommonParameter(ModelCommonParameterInsertForm form) {
|
||||
bd.getBusinessDatabase().eq("common_name", form.getCommon().getCommonName()).doDelete(ModelCommonParameters.class);
|
||||
insertModelCommonParameter(form);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 ModelCommonParameters 列表转换为 ModelCommon 列表
|
||||
*/
|
||||
private List<ModelCommon> convertToModelCommonList(List<ModelCommonParameters> paramsList) {
|
||||
if (paramsList == null || paramsList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Map<String, List<ModelCommonParameters>> groupedByCommonName = paramsList.stream()
|
||||
.collect(Collectors.groupingBy(ModelCommonParameters::getCommonName));
|
||||
List<ModelCommon> result = new ArrayList<>();
|
||||
for (Map.Entry<String, List<ModelCommonParameters>> commonNameEntry : groupedByCommonName.entrySet()) {
|
||||
ModelCommon modelCommon = new ModelCommon();
|
||||
modelCommon.setCommonName(commonNameEntry.getKey());
|
||||
Map<String, List<ModelCommonParameters>> groupedBySubsystem = commonNameEntry.getValue().stream()
|
||||
.collect(Collectors.groupingBy(ModelCommonParameters::getSubsystem));
|
||||
List<ModelCommonItem> items = new ArrayList<>();
|
||||
for (Map.Entry<String, List<ModelCommonParameters>> subsystemEntry : groupedBySubsystem.entrySet()) {
|
||||
ModelCommonItem item = new ModelCommonItem();
|
||||
item.setSubsystem(subsystemEntry.getKey());
|
||||
List<ParametersView> parameters = subsystemEntry.getValue().stream()
|
||||
.map(param -> new ParametersView(param.getParameterId(), param.getParameterName()))
|
||||
.collect(Collectors.toList());
|
||||
item.setParameters(parameters);
|
||||
items.add(item);
|
||||
}
|
||||
modelCommon.setSubsystems(items);
|
||||
result.add(modelCommon);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将ModelCommon 转换为 ModelCommonParameters 列表
|
||||
*/
|
||||
private List<ModelCommonParameters> convertToModelCommonParameters(
|
||||
ModelCommon modelCommon, String userId) {
|
||||
if (modelCommon == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<ModelCommonParameters> result = new ArrayList<>();
|
||||
String commonName = modelCommon.getCommonName();
|
||||
if (modelCommon.getSubsystems() != null) {
|
||||
for (ModelCommonItem item : modelCommon.getSubsystems()) {
|
||||
String subsystem = item.getSubsystem();
|
||||
if (item.getParameters() != null) {
|
||||
for (ParametersView paramView : item.getParameters()) {
|
||||
ModelCommonParameters param = new ModelCommonParameters();
|
||||
param.setSubsystem(subsystem);
|
||||
param.setParameterId(paramView.getParameterId());
|
||||
param.setUserId(userId);
|
||||
param.setCommonName(commonName);
|
||||
param.setParameterName(paramView.getParameterName());
|
||||
result.add(param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import com.xdap.self_development.pojo.Parameter;
|
||||
import com.xdap.self_development.pojo.RevisionRecord;
|
||||
import com.xdap.self_development.pojo.Template;
|
||||
import com.xdap.self_development.pojo.TemplateAndParameter;
|
||||
import com.xdap.self_development.pojo.view.ParametersView;
|
||||
import com.xdap.self_development.pojo.view.TemplateInfoView;
|
||||
import com.xdap.self_development.service.ParameterService;
|
||||
import com.xdap.self_development.utils.FormulaValidator;
|
||||
@ -70,7 +71,8 @@ public class ParameterServiceImpl implements ParameterService {
|
||||
|
||||
// 获取基准模板和最新模板
|
||||
TemplateBenchmark benchmark = getTemplateBenchmark(form.getTemplateRowId());
|
||||
|
||||
// todo 根据上传的部分参数更新模板
|
||||
// todo 部分维护的参数同步到最新的草稿中
|
||||
Template newVersionTemplate;
|
||||
// 如果当前修改的模板为最新版并且为草稿状态,就不需要新建版本
|
||||
if (Objects.equals(benchmark.getLastTemplate().getId(), benchmark.getBaseTemplate().getId())
|
||||
@ -105,6 +107,15 @@ public class ParameterServiceImpl implements ParameterService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ParametersView> getAllParameters(String subsystem) {
|
||||
return bd.getBusinessDatabase()
|
||||
.viewQueryMode(true)
|
||||
.view("getAllParameters")
|
||||
.setVar("subsystem", subsystem)
|
||||
.doQuery(ParametersView.class);
|
||||
}
|
||||
|
||||
private TemplateBenchmark getTemplateBenchmark(String templateRowId) {
|
||||
// 基准模板(用户选择的要比较的版本)
|
||||
Template baseTemplate = bd.getBusinessDatabase()
|
||||
|
||||
@ -4,6 +4,7 @@ CREATE TABLE yfsjglpt_model_common_parameters (
|
||||
`subsystem` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '子系统',
|
||||
`parameter_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数ID',
|
||||
`user_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID',
|
||||
`common_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用名称',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='机型参数常用参数表';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user