admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ConvertLinkController.java
@@ -1,284 +1,285 @@
package com.yeshi.fanli.controller.client.v2;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserConvertLinkTemplate;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.user.UserConvertLinkTemplateService;
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
/**
 * 文案转链
 * @author Administrator
 *
 */
@Controller("convertLinkControllerV2")
@RequestMapping("api/v2/convertlink")
public class ConvertLinkController {
   @Resource
   private UserConvertLinkTemplateService userConvertLinkTemplateService;
   @Resource
   private ConfigService configService;
   @Resource
   private RedisManager redisManager;
   @Resource
   private ConvertLinkManager convertLinkManager;
   /**
    *
    * @Title: getCommonTextList
    * @Description: 获取模板
    * @param acceptData
    * @param uid
    * @param callback
    * @param out
    * void 返回类型
    * @throws
    */
   @RequestMapping(value = "getCommonTextList")
   public void getCommonTextList(AcceptData acceptData, Long uid, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      JSONObject data = new JSONObject();
      List<UserConvertLinkTemplate> list = userConvertLinkTemplateService.listByUid(uid);
      if (list == null)
         list = new ArrayList<>();
      Gson gson = JsonUtil.getApiCommonGson();
      data.put("list", gson.toJson(list));
      data.put("tip", configService.get(ConfigKeyEnum.convertDocTip.getKey()));
      data.put("helpLink", configService.get(ConfigKeyEnum.convertDocHelpLink.getKey()));
      String text = redisManager.getCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid);
      if (text != null) {
         data.put("lastText", text);
         redisManager.removeCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid);
      }
      out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
   }
   /**
    *
    * @Title: setConvertLinkDoc
    * @Description: 暂存文案
    * @param acceptData
    * @param uid
    * @param text
    * @param callback
    * @param out
    * void 返回类型
    * @throws
    */
   @RequestMapping(value = "setConvertLinkDoc")
   public void setConvertLinkDoc(AcceptData acceptData, Long uid, String text, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(text)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
         return;
      }
      redisManager.cacheCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid, text);
      out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
   }
   /**
    *
    * @Title: addCommonText
    * @Description: 添加模板
    * @param acceptData
    * @param uid
    * @param template
    * @param callback
    * @param out
    * void 返回类型
    * @throws
    */
   @RequestMapping(value = "addCommonText")
   public void addCommonText(AcceptData acceptData, Long uid, String template, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(template)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
         return;
      }
      UserConvertLinkTemplate bean = new UserConvertLinkTemplate();
      bean.setUid(uid);
      bean.setTemplate(template);
      try {
         userConvertLinkTemplateService.addConvertLinkTemplate(bean);
      } catch (Exception e) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
         return;
      }
      out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
   }
   /**
    *
    * @Title: deleteCommonText
    * @Description: 删除模板
    * @param acceptData
    * @param uid
    * @param id
    * @param callback
    * @param out
    * void 返回类型
    * @throws
    */
   @RequestMapping(value = "deleteCommonText")
   public void deleteCommonText(AcceptData acceptData, Long uid, String id, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(id)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板ID为空")));
         return;
      }
      try {
         userConvertLinkTemplateService.deleteConvertLinkTemplate(id, uid);
      } catch (Exception e) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
         return;
      }
      out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
   }
   @RequestMapping(value = "updateCommonText")
   public void updateCommonText(AcceptData acceptData, Long uid, String id, String template, String callback,
         PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(id)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板ID为空")));
         return;
      }
      if (StringUtil.isNullOrEmpty(template)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板内容为空")));
         return;
      }
      UserConvertLinkTemplate bean = new UserConvertLinkTemplate();
      bean.setUid(uid);
      bean.setTemplate(template);
      bean.setId(id);
      try {
         userConvertLinkTemplateService.updateTemplate(bean);
      } catch (Exception e) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
         return;
      }
      out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
   }
   /**
    *
    * @Title: convert
    * @Description: 文案转链
    * @param acceptData
    * @param uid
    * @param text
    * @param callback
    * @param out
    * void 返回类型
    * @throws
    */
   @RequestMapping(value = "convert")
   public void convert(AcceptData acceptData, Long uid, String text, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(text)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
         return;
      }
      try {
         String key = RedisKeyEnum.convertLinkDocResultTemp.getKey() + uid + "-"
               + StringUtil.Md5(UUID.randomUUID().toString());
         String result = convertLinkManager.convertLinkFromText(text, uid, true);
         redisManager.cacheCommonString(key, result, 60);
         JSONObject data = new JSONObject();
         data.put("id", key);
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
      } catch (Exception e) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
         return;
      }
   }
   @RequestMapping(value = "getConvertResult")
   public void getConvertResult(AcceptData acceptData, Long uid, String id, String callback, PrintWriter out) {
      if (uid == null || uid == 0L) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
         return;
      }
      if (StringUtil.isNullOrEmpty(id)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案ID为空")));
         return;
      }
      String key =id;
      String result = redisManager.getCommonString(key);
      if (StringUtil.isNullOrEmpty(result)) {
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("获取转链结果出错")));
      } else {
         redisManager.removeCommonString(key);
         JSONObject data = new JSONObject();
         data.put("data", result);
         data.put("tip", "1.转好的链接/口令有效期,请在有效期内推广分享;\r\n" + "2.已经转好的链接/口令请不要修改,以免无法追踪到订单;\r\n"
               + "3.请确保转换链接合法合规,一切违法的链/口令产生的法律后果自行承担与本App无关。");
         out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
      }
   }
}
package com.yeshi.fanli.controller.client.v2;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import com.yeshi.fanli.entity.SystemFunction;
import com.yeshi.fanli.service.inter.user.UserFunctionsLimitService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserConvertLinkTemplate;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.user.UserConvertLinkTemplateService;
import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
import com.yeshi.fanli.util.RedisKeyEnum;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONObject;
/**
 * 文案转链
 *
 * @author Administrator
 */
