package com.yc.sdk.shopping.action;
|
|
import java.util.Set;
|
import java.util.List;
|
import java.util.Map.Entry;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import com.google.gson.JsonArray;
|
import com.google.gson.JsonElement;
|
import com.google.gson.JsonObject;
|
import com.yc.action.BaseAction;
|
import com.yc.entity.DataSourceEntity;
|
import com.yc.multiData.MultiDataSource;
|
import com.yc.multiData.SpObserver;
|
import com.yc.sdk.shopping.action.api.ShopCcCode;
|
import com.yc.sdk.shopping.entity.InformationDetailEntity;
|
import com.yc.sdk.shopping.entity.InformationEntity;
|
import com.yc.sdk.shopping.entity.SettingEntity;
|
import com.yc.sdk.shopping.entity.ShopCcCodeEntity;
|
import com.yc.sdk.shopping.service.InformationIfc;
|
import com.yc.sdk.shopping.service.SettingIfc;
|
import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
|
import com.yc.sdk.shopping.util.SettingKey;
|
import com.yc.utils.SessionKey;
|
|
|
@Controller
|
@RequestMapping("/shopping/information.do")
|
public class Information extends BaseAction{
|
@Autowired
|
InformationIfc informationIfc ;
|
@Autowired
|
SettingIfc settingIfc ;
|
@Autowired
|
ShoppingImageDataIfc imgData ;
|
|
@RequestMapping(params = "m=getInformationByShowBannerOnHomePage")
|
public void getInformationByShowBannerOnHomePage(HttpServletRequest request,HttpServletResponse response) {
|
HttpSession session=request.getSession();
|
//String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
|
//String outFormat = request.getParameter("OutFormat") ;
|
//String infoDocCode = request.getParameter(SettingKey.INFODOCCODE) ;
|
//String title = request.getParameter(SettingKey.TITLE) ;
|
//InformationEntity info = null ;
|
String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID)==null?"":(String)session.getAttribute(SessionKey.WEIXIN_OPENID)) ;
|
SettingEntity settingEntity = null ;
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
settingEntity = settingIfc.getSettingEntity(request) ;
|
|
String hostUrl = SettingKey.getHostUrl(request);
|
//String hostUrl = SettingKey.getHostUrl(request) ;
|
//将微信corpid组装成url
|
//String wxQueryString = SettingKey.getQueryStringByWx(request);
|
//boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
|
|
//取网店 shopcccode
|
ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
JsonArray jsonArray = new JsonArray();
|
List<InformationEntity> infoList = informationIfc.getInformationsByShowBannerOnHomePage(shopCcCodeEntity.getShopCcCode());
|
for(int k = 0 ;infoList !=null && k < infoList.size();k++) {
|
InformationEntity info = infoList.get(k) ;
|
JsonObject jsonObject = new JsonObject();
|
request.setAttribute(SettingKey.FROMOPENID, openId);
|
String description = imgData.getDescriptionByNewImgLink(info!=null?info.getDescription():"", request) ;
|
jsonObject.addProperty("doccode", (info!=null? info.getDocCode():""));
|
jsonObject.addProperty("title", (info!=null? info.getTitle():""));
|
|
// BannerImage 格式: 790F20EF-270C-4869-BAAD-D9811587022C;6370;6371
|
JsonArray bannerImageArray = new JsonArray();
|
bannerImageArray.add(SettingKey.getUrl(hostUrl, info!=null&& info.getBannerImageUrl()!=null&&!"".equals(info.getBannerImageUrl())?info.getBannerImageUrl():"", dataSourceEntity.getDbId()+"",null));
|
/*
|
if (info.getBannerImage()!=null && ! info.getBannerImage().equals("")) {
|
String bnannerImages[] = info.getBannerImage().split(";") ;
|
String unid = bnannerImages[0] ;
|
//旧版上传控件上传的内容没有 seq
|
if (bnannerImages.length == 1) {
|
String bnannerImageUrl = imgData.getImageUrl(unid,settingEntity.getImageBannerWidth(),settingEntity.getImageBannerHeight(),settingEntity.isShowBannerOrgImage(),settingEntity.isFromCached(),request) ;
|
bannerImageArray.add(bnannerImageUrl);
|
}else {
|
//新版上传控件上传的内容有 seq
|
for (int i =0 ;i<bnannerImages.length;i++) {
|
if (i == 0) continue ;
|
String unids = unid + ";" + bnannerImages[i] ; //新版上传控件上传的格式会带有 seq
|
String bnannerImageUrl = imgData.getImageUrl(unids,settingEntity.getImageBannerWidth(),settingEntity.getImageBannerHeight(),settingEntity.isShowBannerOrgImage(),settingEntity.isFromCached(),request) ;
|
bannerImageArray.add(bnannerImageUrl);
|
}
|
}
|
}*/
|
|
jsonObject.add("bannerImages", bannerImageArray);
|
|
jsonObject.addProperty("isShowBannerOnHomePage", (info!=null? info.isShowBannerOnHomePage():false));
|
jsonObject.addProperty("isShowBannerOnDetailPage", (info!=null? info.isShowBannerOnDetailPage():false));
|
jsonObject.addProperty("description", description);
|
jsonArray.add(jsonObject);
|
|
}
|
json.add("list", jsonArray);
|
this.printJson(response, json.toString());
|
return ;
|
|
}catch (DataAccessException e) {
|
e.printStackTrace();
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}catch (Exception e ){
|
e.printStackTrace();
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=get")
|
public void getInformationEntity(HttpServletRequest request,HttpServletResponse response) {
|
HttpSession session=request.getSession();
|
//String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
|
String outFormat = request.getParameter("OutFormat") ;
|
String infoDocCode = request.getParameter(SettingKey.INFODOCCODE) ;
|
String title = request.getParameter(SettingKey.TITLE) ;
|
InformationEntity info = null ;
|
SettingEntity settingEntity = null ;
|
JsonObject json = new JsonObject();
|
JsonObject errJson = new JsonObject();
|
String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID)==null?"":(String)session.getAttribute(SessionKey.WEIXIN_OPENID)) ;
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
settingEntity = settingIfc.getSettingEntity(request) ;
|
String hostUrl = SettingKey.getHostUrl(request);
|
|
//取网店 shopcccode
|
ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
//内容
|
JsonArray jsonArray = new JsonArray();
|
List<InformationDetailEntity> informationDetailList = informationIfc.getInformationDetail(infoDocCode,title,shopCcCodeEntity.getShopCcCode(),dataSourceEntity.getMiniAppId());
|
for (int i = 0 ;informationDetailList != null && i < informationDetailList.size();i++) {
|
InformationDetailEntity informationDetailEntity = informationDetailList.get(i) ;
|
if (informationDetailEntity.isShowBottom()) {
|
continue ;
|
}
|
JsonObject jsonObject= getJsonObject( informationDetailEntity, request, settingEntity) ;
|
jsonArray.add(jsonObject);
|
}
|
|
|
|
info = informationIfc.getInformation(infoDocCode,title,shopCcCodeEntity.getShopCcCode());
|
|
request.setAttribute(SettingKey.FROMOPENID, openId);
|
String description = imgData.getDescriptionByNewImgLink(info!=null?info.getDescription():"", request) ;
|
json.addProperty("title", (info!=null? info.getTitle():""));
|
json.addProperty(SettingKey.INFODOCCODE, (info!=null? info.getDocCode():""));
|
|
// BannerImage 格式: 790F20EF-270C-4869-BAAD-D9811587022C;6370;6371
|
JsonArray bannerImageArray = new JsonArray();
|
bannerImageArray.add(SettingKey.getUrl(hostUrl, info!=null&& info.getBannerImageUrl()!=null&&!"".equals(info.getBannerImageUrl())?info.getBannerImageUrl():"", dataSourceEntity.getDbId()+"",null) );
|
/*
|
if (info != null && info.getBannerImage()!=null && ! info.getBannerImage().equals("")) {
|
String bnannerImages[] = info.getBannerImage().split(";") ;
|
String unid = bnannerImages[0] ;
|
//旧版上传控件上传的内容没有 seq
|
if (bnannerImages.length == 1) {
|
String bnannerImageUrl = imgData.getImageUrl(unid,settingEntity.getImageBannerWidth(),settingEntity.getImageBannerHeight(),settingEntity.isShowBannerOrgImage(),settingEntity.isFromCached(),request) ;
|
bannerImageArray.add(bnannerImageUrl);
|
}else {
|
//新版上传控件上传的内容有 seq
|
for (int i =0 ;i<bnannerImages.length;i++) {
|
if (i == 0) continue ;
|
String unids = unid + ";" + bnannerImages[i] ; //新版上传控件上传的格式会带有 seq
|
String bnannerImageUrl = imgData.getImageUrl(unids,settingEntity.getImageBannerWidth(),settingEntity.getImageBannerHeight(),settingEntity.isShowBannerOrgImage(),settingEntity.isFromCached(),request) ;
|
bannerImageArray.add(bnannerImageUrl);
|
}
|
}
|
}*/
|
|
json.add("bannerImages", bannerImageArray);
|
|
json.addProperty("isShowBannerOnHomePage", (info!=null? info.isShowBannerOnHomePage():false));
|
json.addProperty("isShowBannerOnDetailPage", (info!=null? info.isShowBannerOnDetailPage():false));
|
json.addProperty("description", description);
|
json.add("list", jsonArray); //内容
|
|
//页脚
|
JsonArray bottomJsonArray = new JsonArray();
|
for (int i = 0 ;informationDetailList != null && i < informationDetailList.size();i++) {
|
InformationDetailEntity informationDetailEntity = informationDetailList.get(i) ;
|
if (! informationDetailEntity.isShowBottom()) {
|
continue ;
|
}
|
JsonObject jsonObject= getJsonObject( informationDetailEntity, request, settingEntity) ;
|
bottomJsonArray.add(jsonObject) ;
|
}
|
json.add("bottomList", bottomJsonArray); //页脚
|
|
if (outFormat!=null&&"json".equalsIgnoreCase(outFormat)) {
|
this.printJson(response, json.toString());
|
}else {
|
this.print(response, description);
|
}
|
return ;
|
|
}catch (DataAccessException e) {
|
e.printStackTrace();
|
if (outFormat!=null&&"json".equalsIgnoreCase(outFormat)) {
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
}else {
|
this.print(response, (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
}
|
return;
|
}catch (Exception e ){
|
e.printStackTrace();
|
if (outFormat!=null&&"json".equalsIgnoreCase(outFormat)) {
|
errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
}else {
|
this.print(response, (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
}
|
return;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
private JsonObject getJsonObject(InformationDetailEntity informationDetailEntity,HttpServletRequest request,SettingEntity settingEntity) {
|
if (informationDetailEntity == null) return null ;
|
String hostUrl = SettingKey.getHostUrl(request) ;
|
//将微信corpid组装成url
|
String wxQueryString = SettingKey.getQueryStringByWx(request);
|
boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
|
|
JsonObject jsonObject= new JsonObject();
|
String url = "" ,queryString = "";
|
if (informationDetailEntity.getLink() != null && ! "".equals(informationDetailEntity.getLink())) {
|
String urlLink = informationDetailEntity.getLink(isMoblieBrowser) ;
|
String flag = urlLink.indexOf("?") >= 0 ?"&":"?" ;
|
|
url = (!urlLink.toLowerCase().trim().startsWith("http://")&&!urlLink.toLowerCase().trim().startsWith("https://")? hostUrl:"") + urlLink + (wxQueryString == null||"".equals(wxQueryString)?"":flag + wxQueryString) ;
|
}
|
|
String imgUrl = imgData.getImageUrl(informationDetailEntity.getImage(),settingEntity.getImageBannerWidth(),settingEntity.getImageBannerHeight(),settingEntity.isShowBannerOrgImage(),settingEntity.isFromCached(),request) ;
|
jsonObject.addProperty("url", url==null?"":url);
|
jsonObject.addProperty("imgUrl", imgUrl);
|
|
//拼接小程序文件路径
|
if (informationDetailEntity.getLink()!=null&&!"".equals(informationDetailEntity.getLink())) {
|
int pos = informationDetailEntity.getLink().indexOf("?") ;
|
if (pos >= 0) {
|
queryString = informationDetailEntity.getLink().substring(pos+1);
|
}
|
}
|
String pathUrl = informationDetailEntity.getPathUrl() ;
|
if (pathUrl!=null&&!"".equals(pathUrl) && queryString!=null && !"".equals(queryString)) {
|
pathUrl += (pathUrl.indexOf("?")<0 ? "?":"&") + queryString ;
|
}
|
|
if ((pathUrl == null || "".equals(pathUrl)) && informationDetailEntity.getLink() !=null && !"".equals(informationDetailEntity.getLink())) {
|
if (informationDetailEntity.getLink().startsWith("http://") || informationDetailEntity.getLink().startsWith("https://")) {
|
pathUrl = informationDetailEntity.getLink() ;
|
}
|
}
|
|
jsonObject.addProperty("pathcode", informationDetailEntity.getPathCode());
|
jsonObject.addProperty("pathurl", pathUrl); //小程序路径
|
jsonObject.addProperty("isTabBarButton", informationDetailEntity.isTabBarButton());
|
return jsonObject;
|
}
|
|
@RequestMapping(params = "m=saveenquiry")
|
public void saveEnquiry(HttpServletRequest request,HttpServletResponse response) {
|
//HttpSession session=request.getSession();
|
//String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
|
|
String hostUrl = SettingKey.getHostUrl(request) ;
|
//将微信corpid组装成url
|
String wxQueryString = SettingKey.getQueryStringByWx(request);
|
boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
|
|
String cltCode = request.getParameter("cltcode");
|
String cltName = request.getParameter("cltname");
|
String telephone = request.getParameter("telephone");
|
String email = request.getParameter("email");
|
String enquiry = request.getParameter("enquiry") ;
|
|
JsonObject json = new JsonObject() ;
|
JsonObject errJson = new JsonObject() ;
|
if (cltName== null || "".equals(cltName) || cltName.length()<2 ) {
|
errJson.addProperty("cltname", "名字应在 3 至 32 个字符之间!");
|
}
|
if (telephone== null || "".equals(telephone) || telephone.length()<11 ) {
|
errJson.addProperty("telephone", "电话应在 11 至 32 个字符之间!");
|
}
|
if (enquiry== null || "".equals(enquiry) || enquiry.length()<10 ) {
|
errJson.addProperty("enquiry", "咨询内容长度应在 10 至 3000 个字符之间!");
|
}
|
|
Set<Entry<String, JsonElement>> it = errJson.entrySet();
|
if (! it.isEmpty() && it.size() != 0) {
|
//{"error":{"firstname":"\u540d\u5b57\u5fc5\u987b\u5728 1 \u81f3 32 \u5b57\u7b26\u4e4b\u95f4\uff01","lastname":"\u59d3\u6c0f\u5fc5\u987b\u5728 1 \u81f3 32 \u5b57\u7b26\u4e4b\u95f4\uff01","email":"\u65e0\u6548\u7684\u90ae\u7bb1\u5730\u5740\uff01","telephone":"\u7535\u8bdd\u53f7\u7801\u5fc5\u987b\u4e3a 3 \u81f3 32 \u5b57\u8282\uff01","address_1":"\u5730\u5740\u957f\u5ea6\u5fc5\u987b\u5728 3 \u81f3 128 \u5b57\u7b26\u4e4b\u95f4\uff01","city":"\u57ce\u5e02\u540d\u5fc5\u987b\u5728 3 \u81f3 128 \u5b57\u8282\u4e4b\u95f4\uff01","zone":"\u8bf7\u9009\u62e9\u5730\u533a\/\u7701\u4efd\uff01","password":"\u5bc6\u7801\u5fc5\u987b\u5728 3 \u81f3 20 \u5b57\u7b26\u4e4b\u95f4\uff01","warning":"\u8b66\u544a\uff1a\u60a8\u672a\u540c\u610f\u6761\u6b3e Privacy Policy\uff01"}}
|
//errJson.addProperty("warning", "警告:您未同意条款 Privacy Policy!");
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}
|
SettingEntity settingEntity = null ;
|
try {
|
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
|
SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
|
settingEntity = settingIfc.getSettingEntity(request) ;
|
|
//取网店 shopcccode
|
ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
|
|
informationIfc.saveEnquiry(cltCode, cltName, telephone, email, enquiry,shopCcCodeEntity.getShopCcCode());
|
json.addProperty("redirect", hostUrl+"/shopping/" + (isMoblieBrowser?"mobile/":"") + "information/contactsuccess.jsp"+(wxQueryString == null||"".equals(wxQueryString)?"":"?" + wxQueryString));
|
this.printJson(response, json.toString());
|
return ;
|
} catch( DataAccessException e) {
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}catch( Exception e) {
|
errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage():e.getMessage()));
|
json.add("error", errJson);
|
this.printJson(response, json.toString());
|
return ;
|
}finally {
|
SpObserver.setDBtoInstance();
|
}
|
|
|
}
|
|
}
|