Commit 0f87a7ef8d9312f6708c127a4163bf786eef7581

Authored by 娄高锋
1 parent d8d6d926

驾驶员出勤接口,添加按公司查询的版本

src/main/java/com/bsth/server_rs/bigdata/BigscreenService.java
@@ -800,6 +800,225 @@ public class BigscreenService { @@ -800,6 +800,225 @@ public class BigscreenService {
800 return JSON.parseObject(JSON.toJSONString(resMap)); 800 return JSON.parseObject(JSON.toJSONString(resMap));
801 } 801 }
802 802
  803 + @GET
  804 + @Path("/selectData/attendance/{gsdm}")
  805 + public JSONObject attendance(@PathParam("gsdm") String gsdm){
  806 + Map<String, Object> resMap = new HashMap<String, Object>();
  807 +
  808 + int day = 7;//天数
  809 +
  810 + Date dd = new Date();
  811 + String date = sd.format(dd); //yyyy-MM-dd 当天
  812 + Date dd2 = new Date();
  813 + dd2.setTime(dd.getTime() - ((long)(day-1))*1000*60*60*24);
  814 + String date2 = sd.format(dd2); //yyyy-MM-dd 6天前(加上当天就是取7天数据)
  815 +
  816 + String[] dates = new String[day];
  817 + Map<String, Integer> datesMap = new HashMap<String, Integer>();
  818 +
  819 + for(int i = 0; i < day; i++){
  820 + Date tempDate = new Date();
  821 + tempDate.setTime(dd2.getTime() + ((long)i)*1000*60*60*24);
  822 + String format = sd.format(tempDate);
  823 + dates[i] = format;
  824 + datesMap.put(format, i);
  825 + }
  826 +
  827 +
  828 + String yyxlSql="SELECT line_code from bsth_c_line "
  829 + + " where nature in ('yxl','cgxl','gjxl','csbs','cctxl')";
  830 + List<Map<String, Object>> yyxlList=jdbcTemplate.query(yyxlSql,
  831 + new RowMapper<Map<String, Object>>(){
  832 + @Override
  833 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  834 + Map<String, Object> m=new HashMap<String,Object>();
  835 + m.put("lineCode", rs.getString("line_code"));
  836 + return m;
  837 + }
  838 + });
  839 + Set<String> yyLine = new HashSet<String>();
  840 + for(Map<String, Object> t : yyxlList){
  841 + if(t.get("lineCode") != null){
  842 + yyLine.add(t.get("lineCode").toString());
  843 + }
  844 + }
  845 +
  846 +
  847 + List<Map<String, Object>> attList = new ArrayList<Map<String, Object>>();
  848 + List<Map<String, Object>> lackList = new ArrayList<Map<String, Object>>();
  849 +
  850 + for(int i = 0; i < dates.length; i++){
  851 + Set<String> jhSet = new HashSet<String>();
  852 + Set<String> sjSet = new HashSet<String>();
  853 + List<ScheduleRealInfo> findAll = scheduleRealInfoRepository.findAll(dates[i]);
  854 + List<ScheduleRealInfo> list_s = new ArrayList<ScheduleRealInfo>();
  855 + for(ScheduleRealInfo s : findAll){
  856 + if(s.getGsBm() != null && s.getGsBm().equals(gsdm)){//直属公司
  857 + if(s.getXlBm() != null && yyLine.contains(s.getXlBm())){//营运线路
  858 + if(!isInOut(s)){
  859 + Set<ChildTaskPlan> cts = s.getcTasks();
  860 + if (cts != null && cts.size() > 0) {
  861 + list_s.add(s);
  862 + } else {
  863 + if (s.getZdsjActual() != null && s.getFcsjActual() != null) {
  864 + list_s.add(s);
  865 + }
  866 + }
  867 +
  868 + if(!s.isSflj() && !s.isCcService()){
  869 + jhSet.add(s.getjGh() + "/" + s.getjName());
  870 + }
  871 + }
  872 + }
  873 + }
  874 + }
  875 +
  876 + for(ScheduleRealInfo s : list_s){
  877 + if(!(s.getStatus() == -1)){
  878 + sjSet.add(s.getjGh() + "/" + s.getjName());
  879 + }
  880 +
  881 + if (s.isSflj()){
  882 + continue;
  883 + }
  884 + Set<ChildTaskPlan> cts;
  885 + cts = s.getcTasks();
  886 + //有子任务
  887 + if (cts != null && cts.size() > 0) {
  888 + for(ChildTaskPlan c : cts){
  889 + if(c.getCcId()==null){
  890 + if(c.getMileageType().equals("service")){
  891 + if(c.isDestroy() && (c.getDestroyReason()==null? "" : c.getDestroyReason()).equals("缺人")){
  892 + Map<String, Object> m = new HashMap<String, Object>();
  893 + m.put("gsName", s.getGsName());
  894 + m.put("lineName", s.getXlName());
  895 + m.put("driverName", s.getjName());
  896 + m.put("date", s.getRealExecDate());
  897 + m.put("time", c.getStartDate());
  898 + if(c.getRemarks() != null && c.getRemarks().trim().length() > 0){
  899 + m.put("explain", c.getRemarks());
  900 + } else {
  901 + m.put("explain", s.getRemarks()!=null?s.getRemarks():"");
  902 + }
  903 + lackList.add(m);
  904 + }
  905 + }
  906 + }
  907 + }
  908 + }
  909 + //主任务烂班
  910 + else if(s.getStatus() == -1 && !s.isCcService()){
  911 + if(s.getAdjustExps().equals("缺人")){
  912 + Map<String, Object> m = new HashMap<String, Object>();
  913 + m.put("gsName", s.getGsName());
  914 + m.put("lineName", s.getXlName());
  915 + m.put("driverName", s.getjName());
  916 + m.put("date", s.getRealExecDate());
  917 + m.put("time", s.getFcsj());
  918 + m.put("explain", s.getRemarks()!=null?s.getRemarks():"");
  919 + lackList.add(m);
  920 + }
  921 + }
  922 + }
  923 +
  924 + Map<String, Object> att = new HashMap<String, Object>();
  925 + att.put("date", dates[i]);
  926 + att.put("jh", jhSet.size());
  927 + att.put("sj", sjSet.size());
  928 + attList.add(att);
  929 + }
  930 +
  931 + String gpLineSql = "select p.branche_company_code, b.business_name, count(1) jsy"
  932 + + " from (select e.jsy from bsth_c_s_ecinfo e"
  933 + + " where e.is_cancel = 0 group by e.jsy) a"
  934 + + " left join bsth_c_personnel p on a.jsy = p.id"
  935 + + " left join bsth_c_business b on p.company_code = b.up_code"
  936 + + " and p.branche_company_code = b.business_code"
  937 + + " where p.company_code = '"+gsdm+"'"
  938 + + " group by p.branche_company_code, b.business_name"
  939 + + " order by p.branche_company_code";
  940 + List<Map<String, Object>> ecList=jdbcTemplate.query(gpLineSql,
  941 + new RowMapper<Map<String, Object>>(){
  942 + @Override
  943 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  944 + Map<String, Object> m=new HashMap<String,Object>();
  945 + m.put("company", rs.getString("branche_company_code"));
  946 + m.put("companyName", rs.getString("business_name"));
  947 + m.put("jsy", rs.getString("jsy"));
  948 + return m;
  949 + }
  950 + });
  951 +
  952 + List<Integer> keyList = new ArrayList<Integer>();
  953 + Map<Integer, Map<String, Object>> keyMap = new HashMap<Integer, Map<String, Object>>();
  954 + List<Map<String, Object>> jsyList = new ArrayList<Map<String, Object>>();
  955 + for(Map<String, Object> m : ecList){
  956 + if(m.get("company") != null && m.get("company").toString().trim().length() > 0){
  957 + Integer i = Integer.valueOf(m.get("company").toString().trim());
  958 + if(!keyMap.containsKey(i)){
  959 + Map<String, Object> temp = new HashMap<String, Object>();
  960 + temp.put("company", m.get("companyName").toString());
  961 + temp.put("jsy", m.get("jsy").toString());
  962 + keyMap.put(i, temp);
  963 + keyList.add(i);
  964 + jsyList.add(temp);
  965 + }
  966 + }
  967 + }
  968 +
  969 + String xlSql = "select a.jsy, b.spy, c.cl from"
  970 + + " (select count(1) jsy from (select a.jsy from bsth_c_s_ecinfo a"
  971 + + " left join bsth_c_personnel p on a.jsy=p.id where a.is_cancel = 0"
  972 + + " and a.spy is not null and a.jsy is not null"
  973 + + " and p.company_code = '"+gsdm+"'"
  974 + + " group by jsy) a) a"
  975 + + " LEFT JOIN"
  976 + + " (select count(1) spy from (select b.spy from bsth_c_s_ecinfo b"
  977 + + " left join bsth_c_personnel p on b.spy=p.id where b.is_cancel = 0"
  978 + + " and b.spy is not null and p.company_code = '"+gsdm+"'"
  979 + + " group by spy) b) b"
  980 + + " on 1=1"
  981 + + " LEFT JOIN"
  982 + + " (select count(1) cl from (select c.cl from bsth_c_s_ccinfo c"
  983 + + " left join bsth_c_cars car on c.cl=car.id where c.is_cancel = 0"
  984 + + " and c.cl is not null and car.business_code = '"+gsdm+"'"
  985 + + " and c.xl in(select e.xl from bsth_c_s_ecinfo e"
  986 + + " where e.is_cancel = 0 and e.spy is not null) group by c.cl) c) c"
  987 + + " on 1=1";
  988 + List<Map<String, Object>> xlConfigList=jdbcTemplate.query(xlSql,
  989 + new RowMapper<Map<String, Object>>(){
  990 + @Override
  991 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  992 + Map<String, Object> m=new HashMap<String,Object>();
  993 + m.put("jsy", rs.getString("jsy"));
  994 + m.put("spy", rs.getString("spy"));
  995 + m.put("cl", rs.getString("cl"));
  996 + return m;
  997 + }
  998 + });
  999 + long jsy = 0l, spy = 0l, cl = 0l;
  1000 + for(Map<String, Object> t : xlConfigList){
  1001 + if(t.get("jsy") != null){
  1002 + jsy += Long.valueOf(t.get("jsy").toString());
  1003 + }
  1004 + if(t.get("spy") != null){
  1005 + spy += Long.valueOf(t.get("spy").toString());
  1006 + }
  1007 + if(t.get("cl") != null){
  1008 + cl += Long.valueOf(t.get("cl").toString());
  1009 + }
  1010 + }
  1011 +
  1012 + resMap.put("jsyList", jsyList);
  1013 + resMap.put("attList", attList);
  1014 + resMap.put("lackList", lackList);
  1015 + resMap.put("salesmanJsy", jsy);
  1016 + resMap.put("salesmanSpy", spy);
  1017 + resMap.put("salesmanCl", cl);
  1018 +
  1019 + return JSON.parseObject(JSON.toJSONString(resMap));
  1020 + }
  1021 +
803 /** 按月份查询统计指标 */ 1022 /** 按月份查询统计指标 */
804 @GET 1023 @GET
805 @Path("/selectData/getMonthly/{month}") 1024 @Path("/selectData/getMonthly/{month}")