纪新园 2 лет назад
Родитель
Сommit
40d75118af

+ 4 - 0
blade-service-api/blade-purchase-sales-api/src/main/java/org/springblade/purchase/sales/feign/IOrderDescClient.java

@@ -34,6 +34,7 @@ public interface IOrderDescClient {
 	String GET_BY_BILLNO = API_PREFIX + "/getByBillNo";
 	String GET_BY_ORDER_FILES = API_PREFIX + "/getByOrderFiles";
 	String CORP_ANALYSIS = API_PREFIX + "/corpAnalysis";
+	String CORP_ANALYSIS_DWT = API_PREFIX + "/corpAnalysisDWT";
 	String UNDER_REVIEW_TH = API_PREFIX + "/underReviewTH";
 	String PASS_CANCEL_TH = API_PREFIX + "/passCancelTH";
 	String PASS_CHECK_TH = API_PREFIX + "/passCheckTH";
@@ -106,6 +107,9 @@ public interface IOrderDescClient {
 	@PostMapping(CORP_ANALYSIS)
 	int corpAnalysis(@RequestBody Order order);
 
+	@PostMapping(CORP_ANALYSIS_DWT)
+	int corpAnalysisDWT(@RequestBody Order order);
+
 	@GetMapping(UNDER_REVIEW_TH)
 	R underReviewTH(@RequestParam("id") Long id);
 

+ 95 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/controller/DataAnalysisController.java

@@ -0,0 +1,95 @@
+package org.springblade.purchase.sales.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springblade.core.tool.api.R;
+import org.springblade.purchase.sales.entity.Order;
+import org.springblade.purchase.sales.service.IOrderService;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 国内贸易app数据分析
+ * @author :jixinyuan
+ * @date : 2023/6/1
+ */
+
+@RestController
+@AllArgsConstructor
+@RequestMapping("/app/dataAnalysis")
+@Api(value = "国内贸易app数据分析", tags = "国内贸易app数据分析")
+public class DataAnalysisController {
+
+	private final IOrderService orderService;
+
+
+	/**
+	 * app营业分析
+	 */
+	@GetMapping("/turnoverAnalysis")
+	@ApiOperation(value = "app营业分析", notes = "传入参数")
+	public R<Map<String, Object>> turnoverAnalysis(@RequestParam(value = "statusDate", required = false) String statusDate,
+												   @RequestParam(value = "endDate", required = false) String endDate) {
+		Map<String, Object> map = new HashMap<>();
+		//销售
+		BigDecimal income = new BigDecimal("0.00");
+		//支出
+		BigDecimal expenditure = new BigDecimal("0.00");
+		//利润
+		BigDecimal profit = new BigDecimal("0.00");
+		//成本
+		BigDecimal cost = new BigDecimal("0.00");
+		//平均客单价
+		BigDecimal averageAmount = new BigDecimal("0.00");
+		Map<String, BigDecimal> mapXS = orderService.turnoverAnalysisDWT("XS", null, statusDate, endDate);
+
+		Map<String, BigDecimal> mapCG = orderService.turnoverAnalysisDWT("CG", null, statusDate, endDate);
+
+		income = income.add(mapXS.get("income"));
+
+		expenditure = expenditure.add(mapCG.get("expenditure"));
+
+		cost = cost.add(mapXS.get("cost"));
+
+		profit = profit.add(mapXS.get("profit"));
+
+		Order order = new Order();
+		order.setBillType("XS");
+		order.setTradeType("GN");
+		List<Order> orderList = orderService.turnoverAnalysisDWTList("XS", null, statusDate, endDate);
+		if (orderList.size() > 0 && !income.equals(new BigDecimal("0.00"))) {
+			averageAmount = averageAmount.add(income.divide(new BigDecimal(orderList.size()), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP));
+		}
+		if (!new BigDecimal("0.00").equals(income)){
+			income = income.divide(new BigDecimal("1000"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP);
+		}
+		if (!new BigDecimal("0.00").equals(expenditure)){
+			expenditure = expenditure.divide(new BigDecimal("1000"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP);
+		}
+		if (!new BigDecimal("0.00").equals(profit)){
+			profit = profit.divide(new BigDecimal("1000"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP);
+		}
+		if (!new BigDecimal("0.00").equals(cost)){
+			cost = cost.divide(new BigDecimal("1000"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP);
+		}
+		if (!new BigDecimal("0.00").equals(averageAmount)){
+			averageAmount = averageAmount.divide(new BigDecimal("1000"), MathContext.DECIMAL32).setScale(2, BigDecimal.ROUND_HALF_UP);
+		}
+		map.put("income", income);
+		map.put("expenditure", expenditure);
+		map.put("profit", profit);
+		map.put("cost", cost);
+		map.put("averageAmount", averageAmount);
+		return R.data(map);
+	}
+
+}

+ 7 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/feign/OrderDescClient.java

@@ -265,6 +265,13 @@ public class OrderDescClient implements IOrderDescClient {
 	}
 
 	@Override
+	@GetMapping(CORP_ANALYSIS_DWT)
+	public int corpAnalysisDWT(Order order) {
+		order.setTenantId(AuthUtil.getTenantId());
+		return iOrderService.corpAnalysisDWT(order);
+	}
+
+	@Override
 	@GetMapping(UNDER_REVIEW_TH)
 	public R underReviewTH(Long id) {
 		Order order = new Order();

+ 10 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/mapper/OrderMapper.java

@@ -370,4 +370,14 @@ public interface OrderMapper extends BaseMapper<Order> {
 									 @Param("billType") String billType,
 									 @Param("itemId") Long itemId,
 									 @Param("corpId") Long corpId);
+
+    Map<String, BigDecimal> turnoverAnalysisDWT(@Param("billType")String billType, @Param("type")String type,
+												@Param("statusDate")String statusDate, @Param("endDate")String endDate);
+
+
+	List<Order> turnoverAnalysisDWTList(@Param("tenantId")String tenantId, @Param("type")String type,
+										@Param("statusDate")String statusDate, @Param("endDate")String endDate,
+										@Param("billType")String billType);
+
+	int corpAnalysisDWT(@Param("order")Order order);
 }

+ 77 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/mapper/OrderMapper.xml

@@ -3578,6 +3578,83 @@ ORDER BY
             AND bo.order_status NOT IN ('录入')
         </if>
     </select>
+    <select id="turnoverAnalysisDWT" resultType="java.util.Map">
+        SELECT
+        ifnull( sum( order_amount ), 0 ) as income,
+        ifnull( sum( order_amount ), 0 ) as expenditure,
+        ifnull( sum( gross_profit ), 0 ) as profit,
+        ifnull( sum( purchase_amount ), 0 ) as cost
+        FROM
+        business_order
+        WHERE
+        is_deleted = 0
+        AND trade_type = 'GN'
+        <if test="billType != null and billType != ''">
+            AND bill_type = #{billType}
+        </if>
+        <if test="type != null and type != '' and type == 1">
+            AND TO_DAYS(busines_date)=TO_DAYS(NOW())
+        </if>
+        <if test="type != null and type != '' and type == 2">
+            AND YEARWEEK(DATE_FORMAT(busines_date,'%Y-%m-%d'))=YEARWEEK(NOW())
+        </if>
+        <if test="type != null and type != '' and type == 3">
+            AND DATE_FORMAT(busines_date,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m')
+        </if>
+        <if test="statusDate != null and statusDate != ''">
+            and DATE_FORMAT(busines_date,'%Y-%m-%d') &gt;= DATE_FORMAT(#{statusDate},'%Y-%m-%d')
+        </if>
+        <if test="endDate != null and endDate != ''">
+            and DATE_FORMAT(busines_date,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
+        </if>
+    </select>
+    <select id="turnoverAnalysisDWTList" resultType="org.springblade.purchase.sales.entity.Order">
+        SELECT
+        *
+        FROM
+        business_order
+        where
+        is_deleted = 0
+        AND trade_type = 'GN'
+        <if test="billType != null and billType != ''">
+            AND bill_type = #{billType}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND tenant_id = #{tenantId}
+        </if>
+        <if test="type != null and type != '' and type == 1">
+            AND TO_DAYS(busines_date)=TO_DAYS(NOW())
+        </if>
+        <if test="type != null and type != '' and type == 2">
+            AND YEARWEEK(DATE_FORMAT(busines_date,'%Y-%m-%d'))=YEARWEEK(NOW())
+        </if>
+        <if test="type != null and type != '' and type == 3">
+            AND DATE_FORMAT(busines_date,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m')
+        </if>
+        <if test="statusDate != null and statusDate != ''">
+            and DATE_FORMAT(busines_date,'%Y-%m-%d') &gt;= DATE_FORMAT(#{statusDate},'%Y-%m-%d')
+        </if>
+        <if test="endDate != null and endDate != ''">
+            and DATE_FORMAT(busines_date,'%Y-%m-%d') &lt;= DATE_FORMAT(#{endDate},'%Y-%m-%d')
+        </if>
+    </select>
+    <select id="corpAnalysisDWT" resultType="java.lang.Integer">
+        select count(id)
+        from
+        business_order
+        where
+        is_deleted = 0
+        AND trade_type = 'GN'
+        <if test="order.corpId != null">
+            AND corp_id = #{order.corpId}
+        </if>
+        <if test="order.corpType != null and order.corpType != '' and order.corpType == 1">
+            and busines_date between date_sub(now(),interval 6 month) and now();
+        </if>
+        <if test="order.corpType != null and order.corpType != '' and order.corpType == 2">
+            AND busines_date between date_sub(now(),interval 6 month) and now();
+        </if>
+    </select>
 
     <update id="updateStockGoods" parameterType="org.springblade.stock.entity.StockGoods">
         UPDATE business_stock_goods SET surplus_route_quantity = #{surplusRouteQuantity},locking_quantity = #{lockingQuantity} WHERE tenant_id = #{tenantId} AND id = #{id} AND is_deleted = 0

+ 6 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/service/IOrderService.java

@@ -526,4 +526,10 @@ public interface IOrderService extends IService<Order> {
 	R quickBillingMall(Order order);
 
 	R cancelOrderMall(Order order);
+
+	Map<String, BigDecimal> turnoverAnalysisDWT(String xs, String type, String statusDate, String endDate);
+
+	List<Order> turnoverAnalysisDWTList(String billType,String type, String statusDate, String endDate);
+
+	int corpAnalysisDWT(Order order);
 }

+ 17 - 0
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/service/impl/OrderServiceImpl.java

@@ -531,6 +531,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 				orderMessage.setCntrVolumn(cntrVolumn);
 				//总提价
 				orderMessage.setCartonWeight(cartonWeight);
+				//总采购金额
+				orderMessage.setPurchaseAmount(reduce);
 			} else if (CollectionUtils.isNotEmpty(list) && order.getTradeType().equals(OrderTypeEnum.EXPORT.getType())) {
 				// 出口的毛利额=销售价 * 汇率 - (采购价+配件价格)    毛利率 =毛利额/(采购单价+配件价格)
 				// 金额求和
@@ -6838,6 +6840,21 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 		return R.data("操作成功");
 	}
 
+	@Override
+	public Map<String, BigDecimal> turnoverAnalysisDWT(String billType, String type, String statusDate, String endDate) {
+		return baseMapper.turnoverAnalysisDWT(billType,type,statusDate,endDate);
+	}
+
+	@Override
+	public List<Order> turnoverAnalysisDWTList(String billType, String type, String statusDate, String endDate) {
+		return baseMapper.turnoverAnalysisDWTList(AuthUtil.getTenantId(), type, statusDate, endDate, billType);
+	}
+
+	@Override
+	public int corpAnalysisDWT(Order order) {
+		return baseMapper.corpAnalysis(order);
+	}
+
 	/**
 	 * 状态统计
 	 * <p>

+ 2 - 0
blade-service/blade-stock/src/main/java/org/springblade/stock/feign/StockGoodsClient.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import io.seata.spring.annotation.GlobalTransactional;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springblade.client.entity.StorageDesc;
@@ -256,6 +257,7 @@ public class StockGoodsClient implements IStockGoodsClient {
 	@Override
 	@PostMapping(UPDATE_STOCK_LIST)
 	@Transactional(rollbackFor = Exception.class)
+	@GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
 	public boolean updateStockList(List<StockGoods> stockGoods) {
 		stockGoodsService.updateBatchById(stockGoods);
 		return redisClient.basicData("stockGoods");