@Controller("convertLinkControllerV2")
@RequestMapping("api/v2/convertlink")
public class ConvertLinkController {
    @Resource
    private UserConvertLinkTemplateService userConvertLinkTemplateService;
    @Resource
    private ConfigService configService;
    @Resource
    private RedisManager redisManager;
    @Resource
    private ConvertLinkManager convertLinkManager;
    @Resource
    private UserFunctionsLimitService userFunctionsLimitService;
    /**
     * @param acceptData
     * @param uid
     * @param callback
     * @param out        void 返回类型
     * @throws
     * @Title: getCommonTextList
     * @Description: 获取模板
     */
    @RequestMapping(value = "getCommonTextList")
    public void getCommonTextList(AcceptData acceptData, Long uid, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        JSONObject data = new JSONObject();
        List<UserConvertLinkTemplate> list = userConvertLinkTemplateService.listByUid(uid);
        if (list == null)
            list = new ArrayList<>();
        Gson gson = JsonUtil.getApiCommonGson();
        data.put("list", gson.toJson(list));
        data.put("tip", configService.getValue(ConfigKeyEnum.convertDocTip.getKey(), acceptData.getSystem()));
        data.put("helpLink", configService.getValue(ConfigKeyEnum.convertDocHelpLink.getKey(), acceptData.getSystem()));
        String text = redisManager.getCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid);
        if (text != null) {
            data.put("lastText", text);
            redisManager.removeCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid);
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
    }
    /**
     * @param acceptData
     * @param uid
     * @param text
     * @param callback
     * @param out        void 返回类型
     * @throws
     * @Title: setConvertLinkDoc
     * @Description: 暂存文案
     */
    @RequestMapping(value = "setConvertLinkDoc")
    public void setConvertLinkDoc(AcceptData acceptData, Long uid, String text, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(text)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
            return;
        }
        redisManager.cacheCommonString(RedisKeyEnum.convertLinkDocTemp.getKey() + uid, text);
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
    }
    /**
     * @param acceptData
     * @param uid
     * @param template
     * @param callback
     * @param out        void 返回类型
     * @throws
     * @Title: addCommonText
     * @Description: 添加模板
     */
    @RequestMapping(value = "addCommonText")
    public void addCommonText(AcceptData acceptData, Long uid, String template, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(template)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
            return;
        }
        UserConvertLinkTemplate bean = new UserConvertLinkTemplate();
        bean.setUid(uid);
        bean.setTemplate(template);
        try {
            userConvertLinkTemplateService.addConvertLinkTemplate(bean);
        } catch (Exception e) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
            return;
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
    }
    /**
     * @param acceptData
     * @param uid
     * @param id
     * @param callback
     * @param out        void 返回类型
     * @throws
     * @Title: deleteCommonText
     * @Description: 删除模板
     */
    @RequestMapping(value = "deleteCommonText")
    public void deleteCommonText(AcceptData acceptData, Long uid, String id, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板ID为空")));
            return;
        }
        try {
            userConvertLinkTemplateService.deleteConvertLinkTemplate(id, uid);
        } catch (Exception e) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
            return;
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
    }
    @RequestMapping(value = "updateCommonText")
    public void updateCommonText(AcceptData acceptData, Long uid, String id, String template, String callback,
                                 PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板ID为空")));
            return;
        }
        if (StringUtil.isNullOrEmpty(template)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("模板内容为空")));
            return;
        }
        UserConvertLinkTemplate bean = new UserConvertLinkTemplate();
        bean.setUid(uid);
        bean.setTemplate(template);
        bean.setId(id);
        try {
            userConvertLinkTemplateService.updateTemplate(bean);
        } catch (Exception e) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
            return;
        }
        out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("")));
    }
    /**
     * @param acceptData
     * @param uid
     * @param text
     * @param callback
     * @param out        void 返回类型
     * @throws
     * @Title: convert
     * @Description: 文案转链
     */
    @RequestMapping(value = "convert")
    public void convert(AcceptData acceptData, Long uid, String text, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(text)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案为空")));
            return;
        }
        if (userFunctionsLimitService.isLimit(uid, SystemFunction.share, new Date())) {
            out.print(JsonUtil.loadFalseResult(1, "该功能限制使用"));
            return;
        }
        try {
            String key = RedisKeyEnum.convertLinkDocResultTemp.getKey() + uid + "-"
                    + StringUtil.Md5(UUID.randomUUID().toString());
            String result = convertLinkManager.convertLinkFromText(acceptData.getSystem(), text, uid, true, true);
            redisManager.cacheCommonString(key, result, 60);
            JSONObject data = new JSONObject();
            data.put("id", key);
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
        } catch (Exception e) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(e.getMessage())));
            return;
        }
    }
    @RequestMapping(value = "getConvertResult")
    public void getConvertResult(AcceptData acceptData, Long uid, String id, String callback, PrintWriter out) {
        if (uid == null || uid == 0L) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("用户未登录")));
            return;
        }
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("文案ID为空")));
            return;
        }
        String key = id;
        String result = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(result)) {
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("获取转链结果出错")));
        } else {
            redisManager.removeCommonString(key);
            JSONObject data = new JSONObject();
            data.put("data", result);
            data.put("tip", "1.转好的链接/口令有有效期,请在有效期内推广分享;\r\n" + "2.已经转好的链接/口令请不要修改,以免无法追踪到订单;\r\n"
                    + "3.请确保转换链接合法合规,一切违法的链接/口令产生的法律后果自行承担与本App无关。");
            out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
        }
    }
}