educode_sales 0.9.93 → 0.9.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51508cb445eacf64d62d59e0f437507abf2d9e5434f53a36096afe63b28f08e0
4
- data.tar.gz: 06d6f1f375007355722c3ece45f56c509891dda30f3426c09a7c0d2d2cbbcf0e
3
+ metadata.gz: 9b7b6e63bd6432ce355c059bed56cd08ec327575c300211edfdd7456b47f803e
4
+ data.tar.gz: 425005691f9b2a971c971468428dc4f4f48e269adba413531e0eafb3e744abcc
5
5
  SHA512:
6
- metadata.gz: 6b5990a12fffd0ffee4f15cb36285b260fafa8e20a99823459a53267eedb8277c8747bcd8a9a6d98d9845845b87ec8893b2b4986d0cd665ed47f8b314758a861
7
- data.tar.gz: d38671efcd59171eb66ac920c045e46c0a4bf97f6117cc9b8fd3e714a8640a76729d6374c4c2292769a526cec6a614df51bb0c90795d7b40e1e97b525599e5b0
6
+ metadata.gz: ef43f0359464d39687502f0e5ba43c01855f5c9d9a6c53dc5a360a0ea79d8cb2b916d103e0d99519ff491cd4deb7a2ac9456b2a250b0bcf6c0d884b643168c8e
7
+ data.tar.gz: 4397b3bef68f798255cccac646cb30f706d0161daa8596f55891b261c0ddd4b93c81c5b4f2b2966856ca970607e02bb6d7a8ba80f4237447967c905eb425b65f
@@ -166,7 +166,7 @@ module EducodeSales
166
166
  respond_to do |format|
167
167
  format.html do
168
168
  common = Common.find_by(clazz: 'staff_type', name: '销售')
169
- @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
169
+ @staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
170
170
  gon.school_tags = SchoolTag.where(for_missions: true).map { |d| {value: d.id, name: d.name } }
171
171
  end
172
172
  format.json do
@@ -199,7 +199,9 @@ module EducodeSales
199
199
  schools.*,
200
200
  s.major_count,
201
201
  s.department_id,
202
- departments.name AS department_name
202
+ departments.name AS department_name,
203
+ (SELECT COUNT(user_extensions.id) FROM user_extensions WHERE user_extensions.department_id = s.department_id AND user_extensions.identity = 0) AS teacher_count,
204
+ (SELECT COUNT(user_extensions.id) FROM user_extensions WHERE user_extensions.department_id = s.department_id AND user_extensions.identity = 1) AS student_count
203
205
  ").joins("
204
206
  JOIN schools ON s.id = schools.id
205
207
  LEFT JOIN departments ON s.department_id = departments.id
@@ -1,16 +1,28 @@
1
1
  x = EducodeSales::Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
2
2
  o = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
3
+ business_ids_group_a = EducodeSales::Business.where(department_id: @customers.map(&:department_id)).group_by(&:department_id)
4
+ business_ids_group_b = EducodeSales::Business.where(school_id: @customers.map(&:id)).group_by(&:school_id)
5
+ all_follow_ups = EducodeSales::FollowUp.where(business_id: business_ids_group_a.values.flatten.map(&:id) + business_ids_group_b.values.flatten.map(&:id))
6
+ customer_follows_a = EducodeSales::CustomerFollow.where(department_id: @customers.map(&:department_id)).group_by(&:department_id)
7
+ customer_follows_b = EducodeSales::CustomerFollow.where(school_id: @customers.map(&:id)).group_by(&:school_id)
8
+ all_school_tags = SchoolTag.joins(:school_tag_middles).where(school_tag_middles: { school_id: @customers.map(&:id) }).select(:school_id, :name, :for_missions)
9
+ business_count_group_a = EducodeSales::Business.where(department_id: @customers.map(&:department_id)).group(:department_id).count
10
+ business_count_group_b = EducodeSales::Business.where(school_id: @customers.map(&:id)).group(:school_id).count
11
+ o_business_count_group_a = EducodeSales::Business.where(department_id: @customers.map(&:department_id)).where("educode_sales_businesses.clazz_id = ?", o).group(:department_id).count
12
+ o_business_count_group_b = EducodeSales::Business.where(school_id: @customers.map(&:id)).where("educode_sales_businesses.clazz_id = ?", o).group(:school_id).count
13
+ all_staffs_group = EducodeSales::CustomerExtension.where(school_id: @customers.map(&:id)).includes(customer_staff: :user).group_by(&:school_id)
14
+
3
15
  json.data do
