|
|
@@ -0,0 +1,194 @@
|
|
|
+package com.uas.platform.b2b.openapi.service.impl;
|
|
|
+
|
|
|
+import com.uas.platform.b2b.dao.CommonDao;
|
|
|
+import com.uas.platform.b2b.openapi.model.CustTrading;
|
|
|
+import com.uas.platform.b2b.openapi.service.TradingDataService;
|
|
|
+import com.uas.platform.b2b.openapi.support.NumFormat;
|
|
|
+import com.uas.platform.b2b.openapi.support.ErpRate;
|
|
|
+import com.uas.platform.b2b.openapi.support.TimeStauts;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.ui.ModelMap;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.sql.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: huj
|
|
|
+ * @Date: Created in 15:45 2018/9/20.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TradingDataServiceImpl implements TradingDataService{
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getTradingSum(Long enUU) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ // 获取累计交易时间
|
|
|
+ Double timeSum = getTimeSum(enUU, null);
|
|
|
+ // 获取累计验收金额
|
|
|
+ Double acceptSum = getAcceptSum(enUU, null);
|
|
|
+ // 获取累计验退金额
|
|
|
+ Double returnSum = getReturnSum(enUU, null);
|
|
|
+ // 获取累计实收金额
|
|
|
+ Double realSum = NumFormat.getTwo(acceptSum - returnSum);
|
|
|
+ // 获取累计对账金额
|
|
|
+ Double apCheckSum = getApCheckSum(enUU);
|
|
|
+ // 获取累计发票金额
|
|
|
+ Double apBillSum = getApBillSum(enUU);
|
|
|
+ // 获取历史退货率
|
|
|
+ String historyReturn = NumFormat.getPercent(realSum/getOrderSum(enUU));
|
|
|
+ map.put("timeSum", timeSum);
|
|
|
+ map.put("acceptSum", acceptSum);
|
|
|
+ map.put("returnSum", returnSum);
|
|
|
+ map.put("realSum", realSum);
|
|
|
+ map.put("apCheckSum", apCheckSum);
|
|
|
+ map.put("apBillSum", apBillSum);
|
|
|
+ map.put("historyReturn", historyReturn);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getCustTrading(Long enUU) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ List<CustTrading> datas = getCust(enUU);
|
|
|
+ if (CollectionUtils.isNotEmpty(datas)) {
|
|
|
+ for (CustTrading custTrading : datas) {
|
|
|
+ Double acceptSum = getAcceptSum(enUU, custTrading.getCustUU());
|
|
|
+ Double returnSum = getReturnSum(enUU, custTrading.getCustUU());
|
|
|
+ custTrading.setRealAccept(NumFormat.getTwo(acceptSum - returnSum));
|
|
|
+ custTrading.setAcceptPercent(NumFormat.getPercent((acceptSum - returnSum) / acceptSum));
|
|
|
+ Integer acceptNum = getAcceptNum(enUU, custTrading.getCustUU());
|
|
|
+ Integer realNum = acceptNum - getReturnNum(enUU, custTrading.getCustUU());
|
|
|
+ custTrading.setRealNum(realNum);
|
|
|
+ if (0 != acceptNum) {
|
|
|
+ custTrading.setNumPercent(NumFormat.getPercent((double) realNum / acceptNum));
|
|
|
+ }
|
|
|
+ custTrading.setTimeSum(NumFormat.getOne(getTimeSum(enUU, custTrading.getCustUU())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("date", datas);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelMap getRecentOfYear(Long enUU) {
|
|
|
+ ModelMap map = new ModelMap();
|
|
|
+ // 有交易额客户数量
|
|
|
+
|
|
|
+ // 验收金额
|
|
|
+
|
|
|
+ // 验收笔数
|
|
|
+
|
|
|
+ // 验退金额
|
|
|
+
|
|
|
+ // 验退笔数
|
|
|
+
|
|
|
+ // 实收金额
|
|
|
+
|
|
|
+ // 实收笔数
|
|
|
+
|
|
|
+ // 对账金额
|
|
|
+
|
|
|
+ // 对账笔数
|
|
|
+
|
|
|
+ // 开票金额
|
|
|
+
|
|
|
+ // 开票笔数
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Double getTimeSum(Long enUU, Long custUU){
|
|
|
+ StringBuffer last = new StringBuffer("SELECT pu_date from purc$orders " +
|
|
|
+ "WHERE pu_venduu = " + enUU + " pu_date is not null ");
|
|
|
+ if (!StringUtils.isEmpty(custUU)) {
|
|
|
+ last.append("and pu_enuu = " + custUU + "");
|
|
|
+ }
|
|
|
+ StringBuffer first = last.append(" ORDER BY pu_date asc limit 1");
|
|
|
+ last.append(" ORDER BY pu_date desc limit 1");
|
|
|
+ Date lastTime = commonDao.queryForObject(last.toString(), Date.class);
|
|
|
+ Date firstTime = commonDao.queryForObject(first.toString(), Date.class);
|
|
|
+ StringBuffer result = new StringBuffer("SELECT TIMESTAMPDIFF(MONTH," + firstTime + "," + lastTime +")");
|
|
|
+ Double resultTime = commonDao.queryForObject(result.toString(), Double.class) / TimeStauts.TYEAR.value();
|
|
|
+ return NumFormat.getOne(resultTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getAcceptSum(Long enUU, Long custUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' " +
|
|
|
+ "then a.amount * " + ErpRate.USD_RATE+ " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result " +
|
|
|
+ "FROM (SELECT SUM(pai_qty*pai_orderprice) amount,pa_currency currency FROM purc$accept LEFT JOIN purc$acceptitem " +
|
|
|
+ "on pai_paid=pa_id WHERE pa_venduu= " + enUU);
|
|
|
+ if (!StringUtils.isEmpty(custUU)) {
|
|
|
+ sql.append(" and pu_enuu = " + custUU + " ");
|
|
|
+ }
|
|
|
+ sql.append(" GROUP BY pa_currency) a");
|
|
|
+ Double result = commonDao.queryForObject(sql.toString(), Double.class);
|
|
|
+ return NumFormat.getTwo(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getReturnSum(Long enUU, Long custUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' " +
|
|
|
+ "then a.amount * " + ErpRate.USD_RATE+ " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result " +
|
|
|
+ "FROM (SELECT SUM(pri_qty*pri_orderprice) amount,pr_currency currency FROM purc$return LEFT JOIN purc$returnitem " +
|
|
|
+ "on pri_prid=pr_id WHERE pr_venduu= " + enUU);
|
|
|
+ if (!StringUtils.isEmpty(custUU)) {
|
|
|
+ sql.append(" and pr_enuu = " + custUU + " ");
|
|
|
+ }
|
|
|
+ sql.append(" GROUP BY pr_currency) a");
|
|
|
+ Double result = commonDao.queryForObject(sql.toString(), Double.class);
|
|
|
+ return NumFormat.getTwo(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getApCheckSum(Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' " +
|
|
|
+ "then a.amount * " + ErpRate.USD_RATE+ " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result " +
|
|
|
+ "FROM (select sum(pa_checkamount) amount,pa_currency currency from purc$apcheck where pa_enuu = " + enUU +
|
|
|
+ " and pa_checkstatus = '已确认' GROUP BY pa_currency) a");
|
|
|
+ Double result = commonDao.queryForObject(sql.toString(), Double.class);
|
|
|
+ return NumFormat.getTwo(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getApBillSum(Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' " +
|
|
|
+ "then a.amount * " + ErpRate.USD_RATE+ " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result " +
|
|
|
+ "FROM (SELECT SUM(pab_paymount) amount,pab_currency currency FROM purc$apbill WHERE pad_venduu=" + enUU +
|
|
|
+ " GROUP BY pab_currency) a");
|
|
|
+ Double result = commonDao.queryForObject(sql.toString(), Double.class);
|
|
|
+ return NumFormat.getTwo(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getOrderSum(Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT sum(case currency when 'RMB' then a.amount when 'USD' " +
|
|
|
+ "then a.amount * " + ErpRate.USD_RATE+ " when 'HKD' then a.amount * " + ErpRate.HKD_RATE + " end) result " +
|
|
|
+ "FROM (SELECT sum(pd_price) amount,pu_currency currency FROM purc$orders LEFT JOIN purc$orderitems " +
|
|
|
+ "on pu_id=pd_puid where pu_venduu = " + enUU + " GROUP BY pu_currency) a");
|
|
|
+ Double result = commonDao.queryForObject(sql.toString(), Double.class);
|
|
|
+ return NumFormat.getTwo(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CustTrading> getCust(Long enUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT en_uu custUU,en_name custName FROM sec$enterprises WHERE en_uu in " +
|
|
|
+ "(SELECT ve_myenuu FROM purc$vendors WHERE ve_vendenuu= " + enUU + " ) ORDER BY en_name");
|
|
|
+ return commonDao.queryForList(sql.toString(), CustTrading.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getAcceptNum(Long enUU, Long custUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM purc$accept WHERE pa_venduu= " + enUU +
|
|
|
+ " AND pa_enuu=" + custUU + "");
|
|
|
+ Integer result = commonDao.queryForObject(sql.toString(), Integer.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getReturnNum(Long enUU, Long custUU) {
|
|
|
+ StringBuffer sql = new StringBuffer("SELECT COUNT(1) FROM purc$return WHERE pr_venduu= " + enUU +
|
|
|
+ " and pr_enuu= " + custUU + "");
|
|
|
+ Integer result = commonDao.queryForObject(sql.toString(), Integer.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|