<commit_before>package com.sqe.shop.controller.front;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sqe.shop.common.Constants;
import com.sqe.shop.controller.base.BaseFrontController;
import com.sqe.shop.model.Message;
import com.sqe.shop.model.Product;
import com.sqe.shop.model.ProductType;
import com.sqe.shop.service.CommentService;
import com.sqe.shop.service.ImageService;
import com.sqe.shop.service.MessageService;
import com.sqe.shop.service.ProductService;
import com.sqe.shop.service.ProductTypeService;
import com.sqe.shop.service.ShopService;
import com.sqe.shop.service.biz.BizProductService;
import com.sqe.shop.service.cached.CachedService;
import com.sqe.shop.util.PageUtil;

@Controller
@RequestMapping("/product")
public class FrontProductController extends BaseFrontController {
	
	private static final Logger logger = LoggerFactory.getLogger(FrontProductController.class);
	
	@Autowired
	private ProductService productService;
	@Autowired
	private ImageService imageService;
	@Autowired
	private CommentService commentService;
	@Autowired
	private MessageService messageService;
	@Autowired
	private ProductTypeService productTypeService;
	@Autowired
	private CachedService cachedService;
	@Autowired
	private ShopService shopService;
	
	@Autowired
	private BizProductService bizProductService;
	
	/**
	 * 产品列表页
	 * @param model
	 * @param parentType
	 * @param childType
	 * @param typeName
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="list")
	public ModelAndView list(ModelAndView model, Long parentType, Long childType,String typeName,String searchText,
			@RequestParam(name="pageNo", defaultValue="1") int pageNo,  
			@RequestParam(name="pageSize", defaultValue="12") int pageSize) throws UnsupportedEncodingException {
		/*pageSize=12;*/
		model.addObject("parentType", parentType);
		
		Product product = new Product();
		ProductType productType = new ProductType();
		
		//没有一级分类 选取默认分类
		/*if(parentType==null && childType==null){
			productType = new ProductType();
			productType.setTypeLevel(1);
			PageUtil<ProductType> typePage = productTypeService.getBeanListByParm(productType, 1, -1);
			if(typePage!=null && !typePage.getList().isEmpty()){
				productType = typePage.getList().get(0);
				product.setProductTypeId(productType.getId());
			}
			model.setViewName("shop/404");
			return model;
		}*/
		
		//查询条件里拼接是一级分类还是二级分类
		if(parentType!=null){
			product.setProductTypeId(parentType);
		}
		if(childType!=null){
			product.setProductSubtypeId(childType);
		}
		product.setProductStatus(Constants.PRODUCT_ON);
		if(StringUtils.isNotBlank(searchText)){
			searchText = URLDecoder.decode(searchText, UTF8);
			product.setProductName(searchText);
		}
		//查询
		PageUtil<Map<String, Object>> page = productService.getMapListByParm(product, pageNo, pageSize);
		model.addObject("page", page);
		
		//title参数国际化
		ProductType type= new ProductType();
		if(childType!=null){
			type = productTypeService.getById(childType);
		} else if(parentType!=null) {
			type = productTypeService.getById(parentType);
		} else {
			productType.setTypeNameCh("产品列表");
			productType.setTypeName("Product list");
			type = productType;
		}
		if(cachedService.getLang().equals("zh")){
			model.addObject("title", type.getTypeNameCh()==null?"":type.getTypeNameCh());
		} else {
			model.addObject("title", type.getTypeName()==null?"":type.getTypeName());
		}
		
