admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/SystemClientController.java
@@ -1,154 +1,171 @@
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.IPUtil;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.push.DeviceActive;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.CustomerContent;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.CustomerContentService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.push.DeviceActiveService;
import com.yeshi.fanli.service.inter.push.IOSPushService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.util.ThreadUtil;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v1/systemclient")
public class SystemClientController {
   @Resource
   private BusinessSystemService businessSystemService;
   @Resource
   private SystemClientParamsService systemClientParamsService;
   @Resource
   private IOSPushService iosPushService;
   @Resource
   private ConfigService configService;
   @Resource
   private DeviceActiveService deviceActiveService;
   @Resource
   private CustomerContentService customerContentService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @RequestMapping("getsystemclientparams")
   public void getSystemClientParams(AcceptData acceptData, Long uid, String mac, HttpServletRequest request,
         PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print("系统不存在");
         return;
      }
      List<SystemClientParams> systemClientParamsList = systemClientParamsService
            .getSystemClientParamsBySystemId(system.getId(), Integer.parseInt(acceptData.getVersion()));
      if (systemClientParamsList == null || systemClientParamsList.size() == 0) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
         return;
      }
      // TODO 需要改成数据库控制,暂时写成这样
      List<SystemClientParams> list = new ArrayList<>();
      for (SystemClientParams sp : systemClientParamsList) {
         SystemClientParams ssp = new SystemClientParams();
         try {
            PropertyUtils.copyProperties(ssp, sp);
         } catch (Exception e) {
         }
         if (ssp.getKey().equalsIgnoreCase("iosonling") && "ios".equalsIgnoreCase(acceptData.getPlatform())
               && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) {
            ssp.setValue("1");
         } else if (ssp.getKey().equalsIgnoreCase("home_weex_url")) {
            if (("android".equalsIgnoreCase(acceptData.getPlatform())
                  && Integer.parseInt(acceptData.getVersion()) < 36)) {
               // 老版本weex(1.5.1之前的)
               ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js");
            } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())
                  && Integer.parseInt(acceptData.getVersion()) < 44 && system.getId().longValue() != 5L)
               ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js");
         }
         list.add(ssp);
      }
      Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
      JSONObject data = new JSONObject();
      data.put("count", list.size());
      data.put("systemClientParamsList", gson.toJson(list));
      out.print(JsonUtil.loadTrueResult(data));
      String ipInfo = IPUtil.getRemotIP(request) + ":" + request.getRemotePort();
      ThreadUtil.run(new Runnable() {
         @Override
         public void run() {
            try {
               // 安卓平台添加设备活跃记录
               DeviceActive da = new DeviceActive();
               da.setDevice(acceptData.getDevice());
               da.setPlatform("android".equalsIgnoreCase(acceptData.getPlatform()) ? DeviceActive.PLATFORM_ANDROID
                     : DeviceActive.PLATFORM_IOS);
               da.setVersionCode(Integer.parseInt(acceptData.getVersion()));
               da.setIpInfo(ipInfo);
               da.setChannel(acceptData.getChannel());
               da.setImei(acceptData.getImei());
               da.setMac(mac);
               deviceActiveService.addDeviceActive(da);
            } catch (Exception e) {
               e.printStackTrace();
            }
            // 用户等级更新
            try {
               userInfoExtraService.updateUserRankByUid(uid);
            } catch (Exception e) {
               LogHelper.errorDetailInfo(e);
            }
         }
      });
      return;
   }
   /**
    *
    * 方法说明: 联系客服接口
    *
    * @author mawurui createTime 2018年4月10日 上午9:02:41
    */
   @RequestMapping("contactCustomerService")
   public void contactCustomerService(AcceptData acceptData, PrintWriter out) {
      String title = "联系客服";
      List<CustomerContent> contentList = customerContentService.contactCustomerService(title);
      JSONObject data = new JSONObject();
      data.put("contentList", JsonUtil.getSimpleGsonWithDate().toJson(contentList));
      out.print(JsonUtil.loadTrueResult(data));
   }
}
package com.yeshi.fanli.controller.client.v1;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.IPUtil;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.push.DeviceActive;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.system.CustomerContent;
import com.yeshi.fanli.entity.system.SystemClientParams;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.CustomerContentService;
import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
import com.yeshi.fanli.service.inter.push.DeviceActiveService;
import com.yeshi.fanli.service.inter.push.IOSPushService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.annotation.UserActive;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v1/systemclient")
public class SystemClientController {
   @Resource
   private BusinessSystemService businessSystemService;
   @Resource
   private SystemClientParamsService systemClientParamsService;
   @Resource
   private IOSPushService iosPushService;
   @Resource
   private ConfigService configService;
   @Resource
   private DeviceActiveService deviceActiveService;
   @Resource
   private CustomerContentService customerContentService;
   @Resource
   private UserInfoExtraService userInfoExtraService;
   @UserActive(uid="#uid")
   @RequestMapping("getsystemclientparams")
   public void getSystemClientParams(AcceptData acceptData, Long uid, String mac, HttpServletRequest request,
         PrintWriter out) {
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
            acceptData.getPackages(),acceptData.getSystem());
      if (system == null) {
         out.print("系统不存在");
         return;
      }
      List<SystemClientParams> systemClientParamsList = systemClientParamsService
            .getSystemClientParamsBySystemId(system.getId(), Integer.parseInt(acceptData.getVersion()));
      if (systemClientParamsList == null || systemClientParamsList.size() == 0) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
         return;
      }
      // TODO 需要改成数据库控制,暂时写成这样
      List<SystemClientParams> list = new ArrayList<>();
      for (SystemClientParams sp : systemClientParamsList) {
         SystemClientParams ssp = new SystemClientParams();
         try {
            PropertyUtils.copyProperties(ssp, sp);
         } catch (Exception e) {
         }
         if (ssp.getKey().equalsIgnoreCase("iosonling") && "ios".equalsIgnoreCase(acceptData.getPlatform())
               && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()),acceptData.getSystem())) {
            ssp.setValue("1");
         } else if (ssp.getKey().equalsIgnoreCase(ConfigKeyEnum.homeWeexUrl.getKey())) {
            if (("android".equalsIgnoreCase(acceptData.getPlatform())
                  && Integer.parseInt(acceptData.getVersion()) < 36)) {
               // 老版本weex(1.5.1之前的)
               ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js");
            } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())
                  && Integer.parseInt(acceptData.getVersion()) < 44 && system.getId().longValue() != 5L)
               ssp.setValue("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_v2.js");
         }
         // 同步管理config
         if (ssp.getKey().equalsIgnoreCase("inviteRules")) {
            ssp.setValue(configService.getValue(ConfigKeyEnum.inviteRules.getKey(),acceptData.getSystem()));
         }
         list.add(ssp);
      }
      SystemClientParams ssp = new SystemClientParams();
      ssp.setKey(ConfigKeyEnum.homePageBgColors.getKey());
      ssp.setValue(configService.getValue(ConfigKeyEnum.homePageBgColors,acceptData.getSystem()));
      list.add(ssp);
      Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
      JSONObject data = new JSONObject();
      data.put("count", list.size());
      data.put("systemClientParamsList", gson.toJson(list));
      out.print(JsonUtil.loadTrueResult(data));
      String ipInfo = IPUtil.getRemotIP(request) + ":" + request.getRemotePort();
      ThreadUtil.run(new Runnable() {
         @Override
         public void run() {
            try {
               // 安卓平台添加设备活跃记录
               DeviceActive da = new DeviceActive();
               da.setDevice(acceptData.getDevice());
               da.setPlatform("android".equalsIgnoreCase(acceptData.getPlatform()) ? DeviceActive.PLATFORM_ANDROID
                     : DeviceActive.PLATFORM_IOS);
               da.setVersionCode(Integer.parseInt(acceptData.getVersion()));
               da.setIpInfo(ipInfo);
               da.setChannel(acceptData.getChannel());
               da.setImei(acceptData.getImei());
               da.setMac(mac);
               deviceActiveService.addDeviceActive(da);
            } catch (Exception e) {
               e.printStackTrace();
            }
            // 用户等级更新
            try {
               userInfoExtraService.updateUserRankByUid(uid);
            } catch (Exception e) {
               LogHelper.errorDetailInfo(e);
            }
         }
      });
      return;
   }
   /**
    *
    * 方法说明: 联系客服接口
    *
    * @author mawurui createTime 2018年4月10日 上午9:02:41
    */
   @RequestMapping("contactCustomerService")
   public void contactCustomerService(AcceptData acceptData, PrintWriter out) {
      String title = "联系客服";
      List<CustomerContent> contentList = customerContentService.contactCustomerService(title);
      JSONObject data = new JSONObject();
      data.put("contentList", JsonUtil.getSimpleGsonWithDate().toJson(contentList));
      out.print(JsonUtil.loadTrueResult(data));
   }
}