package org.cs.mgr.product.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.cs.core.model.Dic;
import org.cs.core.service.IDicService;
import org.cs.core.service.impl.BaseService;
import org.cs.mgr.admin.dao.IDCProjectDao;
import org.cs.mgr.admin.model.DCProject;
import org.cs.mgr.product.dao.IMgmProductCategoryDao;
import org.cs.mgr.product.dao.IMgmProductDao;
import org.cs.mgr.product.dao.IMgmProductViewDao;
import org.cs.mgr.product.model.MgmProduct;
import org.cs.mgr.product.model.MgmProductCategory;
import org.cs.mgr.product.model.MgmProductView;
import org.cs.mgr.product.service.IMgmProductService;
import org.cs.util.Pager;
import org.cs.util.StringUtil;
import org.cs.util.XMLUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;

/**
 * 
 * @ClassName: IMgmProductService
 * @Description:  
 * @author: sunny_shi
 * @date: 2018-06-09 13:29:09
 */
@Service("mgmProductService")
public class MgmProductService extends BaseService<MgmProduct> implements IMgmProductService{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private IMgmProductDao mgmProductDao;
	@Autowired
	private IMgmProductViewDao mgmProductViewDao;
	
	@Autowired
	private IMgmProductCategoryDao mgmProductCategoryDao;
	@Autowired
	private IDCProjectDao dcprojectDao;
	@Autowired
	private IDicService dicService;
	
	@Override
	@Transactional(readOnly = true)
	public Pager getMgmProducts(Pager page){
		return this.mgmProductDao.queryMgmProducts(page);
	}
	
	
	@Override
	@Transactional(readOnly = true)
	public Pager getMgmProducts(Pager page, Map<String, String> map){
		return this.mgmProductDao.queryMgmProducts(page, map);
	}
	/**
	 * 自动生成
	 * @Title: delMgmProduct 
	 * @Description: TODO
	 * @param id						主键id
	 * @return
	 * @return: boolean
	 */
	@Override
	@Transactional(readOnly = false)
	public boolean delMgmProduct(Integer id){
	
		MgmProduct mgmProduct = this.mgmProductDao.findById(id);
		if(mgmProduct != null){
			mgmProduct.setIsDelete(true);				
			this.mgmProductDao.update(mgmProduct);
		}
		return true;
	}
	
	
	/**
	 * 自动生成
	 * @Title: addMgmProduct 
	 * @Description: TODO
	 * @param mgmProduct						对象retu
	 * @return
	 * @return: boolean
	 */
	@Override
	@Transactional(readOnly = false)
	public String addMgmProduct(MgmProduct mgmProduct){
	
		/*String reg = "^[0-9]+(.[0-9]+)?$";
		if(!mgmProduct.getCommissionRate().matches(reg)){
			return "{\"code\":500,\"data\":\"佣金比率请输入正确的数字\"}";
		}*/
		
		mgmProduct.setProductAttr(XMLUtil.getNewContent(mgmProduct.getProductAttr()));
		mgmProduct.setProductBody(XMLUtil.getNewContent(mgmProduct.getProductBody()));
		mgmProduct.setPolicy(XMLUtil.getNewContent(mgmProduct.getPolicy()));


		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", mgmProduct.getProductName());
		List<?> mpold = this.mgmProductDao.findByHql("from MgmProduct where productName = :name", params);
		if(mpold != null && !mpold.isEmpty()){
			return "{\"code\":500,\"data\":\"商品已存在\"}";
		}
		
		if(mgmProduct != null){
			mgmProduct.setCreateDate(new Date());
			if(mgmProduct.getGcId() != null && mgmProduct.getGcId().intValue() != 0){
				MgmProductCategory mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcId());
				mgmProduct.setGc(mpc.getGcName());
				if(mgmProduct.getGcParentId() != null && mgmProduct.getGcParentId().intValue() != 0){
					mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcParentId());
					mgmProduct.setGc(mpc.getGcName());
					if(mgmProduct.getGcThreeId() != null && mgmProduct.getGcThreeId().intValue() != 0){
						mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcThreeId());
						mgmProduct.setGc(mpc.getGcName());
						if(mgmProduct.getGcFourId() != null && mgmProduct.getGcFourId().intValue() != 0){
							mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcFourId());
							mgmProduct.setGc(mpc.getGcName());
						}
					}
				}
			}
			mgmProduct.setIsDelete(false);
			mgmProduct.setModifyDate(new Date());
			mgmProduct.setOnsaleTime(new Date());
			mgmProduct.setProductAddtime(new Date());
			if(mgmProduct.getProductGroupImg().indexOf(",") >= 0){
				mgmProduct.setProductGroupImg(mgmProduct.getProductGroupImg().trim().substring(0, mgmProduct.getProductGroupImg().trim().length()-1));
			}
			if(mgmProduct.getProductImg().indexOf(",") >= 0){
				mgmProduct.setProductImg(mgmProduct.getProductImg().trim().substring(0, mgmProduct.getProductImg().trim().length()-1));
			}
			mgmProduct.setProductState("1");
			mgmProduct.setProductType(this.mgmProductCategoryDao.findById(mgmProduct.getGcId()).getType());
			if(mgmProduct.getProductType().equals("1")){
				MgmProductCategory mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcParentId());
				if(mpc != null){
					
					DCProject dcproject = this.dcprojectDao.findById(mpc.getProjectId());
					if(dcproject == null) {
						return "{\"code\":500,\"data\":\"所选地产分类没有关联项目\"}";
					}
					mgmProduct.setProvince(dcproject.getProvince());
					mgmProduct.setProvinceCode(dcproject.getProvinceCode());
					mgmProduct.setCity(dcproject.getCity());
					mgmProduct.setCityCode(dcproject.getCityCode());
					mgmProduct.setGc(mgmProduct.getXmType());
				}else {
					return "{\"code\":500,\"data\":\"请选择对应的分类\"}";
				}
			}
