|
@@ -0,0 +1,166 @@
|
|
|
+package com.ozs.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.ozs.common.constant.UserConstants;
|
|
|
+import com.ozs.common.utils.StringUtils;
|
|
|
+import com.ozs.common.utils.bean.BeanUtils;
|
|
|
+import com.ozs.entity.MonitorSystem;
|
|
|
+import com.ozs.entity.SvcAddress;
|
|
|
+import com.ozs.entity.vo.MonitorSystemVo;
|
|
|
+import com.ozs.mapper.MonitorSystemMapper;
|
|
|
+import com.ozs.mapper.SvcAddressMapper;
|
|
|
+import com.ozs.service.MonitorSystemService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wyy
|
|
|
+ * @subject
|
|
|
+ * @creat 2023/7/25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MonitorSystemServiceImpl extends ServiceImpl<MonitorSystemMapper, MonitorSystem> implements MonitorSystemService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MonitorSystemMapper monitorSystemMapper;
|
|
|
+ @Autowired
|
|
|
+ private SvcAddressMapper svcAddressMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertMonitorSystem(MonitorSystem monitorSystem) {
|
|
|
+ int row = monitorSystemMapper.insertMonitorSystem(monitorSystem);
|
|
|
+ Integer grantType =1;
|
|
|
+
|
|
|
+ SvcAddress svc = new SvcAddress();
|
|
|
+ svc.setClientId(monitorSystem.getClientId());
|
|
|
+ svc.setClientSecret(monitorSystem.getClientSecret());//正式环境
|
|
|
+ svc.setGrantType(grantType);
|
|
|
+ svc.setEnv(2);
|
|
|
+ int row1 = svcAddressMapper.insert(svc);
|
|
|
+ SvcAddress svc1 = new SvcAddress();
|
|
|
+ svc1.setClientId(monitorSystem.getClientId());
|
|
|
+ svc1.setClientSecret(monitorSystem.getTestSecret());//测试环境
|
|
|
+ svc1.setGrantType(grantType);
|
|
|
+ svc1.setEnv(1);
|
|
|
+ int row2 = svcAddressMapper.insert(svc1);
|
|
|
+ return row+row1+row2;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByIds(Long[] ids) {
|
|
|
+ for(Long id :ids){
|
|
|
+ MonitorSystem monitorSystem = monitorSystemMapper.selectById(id);
|
|
|
+ LambdaQueryWrapper<SvcAddress> wrapper = new LambdaQueryWrapper<SvcAddress>();
|
|
|
+ wrapper.eq(SvcAddress::getClientId,monitorSystem.getClientId());
|
|
|
+ svcAddressMapper.delete(wrapper);
|
|
|
+ monitorSystemMapper.deleteById(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateMonitorSystem(MonitorSystem monitorSystem) {
|
|
|
+ //原
|
|
|
+ MonitorSystem monitor = monitorSystemMapper.selectById(monitorSystem.getId());
|
|
|
+ List<SvcAddress> list = svcAddressMapper.svcList(monitor.getClientId());
|
|
|
+ if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
|
|
|
+ list.forEach(l -> {
|
|
|
+ if (l.getEnv().equals(1)) {//测试环境
|
|
|
+ monitor.setTestSecret(l.getClientSecret());
|
|
|
+ } else if (l.getEnv().equals(2)) {//正式环境
|
|
|
+ monitor.setClientSecret(l.getClientSecret());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Integer grantType =1;
|
|
|
+ int row1 = 0;
|
|
|
+ int row2 = 0;
|
|
|
+ if(!monitorSystem.getClientId().equals(monitor.getClientId()) || !monitorSystem.getClientSecret().equals(monitor.getClientSecret())
|
|
|
+ || !monitorSystem.getTestSecret().equals(monitor.getTestSecret())){//客户端编号或者正式环境密钥或者测试环境密钥改变
|
|
|
+ LambdaQueryWrapper<SvcAddress> wrapper = new LambdaQueryWrapper<SvcAddress>();
|
|
|
+ wrapper.eq(SvcAddress::getClientId,monitor.getClientId());
|
|
|
+ svcAddressMapper.delete(wrapper);
|
|
|
+
|
|
|
+ SvcAddress svc = new SvcAddress();
|
|
|
+ svc.setClientId(monitorSystem.getClientId());
|
|
|
+ svc.setClientSecret(monitorSystem.getClientSecret());//正式环境
|
|
|
+ svc.setGrantType(grantType);
|
|
|
+ svc.setEnv(2);
|
|
|
+ row1 = svcAddressMapper.insert(svc);
|
|
|
+ SvcAddress svc1 = new SvcAddress();
|
|
|
+ svc1.setClientId(monitorSystem.getClientId());
|
|
|
+ svc1.setClientSecret(monitorSystem.getTestSecret());//测试环境
|
|
|
+ svc1.setGrantType(grantType);
|
|
|
+ svc1.setEnv(1);
|
|
|
+ row2 = svcAddressMapper.insert(svc1);
|
|
|
+ }
|
|
|
+ int row = monitorSystemMapper.updateById(monitorSystem);
|
|
|
+ return row+row1+row2;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String checkClientIdUnique(MonitorSystem monitorSystem) {
|
|
|
+ Long id = StringUtils.isNull(monitorSystem.getId()) ? -1L : monitorSystem.getId();
|
|
|
+ MonitorSystem monitor = monitorSystemMapper.checkClientIdUnique(monitorSystem.getClientId());
|
|
|
+ if (StringUtils.isNotNull(monitor) && monitor.getId().longValue() != id.longValue()) {
|
|
|
+ return UserConstants.NOT_UNIQUE;
|
|
|
+ }
|
|
|
+ return UserConstants.UNIQUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String checkSystemOnline(MonitorSystem monitorSystem) {
|
|
|
+ Long id = StringUtils.isNull(monitorSystem.getId()) ? -1L : monitorSystem.getId();
|
|
|
+ MonitorSystem monitor = monitorSystemMapper.checkSystemOnline(id);
|
|
|
+ if (StringUtils.isNotNull(monitor.getStatus()) && monitor.getStatus().equals(1)){
|
|
|
+ return UserConstants.EXCEPTION;
|
|
|
+ }
|
|
|
+ return UserConstants.NORMAL;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MonitorSystem getMonitorSystem(Long id) {
|
|
|
+ MonitorSystem monitor = monitorSystemMapper.checkSystemOnline(id);
|
|
|
+ List<SvcAddress> list = svcAddressMapper.svcList(monitor.getClientId());
|
|
|
+ if (!CollectionUtils.isEmpty(list) && Objects.nonNull(list.get(0))) {
|
|
|
+ list.forEach(l -> {
|
|
|
+ if (l.getEnv().equals(1)) {//测试环境
|
|
|
+ monitor.setTestSecret(l.getClientSecret());
|
|
|
+ } else if (l.getEnv().equals(2)) {//正式环境
|
|
|
+ monitor.setClientSecret(l.getClientSecret());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return monitor;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<MonitorSystemVo> pageList(MonitorSystemVo monitorSystemVo) {
|
|
|
+ LambdaQueryWrapper<MonitorSystem> wrapper = new LambdaQueryWrapper<MonitorSystem>();
|
|
|
+ wrapper.like(!Objects.isNull(monitorSystemVo.getMonitorSystemName()),MonitorSystem::getMonitorSystemName,monitorSystemVo.getMonitorSystemName());
|
|
|
+ wrapper.eq(!Objects.isNull(monitorSystemVo.getStatus()),MonitorSystem::getStatus,monitorSystemVo.getStatus());
|
|
|
+ int pageNum = Integer.parseInt(monitorSystemVo.getPageNum().toString());
|
|
|
+ int pageSize = Integer.parseInt(monitorSystemVo.getPageSize().toString());
|
|
|
+ com.github.pagehelper.Page<MonitorSystem> page = PageHelper
|
|
|
+ .startPage(pageNum, pageSize).doSelectPage(() -> monitorSystemMapper.selectList(wrapper));
|
|
|
+ com.baomidou.mybatisplus.extension.plugins.pagination.Page<MonitorSystemVo> pageR =
|
|
|
+ new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize);
|
|
|
+ if (!ObjectUtils.isEmpty(page) && page.getResult().size() > 0) {
|
|
|
+ List<MonitorSystemVo> dto1 = page.getResult().stream().map(o -> {
|
|
|
+ MonitorSystemVo monitorSystemVo1 = new MonitorSystemVo();
|
|
|
+ BeanUtils.copyProperties(o, monitorSystemVo1);
|
|
|
+ return monitorSystemVo1;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ pageR.setRecords(dto1);
|
|
|
+ }
|
|
|
+ return pageR;
|
|
|
+ }
|
|
|
+}
|