From ef81a5cbfbb98974ed1ba54d0e47b7e74a9b96b9 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 06 六月 2024 15:33:55 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java |  215 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 182 insertions(+), 33 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
index 4b71a2d..8262bf3 100644
--- a/smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/IvrLibaTargetServiceImpl.java
@@ -1,97 +1,246 @@
 package com.smartor.service.impl;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.Gson;
 import com.ruoyi.common.utils.DateUtils;
-import com.smartor.domain.IvrLibaTarget;
+import com.ruoyi.common.utils.DtoConversionUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.smartor.domain.*;
 import com.smartor.mapper.IvrLibaTargetMapper;
+import com.smartor.mapper.IvrLibaTargetTagMapper;
+import com.smartor.mapper.IvrLibaTargetoptionMapper;
 import com.smartor.service.IIvrLibaTargetService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 鎸囨爣閫夐」搴揝ervice涓氬姟灞傚鐞�
- * 
+ *
  * @author ruoyi
  * @date 2023-12-14
  */
+@Slf4j
 @Service
-public class IvrLibaTargetServiceImpl implements IIvrLibaTargetService
-{
+public class IvrLibaTargetServiceImpl implements IIvrLibaTargetService {
     @Autowired
     private IvrLibaTargetMapper ivrLibaTargetMapper;
 
+    @Autowired
+    private IvrLibaTargetTagMapper ivrLibaTargetTagMapper;
+
+    @Autowired
+    private IvrLibaTargetoptionMapper ivrLibaTargetoptionMapper;
+
     /**
      * 鏌ヨ鎸囨爣閫夐」搴�
-     * 
-     * @param targetID 鎸囨爣閫夐」搴撲富閿�
+     *
+     * @param id 鎸囨爣閫夐」搴撲富閿�
      * @return 鎸囨爣閫夐」搴�
      */
     @Override
-    public IvrLibaTarget selectIvrLibaTargetByTargetID(Long targetID)
-    {
-        return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(targetID);
+    public IvrLibaTarget selectIvrLibaTargetByTargetID(Long id) {
+        return ivrLibaTargetMapper.selectIvrLibaTargetByTargetID(id);
     }
 
     /**
      * 鏌ヨ鎸囨爣閫夐」搴撳垪琛�
-     * 
+     *
      * @param ivrLibaTarget 鎸囨爣閫夐」搴�
      * @return 鎸囨爣閫夐」搴�
      */
     @Override
-    public List<IvrLibaTarget> selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget)
-    {
+    public List<IvrLibaTarget> selectIvrLibaTargetList(IvrLibaTarget ivrLibaTarget) {
         return ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
+    }
+
+    @Override
+    public List<IvrLibaTargetVO> targetInfo(IvrLibaTarget ivrLibaTarget) {
+        List<IvrLibaTarget> ivrLibaTargets = ivrLibaTargetMapper.selectIvrLibaTargetList(ivrLibaTarget);
+        List<IvrLibaTargetVO> ivrLibaTargetVOS = DtoConversionUtils.sourceToTarget(ivrLibaTargets, IvrLibaTargetVO.class);
+        for (IvrLibaTargetVO ivrLibaTarget1 : ivrLibaTargetVOS) {
+            IvrLibaTargetoption ivrLibaTargetoption = new IvrLibaTargetoption();
+            ivrLibaTargetoption.setTargetid(ivrLibaTarget1.getId());
+            //鑾峰彇璇ユ寚鏍囩殑閫夐」
+            List<IvrLibaTargetoption> ivrLibaTargetoptions = ivrLibaTargetoptionMapper.selectIvrLibaTargetoptionList(ivrLibaTargetoption);
+            if (CollectionUtils.isNotEmpty(ivrLibaTargetoptions)) {
+                for (IvrLibaTargetoption ivrLibaTargetoption1 : ivrLibaTargetoptions) {
+                    ObjectMapper objectMapper = new ObjectMapper();
+                    try {
+                        if (StringUtils.isNotEmpty(ivrLibaTargetoption1.getDynamiccruxsJson()))
+                            ivrLibaTargetoption1.setDynamiccruxs(objectMapper.readValue(ivrLibaTargetoption1.getDynamiccruxsJson(), List.class));
+                        if (StringUtils.isNotEmpty(ivrLibaTargetoption1.getNodynamiccruxsJson()))
+                            ivrLibaTargetoption1.setNodynamiccruxs(objectMapper.readValue(ivrLibaTargetoption1.getNodynamiccruxsJson(), List.class));
+                    } catch (JsonProcessingException e) {
+                        e.printStackTrace();
+                    }
+                }
+                ivrLibaTarget1.setTargetoptionList(ivrLibaTargetoptions);
+            }
+            //鑾峰彇璇ユ寚鏍囩殑鏍囩
+            List<BaseTag> baseTags = ivrLibaTargetTagMapper.selectTagName(ivrLibaTarget1.getId());
+            ivrLibaTarget1.setBaseTagList(baseTags);
+        }
+        //涓嬮潰鐢ㄥ乏澶栨劅瑙夋湁鐐归棶棰橈紝where涓殑option鐨刣el浼氬鑷村乏杈圭殑鏌ヨ涓嶅叏锛屽厛涓嶇敤鍚�
+//        ivrLibaTargetMapper.targetInfo(ivrLibaTarget)
+        return ivrLibaTargetVOS;
     }
 
     /**
      * 鏂板鎸囨爣閫夐」搴�
-     * 
-     * @param ivrLibaTarget 鎸囨爣閫夐」搴�
+     *
+     * @param ivrLibaTargetVO 鎸囨爣閫夐」搴�
      * @return 缁撴灉
      */
     @Override
-    public int insertIvrLibaTarget(IvrLibaTarget ivrLibaTarget)
-    {
+    @Transactional(rollbackFor = Exception.class)
+    public int insertIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
+        //鏂板鎸囨爣淇℃伅
+        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
         ivrLibaTarget.setCreateTime(DateUtils.getNowDate());
-        return ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
+        ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
+
+        //鏂板璇ユ寚鏍囧搴旂殑鏍囩淇℃伅
+        for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) {
+            IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
+            ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid());
+            ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
+            //鍓嶇浼犳潵鐨刡aseTag鐨則agid灏辨槸鎸囨爣鏍囩鐨勪富閿甶d,涓嶆槸baseTag鐨勪富閿�
+            ivrLibaTargetTag.setTagid(baseTag.getTagid());
+            ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
+        }
+
+        //鏂板璇ユ寚鏍囧搴旂殑鎸囨爣閫夐」淇℃伅
+        for (IvrLibaTargetoption targetoption : ivrLibaTargetVO.getTargetoptionList()) {
+            if (ObjectUtils.isEmpty(targetoption)) continue;
+            log.info("targetoption鐨勬暟鎹负锛歿}", targetoption);
+            targetoption.setTargetid(ivrLibaTarget.getId());
+            ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(targetoption);
+        }
+
+        log.info("鎸囨爣id涓猴細{}", ivrLibaTarget.getId().intValue());
+        return ivrLibaTarget.getId().intValue();
     }
 
     /**
-     * 淇敼鎸囨爣閫夐」搴�
-     * 
-     * @param ivrLibaTarget 鎸囨爣閫夐」搴�
+     * 鏂板鎴栦慨鏀规寚鏍囬�夐」搴�
+     *
+     * @param ivrLibaTargetVO 鎸囨爣閫夐」搴�
      * @return 缁撴灉
      */
     @Override
-    public int updateIvrLibaTarget(IvrLibaTarget ivrLibaTarget)
-    {
+    @Transactional(rollbackFor = Exception.class)
+    public int saveOrupdateIvrLibaTarget(IvrLibaTargetVO ivrLibaTargetVO) {
+        IvrLibaTarget ivrLibaTarget = DtoConversionUtils.sourceToTarget(ivrLibaTargetVO, IvrLibaTarget.class);
         ivrLibaTarget.setUpdateTime(DateUtils.getNowDate());
-        return ivrLibaTargetMapper.updateIvrLibaTarget(ivrLibaTarget);
+        if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 1) {
+            //鏂板
+            ivrLibaTargetMapper.insertIvrLibaTarget(ivrLibaTarget);
+        } else if (ivrLibaTargetVO.getIsoperation() != null && ivrLibaTargetVO.getIsoperation() == 2) {
+            //淇敼
+            ivrLibaTargetMapper.updateIvrLibaTarget(ivrLibaTarget);
+        }
+
+        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getBaseTagList())) {
+            for (BaseTag baseTag : ivrLibaTargetVO.getBaseTagList()) {
+                if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 1) {
+                    //鏂板
+                    IvrLibaTargetTag ivrLibaTargetTag = new IvrLibaTargetTag();
+                    ivrLibaTargetTag.setTagcategoryid(baseTag.getTagcategoryid());
+                    ivrLibaTargetTag.setTargetid(ivrLibaTarget.getId());
+                    //鍓嶇浼犳潵鐨刡aseTag鐨則agid灏辨槸鎸囨爣鏍囩鐨勪富閿甶d,涓嶆槸baseTag鐨勪富閿�
+                    ivrLibaTargetTag.setTagid(baseTag.getTagid());
+                    ivrLibaTargetTagMapper.insertIvrLibaTargetTag(ivrLibaTargetTag);
+                } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 2) {
+                    //鍓嶇椤甸潰搴旇娌℃湁淇敼
+                } else if (baseTag.getIsoperation() != null && baseTag.getIsoperation() == 3) {
+                    //鍒犻櫎
+                    ivrLibaTargetTagMapper.deleteIvrLibaTargetTagById(baseTag.getTagid());
+                }
+            }
+        }
+        if (CollectionUtils.isNotEmpty(ivrLibaTargetVO.getTargetoptionList()) && ivrLibaTargetVO.getValueType() == 1) {
+            //閫夐」澶勭悊
+            for (IvrLibaTargetoption ivrLibaTargetoption : ivrLibaTargetVO.getTargetoptionList()) {
+                if (CollectionUtils.isNotEmpty(ivrLibaTargetoption.getNodynamiccruxs())) {
+                    ivrLibaTargetoption.setNodynamiccruxsJson(new Gson().toJson(ivrLibaTargetoption.getNodynamiccruxs()));
+                }
+                if (CollectionUtils.isNotEmpty(ivrLibaTargetoption.getDynamiccruxs())) {
+                    ivrLibaTargetoption.setDynamiccruxsJson(new Gson().toJson(ivrLibaTargetoption.getDynamiccruxs()));
+                }
+
+                if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 1) {
+                    //鏂板
+                    ivrLibaTargetoption.setTargetid(ivrLibaTarget.getId());
+                    ivrLibaTargetoptionMapper.insertIvrLibaTargetoption(ivrLibaTargetoption);
+                } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 2) {
+                    //淇敼
+                    ivrLibaTargetoptionMapper.updateIvrLibaTargetoption(ivrLibaTargetoption);
+                } else if (ivrLibaTargetoption.getIsoperation() != null && ivrLibaTargetoption.getIsoperation() == 3) {
+                    // 鍒犻櫎
+                    ivrLibaTargetoptionMapper.deleteIvrLibaTargetoptionByTargetoptionid(ivrLibaTargetoption.getTargetoptionid());
+                }
+
+            }
+        } else if (ivrLibaTargetVO.getValueType() == 2 || ivrLibaTargetVO.getValueType() == 3) {
+        }
+
+        return ivrLibaTarget.getId().intValue();
     }
