Browse Source

增加后台录入询盘的入口

chenlei1231 4 weeks ago
parent
commit
23b199edfa

+ 87 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/controller/AdwebEnquiryController.java

@@ -37,6 +37,7 @@ import org.jeecg.modules.adweb.common.util.DateUtil;
 import org.jeecg.modules.adweb.enquiry.constant.EnquirySendStatus;
 import org.jeecg.modules.adweb.enquiry.dto.EnquiryDTO;
 import org.jeecg.modules.adweb.enquiry.dto.param.EffectiveEnquiryParamDto;
+import org.jeecg.modules.adweb.enquiry.dto.param.EnquiryForm;
 import org.jeecg.modules.adweb.enquiry.dto.param.EnquiryListSearchDto;
 import org.jeecg.modules.adweb.enquiry.dto.param.EnquirySearchDto;
 import org.jeecg.modules.adweb.enquiry.dto.result.EnquiryListDto;
@@ -277,10 +278,43 @@ public class AdwebEnquiryController extends JeecgController<AdwebEnquiry, IAdweb
    */
   @AutoLog(value = "询盘信息存储表单-添加")
   @Operation(summary = "询盘信息存储表单-添加")
-  @PreAuthorize("@jps.requiresPermissions('adweb:adweb_enquiry:add')")
   @PostMapping(value = "/add")
-  public Result<String> add(@RequestBody AdwebEnquiry adwebEnquiry) {
-    adwebEnquiryService.save(adwebEnquiry);
+  public Result<String> add(@RequestBody EnquiryForm enquiryForm) {
+    String defaultPlugin = "wpforms";
+
+    if (StringUtils.isBlank(enquiryForm.getSiteCode())) {
+      return Result.error("当前未选择站点");
+    }
+
+    QueryWrapper<AdwebSite> queryWrapper = new QueryWrapper<>();
+    queryWrapper
+        .ne("status", 0)
+        .in("create_type", Arrays.asList("manual", "wp"))
+        .eq("code", enquiryForm.getSiteCode());
+
+    AdwebSite adwebSite = adwebSiteService.getOne(queryWrapper);
+
+    String maxRecordId =
+        adwebEnquiryMapper.getMaxRecordIdByCode(adwebSite.getCode(), defaultPlugin);
+    if (StringUtils.isEmpty(maxRecordId)) {
+      maxRecordId = "1";
+    } else {
+      maxRecordId = String.valueOf((int) Double.parseDouble(maxRecordId) + 1);
+    }
+
+    JSONObject formObject = generateFormJsonObject(enquiryForm, adwebSite);
+    EnquiryDTO enquiryDTO = new EnquiryDTO();
+    enquiryDTO.setForms(formObject);
+    enquiryDTO.setFromIp("");
+    enquiryDTO.setFromEmail(enquiryForm.getEmail());
+    enquiryDTO.setFromSource(enquiryForm.getFromSource());
+    enquiryDTO.setCountryCode(enquiryForm.getCountryCode());
+    enquiryDTO.setPluginName(defaultPlugin);
+    enquiryDTO.setSiteHost(adwebSite.getDomain().replace("https://", ""));
+    enquiryDTO.setRecordCtime(new Date());
+    enquiryDTO.setRecordId(maxRecordId);
+    // 推送询盘
+    adwebEnquiryService.addEnquiry(enquiryDTO, defaultPlugin, adwebSite);
     return Result.OK("添加成功!");
   }
 
@@ -839,4 +873,54 @@ public class AdwebEnquiryController extends JeecgController<AdwebEnquiry, IAdweb
 
     return enquiryEmailMessage;
   }
+
+  private static JSONObject generateFormJsonObject(EnquiryForm adwebEnquiry, AdwebSite adwebSite) {
+    // 创建外层json
+    JSONObject outObject = new JSONObject();
+
+    // 创建内容json
+    JSONObject object1 = new JSONObject();
+    object1.put("name", "Name");
+    object1.put("value", adwebEnquiry.getName());
+    object1.put("id", "1");
+    object1.put("type", "text");
+    outObject.put("1", object1);
+
+    JSONObject object2 = new JSONObject();
+    object2.put("name", "Email");
+    object2.put("value", adwebEnquiry.getEmail());
+    object2.put("id", "2");
+    object2.put("type", "email");
+    outObject.put("2", object2);
+
+    JSONObject object3 = new JSONObject();
+    object3.put("name", "Phone");
+    object3.put("value", adwebEnquiry.getPhone());
+    object3.put("id", "3");
+    object3.put("type", "phone");
+    outObject.put("3", object3);
+
+    JSONObject object4 = new JSONObject();
+    object4.put("name", "Message");
+    object4.put("value", adwebEnquiry.getMessage());
+    object4.put("id", "4");
+    object4.put("type", "textarea");
+    outObject.put("4", object4);
+
+    JSONObject object5 = new JSONObject();
+    object5.put("name", "Customer IP");
+    object5.put("value", "::1");
+    object5.put("id", "5");
+    object5.put("type", "hidden");
+    outObject.put("5", object5);
+
+    JSONObject object6 = new JSONObject();
+    object6.put("name", "From Page");
+    object6.put("value", adwebSite.getDomain());
+    object6.put("id", "6");
+    object6.put("type", "hidden");
+    outObject.put("6", object6);
+
+    return outObject;
+  }
 }

+ 20 - 23
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/dto/EnquiryDTO.java

@@ -1,36 +1,33 @@
 package org.jeecg.modules.adweb.enquiry.dto;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
-
-import lombok.Data;
-
 import java.util.Date;
