Browse Source

销售管理、采购管理

yumeng 5 tháng trước cách đây
mục cha
commit
c7a4e46977

+ 54 - 25
ruixuan-live/src/main/java/com/ruixuan/isc/controller/KwaiXiaoDianReportController.java

@@ -81,7 +81,7 @@ public class KwaiXiaoDianReportController {
                 }
                 List<Long> itemIds = kwaixiaodianItemGetService.getItemIdsByUserIds(userIds);
                 requestMap.put("itemIds", itemIds);
-            } else if ("industry_courtship_manager".equals(roleId) ) { // 招商、采购经理角色查看部门下所有成员数据
+            } else if ("industry_courtship_manager".equals(roleId)) { // 招商、采购经理角色查看部门下所有成员数据
                 List<Long> courtshipPurchaseIds = kwaixiaodianItemGetService.getUserIds(userId);
                 if (Check.isNull(courtshipPurchaseIds)) {
                     throw new Exception("此用户未查询到部门成员信息");
@@ -858,15 +858,22 @@ public class KwaiXiaoDianReportController {
 
 
     @GetMapping("/getSaleDetail")
-    public TableDataInfo getSaleDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
+    public TableDataInfo getSaleDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long loginUserId) {
         TableDataInfo rspData = new TableDataInfo();
         try {
-            if (Check.isNull(userId)) {
-                throw new Exception("请传入用户ID");
-            }
             Map<String, Object> requestMap = new HashMap<>();
-            requestMap.put("userId", userId);
-
+            if (!Check.isNull(userId)) {
+                requestMap.put("userId", userId);
+            } else {
+                requestMap.put("userId", null);
+                String roleId = sysRoleService.getRoleBYUserId(loginUserId);
+                if ("admin".equals(roleId)) {
+                    requestMap.put("companyId", null);
+                } else {
+                    Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
+                    requestMap.put("companyId", companyId);
+                }
+            }
             Long start = DateUtils.strDateToInt(startDate);
             Long end = DateUtils.strDateToInt(endDate);
             requestMap.put("start", start);
@@ -889,11 +896,8 @@ public class KwaiXiaoDianReportController {
 
 
     @GetMapping("/exportSaleDetail")
-    public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
+    public void exportSaleDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
 
-        if (Check.isNull(userId)) {
-            return;
-        }
         if (Check.isNull(startDate)) {
             return;
         }
@@ -902,8 +906,18 @@ public class KwaiXiaoDianReportController {
         }
 
         Map<String, Object> requestMap = new HashMap<>();
-        requestMap.put("userId", userId);
-
+        if (!Check.isNull(userId)) {
+            requestMap.put("userId", userId);
+        } else {
+            requestMap.put("userId", null);
+            String roleId = sysRoleService.getRoleBYUserId(loginUserId);
+            if ("admin".equals(roleId)) {
+                requestMap.put("companyId", null);
+            } else {
+                Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
+                requestMap.put("companyId", companyId);
+            }
+        }
         Long start = DateUtils.strDateToInt(startDate);
         Long end = DateUtils.strDateToInt(endDate);
         requestMap.put("start", start);
@@ -1054,15 +1068,23 @@ public class KwaiXiaoDianReportController {
 
 
     @GetMapping("/getPurchaseDetail")
-    public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize) {
+    public TableDataInfo getPurchaseDetail(String startDate, String endDate, Long userId, Integer pageNum, Integer pageSize, Long loginUserId) {
         TableDataInfo rspData = new TableDataInfo();
         try {
-            if (Check.isNull(userId)) {
-                throw new Exception("请传入用户ID");
-            }
-            Map<String, Object> requestMap = new HashMap<>();
-            requestMap.put("userId", userId);
 
+            Map<String, Object> requestMap = new HashMap<>();
+            if (!Check.isNull(userId)) {
+                requestMap.put("userId", userId);
+            } else {
+                requestMap.put("userId", null);
+                String roleId = sysRoleService.getRoleBYUserId(loginUserId);
+                if ("admin".equals(roleId)) {
+                    requestMap.put("companyId", null);
+                } else {
+                    Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
+                    requestMap.put("companyId", companyId);
+                }
+            }
             Long start = DateUtils.strDateToInt(startDate);
             Long end = DateUtils.strDateToInt(endDate);
             requestMap.put("start", start);
@@ -1085,11 +1107,8 @@ public class KwaiXiaoDianReportController {
 
 
     @GetMapping("/exportPurchaseDetail")
-    public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate) throws IOException, ParseException {
+    public void exportPurchaseDetail(HttpServletRequest request, HttpServletResponse response, Long userId, String startDate, String endDate, Long loginUserId) throws IOException, ParseException {
 
-        if (Check.isNull(userId)) {
-            return;
-        }
         if (Check.isNull(startDate)) {
             return;
         }
@@ -1098,8 +1117,18 @@ public class KwaiXiaoDianReportController {
         }
 
         Map<String, Object> requestMap = new HashMap<>();
-        requestMap.put("userId", userId);
-
+        if (!Check.isNull(userId)) {
+            requestMap.put("userId", userId);
+        } else {
+            requestMap.put("userId", null);
+            String roleId = sysRoleService.getRoleBYUserId(loginUserId);
+            if ("admin".equals(roleId)) {
+                requestMap.put("companyId", null);
+            } else {
+                Long companyId = kwaixiaodianItemGetService.getCompanyId(loginUserId);
+                requestMap.put("companyId", companyId);
+            }
+        }
         Long start = DateUtils.strDateToInt(startDate);
         Long end = DateUtils.strDateToInt(endDate);
         requestMap.put("start", start);

+ 40 - 24
ruixuan-live/src/main/resources/mapper/isc/KwaiXiaoDianReportMapper.xml

@@ -983,27 +983,38 @@
     </select>
     <select id="getSaleDetail" resultType="com.alibaba.fastjson.JSONObject">
         SELECT CAST(t.itemId AS char) AS 'itemId', t.itemTitle,
-               t.itemPicUrl,
-               COUNT(t.oid) AS 'orderNum', round(
-            SUM(t.totalFee) / 100, 2
-            ) AS 'totalFee', SUM(tt.costPrice) AS 'costPrice', t.userId,
-               t.userName
-        FROM (SELECT t1.oid AS 'oid', t1.status AS 'status', t1.total_fee AS 'totalFee', t1.item_id AS 'itemId', t1.item_title AS 'itemTitle', t2.user_id AS 'userId', t2.user_name AS 'userName', t1.item_pic_url AS 'itemPicUrl'
-              FROM kwaixiaodian_order_cursor_list t1
-                       LEFT JOIN kwaixiaodian_item_get t2
-                                 ON t1.item_id = t2.item_id
-              WHERE t1.send_time &gt;= #{start}
-                AND t1.send_time &lt;= #{end}
-                AND t1.status IN (40, 50, 70)
-                AND t2.user_id = #{userId}
-              GROUP BY t1.oid) t
-                 LEFT JOIN
-             (SELECT oid, SUM(cost_price) AS 'costPrice'
-              FROM kwaixiaodian_cost_detail_end
-              WHERE send_time &gt;= #{start}
-                AND send_time &lt;= #{end}
-              GROUP BY oid) tt
-             ON t.oid = tt.oid
+        t.itemPicUrl,
+        COUNT(t.oid) AS 'orderNum', round(
+        SUM(t.totalFee) / 100, 2
+        ) AS 'totalFee', SUM(tt.costPrice) AS 'costPrice', t.userId,
+        t.userName
+        FROM (SELECT t1.oid AS 'oid', t1.status AS 'status', t1.total_fee AS 'totalFee', t1.item_id AS 'itemId',
+        t1.item_title AS 'itemTitle', t2.user_id AS 'userId', t2.user_name AS 'userName', t1.item_pic_url AS
+        'itemPicUrl'
+        FROM kwaixiaodian_order_cursor_list t1
+        LEFT JOIN kwaixiaodian_item_get t2
+        ON t1.item_id = t2.item_id
+        WHERE t1.send_time &gt;= #{start}
+        AND t1.send_time &lt;= #{end}
+        AND t1.status IN (40, 50, 70)
+        <if test='companyId != null'>
+            and t1.company_id = #{companyId}
+        </if>
+
+        <if test='userId != null '>
+            and t2.user_id = #{userId}
+        </if>
+        <if test='userId == null'>
+            and t2.user_id is null
+        </if>
+        GROUP BY t1.oid) t
+        LEFT JOIN
+        (SELECT oid, SUM(cost_price) AS 'costPrice'
+        FROM kwaixiaodian_cost_detail_end
+        WHERE send_time &gt;= #{start}
+        AND send_time &lt;= #{end}
+        GROUP BY oid) tt
+        ON t.oid = tt.oid
         GROUP BY t.itemId
         ORDER BY COUNT(t.oid) DESC
     </select>
@@ -1079,11 +1090,16 @@
         on t1.item_id = t2.item_id
         where t1.send_time &gt;= #{start}
         and t1.send_time &lt;= #{end}
-        <if test='companyId != null and companyId != ""'>
+        and t1.status in (40, 50, 70)
+        <if test='companyId != null'>
             and t1.company_id = #{companyId}
         </if>
-        and t1.status in (40, 50, 70)
-        and t2.courtship_purchase_id = #{userId}
+        <if test='userId != null '>
+            and t2.courtship_purchase_id = #{userId}
+        </if>
+        <if test='userId == null'>
+            and t2.courtship_purchase_id is null
+        </if>
         group by t1.oid) t
         left join
         (select oid, sum(cost_price) as 'costPrice'