Quellcode durchsuchen

openapi其它接口

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@3408 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
administrator vor 10 Jahren
Ursprung
Commit
3701b6edb1

+ 38 - 5
src/main/java/com/uas/platform/b2b/core/util/DateUtils.java

@@ -17,6 +17,30 @@ public class DateUtils {
 	static final SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
 	static final SimpleDateFormat YMD_HMS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Date getMinMonthDate(Date date) {
+		date = date == null ? new Date() : date;
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
+		return calendar.getTime();
+	}
+
+	/**
+	 * 获取月份起始日期
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static String getMinMonthDateS(Date date) {
+		return YMD.format(getMinMonthDate(date));
+	}
+
 	/**
 	 * 获取月份最后日期
 	 * 
@@ -31,6 +55,16 @@ public class DateUtils {
 		return calendar.getTime();
 	}
 
+	/**
+	 * 获取月份最后日期
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static String getMaxMonthDateS(Date date) {
+		return YMD.format(getMaxMonthDate(date));
+	}
+
 	/**
 	 * 比较日期大小
 	 * 
@@ -94,14 +128,14 @@ public class DateUtils {
 	public static Integer getYearmonth(String date) {
 		return Integer.parseInt(ym.format(parse(date, null)));
 	}
-	
+
 	public static Date parse(String date, String f) {
 		if (date == null) {
 			return new Date();
 		}
 		if (f == null) {
 			try {
-				return date.contains(" ") ? YMD_HMS.parse(date) :  YMD.parse(date);
+				return date.contains(" ") ? YMD_HMS.parse(date) : YMD.parse(date);
 			} catch (ParseException e) {
 				return new Date();
 			}
@@ -113,7 +147,7 @@ public class DateUtils {
 			return new Date();
 		}
 	}
-	
+
 	/**
 	 * 当前时间
 	 * 
@@ -122,8 +156,7 @@ public class DateUtils {
 	public static String getCurrentDate() {
 		return format(new Date(), null);
 	}
-	
-	
+
 	public static String format(Date date, String f) {
 		if (date == null) {
 			date = new Date();

+ 3 - 3
src/main/java/com/uas/platform/b2b/data/support/DSUtils.java

@@ -48,9 +48,9 @@ public class DSUtils {
 		bdb.addPropertyValue("url", ds.getUrl());
 		bdb.addPropertyValue("username", ds.getUsername());
 		bdb.addPropertyValue("password", ds.getPassword());
-		bdb.addPropertyValue("initialSize", 5);
-		bdb.addPropertyValue("maxActive", 100);
-		bdb.addPropertyValue("maxIdle", 50);
+		bdb.addPropertyValue("initialSize", 1);
+		bdb.addPropertyValue("maxActive", 20);
+		bdb.addPropertyValue("maxIdle", 2);
 		bdb.addPropertyValue("maxWait", 5000);
 		bdb.addPropertyValue("poolPreparedStatements", true);
 		bdb.addPropertyValue("defaultAutoCommit", true);

+ 108 - 1
src/main/java/com/uas/platform/b2b/openapi/controller/CustDataController.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2b.openapi.controller;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CompletionService;
 import java.util.concurrent.ExecutionException;
@@ -15,8 +16,12 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.uas.platform.b2b.core.util.DateUtils;
 import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.openapi.model.CustData;
+import com.uas.platform.b2b.openapi.model.Forecast;
+import com.uas.platform.b2b.openapi.model.IO;
+import com.uas.platform.b2b.openapi.model.Sale;
 import com.uas.platform.b2b.openapi.model.Stock;
 import com.uas.platform.b2b.openapi.service.CustDataService;
 import com.uas.platform.b2b.openapi.support.ErrorUtils;
@@ -30,7 +35,7 @@ import com.uas.platform.core.exception.SystemError;
  * 获取我的客户的数据
  * 
  * @author yingp
- *
+ * 
  */
 @RestController
 @RequestMapping("/openapi/custdata")
@@ -42,6 +47,8 @@ public class CustDataController {
 	@Autowired
 	private VendorService vendorService;
 
+	private final static String dateFormat = "\\d{4}-\\d{1,2}-\\d{1,2}";
+
 	/**
 	 * 取物料库存信息
 	 * 
@@ -63,6 +70,106 @@ public class CustDataController {
 		});
 	}
 
+	/**
+	 * 取销售订单信息
+	 * 
+	 * <pre>
+	 * 从{@code startDate}截止到当前时间
+	 * </pre>
+	 * 
+	 * @param custId
+	 *            指定客户企业ID
+	 * @param code
+	 *            指定原厂型号
+	 * @param startDate
+	 *            指定开始时间
+	 */
+	@RequestMapping(params = "type=sale")
+	public List<CustData<Sale>> getSaleItems(Long custId, final String code, String startDate) {
+		if (startDate != null && !startDate.matches(dateFormat))
+			throw new SystemError(ErrorUtils.DATE_FORMAT_ERROR);
+		final String brands = SystemSession.getUser().getEnterprise().getEnBrands();
+		if (brands == null)
+			throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
+		// 起始日期为空则取当月第一天
+		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
+		return iteratorCustTasks(custId, new ICallable<CustData<Sale>, Vendor>() {
+
+			@Override
+			public CustData<Sale> call(Vendor cust) throws Exception {
+				return new CustData<Sale>(cust, custDataService.findSales(cust.getMyEnUU(), brands, code, _startDate));
+			}
+
+		});
+	}
+
+	/**
+	 * 取出入库信息
+	 * 
+	 * <pre>
+	 * 从{@code startDate}截止到当前时间
+	 * </pre>
+	 * 
+	 * @param custId
+	 *            指定客户企业ID
+	 * @param code
+	 *            指定原厂型号
+	 * @param startDate
+	 *            指定开始时间
+	 */
+	@RequestMapping(params = "type=io")
+	public List<CustData<IO>> getIOItems(Long custId, final String code, String startDate) {
+		if (startDate != null && !startDate.matches(dateFormat))
+			throw new SystemError(ErrorUtils.DATE_FORMAT_ERROR);
+		final String brands = SystemSession.getUser().getEnterprise().getEnBrands();
+		if (brands == null)
+			throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
+		// 起始日期为空则取当月第一天
+		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
+		return iteratorCustTasks(custId, new ICallable<CustData<IO>, Vendor>() {
+
+			@Override
+			public CustData<IO> call(Vendor cust) throws Exception {
+				return new CustData<IO>(cust, custDataService.findIOs(cust.getMyEnUU(), brands, code, _startDate));
+			}
+
+		});
+	}
+
+	/**
+	 * 取销售预测信息
+	 * 
+	 * <pre>
+	 * 从{@code startDate}截止到当前时间
+	 * </pre>
+	 * 
+	 * @param custId
+	 *            指定客户企业ID
+	 * @param code
+	 *            指定原厂型号
+	 * @param startDate
+	 *            指定开始时间
+	 */
+	@RequestMapping(params = "type=forecast")
+	public List<CustData<Forecast>> getForecastItems(Long custId, final String code, String startDate) {
+		if (startDate != null && !startDate.matches(dateFormat))
+			throw new SystemError(ErrorUtils.DATE_FORMAT_ERROR);
+		final String brands = SystemSession.getUser().getEnterprise().getEnBrands();
+		if (brands == null)
+			throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
+		// 起始日期为空则取当月第一天
+		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
+		return iteratorCustTasks(custId, new ICallable<CustData<Forecast>, Vendor>() {
+
+			@Override
+			public CustData<Forecast> call(Vendor cust) throws Exception {
+				return new CustData<Forecast>(cust, custDataService.findForecasts(cust.getMyEnUU(), brands, code,
+						_startDate));
+			}
+
+		});
+	}
+
 	/**
 	 * 遍历客户资料,并异步执行取数据操作
 	 * 

+ 18 - 10
src/main/java/com/uas/platform/b2b/openapi/model/Forecast.java

@@ -1,12 +1,13 @@
 package com.uas.platform.b2b.openapi.model;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * 销售预测
  * 
  * @author yingp
- *
+ * 
  */
 public class Forecast extends Data implements Serializable {
 
@@ -14,18 +15,25 @@ public class Forecast extends Data implements Serializable {
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	
-	/**
-	 * (在客户系统里面统计的实时)预测数
-	 */
-	private Double forecast;
 
-	public Double getForecast() {
-		return forecast;
+	private List<ForecastItem> items;
+
+	public Forecast(String brand, String code, String title, String spec, String unit, List<ForecastItem> items) {
+		super();
+		setBrand(brand);
+		setCode(code);
+		setTitle(title);
+		setSpec(spec);
+		setUnit(unit);
+		setItems(items);
+	}
+
+	public List<ForecastItem> getItems() {
+		return items;
 	}
 
-	public void setForecast(Double forecast) {
-		this.forecast = forecast;
+	public void setItems(List<ForecastItem> items) {
+		this.items = items;
 	}
 
 }

+ 93 - 0
src/main/java/com/uas/platform/b2b/openapi/model/ForecastItem.java

@@ -0,0 +1,93 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 预测记录
+ * 
+ * @author yingp
+ * 
+ */
+public class ForecastItem implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 预测日期
+	 */
+	private Date date;
+
+	/**
+	 * 预测数量
+	 */
+	private Double qty;
+
+	/**
+	 * 出货日期
+	 */
+	private Date needDate;
+
+	/**
+	 * 截止日期
+	 */
+	private Date endDate;
+
+	/**
+	 * 客户名称
+	 */
+	private String trader;
+
+	public ForecastItem(Date date, Double qty, Date needDate, Date endDate, String trader) {
+		super();
+		this.date = date;
+		this.qty = qty;
+		this.needDate = needDate;
+		this.endDate = endDate;
+		this.trader = trader;
+	}
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public Date getNeedDate() {
+		return needDate;
+	}
+
+	public void setNeedDate(Date needDate) {
+		this.needDate = needDate;
+	}
+
+	public Date getEndDate() {
+		return endDate;
+	}
+
+	public void setEndDate(Date endDate) {
+		this.endDate = endDate;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
+}

+ 50 - 0
src/main/java/com/uas/platform/b2b/openapi/model/IO.java

@@ -0,0 +1,50 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 出入库
+ * 
+ * @author yingp
+ * 
+ */
+public class IO extends Data implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private List<IOItem> in;
+
+	private List<IOItem> out;
+	
+	public IO(String brand, String code, String title, String spec, String unit, List<IOItem> in, List<IOItem> out) {
+		super();
+		setBrand(brand);
+		setCode(code);
+		setTitle(title);
+		setSpec(spec);
+		setUnit(unit);
+		setIn(in);
+		setOut(out);
+	}
+
+	public List<IOItem> getIn() {
+		return in;
+	}
+
+	public void setIn(List<IOItem> in) {
+		this.in = in;
+	}
+
+	public List<IOItem> getOut() {
+		return out;
+	}
+
+	public void setOut(List<IOItem> out) {
+		this.out = out;
+	}
+
+}

+ 49 - 4
src/main/java/com/uas/platform/b2b/openapi/model/IOItem.java

@@ -1,20 +1,65 @@
 package com.uas.platform.b2b.openapi.model;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * 出入库记录
  * 
  * @author yingp
- *
+ * 
  */
-public class IOItem extends Data implements Serializable {
+public class IOItem implements Serializable {
 
 	/**
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	
-	
+
+	/**
+	 * 出、入库数量
+	 */
+	private Double qty;
+
+	/**
+	 * 客户、供应商名称
+	 */
+	private String trader;
+
+	/**
+	 * 发货、收货日期
+	 */
+	private Date date;
+
+	public IOItem(Date date, Double qty, String trader) {
+		super();
+		this.qty = qty;
+		this.trader = trader;
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
 
 }

+ 39 - 0
src/main/java/com/uas/platform/b2b/openapi/model/Sale.java

@@ -0,0 +1,39 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 订单
+ * 
+ * @author yingp
+ * 
+ */
+public class Sale extends Data implements Serializable {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	private List<SaleItem> items;
+
+	public Sale(String brand, String code, String title, String spec, String unit, List<SaleItem> items) {
+		super();
+		setBrand(brand);
+		setCode(code);
+		setTitle(title);
+		setSpec(spec);
+		setUnit(unit);
+		setItems(items);
+	}
+
+	public List<SaleItem> getItems() {
+		return items;
+	}
+
+	public void setItems(List<SaleItem> items) {
+		this.items = items;
+	}
+
+}

+ 48 - 2
src/main/java/com/uas/platform/b2b/openapi/model/SaleItem.java

@@ -1,18 +1,64 @@
 package com.uas.platform.b2b.openapi.model;
 
 import java.io.Serializable;
+import java.util.Date;
 
 /**
  * 销售记录
  * 
  * @author yingp
- *
+ * 
  */
-public class SaleItem extends Data implements Serializable {
+public class SaleItem implements Serializable {
 
 	/**
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * 订单日期
+	 */
+	private Date date;
+
+	/**
+	 * 订单数量
+	 */
+	private Double qty;
+
+	/**
+	 * 客户名称
+	 */
+	private String trader;
+
+	public SaleItem(Date date, Double qty, String trader) {
+		this.date = date;
+		this.qty = qty;
+		this.trader = trader;
+	}
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
 }

+ 107 - 0
src/main/java/com/uas/platform/b2b/openapi/model/TEMP_DATA.java

@@ -0,0 +1,107 @@
+package com.uas.platform.b2b.openapi.model;
+
+public class TEMP_DATA {
+	private String brand;
+	private String code;
+	private String title;
+	private String spec;
+	private String unit;
+
+	public String getBrand() {
+		return brand;
+	}
+
+	public void setBrand(String brand) {
+		this.brand = brand;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public void setTitle(String title) {
+		this.title = title;
+	}
+
+	public String getSpec() {
+		return spec;
+	}
+
+	public void setSpec(String spec) {
+		this.spec = spec;
+	}
+
+	public String getUnit() {
+		return unit;
+	}
+
+	public void setUnit(String unit) {
+		this.unit = unit;
+	}
+
+	public TEMP_DATA(String brand, String code, String title, String spec, String unit) {
+		super();
+		this.brand = brand;
+		this.code = code;
+		this.title = title;
+		this.spec = spec;
+		this.unit = unit;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ((brand == null) ? 0 : brand.hashCode());
+		result = prime * result + ((code == null) ? 0 : code.hashCode());
+		result = prime * result + ((spec == null) ? 0 : spec.hashCode());
+		result = prime * result + ((title == null) ? 0 : title.hashCode());
+		result = prime * result + ((unit == null) ? 0 : unit.hashCode());
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if (this == obj)
+			return true;
+		if (obj == null)
+			return false;
+		if (getClass() != obj.getClass())
+			return false;
+		TEMP_DATA other = (TEMP_DATA) obj;
+		if (brand == null) {
+			if (other.brand != null)
+				return false;
+		} else if (!brand.equals(other.brand))
+			return false;
+		if (code == null) {
+			if (other.code != null)
+				return false;
+		} else if (!code.equals(other.code))
+			return false;
+		if (spec == null) {
+			if (other.spec != null)
+				return false;
+		} else if (!spec.equals(other.spec))
+			return false;
+		if (title == null) {
+			if (other.title != null)
+				return false;
+		} else if (!title.equals(other.title))
+			return false;
+		if (unit == null) {
+			if (other.unit != null)
+				return false;
+		} else if (!unit.equals(other.unit))
+			return false;
+		return true;
+	}
+}

+ 88 - 0
src/main/java/com/uas/platform/b2b/openapi/model/TEMP_FORECAST.java

@@ -0,0 +1,88 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.util.CollectionUtils;
+
+public class TEMP_FORECAST extends Data {
+
+	private Date date;
+
+	private Double qty;
+
+	private Date needDate;
+
+	private Date endDate;
+
+	private String trader;
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public Date getNeedDate() {
+		return needDate;
+	}
+
+	public void setNeedDate(Date needDate) {
+		this.needDate = needDate;
+	}
+
+	public Date getEndDate() {
+		return endDate;
+	}
+
+	public void setEndDate(Date endDate) {
+		this.endDate = endDate;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
+	public static List<Forecast> reduce(List<TEMP_FORECAST> temps) {
+		List<Forecast> forecasts = new ArrayList<Forecast>();
+		if (!CollectionUtils.isEmpty(temps)) {
+			Map<TEMP_DATA, List<ForecastItem>> map = new HashMap<TEMP_DATA, List<ForecastItem>>();
+			for (TEMP_FORECAST temp : temps) {
+				TEMP_DATA data = new TEMP_DATA(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(),
+						temp.getUnit());
+				List<ForecastItem> items = null;
+				if (map.containsKey(data)) {
+					items = map.get(data);
+				} else {
+					items = new ArrayList<ForecastItem>();
+				}
+				items.add(new ForecastItem(temp.getDate(), temp.getQty(), temp.getNeedDate(), temp.getEndDate(), temp
+						.getTrader()));
+				map.put(data, items);
+			}
+			for (TEMP_DATA temp : map.keySet()) {
+				forecasts.add(new Forecast(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(), temp
+						.getUnit(), map.get(temp)));
+			}
+		}
+		return forecasts;
+	}
+
+}

+ 96 - 0
src/main/java/com/uas/platform/b2b/openapi/model/TEMP_IO.java

@@ -0,0 +1,96 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.util.CollectionUtils;
+
+public class TEMP_IO extends Data {
+
+	private Date date;
+
+	private Double qty;
+
+	private String trader;
+
+	private String type;// in/out
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
+	public String getType() {
+		return type;
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public static List<IO> reduce(List<TEMP_IO> temps) {
+		List<IO> ios = new ArrayList<IO>();
+		if (!CollectionUtils.isEmpty(temps)) {
+			Map<TEMP_DATA, List<IOItem>> imap = new HashMap<TEMP_DATA, List<IOItem>>();
+			Map<TEMP_DATA, List<IOItem>> omap = new HashMap<TEMP_DATA, List<IOItem>>();
+			Set<TEMP_DATA> keys = new HashSet<TEMP_DATA>();
+			for (TEMP_IO temp : temps) {
+				TEMP_DATA data = new TEMP_DATA(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(),
+						temp.getUnit());
+				keys.add(data);
+
+				List<IOItem> items = null;
+				if ("in".equals(temp.getType())) {
+					if (imap.containsKey(data)) {
+						items = imap.get(data);
+					} else {
+						items = new ArrayList<IOItem>();
+					}
+				} else {
+					if (omap.containsKey(data)) {
+						items = omap.get(data);
+					} else {
+						items = new ArrayList<IOItem>();
+					}
+				}
+
+				items.add(new IOItem(temp.getDate(), temp.getQty(), temp.getTrader()));
+				if ("in".equals(temp.getType())) {
+					imap.put(data, items);
+				} else {
+					omap.put(data, items);
+				}
+			}
+			for (TEMP_DATA temp : keys) {
+				ios.add(new IO(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(), temp.getUnit(), imap
+						.get(temp), omap.get(temp)));
+			}
+		}
+		return ios;
+	}
+
+}

+ 67 - 0
src/main/java/com/uas/platform/b2b/openapi/model/TEMP_SALE.java

@@ -0,0 +1,67 @@
+package com.uas.platform.b2b.openapi.model;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.util.CollectionUtils;
+
+public class TEMP_SALE extends Data {
+
+	private Date date;
+
+	private Double qty;
+
+	private String trader;
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public Double getQty() {
+		return qty;
+	}
+
+	public void setQty(Double qty) {
+		this.qty = qty;
+	}
+
+	public String getTrader() {
+		return trader;
+	}
+
+	public void setTrader(String trader) {
+		this.trader = trader;
+	}
+
+	public static List<Sale> reduce(List<TEMP_SALE> temps) {
+		List<Sale> sales = new ArrayList<Sale>();
+		if (!CollectionUtils.isEmpty(temps)) {
+			Map<TEMP_DATA, List<SaleItem>> map = new HashMap<TEMP_DATA, List<SaleItem>>();
+			for (TEMP_SALE temp : temps) {
+				TEMP_DATA data = new TEMP_DATA(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(),
+						temp.getUnit());
+				List<SaleItem> items = null;
+				if (map.containsKey(data)) {
+					items = map.get(data);
+				} else {
+					items = new ArrayList<SaleItem>();
+				}
+				items.add(new SaleItem(temp.getDate(), temp.getQty(), temp.getTrader()));
+				map.put(data, items);
+			}
+			for (TEMP_DATA temp : map.keySet()) {
+				sales.add(new Sale(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(), temp.getUnit(),
+						map.get(temp)));
+			}
+		}
+		return sales;
+	}
+
+}

+ 48 - 0
src/main/java/com/uas/platform/b2b/openapi/service/CustDataService.java

@@ -2,6 +2,9 @@ package com.uas.platform.b2b.openapi.service;
 
 import java.util.List;
 
+import com.uas.platform.b2b.openapi.model.Forecast;
+import com.uas.platform.b2b.openapi.model.IO;
+import com.uas.platform.b2b.openapi.model.Sale;
 import com.uas.platform.b2b.openapi.model.Stock;
 
 public interface CustDataService {
@@ -17,4 +20,49 @@ public interface CustDataService {
 	 */
 	List<Stock> findProductStockInfo(long custId, String brands);
 
+	/**
+	 * 查找销售订单信息
+	 * 
+	 * @param custId
+	 *            客户企业ID
+	 * @param brands
+	 *            客户代理的品牌
+	 * @param code
+	 *            原厂型号
+	 * @param startDate
+	 *            开始日期
+	 * @return
+	 */
+	List<Sale> findSales(long custId, String brands, String code, String startDate);
+	
+	/**
+	 * 查找出入库信息
+	 * 
+	 * @param custId
+	 *            客户企业ID
+	 * @param brands
+	 *            客户代理的品牌
+	 * @param code
+	 *            原厂型号
+	 * @param startDate
+	 *            开始日期
+	 * @return
+	 */
+	List<IO> findIOs(long custId, String brands, String code, String startDate);
+	
+	/**
+	 * 查找预测信息
+	 * 
+	 * @param custId
+	 *            客户企业ID
+	 * @param brands
+	 *            客户代理的品牌
+	 * @param code
+	 *            原厂型号
+	 * @param startDate
+	 *            开始日期
+	 * @return
+	 */
+	List<Forecast> findForecasts(long custId, String brands, String code, String startDate);
+
 }

+ 94 - 3
src/main/java/com/uas/platform/b2b/openapi/service/impl/UASCustDataService.java

@@ -12,14 +12,20 @@ import com.uas.platform.b2b.dao.CommonDao;
 import com.uas.platform.b2b.data.support.DS;
 import com.uas.platform.b2b.data.support.DSUtils;
 import com.uas.platform.b2b.data.support.SpObserver;
+import com.uas.platform.b2b.openapi.model.Forecast;
+import com.uas.platform.b2b.openapi.model.IO;
+import com.uas.platform.b2b.openapi.model.Sale;
 import com.uas.platform.b2b.openapi.model.Stock;
+import com.uas.platform.b2b.openapi.model.TEMP_FORECAST;
+import com.uas.platform.b2b.openapi.model.TEMP_IO;
+import com.uas.platform.b2b.openapi.model.TEMP_SALE;
 import com.uas.platform.b2b.openapi.service.CustDataService;
 
 /**
  * 使用UAS系统的客户的数据
  * 
  * @author yingp
- *
+ * 
  */
 @Service
 public class UASCustDataService implements CustDataService {
@@ -58,9 +64,10 @@ public class UASCustDataService implements CustDataService {
 				// 切换到客户账套
 				SpObserver.putSp(ds.getId());
 				// A,B,C格式的数据改为'A','B','C'格式
-				final String brandsWithFix = StringUtils.collectionToDelimitedString(Arrays.asList(brands.split(",")), ",", "'", "'");
+				final String brandsWithFix = StringUtils.collectionToDelimitedString(Arrays.asList(brands.split(",")),
+						",", "'", "'");
 				return commonDao
-						.query("select pr_brand as brand,pr_orispeccode as code,pr_detail as title,pr_spec as spec,po_onhand as stock,pr_unit unit from productonhand left join product on po_prodcode=pr_code where po_onhand > 0 and pr_brand in ("
+						.query("select pr_brand as brand,pr_orispeccode as code,pr_detail as title,pr_spec as spec,po_onhand as stock,pr_unit as unit from productonhand left join product on po_prodcode=pr_code where po_onhand > 0 and pr_brand in ("
 								+ brandsWithFix + ")", Stock.class);
 			} finally {
 				SpObserver.putSp(currDs);
@@ -69,4 +76,88 @@ public class UASCustDataService implements CustDataService {
 		return new ArrayList<Stock>();
 	}
 
+	@Override
+	public List<Sale> findSales(long custId, String brands, String code, String startDate) {
+		DS ds = getDSFromManage(custId);
+		// 先校验是否可以连接
+		if (ds != null && DSUtils.isConnectable(commonDao.getJdbcTemplate(), ds)) {
+			String currDs = SpObserver.getSp();
+			try {
+				// 切换到客户账套
+				SpObserver.putSp(ds.getId());
+				// A,B,C格式的数据改为'A','B','C'格式
+				final String brandsWithFix = StringUtils.collectionToDelimitedString(Arrays.asList(brands.split(",")),
+						",", "'", "'");
+				StringBuffer sql = new StringBuffer(
+						"select pr_brand as brand,pr_orispeccode as code,pr_detail as title,pr_spec as spec,pr_unit as unit,sa_date as date,sa_custname as trader,sd_qty as qty from sale left join saledetail on sa_id=sd_said left join product on sd_prodcode=pr_code where ");
+				sql.append("sa_statuscode='AUDITED' and sa_date > to_date('").append(startDate)
+						.append("','yyyy-mm-dd')");
+				if (StringUtils.hasText(code))
+					sql.append(" and pr_orispeccode='").append(code).append("'");
+				sql.append(" and pr_brand in (").append(brandsWithFix).append(")");
+				sql.append(" order by pr_brand,pr_orispeccode,sa_date,sd_detno");
+				return TEMP_SALE.reduce(commonDao.query(sql.toString(), TEMP_SALE.class));
+			} finally {
+				SpObserver.putSp(currDs);
+			}
+		}
+		return new ArrayList<Sale>();
+	}
+
+	@Override
+	public List<IO> findIOs(long custId, String brands, String code, String startDate) {
+		DS ds = getDSFromManage(custId);
+		// 先校验是否可以连接
+		if (ds != null && DSUtils.isConnectable(commonDao.getJdbcTemplate(), ds)) {
+			String currDs = SpObserver.getSp();
+			try {
+				// 切换到客户账套
+				SpObserver.putSp(ds.getId());
+				// A,B,C格式的数据改为'A','B','C'格式
+				final String brandsWithFix = StringUtils.collectionToDelimitedString(Arrays.asList(brands.split(",")),
+						",", "'", "'");
+				StringBuffer sql = new StringBuffer(
+						"select pr_brand as brand,pr_orispeccode as code,pr_detail as title,pr_spec as spec,pr_unit as unit,pi_date as date,pi_title as trader,nvl(pd_inqty,0)+nvl(pd_outqty,0) as qty,case when nvl(pd_inqty,0)<>0 then 'in' else 'out' end as type from prodinout left join prodiodetail on pi_id=pd_piid left join product on pd_prodcode=pr_code where ");
+				sql.append("pi_statuscode='POSTED' and pi_date > to_date('").append(startDate)
+						.append("','yyyy-mm-dd')");
+				if (StringUtils.hasText(code))
+					sql.append(" and pr_orispeccode='").append(code).append("'");
+				sql.append(" and pr_brand in (").append(brandsWithFix).append(")");
+				sql.append(" order by pr_brand,pr_orispeccode,pi_date,pd_pdno");
+				return TEMP_IO.reduce(commonDao.query(sql.toString(), TEMP_IO.class));
+			} finally {
+				SpObserver.putSp(currDs);
+			}
+		}
+		return new ArrayList<IO>();
+	}
+
+	@Override
+	public List<Forecast> findForecasts(long custId, String brands, String code, String startDate) {
+		DS ds = getDSFromManage(custId);
+		// 先校验是否可以连接
+		if (ds != null && DSUtils.isConnectable(commonDao.getJdbcTemplate(), ds)) {
+			String currDs = SpObserver.getSp();
+			try {
+				// 切换到客户账套
+				SpObserver.putSp(ds.getId());
+				// A,B,C格式的数据改为'A','B','C'格式
+				final String brandsWithFix = StringUtils.collectionToDelimitedString(Arrays.asList(brands.split(",")),
+						",", "'", "'");
+				StringBuffer sql = new StringBuffer(
+						"select pr_brand as brand,pr_orispeccode as code,pr_detail as title,pr_spec as spec,pr_unit as unit,sf_date as date,cu_name as trader,sf_qty as qty,sd_needdate as needDate,sd_enddate as endDate from saleforecast left join saleforecastdetail on sf_id=sd_sfid left join customer on sd_custcode=cu_code left join product on sd_prodcode=pr_code where ");
+				sql.append("sf_statuscode='AUDITED' and sf_date > to_date('").append(startDate)
+						.append("','yyyy-mm-dd')");
+				if (StringUtils.hasText(code))
+					sql.append(" and pr_orispeccode='").append(code).append("'");
+				sql.append(" and pr_brand in (").append(brandsWithFix).append(")");
+				sql.append(" order by pr_brand,pr_orispeccode,sf_date,sd_detno");
+				return TEMP_FORECAST.reduce(commonDao.query(sql.toString(), TEMP_FORECAST.class));
+			} finally {
+				SpObserver.putSp(currDs);
+			}
+		}
+		return new ArrayList<Forecast>();
+	}
+
 }

+ 7 - 1
src/main/java/com/uas/platform/b2b/openapi/support/ErrorUtils.java

@@ -3,7 +3,7 @@ package com.uas.platform.b2b.openapi.support;
 import com.uas.platform.core.exception.Error;
 
 public class ErrorUtils {
-	
+
 	public static final Error EN_NOT_FOUND = new Error(40002, "没有找到企业");
 
 	public static final Error EN_ID_NOT_FOUND = new Error(40003, "没有找到企业ID");
@@ -20,4 +20,10 @@ public class ErrorUtils {
 
 	public static final Error ACCESS_TOKEN_EXPIRES = new Error(40009, "access_token错误,或access_token已过期");
 
+	public static final Error CUST_IS_NEED = new Error(40010, "必须指定客户ID");
+
+	public static final Error PROD_CODE_IS_NEED = new Error(40010, "必须指定物料编号");
+
+	public static final Error DATE_FORMAT_ERROR = new Error(40011, "日期格式错误");
+
 }

+ 3 - 1
src/main/java/com/uas/platform/b2b/openapi/support/ICallable.java

@@ -4,9 +4,11 @@ package com.uas.platform.b2b.openapi.support;
  * 能传入参数执行的callable
  * 
  * @author yingp
- *
+ * 
  * @param <V>
+ *            返回结果类型
  * @param <T>
+ *            参数类型
  */
 public abstract interface ICallable<V, T> {
 

+ 5 - 1
src/main/java/com/uas/platform/b2b/openapi/support/ICallableAdapter.java

@@ -9,10 +9,14 @@ import java.util.concurrent.Callable;
  * 涉及到一个callable对象调用不同参数循环执行的问题,不能直接在ICallable对象里面设置参数,需要代理执行
  * </pre>
  * 
+ * @see ICallable
+ * 
  * @author yingp
- *
+ * 
  * @param <V>
+ *            返回结果类型
  * @param <T>
+ *            参数类型
  */
 public final class ICallableAdapter<V, T> implements Callable<V> {