+import lombok.Data;
 
 /**
  * @author wfansh
  */
 @Data
 public class EnquiryDTO {
-    // 站点code,关联站点表
-    private String siteCode;
-    private String fromEmail;
-    private Object forms;
-    private String pluginName;
-    private String fromIp;
-    private String siteHost;
+  // 站点code,关联站点表
+  private String siteCode;
+  private String fromEmail;
+  private Object forms;
+  private String pluginName;
+  private String fromIp;
+  private String siteHost;
 
-    @JsonFormat(
-            shape = JsonFormat.Shape.STRING,
-            timezone = "GMT+8",
-            pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date recordCtime;
+  @JsonFormat(shape = JsonFormat.Shape.STRING, timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+  private Date recordCtime;
 
-    private String recordId;
-    // 访问人id
-    private String visitId;
-    // 站点id
-    private Integer siteId;
-    private String siteToken;
-    private String formName;
-    private Object cartItems;
+  private String recordId;
+  // 访问人id
+  private String visitId;
+  // 站点id
+  private Integer siteId;
+  private String siteToken;
+  private String formName;
+  private Object cartItems;
+  private String countryCode;
+  private String fromSource;
 }

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/dto/param/EnquiryForm.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.adweb.enquiry.dto.param;
+
+import lombok.Data;
+
+@Data
+public class EnquiryForm {
+  private String name;
+  private String email;
+  private String siteCode;
+  private String countryCode;
+  private String fromSource;
+  private String phone;
+  private String message;
+}

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/entity/AdwebEnquiry.java

@@ -268,6 +268,11 @@ public class AdwebEnquiry implements Serializable {
   private String company;
 
   /** 来源页面 */
+  @Excel(name = "来源媒体", width = 15)
+  @Schema(description = "来源媒体")
+  private String fromSource;
+
+  /** 来源页面 */
   @Excel(name = "来源页面", width = 15)
   @Schema(description = "来源页面")
   private String fromPage;

+ 8 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/AdwebEnquiryMapper.java

@@ -101,4 +101,12 @@ public interface AdwebEnquiryMapper extends BaseMapper<AdwebEnquiry> {
 
   /** 统计管理的询盘数量 */
   List<JSONObject> getEnquiryCount(List<String> uids);
+
+  /**
+   * 根据站点code查询此站点下询盘最新一条的id
+   *
+   * @param siteCode
+   * @return
+   */
+  String getMaxRecordIdByCode(String siteCode, String plugin);
 }

+ 7 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/mapper/xml/AdwebEnquiryMapper.xml

@@ -426,4 +426,11 @@
         principal_uid
     </select>
 
+    <select id="getMaxRecordIdByCode" parameterType="java.lang.String" resultType="java.lang.String">
+        SELECT MAX(record_id + 0)
+        FROM adweb_enquiry
+        WHERE site_code = #{siteCode}
+          AND plugin_name = #{plugin}
+    </select>
+
 </mapper>

+ 23 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enquiry/service/impl/AdwebEnquiryServiceImpl.java

@@ -298,7 +298,11 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
 
       String forms = FastJsonUtil.toJSONString(enquiryDto.getForms());
       parseFormAndSetFields(adwebEnquiry, forms, adwebSite);
-      setCountryByIp(adwebEnquiry);
+
+      if (StringUtils.isNotBlank(adwebEnquiry.getFromIp())) {
+        setCountryByIp(adwebEnquiry);
+      }
+
       setPrincipal(adwebEnquiry, adwebSite.getEnquiryDistributeType(), adwebSite.getId());
       adwebEnquiryList.add(adwebEnquiry);
 
@@ -857,8 +861,11 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
     adwebEnquiry.setFromEmail(enquiryDto.getFromEmail());
     adwebEnquiry.setPluginName(enquiryDto.getPluginName());
     adwebEnquiry.setRecordId(enquiryDto.getRecordId());
-    adwebEnquiry.setModifyRecordCtime(
-        geoIpUtil.getLocalhostTime(enquiryDto.getFromIp(), enquiryDto.getRecordCtime()));
+    Date modifyRecordCtime =
+        StringUtils.isNotBlank(enquiryDto.getFromIp())
+            ? geoIpUtil.getLocalhostTime(enquiryDto.getFromIp(), enquiryDto.getRecordCtime())
+            : new Date();
+    adwebEnquiry.setModifyRecordCtime(modifyRecordCtime);
     adwebEnquiry.setRecordCtime(enquiryDto.getRecordCtime());
     adwebEnquiry.setSiteCode(adwebSite.getCode());
     adwebEnquiry.setModular(enquiryDto.getPluginName());
@@ -878,6 +885,19 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
     adwebEnquiry.setAcquireMessageTime(adwebSite.getEnquiryMessageTime());
     adwebEnquiry.setIsEnquirySync("enquirySync");
 
+    adwebEnquiry.setFromSource(enquiryDto.getFromSource());
+    adwebEnquiry.setCountryCode(enquiryDto.getCountryCode());
+
+    QueryWrapper<AdwebCountry> queryWrapper = new QueryWrapper<>();
+    queryWrapper.eq("country_iso_code", enquiryDto.getCountryCode());
+
+    AdwebCountry adwebCountry = adwebCountryService.getOne(queryWrapper);
+
+    if (adwebCountry != null) {
+      adwebEnquiry.setCountry(adwebCountry.getCountryName());
+      adwebEnquiry.setCountryName(adwebCountry.getCountryName());
+    }
+
     ObjectMapper objectMapper = new ObjectMapper();
     try {
       String jsonString = objectMapper.writeValueAsString(enquiryDto.getCartItems());