		model.setViewName("shop/product/product_list");
		return model;
	}
	
	/**
	 * 商品详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value="single", method = RequestMethod.GET)
	public ModelAndView single(ModelAndView model, Long productId) {
		//查询单个商品
		Product product = productService.getById(productId);
		if(product==null){
			model.setViewName("shop/404");
			return model;
		}
		model.addAllObjects(bizProductService.getProductDetail(productId, product));
		
		model.setViewName("shop/product/single");
		return model;
	}
	
	/**
	 * 产品私信
	 * @param model
	 * @param message
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="postMessage")
	public Map<String, Object> postMessage(ModelAndView model, Message message) {
		if(message.getProductId()==null){
			return responseError(-1, "error_unknow");
		}
		<commit_msg>产品未审核通过 跳转至404<commit_after>package com.sqe.shop.controller.front;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sqe.shop.common.Constants;
import com.sqe.shop.controller.base.BaseFrontController;
import com.sqe.shop.model.Message;
import com.sqe.shop.model.Product;
import com.sqe.shop.model.ProductType;
import com.sqe.shop.service.CommentService;
import com.sqe.shop.service.ImageService;
import com.sqe.shop.service.MessageService;
import com.sqe.shop.service.ProductService;
import com.sqe.shop.service.ProductTypeService;
import com.sqe.shop.service.ShopService;
import com.sqe.shop.service.biz.BizProductService;
import com.sqe.shop.service.cached.CachedService;
import com.sqe.shop.util.PageUtil;

@Controller
@RequestMapping("/product")
public class FrontProductController extends BaseFrontController {
	
	private static final Logger logger = LoggerFactory.getLogger(FrontProductController.class);
	
	@Autowired
	private ProductService productService;
	@Autowired
	private ImageService imageService;
	@Autowired
	private CommentService commentService;
	@Autowired
	private MessageService messageService;
	@Autowired
	private ProductTypeService productTypeService;
	@Autowired
	private CachedService cachedService;
	@Autowired
	private ShopService shopService;
	
	@Autowired
	private BizProductService bizProductService;
	
	/**
	 * 产品列表页
	 * @param model
	 * @param parentType
	 * @param childType
	 * @param typeName
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value="list")
	public ModelAndView list(ModelAndView model, Long parentType, Long childType,String typeName,String searchText,
			@RequestParam(name="pageNo", defaultValue="1") int pageNo,  
			@RequestParam(name="pageSize", defaultValue="12") int pageSize) throws UnsupportedEncodingException {
		/*pageSize=12;*/
		model.addObject("parentType", parentType);
		
		Product product = new Product();
		ProductType productType = new ProductType();
		
		//没有一级分类 选取默认分类
		/*if(parentType==null && childType==null){
			productType = new ProductType();
			productType.setTypeLevel(1);
			PageUtil<ProductType> typePage = productTypeService.getBeanListByParm(productType, 1, -1);
			if(typePage!=null && !typePage.getList().isEmpty()){
				productType = typePage.getList().get(0);
				product.setProductTypeId(productType.getId());
			}
			model.setViewName("shop/404");
			return model;
		}*/
		
		//查询条件里拼接是一级分类还是二级分类
		if(parentType!=null){
			product.setProductTypeId(parentType);
		}
		if(childType!=null){
			product.setProductSubtypeId(childType);
		}
		product.setProductStatus(Constants.PRODUCT_ON);
		if(StringUtils.isNotBlank(searchText)){
			searchText = URLDecoder.decode(searchText, UTF8);
			product.setProductName(searchText);
		}
		//查询
		PageUtil<Map<String, Object>> page = productService.getMapListByParm(product, pageNo, pageSize);
		model.addObject("page", page);
		
		//title参数国际化
		ProductType type= new ProductType();
		if(childType!=null){
			type = productTypeService.getById(childType);
		} else if(parentType!=null) {
			type = productTypeService.getById(parentType);
		} else {
			productType.setTypeNameCh("产品列表");
			productType.setTypeName("Product list");
			type = productType;
		}
		if(cachedService.getLang().equals("zh")){
			model.addObject("title", type.getTypeNameCh()==null?"":type.getTypeNameCh());
		} else {
			model.addObject("title", type.getTypeName()==null?"":type.getTypeName());
		}
		
		model.setViewName("shop/product/product_list");
		return model;
	}
	
	/**
	 * 商品详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value="single", method = RequestMethod.GET)
	public ModelAndView single(ModelAndView model, Long productId) {
		//查询单个商品
		Product product = productService.getById(productId);
		if(product==null){
			model.setViewName("shop/404");
			return model;
		}
		if(!product.getProductStatus().equals(Constants.PRODUCT_ON)){
			model.setViewName("shop/404");
			return model;
		}
		
		model.addAllObjects(bizProductService.getProductDetail(productId, product));
		
		model.setViewName("shop/product/single");
		return model;
	}
	
	/**
	 * 产品私信
	 * @param model
	 * @param message
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="postMessage")
	public Map<String, Object> postMessage(ModelAndView model, Message message) {
		if(message.getProductId()==null){
			return responseError(-1, "error_unknow");
		}
		
{'fraction_non_alphanumeric': 0.12276627965673902, 'fraction_numerical': 0.00464411913175164, 'mean_word_length': 5.395093608779858, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542645', 'n_tokens_mistral': 3390, 'n_tokens_neox': 3164, 'n_words': 533}