//			mgmProduct.set
			if(StringUtil.isNotBlank(mgmProduct.getXmCode()) && "1".equals(mgmProduct.getProductType())){
				Dic dic = this.dicService.getByTypeAndCode("xm", mgmProduct.getXmCode());
				mgmProduct.setXmType(dic.getName());
				mgmProduct.setGc(dic.getName());
			}
			this.mgmProductDao.insert(mgmProduct);
		}
		return "{\"code\":200,\"data\":\"\"}";
	}
	
	
	/**
	 *  自动生成
	 * @Title: updateMgmProduct 
	 * @Description: TODO
	 * @param mgmProduct2						对象
	 * @return
	 * @return: boolean
	 */
	@Override
	@Transactional(readOnly = false)
	public String updateMgmProduct(MgmProduct mgmProduct2){
	
		/*String reg = "^[0-9]+(.[0-9]+)?$";
		if(!mgmProduct.getCommissionRate().matches(reg)){
			return "{\"code\":500,\"data\":\"佣金比率请输入正确的数字\"}";
		}*/
		
		mgmProduct2.setProductAttr(XMLUtil.getNewContent(mgmProduct2.getProductAttr()));
		mgmProduct2.setProductBody(XMLUtil.getNewContent(mgmProduct2.getProductBody()));
		mgmProduct2.setPolicy(XMLUtil.getNewContent(mgmProduct2.getPolicy()));


		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", mgmProduct2.getProductName());
		params.put("id", mgmProduct2.getId());
		List<?> mpold = this.mgmProductDao.findByHql("from MgmProduct where productName = :name and id != :id", params);
		if(mpold != null && !mpold.isEmpty()){
			return "{\"code\":500,\"data\":\"商品已存在\"}";
		}
		
		MgmProduct mgmProduct = this.mgmProductDao.findById(mgmProduct2.getId());
		if(mgmProduct != null){
			mgmProduct.setProductName(mgmProduct2.getProductName());
			mgmProduct.setProductModel(mgmProduct2.getProductModel());
			mgmProduct.setProductRemark(mgmProduct2.getProductRemark());
			if(mgmProduct2.getGcId()!=null && StringUtil.isNotBlank(mgmProduct2.getGcId().toString())){
				mgmProduct.setGcId(mgmProduct2.getGcId());
			}
			if(mgmProduct2.getGcParentId()!=null && StringUtil.isNotBlank(mgmProduct2.getGcParentId().toString())){
				mgmProduct.setGcParentId(mgmProduct2.getGcParentId());
			}
			if(mgmProduct2.getGcThreeId()!=null &&StringUtil.isNotBlank(mgmProduct2.getGcThreeId().toString())){
				mgmProduct.setGcThreeId(mgmProduct2.getGcThreeId());
			}
			if(mgmProduct2.getGcFourId()!=null && StringUtil.isNotBlank(mgmProduct2.getGcFourId().toString())){
				mgmProduct.setGcFourId(mgmProduct2.getGcFourId());
			}
			mgmProduct.setCommissionRate(mgmProduct2.getCommissionRate());
			mgmProduct.setHotline(mgmProduct2.getHotline());
			mgmProduct.setProductPrice(mgmProduct2.getProductPrice());
			mgmProduct.setUnit(mgmProduct2.getUnit());
			mgmProduct.setWeight(mgmProduct2.getWeight());
			mgmProduct.setIsHome(mgmProduct2.getIsHome());
			mgmProduct.setProductImg(mgmProduct2.getProductImg());
			mgmProduct.setProductGroupImg(mgmProduct2.getProductGroupImg());
			mgmProduct.setProductAttr(mgmProduct2.getProductAttr());
			mgmProduct.setProductBody(mgmProduct2.getProductBody());
			mgmProduct.setPolicy(mgmProduct2.getPolicy());
			mgmProduct.setOpenFlag(mgmProduct2.getOpenFlag());
			
			if(mgmProduct.getGcId() != null && mgmProduct.getGcId().intValue() != 0){
				MgmProductCategory mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcId());
				mgmProduct.setGc(mpc.getGcName());
				if(mgmProduct.getGcParentId() != null && mgmProduct.getGcParentId().intValue() != 0){
					mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcParentId());
					mgmProduct.setGc(mpc.getGcName());
					if(mgmProduct.getGcThreeId() != null && mgmProduct.getGcThreeId().intValue() != 0){
						mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcThreeId());
						mgmProduct.setGc(mpc.getGcName());
						if(mgmProduct.getGcFourId() != null && mgmProduct.getGcFourId().intValue() != 0){
							mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcFourId());
							mgmProduct.setGc(mpc.getGcName());
						}
					}
				}
			}
			mgmProduct.setIsDelete(false);
			mgmProduct.setModifyDate(new Date());
			if(mgmProduct.getProductGroupImg().indexOf(",") >= 0){
				mgmProduct.setProductGroupImg(mgmProduct.getProductGroupImg().trim().substring(0, mgmProduct.getProductGroupImg().trim().length()-1));
			}
			if(mgmProduct.getProductImg().indexOf(",") >= 0){
				mgmProduct.setProductImg(mgmProduct.getProductImg().trim().substring(0, mgmProduct.getProductImg().trim().length()-1));
			}
			mgmProduct.setProductType(this.mgmProductCategoryDao.findById(mgmProduct.getGcId()).getType());
			if(mgmProduct.getProductType().equals("1")){
				MgmProductCategory mpc = this.mgmProductCategoryDao.findById(mgmProduct.getGcParentId());
				if(mpc != null){
					
					DCProject dcproject = this.dcprojectDao.findById(mpc.getProjectId());
					
					mgmProduct.setProvince(dcproject.getProvince());
					mgmProduct.setProvinceCode(dcproject.getProvinceCode());
					mgmProduct.setCity(dcproject.getCity());
					mgmProduct.setCityCode(dcproject.getCityCode());
					mgmProduct.setGc(mgmProduct.getXmType());
				}
			}
