package com.uas.platform.b2b.erp.controller;

import com.uas.sso.support.Page;
import com.uas.platform.b2b.erp.model.VendorRecommend;
import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
import com.uas.platform.b2b.model.Product;
import com.uas.platform.b2b.service.VendorService;
import com.uas.platform.core.logging.BufferedLoggerManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 供应商推荐
 * Created by dongbw
 * 18/01/18 14:00.
 */
@RestController
@RequestMapping("/public/recommend")
public class VendorRecommendController {

    @Autowired
    private VendorService vendorService;

    private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);

    /**
     * 获取当前企业推荐供应商
     *
     * @param productMatchCondition 物料模糊匹配条件
     * @param enterpriseMatchCondition 企业搜索匹配条件
     * @param page 页面
     * @param size 每页条数
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Page<VendorRecommend> getVendorRecommend (Long enUU, String productMatchCondition, String enterpriseMatchCondition, int page, int size) {
        Page<VendorRecommend> vendorRecommendPage = vendorService.getVendorRecommend(enUU, productMatchCondition, enterpriseMatchCondition, page, size);
//        logger.log("供应商推荐","获取当前企业推荐供应商：" + enUU, vendorRecommendPage.getNumberOfElements());
        return vendorRecommendPage;
    }

    /**
     * 根据条件获取物料型号和品牌值对（UAS品牌和型号联想词接口）
     *
     * @param field 需要的字段名
     * @param condition 物料模糊匹配条件
     * @return 物料型号和品牌值对List
     */
    @RequestMapping(value = "/product/associate", method = RequestMethod.GET)
    public List<Product> getProductAssociate (String field, String condition) {
        List<Product> products = vendorService.getProductAssociate(field, condition);
//        logger.log("供应商推荐","根据条件获取物料型号和品牌值对", products.size());
        return products;
    }

    /**
     * 获取推荐企业物料列表（匹配到的排前面）
     * @param page 页数
     * @param size 每页条数
     * @param enUU 当前企业UU
     * @param vendUU 推荐供应商企业UU
     * @param productMatchCondition 列表的物料匹配搜索条件  不带where
     * @param whereCondition where条件（product的筛选条件拼接） 不带where
     * @return
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Page<Product> getVendorRecommendDetail(int page, int size, Long enUU, Long vendUU, String productMatchCondition, String whereCondition) {
        Page<Product> productPage = vendorService.getProductsByVendorRecommend(page, size, enUU, vendUU, productMatchCondition, whereCondition);
//        logger.log("供应商推荐","获取当前企业推荐供应商：" + enUU, productPage.getNumberOfElements());
        return productPage;
    }
}
