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

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

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 com.uas.platform.b2b.erp.model.BarcodeSet;
import com.uas.platform.b2b.erp.service.BarcodeSetService;
import com.uas.platform.b2b.erp.support.ErpBufferedLogger;
import com.uas.platform.b2b.service.B2bCodeSetService;
import com.uas.platform.core.logging.BufferedLoggerManager;
import com.uas.platform.core.util.serializer.FlexJsonUtils;

/**
 * b2b端条码产生规则表数据接口
 * @author aof
 * @date 2015年9月13日
 */
@Controller
@RequestMapping("/erp/Barcode")
public class BarcodeSetController {

	@Autowired
	private BarcodeSetService barcodeSetService;

	@Autowired
	private B2bCodeSetService b2bCodeSetService;
	
	private final static ErpBufferedLogger logger = BufferedLoggerManager.getLogger(ErpBufferedLogger.class);
	
	/**
	 * 保存条码产生规则表
	 * @param data
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping(value = "/codeSet", method = RequestMethod.POST)
	@ResponseBody
	public void saveBarcodeSet(@RequestParam("data") String data) throws UnsupportedEncodingException {
		String jsonStr = URLDecoder.decode(data, "UTF-8");
		List<BarcodeSet> codeSets = FlexJsonUtils.fromJsonArray(jsonStr, BarcodeSet.class);
		b2bCodeSetService.saveOrUpdate(barcodeSetService.convertBarcodeSet(codeSets));
		logger.log("条码产生规则表", "保存条码产生规则表", codeSets.size());
	}
}