+
 
     /**
      * 鎵归噺鍒犻櫎鎸囨爣閫夐」搴�
-     * 
-     * @param targetIDs 闇�瑕佸垹闄ょ殑鎸囨爣閫夐」搴撲富閿�
+     *
      * @return 缁撴灉
      */
     @Override
-    public int deleteIvrLibaTargetByTargetIDs(Long[] targetIDs)
-    {
-        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(targetIDs);
+    public int deleteIvrLibaTargetByTargetIDs(Long[] ids) {
+        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetIDs(ids);
     }
 
     /**
      * 鍒犻櫎鎸囨爣閫夐」搴撲俊鎭�
-     * 
-     * @param targetID 鎸囨爣閫夐」搴撲富閿�
+     *
      * @return 缁撴灉
      */
     @Override
-    public int deleteIvrLibaTargetByTargetID(Long targetID)
-    {
-        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(targetID);
+    public int deleteIvrLibaTargetByTargetID(Long id) {
+        return ivrLibaTargetMapper.deleteIvrLibaTargetByTargetID(id);
+    }
+
+    /**
+     * 鎸囨爣娴嬭瘯闂鍖归厤
+     */
+    @Override
+    public String targetQuesMate(IvrLibaTargetVO ivrLibaTargetVO) {
+
+        for (IvrLibaTargetoption ivrLibaTargetoption : ivrLibaTargetVO.getTargetoptionList()) {
+
+            Matcher matcher = null;
+            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex())) {
+                Pattern pattern = Pattern.compile(ivrLibaTargetoption.getTargetregex());
+                matcher = pattern.matcher(ivrLibaTargetVO.getContent());
+            }
+            //涓嶅寘鍚�
+            Matcher matcher2 = null;
+            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex2())) {
+                Pattern pattern2 = Pattern.compile(ivrLibaTargetoption.getTargetregex2());
+                matcher2 = pattern2.matcher(ivrLibaTargetVO.getContent());
+            }
+            if (StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrLibaTargetoption.getTargetregex2()) && StringUtils.isNotEmpty(ivrLibaTargetoption.getTargetregex()) && matcher.matches()) {
+                return ivrLibaTargetoption.getTargetvalue();
+            }
+
+        }
+        return null;
     }
 }

--
Gitblit v1.9.3