装备管理 youhua
This commit is contained in:
parent
8af623096c
commit
ef087b8e4a
|
|
@ -13,4 +13,11 @@ public class ConfigEntity {
|
|||
|
||||
private String configurationDescription;
|
||||
|
||||
private Long deptId;
|
||||
|
||||
private String remark;
|
||||
|
||||
private String typeId;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
package com.bonus.material.equipment.service.impl;
|
||||
|
||||
import com.bonus.material.equipment.domain.ConfigEntity;
|
||||
import com.bonus.material.equipment.domain.DeptEquipmentConfig;
|
||||
import com.bonus.material.equipment.mapper.DeptEquipmentConfigMapper;
|
||||
import com.bonus.material.equipment.service.IDeptEquipmentConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DeptEquipmentConfigServiceImpl implements IDeptEquipmentConfigService {
|
||||
|
|
@ -20,15 +24,56 @@ public class DeptEquipmentConfigServiceImpl implements IDeptEquipmentConfigServi
|
|||
}
|
||||
|
||||
@Override
|
||||
public int saveBatch(DeptEquipmentConfig configList) {
|
||||
configList.setTypeId(configList.getEquipmentId());
|
||||
configList.setConfigValue(configList.getBasicConfig());
|
||||
//直接先删除对应的设备信息 通过公司id 和设备id进行删除
|
||||
DeptEquipmentConfig team = new DeptEquipmentConfig();
|
||||
team.setDeptId(configList.getDeptId());
|
||||
team.setTypeId(configList.getTypeId());
|
||||
mapper.deleteByDeptIdAndTypeId(team);
|
||||
public int saveBatch(DeptEquipmentConfig configList) {
|
||||
configList.setTypeId(configList.getEquipmentId());
|
||||
configList.setConfigValue(configList.getBasicConfig());
|
||||
DeptEquipmentConfig team = new DeptEquipmentConfig();
|
||||
team.setDeptId(configList.getDeptId());
|
||||
team.setTypeId(configList.getTypeId());
|
||||
mapper.deleteByDeptIdAndTypeId(team);
|
||||
|
||||
return mapper.insertOrUpdateBatch(configList);
|
||||
List<ConfigEntity> originalConfigs = configList.getConfigs();
|
||||
if (originalConfigs == null || originalConfigs.isEmpty()) {
|
||||
return 1; // 只删除,无新增
|
||||
}
|
||||
// 合并逻辑:以 deptId + typeId + configType 为 key,configValue 累加
|
||||
Map<String, ConfigEntity> mergedMap = new LinkedHashMap<>();
|
||||
for (ConfigEntity item : originalConfigs) {
|
||||
item.setDeptId(configList.getDeptId());
|
||||
item.setTypeId(configList.getTypeId());
|
||||
item.setRemark(configList.getRemark());
|
||||
String key = item.getDeptId() + "_" + item.getTypeId() + "_" + item.getConfigurationType();
|
||||
|
||||
if (mergedMap.containsKey(key)) {
|
||||
ConfigEntity existing = mergedMap.get(key);
|
||||
// configValue 是 String,需转数字再相加
|
||||
try {
|
||||
double newVal = parseDoubleOrZero(item.getBasicConfig());
|
||||
double oldVal = parseDoubleOrZero(existing.getBasicConfig());
|
||||
double newrateVal = parseDoubleOrZero(item.getConfigurationRate());
|
||||
double oldrateVal = parseDoubleOrZero(existing.getConfigurationRate());
|
||||
existing.setBasicConfig(String.valueOf(newVal + oldVal));
|
||||
existing.setConfigurationRate(String.valueOf(newrateVal+oldrateVal));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
mergedMap.put(key, item);
|
||||
}
|
||||
}
|
||||
|
||||
configList.setConfigs(new ArrayList<>(mergedMap.values()));
|
||||
return mapper.insertOrUpdateBatch(configList);
|
||||
}
|
||||
private double parseDoubleOrZero(String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
<foreach collection="configs" item="item" separator=",">
|
||||
(
|
||||
#{deptId},
|
||||
#{equipmentId},
|
||||
#{typeId},
|
||||
#{item.configurationType},
|
||||
#{item.basicConfig},
|
||||
#{item.configurationRate},
|
||||
|
|
|
|||
Loading…
Reference in New Issue