4
16
  json.array! @customers do |d|
5
17
  if d['department_id']
6
- business_ids = EducodeSales::Business.where(department_id: d['department_id']).ids
7
- customer_follows = EducodeSales::CustomerFollow.where(department_id: d['department_id'])
18
+ business_ids = business_ids_group_a[d['department_id']]&.map(&:id) || []
19
+ customer_follows = customer_follows_a[d['department_id']] || []
8
20
  else
9
- business_ids = EducodeSales::Business.where(school_id: d.id).ids
10
- customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
21
+ business_ids = business_ids_group_b[d.id]&.map(&:id) || []
22
+ customer_follows = customer_follows_b[d.id] || []
11
23
  end
12
- follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
13
-
24
+ follow_ups = all_follow_ups.select { |f| business_ids&.include?(f.business_id) }
25
+
14
26
  a_last_follow_time = follow_ups.last&.created_at&.to_s
15
27
  b_last_follow_time = customer_follows.last&.created_at&.to_s
16
28
  if a_last_follow_time.present? && b_last_follow_time.present?
@@ -21,24 +33,23 @@ json.data do
21
33
  json.id d.id
22
34
  json.name d.name
23
35
  json.area d.province
24
- json.property d.school_tags.where(for_missions: true).pluck(:name).join("、")
36
+ json.property all_school_tags.select { |t| t.school_id == d.id && t.for_missions? }.pluck(:name).join("、")
25
37
  if d['department_id']
26
- json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.department_id = ?", d['department_id']).size
27
- json.o_business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id = ?", o).where("educode_sales_businesses.department_id = ?", d['department_id']).size
38
+ json.business business_count_group_a[d['department_id']] || 0
39
+ json.o_business o_business_count_group_a[d['department_id']] || 0
28
40
  else
29
- json.business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_businesses.school_id = ?", d.id).size
30
- json.o_business EducodeSales::Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id = ?", o).where("educode_sales_businesses.school_id = ?", d.id).size
41
+ json.business business_count_group_b[d.id] || 0
42
+ json.o_business o_business_count_group_b[d.id] || 0
31
43
  end
32
44
  json.unit "#{d.name}---#{d['department_name']}"
33
-
34
- # json.follow follow_ups.size + customer_follows.size
45
+
35
46
  json.follow customer_follows.size
36
- json.staff EducodeSales::CustomerExtension.where(school_id: d.id).map { |d| d.customer_staff&.user&.real_name }.join("、")
47
+ json.staff all_staffs_group[d.id]&.map { |d| d.customer_staff&.user&.real_name }&.join("、")
37
48
  json.department d['department_name'] || ''
38
49
  json.major_count d['major_count']
39
50
  json.department_id d['department_id'] || ''
40
- json.teacher_counts UserExtension.where(department_id: d.department_id, identity: 'teacher').size
41
- json.student_counts UserExtension.where(department_id: d.department_id, identity: 'student').size
51
+ json.teacher_counts d['teacher_count']
52
+ json.student_counts d['student_count']
42
53
  end
43
54
  end
44
55
 
@@ -1,3 +1,3 @@
1
1
  module EducodeSales
2
- VERSION = '0.9.93'
2
+ VERSION = '0.9.94'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: educode_sales
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.93
4
+ version: 0.9.94
5
5
  platform: ruby
6
6
  authors:
7
7
  - anke1460