//			mgmProduct.set
			if(StringUtil.isNotBlank(mgmProduct.getXmCode()) && "1".equals(mgmProduct.getProductType())){
				Dic dic = this.dicService.getByTypeAndCode("xm", mgmProduct.getXmCode());
				mgmProduct.setXmType(dic.getName());
				mgmProduct.setGc(dic.getName());
			}
			
//			mgmProduct.mergeTo(mgmProduct2);
			this.mgmProductDao.update(mgmProduct);
		}
		
		return "{\"code\":200,\"data\":\"\"}";
	}
	
	@Override
	 public Pager queryProductPager(Pager page, Map<String, String> map){
		 Pager pager = this.mgmProductDao.queryProductPager(page, map);
		 /*for(Object mp:pager.getResults()){
			 MgmProduct m = (MgmProduct) mp;
			 String reg = "^[0-9]+(.[0-9]+)?$";
			 if(m.getCommissionRate().matches(reg)){
				 m.setCommissionRate(m.getCommissionRate()+"%");
			 }
		 }*/
		 return pager;
	 }
	
	@Override
	@Transactional(readOnly = false)
	 public JSONObject queryProductDetail(Map<String, String> map){
		String productid = map.get("productid");
		if(StringUtils.isBlank(productid.trim())) {
			return getJson(0, "", "未获取到产品信息");
		}
		//浏览记录
		String userid = map.get("userid");
		MgmProductView mpv = new MgmProductView();
		mpv.setCreateDate(new Date());
		mpv.setIsDelete(false);
		mpv.setModifyDate(new Date());
		mpv.setProductId(Integer.valueOf(productid));
		if(StringUtil.isBlank(userid)){
			mpv.setUserId(0);
		}else{
			mpv.setUserId(Integer.valueOf(userid));
		}
		mpv.setIp(map.get("ip"));
		mpv.setViewTime(new Date());
		mpv = this.mgmProductViewDao.insert(mpv);
		
		MgmProduct mp = this.mgmProductDao.findById(Integer.valueOf(productid));
		if(mp.getViewTotal() != null)
		{
			mp.setViewTotal(mp.getViewTotal() + 1);
			mp = this.mgmProductDao.update(mp);
		}else {
			mp.setViewTotal(1);
			mp = this.mgmProductDao.update(mp);
		}
		 Map<String, Object> mpro = this.mgmProductDao.queryProductDetail(map);
		 /*String reg = "^[0-9]+(.[0-9]+)?$";
		if( mpro.get("commissionRate").toString().matches(reg)){
			mpro.put("commissionRate", mpro.get("commissionRate") + "%");
		}*/
		return getJson(1, mpro, "success");
	 }
	
	@Override
	public JSONObject categoryProduct( Map<String, String> data1){
		
		String categoryid = data1.get("categoryid");
		String num = data1.get("num");
		String type = data1.get("type");
		String ismore = data1.get("ismore");
		String page = data1.get("page");
		String pageSize = data1.get("pageSize");
		String userType = data1.get("userType");
		if(StringUtil.isBlank(pageSize)){
			pageSize = "10";
		}
		
		JSONObject json = new JSONObject();
		//分类
		List<Map<String, String>> clist = new ArrayList<>();
		//商品分类集合
		List<Map<String, Object>> productlist = new ArrayList<>();
		Map<String, String> map = new HashMap<>();
		//1 下一页（更多页面）
		if("1".equals(ismore)){
			
			if("xm".equals(categoryid)){
				//更多页面 地产的二级分类页面
				List<Dic> dlist = dicService.getByType(categoryid);
				for(Dic dic: dlist){
					map = new HashMap<>();
					map.put("name", dic.getName());
					map.put("type", "1");
					map.put("num", "1");
					map.put("twotype", "");
					map.put("id", dic.getCode());
					clist.add(map);
				}
				
				Map<String, Object> cate = new HashMap<>();
				cate.put("name", dlist.get(0).getName());
				cate.put("type", "1");
				cate.put("num", "1");
				cate.put("twotype", "");
				cate.put("id", dlist.get(0).getCode().toString());
				
				Map<String, String> maps = new HashMap<>();
				maps.put("type", "1");
				maps.put("num", "1");
				maps.put("categoryid", dlist.get(0).getCode().toString());
				maps.put("cityCode", data1.get("cityCode"));
				maps.put("city", data1.get("city"));
				maps.put("userType", data1.get("userType"));
				if(StringUtil.isBlank(page)){
					cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
				}else{
					cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
				}
				productlist.add(cate);//商品分类集合
				json.put("pager", productlist);
				
			}else{
				//更多页面 非地产的2级和三级页面
				Map<String, String> map1 = new HashMap<>();
				map1.put("id", categoryid);
				List<MgmProductCategory> mlist = this.mgmProductCategoryDao.queryShowCategory(map1);
				for(MgmProductCategory mpc:mlist){
					map = new HashMap<>();
					map.put("name", mpc.getGcName());
					map.put("type", mpc.getType());
					map.put("num", mpc.getNum().toString());
					map.put("twotype", mpc.getTwoType());
					map.put("id", mpc.getId().toString());
					clist.add(map);
				}
				
				if(mlist.isEmpty()){
					Map<String, Object> cate = new HashMap<>();
					productlist.add(cate);//商品分类集合
					json.put("pager", productlist);
				}else{
					
					if("3".equals(mlist.get(0).getTwoType()) && 2 == mlist.get(0).getNum().intValue()){//汽车类别2级，结构不同
						Map<String, String> map2 = new HashMap<>();
						map2.put("id", mlist.get(0).getId().toString());
						List<MgmProductCategory> mplist = this.mgmProductCategoryDao.queryShowCategory(map2);
						for(MgmProductCategory mpc:mplist){
							Map<String, Object> cate = new HashMap<>();
							cate.put("name", mpc.getGcName());
							cate.put("type", mpc.getType());
							cate.put("num", mpc.getNum().toString());
							cate.put("twotype", mpc.getTwoType());
							cate.put("id", mpc.getId().toString());
							
							Map<String, String> maps = new HashMap<>();
							maps.put("type", mpc.getType());
							maps.put("num", mpc.getNum().toString());
							maps.put("categoryid", mpc.getId().toString());
							maps.put("cityCode", data1.get("cityCode"));
							maps.put("city", data1.get("city"));
							maps.put("userType", data1.get("userType"));
							if(StringUtil.isBlank(page)){
								cate.put("pager", queryProductPager(new Pager(1,3), maps));
							}else{
								cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page),3), maps));
							}
							productlist.add(cate);//商品分类集合
						}
						json.put("pager", productlist);
					}else{//非汽车2级和3级页面
						Map<String, Object> cate = new HashMap<>();
						cate.put("name", mlist.get(0).getGcName());
						cate.put("type", mlist.get(0).getType());
						cate.put("num", mlist.get(0).getNum().toString());
						cate.put("twotype", mlist.get(0).getTwoType());
						cate.put("id", mlist.get(0).getId().toString());
						
						Map<String, String> maps = new HashMap<>();
						maps.put("type", mlist.get(0).getType());
						maps.put("num", mlist.get(0).getNum().toString());
						maps.put("categoryid", mlist.get(0).getId().toString());
						maps.put("cityCode", data1.get("cityCode"));
						maps.put("city", data1.get("city"));
						maps.put("userType", data1.get("userType"));
						if(StringUtil.isBlank(page)){
							cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
						}else{
							cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
						}
						productlist.add(cate);//商品分类集合
						json.put("pager", productlist);
					}
				}
			}
			
		}else if("2".equals(ismore)){//首页和更多也当前页面检索
			if(StringUtil.isBlank(categoryid)){//首页内容初始化
				Dic dics = this.dicService.getByTypeAndCode("dcsort", "dcsort");
				type = "1";
				num = "0";
				//首页菜单
				Map<String, String> dcmap = new HashMap<>();
				dcmap.put("name", "地产");
				dcmap.put("type", "1");
				dcmap.put("num", "0");
				dcmap.put("twotype", "");
				dcmap.put("id", "xm");
				if(dics == null || StringUtil.isBlank(dics.getValue())){
					clist.add(dcmap);
				}
				//clist.add(map);
				List<MgmProductCategory> mlist = this.mgmProductCategoryDao.queryShowCategory(new HashMap<String, String>());
				for(int i=0;i<mlist.size();i++){
					MgmProductCategory mpc = mlist.get(i);
					if((i+1 + "").equals(dics.getValue())){
						clist.add(dcmap);
					}
					map = new HashMap<>();
					map.put("name", mpc.getGcName());
					map.put("type", mpc.getType());
					map.put("num", mpc.getNum().toString());
					map.put("twotype", mpc.getTwoType());
					map.put("id", mpc.getId().toString());
					clist.add(map);
				}
				
				Map<String, Object> cate = new HashMap<>();
				cate.put("name", clist.get(0).get("name"));
				cate.put("type", clist.get(0).get("type"));
				cate.put("num", clist.get(0).get("num"));
				cate.put("twotype", clist.get(0).get("twotype"));
				cate.put("id", clist.get(0).get("id"));
				
				Map<String, String> maps = new HashMap<>();
				maps.put("type", clist.get(0).get("type"));
				maps.put("num", clist.get(0).get("num"));
				maps.put("categoryid", clist.get(0).get("id"));
				maps.put("cityCode", data1.get("cityCode"));
				maps.put("city", data1.get("city"));
				maps.put("isHome", "1");
				maps.put("userType", data1.get("userType"));
				if(StringUtil.isBlank(page)){
					cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
				}else{
					cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
				}
				productlist.add(cate);//商品分类集合
				json.put("pager", productlist);
				
			}else if("xm".equals(categoryid)){//首页地产当前页检索，从其他分类点地产分类
				Map<String, Object> cate = new HashMap<>();
				cate.put("name", "地产");
				cate.put("type", type);
				cate.put("num", num);
				cate.put("twotype", "");
				cate.put("id", categoryid);
				
				Map<String, String> maps = new HashMap<>();
				maps.put("type",type );
				maps.put("num", num);
				maps.put("categoryid", categoryid);
				maps.put("cityCode", data1.get("cityCode"));
				maps.put("city", data1.get("city"));
				maps.put("isHome", "1");
				maps.put("userType", data1.get("userType"));
				if(StringUtil.isBlank(page)){
					cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
				}else{
					cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
				}
				productlist.add(cate);//商品分类集合
				json.put("pager", productlist);
				
			}else{//非首页当前页检索
				MgmProductCategory mpc = this.mgmProductCategoryDao.findById(Integer.valueOf(categoryid));
				Dic dic = this.dicService.getByTypeAndCode("xm", categoryid);
				if("1".equals(type)){//地产2级页面当前页
					Map<String, Object> cate = new HashMap<>();
					cate.put("name", dic.getName());
					cate.put("type", type);
					cate.put("num", num);
					cate.put("twotype", "");
					cate.put("id", categoryid);
					
					Map<String, String> maps = new HashMap<>();
					maps.put("type",type );
					maps.put("num", num);
					maps.put("categoryid", categoryid);
					maps.put("cityCode", data1.get("cityCode"));
					maps.put("city", data1.get("city"));
					maps.put("userType", data1.get("userType"));
					if(StringUtil.isBlank(page)){
						cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
					}else{
						cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
					}
					productlist.add(cate);//商品分类集合
					json.put("pager", productlist);
				}else
				if("3".equals(mpc.getTwoType()) && mpc.getNum().intValue() == 2){//非地产当前页面检索
					Map<String, String> map2 = new HashMap<>();
					map2.put("id", categoryid);
					List<MgmProductCategory> mplist = this.mgmProductCategoryDao.queryShowCategory(map2);
					for(MgmProductCategory mpc1:mplist){
						Map<String, Object> cate = new HashMap<>();
						cate.put("name", mpc1.getGcName());
						cate.put("type", mpc1.getType());
						cate.put("num", mpc1.getNum().toString());
						cate.put("twotype", mpc1.getTwoType());
						cate.put("id", mpc1.getId().toString());
						
						Map<String, String> maps = new HashMap<>();
						maps.put("type", mpc1.getType());
						maps.put("num", mpc1.getNum().toString());
						maps.put("categoryid", mpc1.getId().toString());
						maps.put("cityCode", data1.get("cityCode"));
						maps.put("city", data1.get("city"));
						maps.put("userType", data1.get("userType"));
						if(StringUtil.isBlank(page)){
							cate.put("pager", queryProductPager(new Pager(1,3), maps));
						}else{
							cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page),3), maps));
						}
						productlist.add(cate);//商品分类集合
					}
					json.put("pager", productlist);
				}else{//当前页面检索
					Map<String, Object> cate = new HashMap<>();
					cate.put("name", mpc.getGcName());
					cate.put("type", type);
					cate.put("num", num);
					cate.put("twotype", mpc.getTwoType());
					cate.put("id", categoryid);
					
					Map<String, String> maps = new HashMap<>();
					maps.put("type",type );
					maps.put("num", num);
					maps.put("categoryid", categoryid);
					maps.put("cityCode", data1.get("cityCode"));
					maps.put("city", data1.get("city"));
					maps.put("userType", data1.get("userType"));
					if("1".equals(num)){
						maps.put("isHome", "1");
					}
					if(StringUtil.isBlank(page)){
						cate.put("pager", queryProductPager(new Pager(1, Integer.valueOf(pageSize)), maps));
					}else{
						cate.put("pager", queryProductPager(new Pager(Integer.valueOf(page), Integer.valueOf(pageSize)), maps));
					}
					productlist.add(cate);//商品分类集合
					json.put("pager", productlist);
				}
			}
			
		}else{
			return getJson(0, "", "未知查询");
		}
		
		
		json.put("category", clist);
		
		return getJson(1, json, "");
	}
	
}
