Commit 44fbeee657b8cfc285a3613587446bf5964b2497

Authored by 廖磊
1 parent c42739f4

添加日期输入 班次准点率

src/main/java/com/bsth/controller/report/SheetController.java
... ... @@ -19,10 +19,10 @@ public class SheetController extends BaseController<Sheet, Integer>{
19 19 @Autowired
20 20 SheetService sheetService;
21 21 @RequestMapping(value = "/saveListSheet",method = RequestMethod.POST)
22   - public String saveListSheet(){
  22 + public String saveListSheet(@RequestParam String date){
23 23 String result="";
24 24 try {
25   - result = sheetService.saveSheetList();
  25 + result = sheetService.saveSheetList(date);
26 26 } catch (Exception e) {
27 27 // TODO Auto-generated catch block
28 28 e.printStackTrace();
... ...
src/main/java/com/bsth/data/schedule/thread/CalcOilThread.java
... ... @@ -34,7 +34,7 @@ public class CalcOilThread extends Thread{
34 34 dlbService.obtainDsq();
35 35 logger.info("计算路单里程加注量结束!");
36 36 logger.info("开始计算班次准点率....");
37   - sheetService.saveSheetList();
  37 + sheetService.saveSheetList("");
38 38 logger.info("计算班次准点率结束!");
39 39 //清除安全驾驶数据 先临时蹭这个线程
40 40 SafeDrivCenter.clear();
... ...
src/main/java/com/bsth/repository/sheet/SheetRepository.java
... ... @@ -2,6 +2,8 @@ package com.bsth.repository.sheet;
2 2  
3 3 import com.bsth.entity.sheet.Sheet;
4 4 import com.bsth.repository.BaseRepository;
  5 +
  6 +import org.springframework.data.jpa.repository.Query;
5 7 import org.springframework.stereotype.Repository;
6 8  
7 9 /**
... ... @@ -9,4 +11,6 @@ import org.springframework.stereotype.Repository;
9 11 */
10 12 @Repository
11 13 public interface SheetRepository extends BaseRepository<Sheet, Integer>{
  14 + @Query(value = "select count(*) from Sheet s where s.date = ?1")
  15 + int countByDate(String date);
12 16 }
... ...
src/main/java/com/bsth/service/report/SheetService.java
... ... @@ -8,7 +8,7 @@ import com.bsth.service.BaseService;
8 8  
9 9 public interface SheetService extends BaseService<Sheet, Integer>{
10 10 public List<Map<String, Object>> bcPunctual(Map<String, Object> map);
11   - public String saveSheetList() throws Exception;
  11 + public String saveSheetList(String date) throws Exception;
12 12 public List<Map<String, Object>> countList(Map<String, Object> map);
13 13  
14 14 public List<Sheet> sheetList(Integer id);
... ...
src/main/java/com/bsth/service/report/impl/SheetServiceImpl.java
... ... @@ -82,48 +82,53 @@ public class SheetServiceImpl extends BaseServiceImpl&lt;Sheet, Integer&gt; implements
82 82 return fage;
83 83 }
84 84 @Override
85   - public String saveSheetList() throws Exception{
  85 + public String saveSheetList(String rq) throws Exception{
86 86 Map<String, Object> map=new HashMap<String,Object>();
87 87 String result = "failure";
  88 +
88 89 try {
89 90 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
90   - Date dNow = new Date(); //当前时间
91   - Calendar calendar = Calendar.getInstance(); //得到日历
92   - calendar.setTime(dNow);//把当前时间赋给日历
93   - calendar.add(Calendar.DAY_OF_MONTH, -3); //设置为前三天
94   -
95   - String rq=sdf.format(calendar.getTime());
96   -// String rq="2017-05-16";
97   -
98   - List<Line> lineList = (List<Line>) lineRepository.findAll();
99 91  
100   - List<ScheduleRealInfo> lists= scheduleRealInfoRepository.findByDate(rq);
101   - List<Sheet> listAdds=new ArrayList<Sheet>();
102   - for (int i = 0; i < lineList.size(); i++) {
103   - List<ScheduleRealInfo> list=new ArrayList<ScheduleRealInfo>();
104   - String line=lineList.get(i).getLineCode();
105   - for (int j = 0; j < lists.size(); j++) {
106   - ScheduleRealInfo s=lists.get(j);
107   - if(!isInOut(s)){
108   - if(s.getXlBm().equals(line)){
109   - list.add(s);
  92 + if(rq.equals("")){
  93 + Date dNow = new Date(); //当前时间
  94 + Calendar calendar = Calendar.getInstance(); //得到日历
  95 + calendar.setTime(dNow);//把当前时间赋给日历
  96 + calendar.add(Calendar.DAY_OF_MONTH, -3); //设置为前三天
  97 + rq=sdf.format(calendar.getTime());
  98 + }
  99 + int count=sheetRepository.countByDate(rq);
  100 + if(count<=0){
  101 + List<Line> lineList = (List<Line>) lineRepository.findAll();
  102 +
  103 + List<ScheduleRealInfo> lists= scheduleRealInfoRepository.findByDate(rq);
  104 + List<Sheet> listAdds=new ArrayList<Sheet>();
  105 + for (int i = 0; i < lineList.size(); i++) {
  106 + List<ScheduleRealInfo> list=new ArrayList<ScheduleRealInfo>();
  107 + String line=lineList.get(i).getLineCode();
  108 + for (int j = 0; j < lists.size(); j++) {
  109 + ScheduleRealInfo s=lists.get(j);
  110 + if(!isInOut(s)){
  111 + if(s.getXlBm().equals(line)){
  112 + list.add(s);
  113 + }
110 114 }
111 115 }
112   -
113   - }
114   - if(list.size()>0){
115   - List<Sheet> listAdd=punctualByLine(line,list);
116   - if(listAdd.size()>0){
117   - listAdds.addAll(listAdd);
  116 + if(list.size()>0){
  117 + List<Sheet> listAdd=punctualByLine(line,list);
  118 + if(listAdd.size()>0){
  119 + listAdds.addAll(listAdd);
  120 + }
118 121 }
  122 +
119 123 }
120 124  
121   - }
122   -
123   - if(listAdds.size()>0){
124   - new BatchSaveUtils<Sheet>().saveList(listAdds, Sheet.class);
125   - }
126   - result = "success";
  125 + if(listAdds.size()>0){
  126 + new BatchSaveUtils<Sheet>().saveList(listAdds, Sheet.class);
  127 + }
  128 + result = "success";
  129 + }else{
  130 + result ="count";
  131 + }
127 132 }catch (Exception e) {
128 133 // TODO Auto-generated catch block
129 134 throw e;
... ...