Browse Source

导出excel

wangjianguo 9 years ago
parent
commit
4a3145c523

+ 23 - 2
VisualInspection/js/statistics/assess_ranking.js

@@ -55,7 +55,7 @@ function getEmployeeInfos(url,param){
                 +"<td width='67px;'>"+getItemScore(data[i], '仪容仪表')+"</td><td width='67px;'>"+getItemScore(data[i], '表情')+"</td>"
                 +"<td width='67px;'>"+getItemScore(data[i], '动作')+"</td><td width='67px;'>"+getItemScore(data[i], '文明用语')+"</td>"
                 +"<td width='67px;'>"+ getItemScore(data[i], '工作纪律') +"</td><td width='67px;'>"+data[i].check_all_score+"</td>"
-                +"<td width='67px;'>"+filter(data[i].checked_num,'0')+"</td><td width='67px;'>"+average(data[i])+"</td>"
+                +"<td width='67px;'>"+filter(data[i].checked_num,'0')+"</td><td width='67px;'>"+filterByZeroHandle(average(data[i]).toFixed(2),'0')+"</td>"
                 +"<td width='75px;'>"+"</td><td>"+"</td></tr>";
         }
        $(".table-tbody").append(strTbody);   
@@ -104,6 +104,27 @@ function getItemScore(obj, check_item_name){
     return 0 ;
 }
 
+function filterByZeroHandle(value , default_display_value){
+        if(isNaN(value)|| value=='0.00'){
+            return default_display_value ;
+        }else{
+            return value ;
+        }
+       
+}
 
-
+function exportExcel(){
+    var start_date = $("#start-time").val();
+    var end_date = $("#end-time").val();
+    var dept_id = $("#fsList").val();
+    if(start_date==null||start_date==''||start_date==undefined||end_date==null||end_date==''||end_date==undefined){
+        tip("请选择起止日期");
+        return ;
+    }else{
+        start_date += " 00:00:00";
+        end_date += " 00:00:00";
+    }
+    window.open("http://localhost:8089/file/employee/order?dept_id="+dept_id+"&start_date="+start_date+"&end_date="+end_date);
+    //window.location.href="http://localhost:8089/file/employee/order?id="+dept_id+"&start="+start_date+"&end="+end_date;
+}
 

+ 1 - 1
VisualInspection/view/statistics/emp_ranking.html

@@ -20,7 +20,7 @@
                     <button class="btn btn-primary " type="button" onclick="queryEmpClick()">查询</button>
                 </div>
                 <div class="col-sm-6">
-                    <button class="btn btn-primary " type="button" >导出Excel</button>
+                    <button class="btn btn-primary " type="button" onclick="exportExcel()">导出Excel</button>
                 </div>
             </div>
         </form>

+ 4 - 0
VisualInspection_server/src/main/java/com/xintong/visualinspection/bean/StatisticsBo.java

@@ -25,4 +25,8 @@ public class StatisticsBo {
     
     private User user;
     
+    //private Integer[] emp_assess;
+    
+    private int check_score_avg;
+    
 }

+ 17 - 3
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/FileExcelController.java

@@ -1,5 +1,8 @@
 package com.xintong.visualinspection.controller;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -9,10 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.xintong.visualinspection.bean.StatisticsBean;
-import com.xintong.visualinspection.bean.StatisticsBo;
 import com.xintong.visualinspection.service.StatisticsService;
 
 /**
@@ -34,8 +37,19 @@ public class FileExcelController extends BaseController {
      * @since  1.0.0
      */
     @RequestMapping(value = "/employee/order",method=RequestMethod.GET)
