|
@@ -0,0 +1,144 @@
|
|
|
+package com.example.xiaoshiweixinback.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.example.xiaoshiweixinback.business.common.base.Records;
|
|
|
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.CacheUtil;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.LoginUtils;
|
|
|
+import com.example.xiaoshiweixinback.domain.Monitor;
|
|
|
+
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.AssoPersonProductDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.GetProductDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.monitoring.AddMonitoringDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.monitoring.CancelMonitoringDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.monitoring.SelectMonitoringDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.product.ProductAddDTO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.ProductVO;
|
|
|
+import com.example.xiaoshiweixinback.mapper.MonitorMapper;
|
|
|
+import com.example.xiaoshiweixinback.mapper.ProductMapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.CachedIntrospectionResults;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author admin
|
|
|
+ * @description 针对表【monitor(产品监控表)】的数据库操作Service实现
|
|
|
+ * @createDate 2024-04-28 16:29:49
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class MonitorService extends ServiceImpl<MonitorMapper, Monitor> {
|
|
|
+
|
|
|
+ private final AssoPersonProductService assoPersonProductService;
|
|
|
+ private final ProductService productService;
|
|
|
+ private final CacheUtil cacheUtil;
|
|
|
+ private final ProductMapper productMapper;
|
|
|
+ /**
|
|
|
+ * 添加监控
|
|
|
+ *
|
|
|
+ * @param addMonitoringDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Integer addMonitoring(AddMonitoringDTO addMonitoringDTO) {
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ Integer productId = addMonitoringDTO.getProductId();
|
|
|
+ String monitorPeriod = addMonitoringDTO.getMonitorPeriod();
|
|
|
+ Integer concernType = addMonitoringDTO.getConcernType();
|
|
|
+
|
|
|
+ //关注产品
|
|
|
+ if (productId != null) {
|
|
|
+ AssoPersonProductDTO assoPersonProductDTO = new AssoPersonProductDTO();
|
|
|
+ assoPersonProductDTO.setProductId(productId);
|
|
|
+ assoPersonProductDTO.setConcernType(concernType);
|
|
|
+ assoPersonProductService.add(assoPersonProductDTO);
|
|
|
+ } else if (productId == null) {
|
|
|
+ ProductAddDTO productAddDTO = new ProductAddDTO();
|
|
|
+ BeanUtils.copyProperties(addMonitoringDTO, productAddDTO);
|
|
|
+ productId = productService.addOrUpdateProduct(productAddDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加监控
|
|
|
+ Monitor monitor = new Monitor();
|
|
|
+ monitor.setCreateId(personnelVO.getUuid());
|
|
|
+ monitor.setMonitorPeriod(monitorPeriod);
|
|
|
+ monitor.setProductId(productId);
|
|
|
+ monitor.insert();
|
|
|
+ //TODO 添加定时任务
|
|
|
+
|
|
|
+ return productId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消监控
|
|
|
+ *
|
|
|
+ * @param cancelMonitoringDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public List<Integer> cancelMonitoring(CancelMonitoringDTO cancelMonitoringDTO) {
|
|
|
+ List<Integer> productIds = cancelMonitoringDTO.getProductIds();
|
|
|
+ Boolean ifCancelConcern = cancelMonitoringDTO.getIfCancelConcern();
|
|
|
+ //取消监控
|
|
|
+ this.cancelMonitorByProductIds(productIds);
|
|
|
+ if (ifCancelConcern != null && ifCancelConcern.equals(true)) {
|
|
|
+ //取消关注
|
|
|
+ assoPersonProductService.cancelConcern(productIds);
|
|
|
+ }
|
|
|
+ //TODO 添加定时任务
|
|
|
+
|
|
|
+ return productIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> cancelMonitorByProductIds(List<Integer> productIds) {
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ LambdaQueryWrapper<Monitor> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(Monitor::getProductId, productIds)
|
|
|
+ .eq(Monitor::getCreateId, personnelVO.getUuid());
|
|
|
+ this.remove(queryWrapper);
|
|
|
+ return productIds;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询监控信息
|
|
|
+ * @param selectMonitoringDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Records selectMonitoring(SelectMonitoringDTO selectMonitoringDTO) {
|
|
|
+ Long current =selectMonitoringDTO.getCurrent();
|
|
|
+ Long size =selectMonitoringDTO.getSize();
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(LoginUtils.getToken());
|
|
|
+ GetProductDTO getProductDTO =new GetProductDTO();
|
|
|
+ getProductDTO.setSize(size);
|
|
|
+ getProductDTO.setCurrent(current);
|
|
|
+ getProductDTO.setPersonUuid(personnelVO.getUuid());
|
|
|
+ List<ProductVO> productVOS = productMapper.getMonitoringProduct(getProductDTO);
|
|
|
+ Long total =productMapper.getMonitoringProductCount(getProductDTO);
|
|
|
+ try {
|
|
|
+ productService.loadProduct(productVOS, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ throw new BusinessException("607","装载错误");
|
|
|
+ }
|
|
|
+ Records records =new Records();
|
|
|
+ records.setTotal(total);
|
|
|
+ records.setData(productVOS);
|
|
|
+ records.setSize(size);
|
|
|
+ records.setCurrent(current);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|