Browse Source

个人报表中,没有统计数据的日期,当日数据显示0,仍返回其他数据

albertshaw 7 years ago
parent
commit
4150b1f349

+ 4 - 0
src/main/java/com/goafanti/common/dao/DailySalesReportMapper.java

@@ -28,6 +28,10 @@ public interface DailySalesReportMapper {
 			@Param("countField") String countField, @Param("amountField") String amountField,
 			@Param("depName") String depName, @Param("name") String name, @Param("position") String position);
 
+	List<PersonalSalesReportBO> selectPersonalByPage(@Param("pageNo") Integer pageNo,
+			@Param("pageSize") Integer pageSize, @Param("depName") String depName, @Param("name") String name,
+			@Param("position") String position);
+
 	Long selectSalesPersonalReportsCount(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
 			@Param("depName") String depName, @Param("name") String name, @Param("position") String position);
 

+ 26 - 1
src/main/java/com/goafanti/common/mapper/DailySalesReportMapper.xml

@@ -25,6 +25,26 @@
     left join department_management dm on dm.id = a.department_id 
   </select>
   
+  <select id="selectPersonalByPage" resultType="com.goafanti.report.bo.PersonalSalesReportBO">
+    SELECT a.id, a.name, dm.name as departmentName, a.position, a.create_time as enrollTime
+	FROM admin a
+	left join department_management dm on dm.id = a.department_id 
+	where 1=1
+	<if test="depName != null">
+		and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
+	</if>
+	<if test="name != null">
+		and a.name like concat(#{name,jdbcType=VARCHAR},'%')
+	</if>
+	<if test="position != null">
+		and a.position like concat(#{position,jdbcType=VARCHAR},'%')
+	</if>
+	order by a.name asc
+	<if test="pageNo != null and pageSize != null">
+		limit #{pageNo,jdbcType=INTEGER}, #{pageSize,jdbcType=INTEGER}
+    </if>
+  </select>
+  
   <select id="selectDailySalesReports" resultMap="BaseResultMap">
     SELECT o.salesman_id as admin_id, a.department_id as dep_id,
 	count(o.order_no) as order_count, sum(o.sign_total_amount) as order_amount
@@ -77,11 +97,16 @@
   <select id="selectSalesPersonalReportsCount" resultType="java.lang.Long">
     SELECT count(distinct(a.id))
 	FROM admin a
+	<if test="startTime != null and endTime != null"> 
 	left join daily_sales_report dsr on dsr.admin_id = a.id
+	</if>
 	<if test="depName != null"> 
 	left join department_management dm on dm.id = a.department_id 
 	</if>
-	where dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
+	where 1=1
+	<if test="startTime != null and endTime != null"> 
+		and dsr.create_time &gt;= #{startTime,jdbcType=TIMESTAMP} and dsr.create_time &lt; #{endTime,jdbcType=TIMESTAMP}
+	</if>
 	<if test="depName != null">
 		and dm.name like concat(#{depName,jdbcType=VARCHAR},'%')
 	</if>

+ 18 - 0
src/main/java/com/goafanti/report/controller/ReportApiController.java

@@ -37,6 +37,15 @@ public class ReportApiController extends BaseApiController {
 		} catch (Exception e) {
 			startTime = new Date();
 		}
+		if (StringUtils.isBlank(depName)) {
+			depName = null;
+		}
+		if (StringUtils.isBlank(name)) {
+			name = null;
+		}
+		if (StringUtils.isBlank(position)) {
+			position = null;
+		}
 		Integer pageSize = StringUtils.isBlank(pSize) ? null : handlePageSize(pSize);
 		Integer pageNo = StringUtils.isBlank(pNo) ? null : handlePageNo(pNo);
 		if (pageSize != null && pageNo != null) {
@@ -55,6 +64,15 @@ public class ReportApiController extends BaseApiController {
 		} catch (Exception e) {
 			startTime = new Date();
 		}
+		if (StringUtils.isBlank(depName)) {
+			depName = null;
+		}
+		if (StringUtils.isBlank(name)) {
+			name = null;
+		}
+		if (StringUtils.isBlank(position)) {
+			position = null;
+		}
 		return res().data(reportService.getReportTotal(startTime, depName, name, position));
 	}
 

+ 7 - 3
src/main/java/com/goafanti/report/service/SalesReportServiceImpl.java

@@ -64,8 +64,12 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
 				name, position);
 		putField(mm, "annuallyTotalCount", "annuallyTotalAmount", rd.getYearStart(), rd.getYearEnd(), depName, name,
 				position);
-		mm.put("totalRecordCount", salesReportMapper.selectSalesPersonalReportsCount(rd.getDailyStart(),
-				rd.getDailyEnd(), depName, name, position));
+		long totalCount = salesReportMapper.selectSalesPersonalReportsCount(rd.getDailyStart(), rd.getDailyEnd(),
+				depName, name, position);
+		if (totalCount == 0) {
+			totalCount = salesReportMapper.selectSalesPersonalReportsCount(null, null, depName, name, position);
+		}
+		mm.put("totalRecordCount", totalCount);
 		return mm;
 	}
 
@@ -115,7 +119,7 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
 		}
 
 		if (list.isEmpty()) {
-			return list;
+			list = salesReportMapper.selectPersonalByPage(pageNo, pageSize, depName, name, position);
 		}
 
 		Map<String, PersonalSalesReportBO> map = new HashMap<>();