博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
品牌接口
阅读量:6080 次
发布时间:2019-06-20

本文共 18325 字,大约阅读时间需要 61 分钟。

package com.j1.mai.action;import java.io.PrintWriter;import java.util.List;import java.util.Map;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.sf.json.JSONArray;import net.sf.json.JSONObject;import org.apache.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Scope;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import com.alibaba.fastjson.JSON;import com.j1.base.dto.ServiceMessage;import com.j1.base.page.Page;import com.j1.base.type.MsgStatus;import com.j1.item.dto.ProductBrandSearchParam;import com.j1.item.model.BrandMarketGoods;import com.j1.item.model.BrandStreet;import com.j1.item.model.BrandStreetItem;import com.j1.item.model.ProductBrand;import com.j1.mai.dto.Response;import com.j1.mai.dto.base.CarefulBrandCategory;import com.j1.mai.dto.rsp.AllBrandStreetResponse;import com.j1.mai.dto.rsp.CarefulSelectBrandsResponse;import com.j1.mai.model.common.JsonResult;import com.j1.mai.model.common.SoaApiBaseAction;import com.j1.mai.util.ArrayUtil;import com.j1.mai.util.BeanTransUtil;import com.j1.mai.util.NumericUtil;import com.j1.mai.util.StringUtil;import com.j1.soa.common.ResultMsg;import com.j1.soa.resource.item.api.BrandMarketGoodsService;import com.j1.soa.resource.item.api.BrandStreetItemService;import com.j1.soa.resource.item.api.BrandStreetService;import com.j1.soa.resource.item.api.ProductBrandSearchService;import com.j1.soa.resource.item.api.ProductBrandService;/** * 品牌相关接口 *  * @author jiucaizi * @since 3.5 */@Controller@Scope("request")@RequestMapping("/brand")public class BrandThemesAction extends SoaApiBaseAction {    static Logger LOG = Logger.getLogger(BrandThemesAction.class);        public final static String BRANDS = "brandList";    public final static String ITEMS = "itemList";        public final static String ALLITEM = "allBrand";    @Autowired    private BrandStreetItemService brandStreetItemService;    @Autowired    private BrandStreetService brandStreetService;        @Autowired    private ProductBrandService productBrandService;        @Autowired    private BrandMarketGoodsService  brandMarketGoodsService;    @Autowired    private ProductBrandSearchService productBrandSearchService;            /**     *  精品街列表 (for h5 ,数据放入data下)     *  1 查询品牌街列表     *  2品牌街列表查询单个品牌街信息     *  3组装结果返回     */    @RequestMapping("/listH5")    public void list2(HttpServletRequest request, HttpServletResponse response,            final @RequestParam(value = "id", required = false) String id) {        BrandStreet brand = new BrandStreet();        /* 客户端(web/wap/app) */        brand.setClient("app");        ServiceMessage
> brandList = null; CarefulSelectBrandsResponse res = new CarefulSelectBrandsResponse(); try { brandList = brandStreetService.getBrandStreetByMul(brand); } catch (Exception e) { LOG.error("brandStreetService.getBrandStreetByMul:" + e); } finally { if(ArrayUtil.resultIsEmp(brandList)) { this.setResultInfo(MsgStatus.NO_RESULT.getCode(), ResultMsg.Common.QUERY_FAILURE).write(request, response); /*writeResponse(request, response, res.setStatus(3).setMsg(ResultMsg.Common.QUERY_FAILURE));*/ return; } else { BeanTransUtil.mapping(brandList,res); /*this._result.put(BRANDS, brandList.getResult());*/ } } int selectID = NumericUtil.parseInt(id, 0); if(selectID != 0) { //逻辑修改为 0值不查询下一级 /*selectStreet = ArrayUtil.findFirstFromList(brandList.getResult()); selectID = selectStreet.getId();*/ //选取品牌街ID BrandStreetItem item = new BrandStreetItem(); item.setBrandStreetId(selectID); LOG.info("setBrandStreetId:" + selectID); /*item.setIsRecomment("Y");*///设置是否推荐(Y/N,为空表示查询全部) item.setIsMarketGoods("Y"); //是否查询品牌推荐商品(Y/N) ServiceMessage
> itemList = null; try { itemList = brandStreetItemService.getBrandStreetItemByStreetId(item); } catch (Exception e) { LOG.error("brandStreetItemService.getBrandStreetItemByStreetId:" + e); } finally { if(ArrayUtil.resultIsEmp(itemList)) { LOG.info("itemList: emp"); /*this._result.put(ITEMS, new JSONArray());*/ } else { LOG.info("itemList: "+ itemList.getResult()); //选取 CarefulBrandCategory care = res.getById(selectID); if(care == null) { LOG.info("select CarefulBrandCategory:null"); } else { BeanTransUtil.mapping(itemList,care); } /*this._result.put(ITEMS, itemList.getResult());*/ } } } this._result.setObjData(JSON.toJSONString(res)); /*this._result.setObjData(res);*/ /*writeResponse(request, response, res.setStatus(0).setMsg(ResultMsg.Common.OK));*/ this.setResultInfo(MsgStatus.NORMAL.getCode(), ResultMsg.Common.OK) .write(request, response); } /** * * 1 查询品牌街列表 * 2品牌街列表查询单个品牌街信息 * 3组装结果返回 */ @RequestMapping("/list") public void list(HttpServletRequest request, HttpServletResponse response, final @RequestParam(value = "id", required = false) String id) { BrandStreet brand = new BrandStreet(); /* 客户端(web/wap/app) */ brand.setClient("app"); ServiceMessage
> brandList = null; CarefulSelectBrandsResponse res = new CarefulSelectBrandsResponse(); try { brandList = brandStreetService.getBrandStreetByMul(brand); } catch (Exception e) { LOG.error("brandStreetService.getBrandStreetByMul:" + e); } finally { if(ArrayUtil.resultIsEmp(brandList)) { /*this.setResultInfo(MsgStatus.NO_RESULT.getCode(), ResultMsg.Common.QUERY_FAILURE).write(request, response);*/ writeResponse(request, response, res.setStatus(3).setMsg(ResultMsg.Common.QUERY_FAILURE)); return; } else { BeanTransUtil.mapping(brandList,res); /*this._result.put(BRANDS, brandList.getResult());*/ } } int selectID = NumericUtil.parseInt(id, 0); if(selectID != 0) { //逻辑修改为 0值不查询下一级 /*selectStreet = ArrayUtil.findFirstFromList(brandList.getResult()); selectID = selectStreet.getId();*/ //选取品牌街ID BrandStreetItem item = new BrandStreetItem(); item.setBrandStreetId(selectID); LOG.info("setBrandStreetId:" + selectID); /*item.setIsRecomment("Y");*///设置是否推荐(Y/N,为空表示查询全部) item.setIsMarketGoods("Y"); //是否查询品牌推荐商品(Y/N) ServiceMessage
> itemList = null; try { itemList = brandStreetItemService.getBrandStreetItemByStreetId(item); } catch (Exception e) { LOG.error("brandStreetItemService.getBrandStreetItemByStreetId:" + e); } finally { if(ArrayUtil.resultIsEmp(itemList)) { LOG.info("itemList: emp"); /*this._result.put(ITEMS, new JSONArray());*/ } else { LOG.info("itemList: "+ itemList.getResult()); //选取 CarefulBrandCategory care = res.getById(selectID); if(care == null) { LOG.info("select CarefulBrandCategory:null"); } else { BeanTransUtil.mapping(itemList,care); } /*this._result.put(ITEMS, itemList.getResult());*/ } } } writeResponse(request, response, res.setStatus(0).setMsg(ResultMsg.Common.OK)); /*this.setResultInfo(MsgStatus.NORMAL.getCode(), ResultMsg.Common.OK) .write(request, response);*/ } /** * * @date 2016年6月15日 下午2:10:14 * @Title: listBrandStreet * @Description:app 3.7.3重新定义json返回 * 1 查询品牌街列表 * 2品牌街列表查询单个品牌街信息 * 3组装结果返回 * @param request * @param response * @param id * @throws */ @RequestMapping("/listBrandStreet") public void listBrandStreet(HttpServletRequest request, HttpServletResponse response, final @RequestParam(value = "id", required = false) String id) { BrandStreet brand = new BrandStreet(); /* 客户端(web/wap/app) */ brand.setClient("app"); try { /*获取品牌街主数据*/ ServiceMessage
> brandListResult = null; CarefulSelectBrandsResponse res = new CarefulSelectBrandsResponse(); brandListResult = brandStreetService.getBrandStreetByMul(brand); if (brandListResult.getStatus() != MsgStatus.NORMAL) { logger.error("getBrandStreetByMul:" + brandListResult.getStatus().getCode() + ":" + brandListResult.getMessage()); this.setResultInfo(brandListResult.getStatus().getCode(), brandListResult.getMessage()); return; } _result.put("brandList", brandListResult.getResult()); int selectID = NumericUtil.parseInt(id, 0); if(selectID != 0) { //逻辑修改为 0值不查询下一级 /*selectStreet = ArrayUtil.findFirstFromList(brandList.getResult()); selectID = selectStreet.getId();*/ //选取品牌街ID BrandStreetItem item = new BrandStreetItem(); item.setBrandStreetId(selectID); LOG.info("setBrandStreetId:" + selectID); item.setIsRecomment("Y");///设置是否推荐(Y/N,为空表示查询全部) item.setIsMarketGoods("N"); //是否查询品牌推荐商品(Y/N) ServiceMessage
> itemListResult = brandStreetItemService.getBrandStreetItemByStreetId(item); if (itemListResult.getStatus() != MsgStatus.NORMAL) { logger.error("getBrandStreetItemByStreetId:" + itemListResult.getStatus().getCode() + ":" + itemListResult.getMessage()); this.setResultInfo(itemListResult.getStatus().getCode(), itemListResult.getMessage()); return; } _result.put("brandStreetItem", itemListResult.getResult()); } } catch (Exception e) { LOG.error(e.getMessage(), e); setResultInfo(MsgStatus.EXCEPTION.getCode(),"品牌街查询数据失败"); } finally { write(request, response); } } /** * 查询品牌列表,含分页 * @Title: findAllByPage * @Description: 根据查询条件分页查询(条件:拼音码,品牌街名称,页数,每页数量) * @param @param request * @param @param response * @param @param pinYin * @param @param brandName * @param @param pnum * @param @param psize 设定文件 * @return void 返回类型 * @throws *//* @RequestMapping("/all2") public void listByPage(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "pinYin", required = false) String pinYin, //品牌首字母拼音码 @RequestParam(value = "brandName", required = false) String brandName,//品牌名称(模糊查询) @RequestParam(value = "pnum", required = false) String pnum, @RequestParam(value = "psize", required = false) String psize) { ProductBrand productBrand = new ProductBrand(); if(!StringUtil.isEmpty(pinYin)) { productBrand.setPin(StringUtil.getTrimString(pinYin)); } if(!StringUtil.isEmpty(brandName)) { productBrand.setProductBrandName(StringUtil.getTrimString(brandName)); } ServiceMessage
> allBrand = null; try { allBrand = productBrandService.pageProductBrand( productBrand, NumericUtil.parseInt(pnum, 1), NumericUtil.parseInt(psize, 500)); } catch (Exception e) { LOG.error("approveGoodsService.findAllByPage:" + e); this.setResultInfo(MsgStatus.EXCEPTION.getCode(), ResultMsg.Common.QUERY_FAILURE) .write(request, response); return; } finally { LOG.debug("approveSortService.findAllByPage:" + allBrand.getStatus()); if(ArrayUtil.resultIsEmpWithPage(allBrand)) { this._result.put("allBrand", new JSONArray()); this._result.put("totalPage", 0); this._result.put("pinYin", StringUtil.getTrimString(pinYin)); this._result.put("brandName", StringUtil.getTrimString(brandName)); this._result.put("psize", NumericUtil.parseInt(psize, 50)); this._result.put("pnum", NumericUtil.parseInt(pnum, 1)); this.setResultInfo(MsgStatus.NO_RESULT.getCode(), ResultMsg.Common.QUERY_FAILURE) .write(request, response); } else { this._result.put("allBrand", allBrand.getResult().getData()); this._result.put("totalPage", allBrand.getResult().getTotalPage()); this._result.put("pinYin", StringUtil.getTrimString(pinYin)); this._result.put("brandName", StringUtil.getTrimString(brandName)); this._result.put("pnum", NumericUtil.parseInt(pnum, 1)); this._result.put("psize", NumericUtil.parseInt(psize, 50)); this.setResultInfo(MsgStatus.NORMAL.getCode(), ResultMsg.Common.OK) .write(request, response); } } } */ /** * 查询品牌列表 * @Title: all * @Description: 查询所有品牌列表(for h5 ,数据放入data下) * @param @param request * @param @param response * @return void 返回类型 品牌列表 */ @RequestMapping("/allH5") public void all2(HttpServletRequest request, HttpServletResponse response) { ProductBrand productBrand = new ProductBrand(); ServiceMessage
> allBrand = null; AllBrandStreetResponse res = new AllBrandStreetResponse(); try { allBrand = productBrandService.pageProductBrand( productBrand,1, 2000); } catch (Exception e) { LOG.error("approveGoodsService.pageProductBrand:" + e); this.setResultInfo(MsgStatus.EXCEPTION.getCode(), ResultMsg.Common.QUERY_FAILURE).write(request, response); /*writeResponse(request, response, res.setStatus(1).setMsg(ResultMsg.Common.QUERY_FAILURE));*/ return; } finally { if(ArrayUtil.resultIsEmpWithPage(allBrand)) { /*writeResponse(request, response, res.setStatus(3).setMsg(ResultMsg.Common.QUERY_FAILURE));*/ this.setResultInfo(MsgStatus.NO_RESULT.getCode(), ResultMsg.Common.QUERY_FAILURE).write(request, response); return; } else { List
brandList = allBrand.getResult().getData(); for(ProductBrand p: brandList) { res.addProductBrand(p); } res.sort(); this._result.setObjData(res); this.setResultInfo(MsgStatus.NORMAL.getCode(), ResultMsg.Common.OK).write(request, response); /*writeResponse(request, response, res.setStatus(0).setMsg(ResultMsg.Common.OK));*/ } } } /** * 查询品牌列表 * @Title: all * @Description: 查询所有品牌列表 * @param @param request * @param @param response * @return void 返回类型 品牌列表 */ @RequestMapping("/all") public void all(HttpServletRequest request, HttpServletResponse response) { ProductBrand productBrand = new ProductBrand(); ServiceMessage
> allBrand = null; AllBrandStreetResponse res = new AllBrandStreetResponse(); try { allBrand = productBrandService.pageProductBrand( productBrand,1, 2000); } catch (Exception e) { LOG.error("approveGoodsService.pageProductBrand:" + e); writeResponse(request, response, res.setStatus(1).setMsg(ResultMsg.Common.QUERY_FAILURE)); return; } finally { if(ArrayUtil.resultIsEmpWithPage(allBrand)) { writeResponse(request, response, res.setStatus(3).setMsg(ResultMsg.Common.QUERY_FAILURE)); return; } else { List
brandList = allBrand.getResult().getData(); for(ProductBrand p: brandList) { res.addProductBrand(p); } res.sort(); writeResponse(request, response, res.setStatus(0).setMsg(ResultMsg.Common.OK)); } } } /** * * @Title: findByProductBrandId * @Description: 根据品牌ID查询品牌信息,推荐商品列表 * @param @param request * @param @param response * @param @param id 品牌ID * @param @param pnum 页数 * @param @param psize 每页条数 * @param @param sort 商品排序(AllSort 0, SaleSort 1, low2High 2, high2Low 3, 4其它) * @return void 返回类型 * @throws */ @RequestMapping("/findProductBrand") public void findByProductBrandId(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "id", required = false) String id, @RequestParam(value = "pnum", required = false) String pnum, @RequestParam(value = "psize", required = false) String psize, @RequestParam(value = "sort", required = false) String sort) { _result.put("pnum", NumericUtil.parseInt(pnum, 1)); try { ServiceMessage
message = productBrandService .getProductBrandByBrandId(NumericUtil.parseInt(id, 1)); _result.put( "productBrand", message.getResult() == null ? new JSONObject() : JSONObject .fromObject(message.getResult())); } catch (Exception e) { LOG.error("productBrandService.getProductBrandById获取失败,异常信息:" + e); _result.put("productBrand", new JSONObject()); } try { BrandMarketGoods item = new BrandMarketGoods(); item.setProductBrandId(NumericUtil.parseInt(id, 1)); // 设置查询品牌街ID ServiceMessage
> sm = brandMarketGoodsService .getBrandGoodsByBrandId(item); _result.put( "brandMarketGoodsList", ArrayUtil.resultIsEmp(sm) ? new JSONArray() : JSONArray .fromObject(sm.getResult())); } catch (Exception e) { LOG.error("brandMarketGoodsService.getBrandGoodsByBrandId获取失败,异常信息:" + e); _result.put("brandMarketGoodsList", new JSONArray()); } try { ProductBrandSearchParam param = new ProductBrandSearchParam(); /* 页数 */ param.setPageNum(NumericUtil.parseInt(pnum, 1)); /* 每页条数 */ param.setPageSize(NumericUtil.parseInt(psize, 20)); /* 品牌ID */ param.setProductBrandId(NumericUtil.parseInt(id, 1)); setSort(param, sort); ServiceMessage
> result = productBrandSearchService .pageBrandGoodsList(param); int totalPage = result.getResult().getTotalPage(); _result.put("totalPage", totalPage); _result.put("brandGoodsList", JSONArray.fromObject(result.getResult().getData())); } catch (Exception e) { LOG.error("productBrandSearchService.pageBrandGoodsList获取失败,异常信息:" + e); _result.put("totalPage", 1); _result.put("brandGoodsList", new JSONArray()); } setResultInfo(MsgStatus.NORMAL.getCode(), "查询成功").write(request, response); } /** * * @Title: setSort * @Description: 设置排序 * @param @param param * @param @param sort 设定文件 * @return void 返回类型 * @throws */ private void setSort(final ProductBrandSearchParam param, final String sort) { //商品排序(AllSort 0, SaleSort 1, low2High 2, high2Low 3, 4其它) int sortNum = NumericUtil.parseInt(sort, 0); int[] rights = {-1,//综合 0, //销售量降序 3, //价格降序 2, //价格升序 -1 //其他 }; int selectSort = -1; if(sortNum < rights.length && sortNum >=0) { selectSort = rights[sortNum]; } if(selectSort >=0) { param.setOrderBy("" + selectSort); } else { param.setOrderBy(null); } /*for(int i: rights) { if(sortNum == i) { param.setOrderBy("" + i); return; } }*/ // orderBy =='0' 销售量降序 // orderBy =='1' 销售量升序 // orderBy =='2' 价格降序 // orderBy =='3' 价格升序 // orderBy =='4' 评论降序 // orderBy =='5' 评论升序 // orderBy =='6' 时间降序 // orderBy =='7' 时间升序 } /** * * @Title: writeResponse * @Description: 通过fastJson方式把返回数据转换Json并写入resp * @param @param request * @param @param response * @param @param res 写入数据 * @return void 返回类型 */ public void writeResponse(HttpServletRequest request, HttpServletResponse response, Response res) { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); String callback = request.getParameter("callback"); String result = null; PrintWriter writer = null; try { writer = response.getWriter(); result = JSON.toJSONString(res); if (!StringUtil.isEmpty(callback)) { result = callback + "(" + result + ")"; } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (writer != null) { writer.write(result); writer.close(); } if (result != null) _result = new JsonResult(); } } }

 

转载地址:http://ryhgx.baihongyu.com/

你可能感兴趣的文章
跟小静读CLR via C#(17)--接口
查看>>
C#WinForm应用程序实现自动填充网页上的用户名和密码并点击登录按钮
查看>>
[Z]一个轻松制作和处理矢量图的工具和方法
查看>>
PetaPoco的默认映射
查看>>
POJ 基本算法(3)
查看>>
最小生成树两个重要的算法:Prim 和 Kruskal
查看>>
SQL SERVER 中常见的高可用方案
查看>>
PHP 反射 初步测试
查看>>
安装MySQLdb-python时无法找到-lprobes_mysql处理一则
查看>>
对计算机模拟人脑的一个小想法
查看>>
CI分页器pagination的原理及实现
查看>>
The Rox Java NIO Tutorial
查看>>
如何选择婴幼儿奶粉?
查看>>
MySQL global Log
查看>>
BZOJ3564 : [SHOI2014]信号增幅仪
查看>>
发布流程考虑
查看>>
Openvswitch手册(1): 架构,SSL, Manager, Bridge
查看>>
EditText中文文档
查看>>
文本比较算法:Needleman/Wunsch算法
查看>>
c++文件读写操作
查看>>