-    public String getEmployeeOrder(HttpServletRequest req,HttpServletResponse resp){
-    	 statisticsService.getEmployeeCheckedInfo(new StatisticsBean(), req, resp);
+    public String getEmployeeOrder(HttpServletRequest req,HttpServletResponse resp,@RequestParam Long dept_id,@RequestParam String start_date,@RequestParam String end_date){
+    	StatisticsBean obj = new StatisticsBean();
+    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
+    	try {
+			Date start = sdf.parse(start_date);
+			Date end = sdf.parse(end_date);
+			obj.setDept_id(dept_id);
+			obj.setStart_date(start);
+			obj.setEnd_date(end);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+    	statisticsService.getEmployeeCheckedInfo(obj, req, resp);
     	return super.returnSuccessResult(null);
     }
     

+ 92 - 79
VisualInspection_server/src/main/java/com/xintong/visualinspection/service/impl/StatisticsServiceImpl.java

@@ -32,88 +32,88 @@ import com.xintong.visualinspection.service.BaseService;
 import com.xintong.visualinspection.service.StatisticsService;
 
 /**
- * 文件名:StatisticsServiceImpl
- * 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
+ * 文件名:StatisticsServiceImpl 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation
+ * 2017 版权所有.
  */
 @Service
 public class StatisticsServiceImpl extends BaseService implements StatisticsService {
 
-    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(StatisticsServiceImpl.class);
-
-    @Autowired
-    private StatisticsDao statisticsDao ;
-    
-    @Autowired
-    private DepartmentDao departmentDao ;
-    
-    @Autowired
-    private UserInfoDao userInfoDao;
-    
+	private static final org.slf4j.Logger logger = LoggerFactory.getLogger(StatisticsServiceImpl.class);
+
+	@Autowired
+	private StatisticsDao statisticsDao;
+
+	@Autowired
+	private DepartmentDao departmentDao;
+
+	@Autowired
+	private UserInfoDao userInfoDao;
+
 	@Override
 	public List<StatisticsBo> getEmployeeCheckedInfo(StatisticsBean obj) {
 		// 查看是否有部门id
 		Long organId = obj.getDept_id();
 		// 将检索出来的数据放到如map中
 		List<StatisticsBean> list = statisticsDao.selectStatistics(obj);
-		
+
 		List<StatisticsBean> timesList = statisticsDao.selectCheckedTimes(obj);
-		
-		Map<Long,StatisticsBo> statisticBoMap = new HashMap<Long,StatisticsBo>();
-		
+
+		Map<Long, StatisticsBo> statisticBoMap = new HashMap<Long, StatisticsBo>();
+
 		User user = new User();
 		user.setPositionid(1);
-		if(obj.getDept_id()!=null)
+		if (obj.getDept_id() != null)
 			user.setOrganid(obj.getDept_id().intValue());
 		List<User> listUserts = userInfoDao.getUsers(user);
-		for(User u:listUserts){
-			if(u.getFee_station_name()!=null){
+		for (User u : listUserts) {
+			if (u.getFee_station_name() != null) {
 				StatisticsBo tmp = new StatisticsBo();
 				tmp.setUser(u);
-				statisticBoMap.put(u.getId()+0L, tmp);				
+				statisticBoMap.put(u.getId() + 0L, tmp);
 			}
 		}
-		
-//		for(User user:CacheUtil.userMap.values()){
-//			if(user.getPositionid() ==1){
-//				if(organId ==null ||  user.getOrganid()+0L == organId+0L ){
-//					StatisticsBo tmp = new StatisticsBo();
-//					tmp.setUser(user);
-//					statisticBoMap.put(user.getId()+0L,tmp);
-//				}
-//			}
-//		}
-		
-		for( StatisticsBean statisticsBean : list ){
-			if(statisticBoMap.containsKey(statisticsBean.getUser_id())){
+
+		// for(User user:CacheUtil.userMap.values()){
+		// if(user.getPositionid() ==1){
+		// if(organId ==null || user.getOrganid()+0L == organId+0L ){
+		// StatisticsBo tmp = new StatisticsBo();
+		// tmp.setUser(user);
+		// statisticBoMap.put(user.getId()+0L,tmp);
+		// }
+		// }
+		// }
+
+		for (StatisticsBean statisticsBean : list) {
+			if (statisticBoMap.containsKey(statisticsBean.getUser_id())) {
 				StatisticsBo tmp = statisticBoMap.get(statisticsBean.getUser_id());
-				if(statisticsBean.getName()!=null && statisticsBean.getScore()!=null){
+				if (statisticsBean.getName() != null && statisticsBean.getScore() != null) {
 					tmp.getChecked_socre_name().add(statisticsBean.getName());
 					tmp.getChecked_score().add(statisticsBean.getScore());
-					tmp.setCheck_all_score(tmp.getCheck_all_score()+statisticsBean.getScore() );					
+					tmp.setCheck_all_score(tmp.getCheck_all_score() + statisticsBean.getScore());
 				}
 			}
 		}
-		
-		for(StatisticsBean statisticsBean : timesList){
-			if(statisticBoMap.containsKey(statisticsBean.getUser_id())){
+
+		for (StatisticsBean statisticsBean : timesList) {
+			if (statisticBoMap.containsKey(statisticsBean.getUser_id())) {
 				StatisticsBo tmp = statisticBoMap.get(statisticsBean.getUser_id());
 				tmp.setChecked_num(statisticsBean.getChecked_num());
 			}
 		}
-		
+
 		List<StatisticsBo> lists = new ArrayList<>(statisticBoMap.values());
 		// 进行排序
 		lists.sort(new Comparator<StatisticsBo>() {
 			@Override
 			public int compare(StatisticsBo o1, StatisticsBo o2) {
-				if(o1.getCheck_all_score() >= o2.getCheck_all_score() ){
+				if (o1.getCheck_all_score() >= o2.getCheck_all_score()) {
 					return 1;
-				}else{
-					return -1 ;
+				} else {
+					return -1;
 				}
 			}
 		});
-	
+
 		return lists;
 	}
 
@@ -121,35 +121,35 @@ public class StatisticsServiceImpl extends BaseService implements StatisticsServ
 	public List<StatisticsBean> getFeeStationCheckedScore(StatisticsBean obj) {
 		// 获取收费站信息收费站人数
 		List<StatisticsBean> lists = departmentDao.selectFeeStationGroup(obj);
-		Map<Long,StatisticsBean> mapStationInfos = new HashMap<>();
-		for(StatisticsBean sta:lists){
+		Map<Long, StatisticsBean> mapStationInfos = new HashMap<>();
+		for (StatisticsBean sta : lists) {
 			mapStationInfos.put(sta.getDept_id(), sta);
 		}
-		
+
 		// 检查人数 和 检查次数
 		List<StatisticsBean> listCheckNum = statisticsDao.selectFeeStationCheckNum(obj);
-		for(StatisticsBean sta:listCheckNum){
-			if(mapStationInfos.containsKey(sta.getDept_id())){
+		for (StatisticsBean sta : listCheckNum) {
+			if (mapStationInfos.containsKey(sta.getDept_id())) {
 				mapStationInfos.get(sta.getDept_id()).setChecked_num(sta.getChecked_num());
 				mapStationInfos.get(sta.getDept_id()).setChecked_people_num(sta.getChecked_people_num());
 			}
 		}
-		
+
 		List<StatisticsBean> listCheckedScore = statisticsDao.selectFeeStationCheckedScore(obj);
-		for(StatisticsBean sta:listCheckedScore){
-			if(mapStationInfos.containsKey(sta.getDept_id())){
+		for (StatisticsBean sta : listCheckedScore) {
+			if (mapStationInfos.containsKey(sta.getDept_id())) {
 				StatisticsBean statis = mapStationInfos.get(sta.getDept_id());
-				statis.setAll_check_score( statis.getAll_check_score()+sta.getScore());
-				if(sta.getScore() <= 15){
-					statis.setScore_fifteen(statis.getScore_fifteen()+1);
-				}else if(sta.getScore()<=50){
-					statis.setScore_fifty(statis.getScore_fifty()+1);
-				}else{
-					statis.setScore_over_fifty(statis.getScore_over_fifty()+1);
+				statis.setAll_check_score(statis.getAll_check_score() + sta.getScore());
+				if (sta.getScore() <= 15) {
+					statis.setScore_fifteen(statis.getScore_fifteen() + 1);
+				} else if (sta.getScore() <= 50) {
+					statis.setScore_fifty(statis.getScore_fifty() + 1);
+				} else {
+					statis.setScore_over_fifty(statis.getScore_over_fifty() + 1);
 				}
 			}
 		}
-		
+
 		return new ArrayList<>(mapStationInfos.values());
 	}
 
@@ -158,32 +158,32 @@ public class StatisticsServiceImpl extends BaseService implements StatisticsServ
 
 		// 获取收费站信息收费站人数
 		List<StatisticsBean> lists = departmentDao.selectFeeStationGroup(obj);
-		Map<Long,StatisticsBean> mapStationInfos = new HashMap<>();
-		for(StatisticsBean sta:lists){
+		Map<Long, StatisticsBean> mapStationInfos = new HashMap<>();
+		for (StatisticsBean sta : lists) {
 			mapStationInfos.put(sta.getDept_id(), sta);
 		}
-		
-		//  检查人数 和 检查次数
+
+		// 检查人数 和 检查次数
 		List<StatisticsBean> listCheckNum = statisticsDao.selectFeeStationCheckNum(obj);
-		for(StatisticsBean sta:listCheckNum){
-			if(mapStationInfos.containsKey(sta.getDept_id())){
+		for (StatisticsBean sta : listCheckNum) {
+			if (mapStationInfos.containsKey(sta.getDept_id())) {
 				mapStationInfos.get(sta.getDept_id()).setChecked_num(sta.getChecked_num());
 				mapStationInfos.get(sta.getDept_id()).setChecked_people_num(sta.getChecked_people_num());
 			}
 		}
-		
+
 		List<StatisticsBean> listCheckedScore = statisticsDao.selectFeeStationCheckedPersonScoreDetail(obj);
-		for(StatisticsBean sta:listCheckedScore){
-			if(mapStationInfos.containsKey(sta.getDept_id())){
+		for (StatisticsBean sta : listCheckedScore) {
+			if (mapStationInfos.containsKey(sta.getDept_id())) {
 				StatisticsBean statis = mapStationInfos.get(sta.getDept_id());
-				statis.setAll_check_score( statis.getAll_check_score()+sta.getScore());
+				statis.setAll_check_score(statis.getAll_check_score() + sta.getScore());
 				statis.getChecked_socre_name().add(sta.getName());
 				statis.getChecked_score().add(sta.getScore());
 			}
 		}
-		
+
 		return new ArrayList<>(mapStationInfos.values());
-	
+
 	}
 
 	@Override
@@ -191,9 +191,22 @@ public class StatisticsServiceImpl extends BaseService implements StatisticsServ
 		// 检索数据
 		List<StatisticsBo> listStatistic = getEmployeeCheckedInfo(obj);
 		// 处理数据
-		// todo ...   
-		
-		
+		//Integer[] emp_assess = new Integer[listStatistic.size()];
+		for (int i = 0; i < listStatistic.size(); i++) {
+			StatisticsBo st = new StatisticsBo();
+			st = listStatistic.get(i);
+			try {
+				st.setCheck_score_avg(listStatistic.get(i).getCheck_all_score() 
+						/ listStatistic.get(i).getChecked_num());
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			/*List<Integer> checked_score_list = st.getChecked_score();
+			for (int j = 0; j < checked_score_list.size(); i++) {
+				emp_assess[j] = checked_score_list.get(i);
+			}*/
+		}
+
 		String path = "D:/file20170606.xls";
 		try (InputStream is = this.getClass().getResourceAsStream("/employee_order.xls")) {
 			try (OutputStream os = new FileOutputStream(path)) {
@@ -222,7 +235,7 @@ public class StatisticsServiceImpl extends BaseService implements StatisticsServ
 			toClient.write(buffer);
 			toClient.flush();
 			toClient.close();
-		}catch(Exception e){
+		} catch (Exception e) {
 			logger.error(e.toString());
 		}
 	}
@@ -230,13 +243,13 @@ public class StatisticsServiceImpl extends BaseService implements StatisticsServ
 	@Override
 	public void getFeeStationCheckedScore(StatisticsBean obj, HttpServletRequest req, HttpServletResponse resp) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void getFeeStationCheckItemScore(StatisticsBean obj, HttpServletRequest req, HttpServletResponse resp) {
 		// TODO Auto-generated method stub
-		
+
 	}
-    
+
 }

BIN
VisualInspection_server/src/main/resources/employee_order.xls