| | |
| | | public class TBatteryGroupServiceImpl implements ITBatteryGroupService |
| | | { |
| | | private static final String ENABLED = "0"; |
| | | private static final String TESTING = "1"; |
| | | |
| | | @Autowired |
| | | private TBatteryGroupMapper batteryGroupMapper; |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int insertBatteryGroup(TBatteryGroup group) |
| | | { |
| | | validate(group, false); |
| | | group.setGroupName(StringUtils.trim(group.getGroupName())); |
| | | group.setCreateTime(new Date()); |
| | | if (StringUtils.isEmpty(group.getStatus())) |
| | | { |
| | | group.setStatus(ENABLED); |
| | | } |
| | | validate(group, false); |
| | | group.setGroupName(StringUtils.trim(group.getGroupName())); |
| | | group.setCreateTime(new Date()); |
| | | int rows = batteryGroupMapper.insertBatteryGroup(group); |
| | | replaceRelations(group); |
| | | return rows; |
| | |
| | | { |
| | | throw new ServiceException("电池组ID不能为空"); |
| | | } |
| | | if (batteryGroupMapper.selectBatteryGroupById(group.getGroupId()) == null) |
| | | TBatteryGroup current = batteryGroupMapper.selectBatteryGroupById(group.getGroupId()); |
| | | if (current == null) |
| | | { |
| | | throw new ServiceException("电池组不存在"); |
| | | } |
| | | if (StringUtils.isEmpty(group.getStatus())) |
| | | { |
| | | group.setStatus(current.getStatus()); |
| | | } |
| | | validateStatusChange(group, current.getStatus()); |
| | | validate(group, true); |
| | | group.setGroupName(StringUtils.trim(group.getGroupName())); |
| | | group.setUpdateTime(new Date()); |
| | |
| | | { |
| | | throw new ServiceException("电池组ID和目标状态不能为空"); |
| | | } |
| | | if (TESTING.equals(group.getStatus()) || !ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus())) |
| | | if (!ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus())) |
| | | { |
| | | throw new ServiceException("电池组状态不正确"); |
| | | } |
| | |
| | | { |
| | | throw new ServiceException("电池组型号不能为空"); |
| | | } |
| | | if (!ENABLED.equals(group.getStatus()) && !"1".equals(group.getStatus())) |
| | | { |
| | | throw new ServiceException("电池组状态不正确"); |
| | | } |
| | | TBatteryGroup existing = batteryGroupMapper.selectBatteryGroupByName(StringUtils.trim(group.getGroupName())); |
| | | if (existing != null && (group.getGroupId() == null || !group.getGroupId().equals(existing.getGroupId()))) |
| | | { |
| | |
| | | if (relation == null || relation.getBatteryGroupFieldId() == null || !fieldIds.add(relation.getBatteryGroupFieldId())) |
| | | { |
| | | throw new ServiceException("模板字段关系不正确"); |
| | | } |
| | | if (relation.getFieldValue() != null && relation.getFieldValue().length() > 500) |
| | | { |
| | | throw new ServiceException("模板字段值长度不能超过500个字符"); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | batteryGroupMapper.batchInsertRelationFields(relations); |
| | | } |
| | | |
| | | private void validateStatusChange(TBatteryGroup group, String currentStatus) |
| | | { |
| | | if ("1".equals(group.getStatus()) && !"1".equals(currentStatus) |
| | | && batteryGroupMapper.countTestingByGroupId(group.getGroupId()) > 0) |
| | | { |
| | | throw new ServiceException("测试中的电池组不能禁用"); |
| | | } |
| | | } |
| | | } |