Commit eb7d970fdc59151a4f14faa5fbcfc2efe13c18a7
1 parent
1b27857c
update
Showing
9 changed files
with
83 additions
and
53 deletions
src/main/java/com/bsth/service/BaseService.java
| ... | ... | @@ -4,6 +4,7 @@ import org.springframework.data.domain.Page; |
| 4 | 4 | import org.springframework.data.domain.Pageable; |
| 5 | 5 | |
| 6 | 6 | import java.io.Serializable; |
| 7 | +import java.util.Collection; | |
| 7 | 8 | import java.util.Map; |
| 8 | 9 | |
| 9 | 10 | /** |
| ... | ... | @@ -70,4 +71,11 @@ public interface BaseService<T, ID extends Serializable> { |
| 70 | 71 | * @return {status:状态编码,msg:错误描述},状态编码 @see com.bsth.common.ResponseCode |
| 71 | 72 | */ |
| 72 | 73 | Map<String, Object> validateEquale(Map<String, Object> params); |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 批量保存。 | |
| 77 | + * @param entities 实体列表 | |
| 78 | + * @return 保存后的entities | |
| 79 | + */ | |
| 80 | + <S extends T> Collection<S> bulkSave(Collection<S> entities); | |
| 73 | 81 | } | ... | ... |
src/main/java/com/bsth/service/impl/BaseServiceImpl.java
| ... | ... | @@ -7,18 +7,23 @@ import com.bsth.service.BaseService; |
| 7 | 7 | import org.slf4j.Logger; |
| 8 | 8 | import org.slf4j.LoggerFactory; |
| 9 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.beans.factory.annotation.Value; | |
| 10 | 11 | import org.springframework.dao.DataIntegrityViolationException; |
| 11 | 12 | import org.springframework.data.domain.Page; |
| 12 | 13 | import org.springframework.data.domain.Pageable; |
| 13 | 14 | |
| 15 | +import javax.persistence.EntityManager; | |
| 14 | 16 | import java.io.Serializable; |
| 15 | -import java.util.HashMap; | |
| 16 | -import java.util.Map; | |
| 17 | +import java.util.*; | |
| 17 | 18 | |
| 18 | 19 | public class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID>{ |
| 19 | 20 | |
| 20 | 21 | @Autowired |
| 21 | 22 | private BaseRepository<T, ID> baseRepository; |
| 23 | + @Autowired | |
| 24 | + private EntityManager entityManager; | |
| 25 | + @Value("${hibernate.jdbc.batch_size}") | |
| 26 | + private int batchSize; | |
| 22 | 27 | |
| 23 | 28 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 24 | 29 | |
| ... | ... | @@ -50,9 +55,25 @@ public class BaseServiceImpl<T, ID extends Serializable> implements BaseService< |
| 50 | 55 | } |
| 51 | 56 | return map; |
| 52 | 57 | } |
| 53 | - | |
| 54 | 58 | |
| 55 | - @Override | |
| 59 | + @Override | |
| 60 | + public <S extends T> Collection<S> bulkSave(Collection<S> entities) { | |
| 61 | + final List<S> savedEntities = new ArrayList<>(entities.size()); | |
| 62 | + int i = 0; | |
| 63 | + for (S t : entities) { | |
| 64 | + entityManager.persist(t); | |
| 65 | + savedEntities.add(t); | |
| 66 | + i++; | |
| 67 | + if (i % batchSize == 0) { | |
| 68 | + entityManager.flush(); | |
| 69 | + entityManager.clear(); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + | |
| 73 | + return savedEntities; | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 56 | 77 | public Iterable<T> findAll() { |
| 57 | 78 | return baseRepository.findAll(); |
| 58 | 79 | } | ... | ... |
src/main/java/com/bsth/service/schedule/SchedulePlanServiceImpl.java
| ... | ... | @@ -101,7 +101,7 @@ public class SchedulePlanServiceImpl extends BaseServiceImpl<SchedulePlan, Long> |
| 101 | 101 | // 人员配置对应的人员 |
| 102 | 102 | EmployeeConfigInfo employeeConfigInfo = employeeConfigMaps.get(scheduleResult_output.getEmployeeConfigId()); |
| 103 | 103 | // 排班明细(这个要迭代的) |
| 104 | - Collection<TTInfoDetail> ttInfoDetails = gbdTTinfoMaps.get(scheduleResult_output.getGuideboardId()); | |
| 104 | + Collection<TTInfoDetail> ttInfoDetails = gbdTTinfoMaps.get(Long.parseLong(scheduleResult_output.getGuideboardId())); | |
| 105 | 105 | for (TTInfoDetail ttInfoDetail : ttInfoDetails) { |
| 106 | 106 | SchedulePlanInfo schedulePlanInfo = new SchedulePlanInfo( |
| 107 | 107 | xl, | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResult_output.java
| ... | ... | @@ -9,13 +9,13 @@ public class ScheduleResult_output { |
| 9 | 9 | /** 具体日期 */ |
| 10 | 10 | private DateTime sd; |
| 11 | 11 | /** 用的是哪一组rule */ |
| 12 | - private Long ruleId; | |
| 12 | + private String ruleId; | |
| 13 | 13 | /** 路牌id */ |
| 14 | - private Long guideboardId; | |
| 14 | + private String guideboardId; | |
| 15 | 15 | /** 人员配置id */ |
| 16 | - private Long employeeConfigId; | |
| 16 | + private String employeeConfigId; | |
| 17 | 17 | /** 车辆配置id */ |
| 18 | - private Long carConfigId; | |
| 18 | + private String carConfigId; | |
| 19 | 19 | |
| 20 | 20 | public DateTime getSd() { |
| 21 | 21 | return sd; |
| ... | ... | @@ -25,36 +25,35 @@ public class ScheduleResult_output { |
| 25 | 25 | this.sd = sd; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public Long getGuideboardId() { | |
| 28 | + public String getRuleId() { | |
| 29 | + return ruleId; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public void setRuleId(String ruleId) { | |
| 33 | + this.ruleId = ruleId; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public String getGuideboardId() { | |
| 29 | 37 | return guideboardId; |
| 30 | 38 | } |
| 31 | 39 | |
| 32 | - public void setGuideboardId(Long guideboardId) { | |
| 40 | + public void setGuideboardId(String guideboardId) { | |
| 33 | 41 | this.guideboardId = guideboardId; |
| 34 | 42 | } |
| 35 | 43 | |
| 36 | - public Long getEmployeeConfigId() { | |
| 44 | + public String getEmployeeConfigId() { | |
| 37 | 45 | return employeeConfigId; |
| 38 | 46 | } |
| 39 | 47 | |
| 40 | - public void setEmployeeConfigId(Long employeeConfigId) { | |
| 48 | + public void setEmployeeConfigId(String employeeConfigId) { | |
| 41 | 49 | this.employeeConfigId = employeeConfigId; |
| 42 | 50 | } |
| 43 | 51 | |
| 44 | - public Long getCarConfigId() { | |
| 52 | + public String getCarConfigId() { | |
| 45 | 53 | return carConfigId; |
| 46 | 54 | } |
| 47 | 55 | |
| 48 | - public void setCarConfigId(Long carConfigId) { | |
| 56 | + public void setCarConfigId(String carConfigId) { | |
| 49 | 57 | this.carConfigId = carConfigId; |
| 50 | 58 | } |
| 51 | - | |
| 52 | - public Long getRuleId() { | |
| 53 | - return ruleId; | |
| 54 | - } | |
| 55 | - | |
| 56 | - public void setRuleId(Long ruleId) { | |
| 57 | - this.ruleId = ruleId; | |
| 58 | - } | |
| 59 | - | |
| 60 | 59 | } | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleResults_output.java
| ... | ... | @@ -25,7 +25,7 @@ public class ScheduleResults_output { |
| 25 | 25 | */ |
| 26 | 26 | public String showGuideboardDesc1() { |
| 27 | 27 | StringBuilder stringBuilder = new StringBuilder(); |
| 28 | - Map<Long, List<ScheduleResult_output>> groupRuleIdGuideBoardMap = new HashMap<>(); | |
| 28 | + Map<String, List<ScheduleResult_output>> groupRuleIdGuideBoardMap = new HashMap<>(); | |
| 29 | 29 | for (ScheduleResult_output s : results) { |
| 30 | 30 | if (groupRuleIdGuideBoardMap.get(s.getRuleId()) == null) { |
| 31 | 31 | groupRuleIdGuideBoardMap.put(s.getRuleId(), new ArrayList<ScheduleResult_output>()); |
| ... | ... | @@ -33,7 +33,7 @@ public class ScheduleResults_output { |
| 33 | 33 | groupRuleIdGuideBoardMap.get(s.getRuleId()).add(s); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - for (Long ruleId : groupRuleIdGuideBoardMap.keySet()) { | |
| 36 | + for (String ruleId : groupRuleIdGuideBoardMap.keySet()) { | |
| 37 | 37 | Collections.sort(groupRuleIdGuideBoardMap.get(ruleId), new Comparator<ScheduleResult_output>() { |
| 38 | 38 | @Override |
| 39 | 39 | public int compare(ScheduleResult_output o1, ScheduleResult_output o2) { |
| ... | ... | @@ -41,8 +41,8 @@ public class ScheduleResults_output { |
| 41 | 41 | } |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | - List<Long> gbids = new ArrayList<>(); | |
| 45 | - List<Long> ecids = new ArrayList<>(); | |
| 44 | + List<String> gbids = new ArrayList<>(); | |
| 45 | + List<String> ecids = new ArrayList<>(); | |
| 46 | 46 | for (ScheduleResult_output so : groupRuleIdGuideBoardMap.get(ruleId)) { |
| 47 | 47 | gbids.add(so.getGuideboardId()); |
| 48 | 48 | ecids.add(so.getEmployeeConfigId()); | ... | ... |
src/main/java/com/bsth/service/schedule/rules/shiftloop/ScheduleRule_input.java
| ... | ... | @@ -12,7 +12,7 @@ import java.util.List; |
| 12 | 12 | */ |
| 13 | 13 | public class ScheduleRule_input { |
| 14 | 14 | /** 规则Id */ |
| 15 | - private Long ruleId; | |
| 15 | + private String ruleId; | |
| 16 | 16 | /** 规则启用日期 */ |
| 17 | 17 | private DateTime qyrq; |
| 18 | 18 | |
| ... | ... | @@ -27,14 +27,14 @@ public class ScheduleRule_input { |
| 27 | 27 | private int startEIndex; |
| 28 | 28 | |
| 29 | 29 | /** 车辆配置id */ |
| 30 | - private Long carConfigId; | |
| 30 | + private String carConfigId; | |
| 31 | 31 | |
| 32 | 32 | // TODO:车辆翻班暂时不考虑进去 |
| 33 | 33 | |
| 34 | 34 | public ScheduleRule_input() {} |
| 35 | 35 | |
| 36 | 36 | public ScheduleRule_input(ScheduleRule1Flat scheduleRule1Flat) { |
| 37 | - this.ruleId = scheduleRule1Flat.getId(); | |
| 37 | + this.ruleId = String.valueOf(scheduleRule1Flat.getId()); | |
| 38 | 38 | this.qyrq = new DateTime(scheduleRule1Flat.getQyrq()); |
| 39 | 39 | List<String> lpIds = Splitter.on(",").splitToList(scheduleRule1Flat.getLpIds()); |
| 40 | 40 | // for (String lpId : lpIds) { |
| ... | ... | @@ -50,14 +50,14 @@ public class ScheduleRule_input { |
| 50 | 50 | employeeConfigIds.addAll(ryCids); |
| 51 | 51 | // 人员初始索引减1 |
| 52 | 52 | this.startEIndex = scheduleRule1Flat.getRyStart() - 1; |
| 53 | - this.carConfigId = scheduleRule1Flat.getCarConfigInfo().getId(); | |
| 53 | + this.carConfigId = String.valueOf(scheduleRule1Flat.getCarConfigInfo().getId()); | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public Long getRuleId() { | |
| 56 | + public String getRuleId() { | |
| 57 | 57 | return ruleId; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public void setRuleId(Long ruleId) { | |
| 60 | + public void setRuleId(String ruleId) { | |
| 61 | 61 | this.ruleId = ruleId; |
| 62 | 62 | } |
| 63 | 63 | |
| ... | ... | @@ -101,11 +101,11 @@ public class ScheduleRule_input { |
| 101 | 101 | this.startEIndex = startEIndex; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public Long getCarConfigId() { | |
| 104 | + public String getCarConfigId() { | |
| 105 | 105 | return carConfigId; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - public void setCarConfigId(Long carConfigId) { | |
| 108 | + public void setCarConfigId(String carConfigId) { | |
| 109 | 109 | this.carConfigId = carConfigId; |
| 110 | 110 | } |
| 111 | 111 | } | ... | ... |
src/main/resources/application.properties
src/main/resources/rules/shiftloop.drl
| ... | ... | @@ -15,7 +15,7 @@ import com.bsth.service.schedule.rules.shiftloop.ScheduleResults_output; |
| 15 | 15 | //------------------------- 第一阶段、计算规则准备数据(天数) ----------------------------// |
| 16 | 16 | |
| 17 | 17 | declare Calcu_days_result |
| 18 | - ruleId : Long // 规则Id | |
| 18 | + ruleId : String // 规则Id | |
| 19 | 19 | qyrq_days : Integer // 开始日期离启用日期的天数 |
| 20 | 20 | sdays : Integer // 总共需要排班的天数 |
| 21 | 21 | calcu_start_date : DateTime // 开始计算日期 |
| ... | ... | @@ -104,18 +104,18 @@ end |
| 104 | 104 | |
| 105 | 105 | //----------------------- 路牌范围循环计算 ------------------------// |
| 106 | 106 | declare Calcu_guideboard_index_result |
| 107 | - ruleId : Long // 规则Id | |
| 107 | + ruleId : String // 规则Id | |
| 108 | 108 | calcu_index : Integer // 计算之后的起始索引 |
| 109 | 109 | end |
| 110 | 110 | declare Calcu_guideboard_index_param_1 |
| 111 | - ruleId : Long // 规则Id | |
| 111 | + ruleId : String // 规则Id | |
| 112 | 112 | oindex : Integer // 原始起始索引 |
| 113 | 113 | range_size : Integer // 范围大小 |
| 114 | 114 | temp : Integer // 原始起始索引距离最后一个索引的大小 |
| 115 | 115 | days_temp : Integer // 开始日期离启用日期的天数 - temp |
| 116 | 116 | end |
| 117 | 117 | declare Calcu_guideboard_index_param_2 |
| 118 | - ruleId : Long // 规则Id | |
| 118 | + ruleId : String // 规则Id | |
| 119 | 119 | s_value : Integer // 商 |
| 120 | 120 | y_value : Integer // 余 |
| 121 | 121 | end |
| ... | ... | @@ -217,18 +217,18 @@ end |
| 217 | 217 | |
| 218 | 218 | //----------------------- 人员范围循环计算 ------------------------// |
| 219 | 219 | declare Calcu_employee_index_result |
| 220 | - ruleId : Long // 规则Id | |
| 220 | + ruleId : String // 规则Id | |
| 221 | 221 | calcu_index : Integer // 计算之后的起始索引 |
| 222 | 222 | end |
| 223 | 223 | declare Calcu_employee_index_param_1 |
| 224 | - ruleId : Long // 规则Id | |
| 224 | + ruleId : String // 规则Id | |
| 225 | 225 | oindex : Integer // 原始起始索引 |
| 226 | 226 | range_size : Integer // 范围大小 |
| 227 | 227 | temp : Integer // 原始起始索引距离最后一个索引的大小 |
| 228 | 228 | days_temp : Integer // 开始日期离启用日期的天数 - temp |
| 229 | 229 | end |
| 230 | 230 | declare Calcu_employee_index_param_2 |
| 231 | - ruleId : Long // 规则Id | |
| 231 | + ruleId : String // 规则Id | |
| 232 | 232 | s_value : Integer // 商 |
| 233 | 233 | y_value : Integer // 余 |
| 234 | 234 | end |
| ... | ... | @@ -332,7 +332,7 @@ end |
| 332 | 332 | |
| 333 | 333 | //----------------------- 路牌范围循环计算 ------------------------// |
| 334 | 334 | declare Calcu_guideboard_range_loop_result |
| 335 | - ruleId : Long // 规则Id | |
| 335 | + ruleId : String // 规则Id | |
| 336 | 336 | firstLoopSize : Integer // 初始的范围循环个数 |
| 337 | 337 | middelLoopCount : Integer // 中间的范围循环次数 |
| 338 | 338 | rangeSize : Integer // 范围大小 |
| ... | ... | @@ -340,7 +340,7 @@ declare Calcu_guideboard_range_loop_result |
| 340 | 340 | end |
| 341 | 341 | |
| 342 | 342 | declare Calcu_guideboard_range_loop_param |
| 343 | - ruleId : Long // 规则Id | |
| 343 | + ruleId : String // 规则Id | |
| 344 | 344 | temp : Integer // 起始索引距离最后一个索引的大小 |
| 345 | 345 | sdays : Integer // 总共需要排班的天数 |
| 346 | 346 | end |
| ... | ... | @@ -409,7 +409,7 @@ end |
| 409 | 409 | |
| 410 | 410 | //----------------------- 人员范围循环计算 ------------------------// |
| 411 | 411 | declare Calcu_employee_range_loop_result |
| 412 | - ruleId : Long // 规则Id | |
| 412 | + ruleId : String // 规则Id | |
| 413 | 413 | firstLoopSize : Integer // 初始的范围循环个数 |
| 414 | 414 | middelLoopCount : Integer // 中间的范围循环次数 |
| 415 | 415 | rangeSize : Integer // 范围大小 |
| ... | ... | @@ -417,7 +417,7 @@ declare Calcu_employee_range_loop_result |
| 417 | 417 | end |
| 418 | 418 | |
| 419 | 419 | declare Calcu_employee_range_loop_param |
| 420 | - ruleId : Long // 规则Id | |
| 420 | + ruleId : String // 规则Id | |
| 421 | 421 | temp : Integer // 起始索引距离最后一个索引的大小 |
| 422 | 422 | sdays : Integer // 总共需要排班的天数 |
| 423 | 423 | end |
| ... | ... | @@ -489,7 +489,7 @@ end |
| 489 | 489 | |
| 490 | 490 | //----------------------- 路牌范围循环计算 ------------------------// |
| 491 | 491 | declare Calcu_loop_guideboard_result |
| 492 | - ruleId : Long // 规则id | |
| 492 | + ruleId : String // 规则id | |
| 493 | 493 | go_list : List // 路牌循环的列表 |
| 494 | 494 | end |
| 495 | 495 | |
| ... | ... | @@ -553,7 +553,7 @@ end |
| 553 | 553 | |
| 554 | 554 | //----------------------- 人员范围循环计算 ------------------------// |
| 555 | 555 | declare Calcu_loop_employee_result |
| 556 | - ruleId : Long // 规则id | |
| 556 | + ruleId : String // 规则id | |
| 557 | 557 | eo_list : List // 人员循环的列表 |
| 558 | 558 | end |
| 559 | 559 | ... | ... |
src/test/java/com/bsth/service/schedule/rules/DroolsRulesTest.java
| ... | ... | @@ -69,14 +69,14 @@ public class DroolsRulesTest { |
| 69 | 69 | scheduleCalcuParam_input.setTtinfoId(1L); |
| 70 | 70 | |
| 71 | 71 | ScheduleRule_input scheduleRule_input1 = new ScheduleRule_input(); |
| 72 | - scheduleRule_input1.setRuleId(1L); | |
| 72 | + scheduleRule_input1.setRuleId("1"); | |
| 73 | 73 | scheduleRule_input1.setQyrq(new DateTime(2016, 7, 22, 0, 0)); |
| 74 | 74 | scheduleRule_input1.getGuideboardIds().addAll(Arrays.asList( |
| 75 | - 9L, 9L , 8L ,8L ,7L ,7L ,6L ,6L, 5L, 5L, 4L, 4L, 3L, 3L, 2L, 2L, 1L, 1L)); | |
| 75 | + "9", "9" , "8" ,"8" ,"7" ,"7" ,"6" ,"6", "5", "5", "4", "4", "3", "3", "2", "2", "1", "1")); | |
| 76 | 76 | scheduleRule_input1.setStartGbdIndex(3); |
| 77 | - scheduleRule_input1.getEmployeeConfigIds().addAll(Arrays.asList(1L, 2L)); | |
| 77 | + scheduleRule_input1.getEmployeeConfigIds().addAll(Arrays.asList("1", "2")); | |
| 78 | 78 | scheduleRule_input1.setStartEIndex(1); |
| 79 | - scheduleRule_input1.setCarConfigId(1L); | |
| 79 | + scheduleRule_input1.setCarConfigId("1"); | |
| 80 | 80 | |
| 81 | 81 | // ScheduleRule_input scheduleRule_input2 = new ScheduleRule_input(); |
| 82 | 82 | // scheduleRule_input2.setRuleId(2L); | ... | ... |