Commit 033a3f716084183c41671ea36387f2afedb60984
1 parent
ef7192bb
1
Showing
1 changed file
with
254 additions
and
254 deletions
src/main/java/com/bsth/server_rs/waybill/WaybillRestService.java
| 1 | -package com.bsth.server_rs.waybill; | |
| 2 | - | |
| 3 | -import java.lang.reflect.Field; | |
| 4 | -import java.util.ArrayList; | |
| 5 | -import java.util.HashMap; | |
| 6 | -import java.util.List; | |
| 7 | -import java.util.Map; | |
| 8 | -import java.util.Set; | |
| 9 | - | |
| 10 | -import javax.ws.rs.GET; | |
| 11 | -import javax.ws.rs.Path; | |
| 12 | -import javax.ws.rs.Produces; | |
| 13 | -import javax.ws.rs.core.MediaType; | |
| 14 | - | |
| 15 | -import org.apache.commons.lang3.StringUtils; | |
| 16 | -import org.joda.time.format.DateTimeFormat; | |
| 17 | -import org.joda.time.format.DateTimeFormatter; | |
| 18 | -import org.slf4j.Logger; | |
| 19 | -import org.slf4j.LoggerFactory; | |
| 20 | -import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | -import org.springframework.stereotype.Component; | |
| 22 | - | |
| 23 | -import com.bsth.entity.DutyEmployee; | |
| 24 | -import com.bsth.entity.ScheduleRealInfo; | |
| 25 | -import com.bsth.redis.ScheduleRedisService; | |
| 26 | -import com.bsth.repository.DutyEmployeeRepository; | |
| 27 | -import com.bsth.server_ws.util.ScheduleCalculator; | |
| 28 | -import com.bsth.util.ConvertUtil; | |
| 29 | -import com.google.common.collect.ArrayListMultimap; | |
| 30 | - | |
| 31 | -/** | |
| 32 | - * @author Hill. | |
| 33 | - */ | |
| 34 | -@Component | |
| 35 | -@Path("/waybill") | |
| 36 | -@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | |
| 37 | -public class WaybillRestService { | |
| 38 | - | |
| 39 | - @Autowired | |
| 40 | - private ScheduleRedisService scheduleRedisService; | |
| 41 | - @Autowired | |
| 42 | - private DutyEmployeeRepository dutyEmployeeRepository; | |
| 43 | - | |
| 44 | - private static Logger logger = LoggerFactory.getLogger(WaybillRestService.class); | |
| 45 | - | |
| 46 | - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"), | |
| 47 | - fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); | |
| 48 | - | |
| 49 | - @GET | |
| 50 | - @Path("/") | |
| 51 | - public Map<String, Object> waybill(Map<String, Object> param) { | |
| 52 | - Map<String, Object> map = new HashMap<String, Object>(); | |
| 53 | - String rq = (String)param.get("date"), companyId = (String)param.get("companyCode"); | |
| 54 | - try { | |
| 55 | - //日期减一天,老接口是这样的 | |
| 56 | - String prveRq = fmtyyyyMMdd.print(fmtyyyyMMdd.parseDateTime(rq).minusDays(1)); | |
| 57 | - | |
| 58 | - //实际排班 | |
| 59 | - ArrayListMultimap<String, ScheduleRealInfo> listMap = scheduleRedisService.findByDateAndGroupByNbbm(prveRq, companyId); | |
| 60 | - //当班调派 | |
| 61 | - long st = fmtyyyyMMddHHmm.parseMillis(prveRq + "00:00"), et = fmtyyyyMMddHHmm.parseMillis(prveRq + "23:59"); | |
| 62 | - List<DutyEmployee> des = dutyEmployeeRepository.findByTime(st, et); | |
| 63 | - //转换成南汇路单需要的格式 | |
| 64 | - List<Waybill> data = toNhWaybill(listMap, des); | |
| 65 | - map.put("errCode", 0); | |
| 66 | - map.put("errMsg", ""); | |
| 67 | - map.put("data", data); | |
| 68 | - } catch (Exception e) { | |
| 69 | - logger.error("", e); | |
| 70 | - map.put("errCode", 1); | |
| 71 | - map.put("errMsg", "服务器出现异常!"); | |
| 72 | - } | |
| 73 | - | |
| 74 | - return map; | |
| 75 | - } | |
| 76 | - | |
| 77 | - private List<Waybill> toNhWaybill(ArrayListMultimap<String, ScheduleRealInfo> listMap, List<DutyEmployee> des) { | |
| 78 | - Set<String> nbbms = listMap.keySet(); | |
| 79 | - List<Waybill> result = new ArrayList<Waybill>(nbbms.size()); | |
| 80 | - Field jGhField = null; | |
| 81 | - try { | |
| 82 | - jGhField = ScheduleRealInfo.class.getDeclaredField("jGh"); | |
| 83 | - } catch (NoSuchFieldException | SecurityException e) { | |
| 84 | - // TODO Auto-generated catch block | |
| 85 | - e.printStackTrace(); | |
| 86 | - } | |
| 87 | - | |
| 88 | - List<ScheduleRealInfo> list; | |
| 89 | - ArrayListMultimap<String, ScheduleRealInfo> jGhListMap; | |
| 90 | - ScheduleRealInfo sch; | |
| 91 | - for (String nbbm : nbbms) { | |
| 92 | - list = listMap.get(nbbm); | |
| 93 | - if (list.size() == 0) | |
| 94 | - continue; | |
| 95 | - //班次信息 | |
| 96 | - Waybill wb = new Waybill(); | |
| 97 | - sch = list.get(0); | |
| 98 | - //日期 | |
| 99 | - wb.setDate(sch.getScheduleDateStr()); | |
| 100 | - //车辆自编号 | |
| 101 | - wb.setInsideCode(sch.getClZbh()); | |
| 102 | - //线路编码 | |
| 103 | - wb.setLineCode(sch.getXlBm()); | |
| 104 | - | |
| 105 | - //按 驾驶员 分组班次,构造路单子项 | |
| 106 | - jGhListMap = new ConvertUtil<ScheduleRealInfo>().groupMultiList(list, "_", jGhField); | |
| 107 | - for (String jGh : jGhListMap.keySet()) { | |
| 108 | - list = jGhListMap.get(jGh); | |
| 109 | - //营业公里 | |
| 110 | - wb.setMiles(ScheduleCalculator.calcYYLC(list)); | |
| 111 | - //驾驶员工号 | |
| 112 | - wb.setDriverJno(list.get(0).getjGh()); | |
| 113 | - wb.setDriverName(list.get(0).getjName()); | |
| 114 | - wb.setDriverId(""); | |
| 115 | - //售票员工号 | |
| 116 | - wb.setConductorJno(""); | |
| 117 | - wb.setConductorName(list.get(0).getsName()); | |
| 118 | - wb.setConductorId(""); | |
| 119 | - for (ScheduleRealInfo sri : list) { | |
| 120 | - if (StringUtils.isNotEmpty(sri.getsGh())) { | |
| 121 | - wb.setConductorJno(sri.getsGh()); | |
| 122 | - break; | |
| 123 | - } | |
| 124 | - } | |
| 125 | - } | |
| 126 | - result.add(wb); | |
| 127 | - } | |
| 128 | - | |
| 129 | - return result; | |
| 130 | - } | |
| 131 | - | |
| 132 | - final class Waybill { | |
| 133 | - // 日期 | |
| 134 | - private String date; | |
| 135 | - // 公司代码 | |
| 136 | - private String companyCode; | |
| 137 | - // 线路名称 | |
| 138 | - private String lineName; | |
| 139 | - // 线路代码 | |
| 140 | - private String lineCode; | |
| 141 | - // 车辆内部编码 | |
| 142 | - private String insideCode; | |
| 143 | - // 驾驶员工号 | |
| 144 | - private String driverJno; | |
| 145 | - // 驾驶员姓名 | |
| 146 | - private String driverName; | |
| 147 | - // 驾驶员身份证号 | |
| 148 | - private String driverId; | |
| 149 | - // 售票员工号 | |
| 150 | - private String conductorJno; | |
| 151 | - // 售票员姓名 | |
| 152 | - private String conductorName; | |
| 153 | - // 售票员身份证号 | |
| 154 | - private String conductorId; | |
| 155 | - // 营运公里 | |
| 156 | - private double miles; | |
| 157 | - | |
| 158 | - public String getDate() { | |
| 159 | - return date; | |
| 160 | - } | |
| 161 | - | |
| 162 | - public void setDate(String date) { | |
| 163 | - this.date = date; | |
| 164 | - } | |
| 165 | - | |
| 166 | - public String getCompanyCode() { | |
| 167 | - return companyCode; | |
| 168 | - } | |
| 169 | - | |
| 170 | - public void setCompanyCode(String companyCode) { | |
| 171 | - this.companyCode = companyCode; | |
| 172 | - } | |
| 173 | - | |
| 174 | - public String getLineName() { | |
| 175 | - return lineName; | |
| 176 | - } | |
| 177 | - | |
| 178 | - public void setLineName(String lineName) { | |
| 179 | - this.lineName = lineName; | |
| 180 | - } | |
| 181 | - | |
| 182 | - public String getLineCode() { | |
| 183 | - return lineCode; | |
| 184 | - } | |
| 185 | - | |
| 186 | - public void setLineCode(String lineCode) { | |
| 187 | - this.lineCode = lineCode; | |
| 188 | - } | |
| 189 | - | |
| 190 | - public String getInsideCode() { | |
| 191 | - return insideCode; | |
| 192 | - } | |
| 193 | - | |
| 194 | - public void setInsideCode(String insideCode) { | |
| 195 | - this.insideCode = insideCode; | |
| 196 | - } | |
| 197 | - | |
| 198 | - public String getDriverJno() { | |
| 199 | - return driverJno; | |
| 200 | - } | |
| 201 | - | |
| 202 | - public void setDriverJno(String driverJno) { | |
| 203 | - this.driverJno = driverJno; | |
| 204 | - } | |
| 205 | - | |
| 206 | - public String getDriverName() { | |
| 207 | - return driverName; | |
| 208 | - } | |
| 209 | - | |
| 210 | - public void setDriverName(String driverName) { | |
| 211 | - this.driverName = driverName; | |
| 212 | - } | |
| 213 | - | |
| 214 | - public String getDriverId() { | |
| 215 | - return driverId; | |
| 216 | - } | |
| 217 | - | |
| 218 | - public void setDriverId(String driverId) { | |
| 219 | - this.driverId = driverId; | |
| 220 | - } | |
| 221 | - | |
| 222 | - public String getConductorJno() { | |
| 223 | - return conductorJno; | |
| 224 | - } | |
| 225 | - | |
| 226 | - public void setConductorJno(String conductorJno) { | |
| 227 | - this.conductorJno = conductorJno; | |
| 228 | - } | |
| 229 | - | |
| 230 | - public String getConductorName() { | |
| 231 | - return conductorName; | |
| 232 | - } | |
| 233 | - | |
| 234 | - public void setConductorName(String conductorName) { | |
| 235 | - this.conductorName = conductorName; | |
| 236 | - } | |
| 237 | - | |
| 238 | - public String getConductorId() { | |
| 239 | - return conductorId; | |
| 240 | - } | |
| 241 | - | |
| 242 | - public void setConductorId(String conductorId) { | |
| 243 | - this.conductorId = conductorId; | |
| 244 | - } | |
| 245 | - | |
| 246 | - public double getMiles() { | |
| 247 | - return miles; | |
| 248 | - } | |
| 249 | - | |
| 250 | - public void setMiles(double miles) { | |
| 251 | - this.miles = miles; | |
| 252 | - } | |
| 253 | - } | |
| 254 | -} | |
| 1 | +package com.bsth.server_rs.waybill; | |
| 2 | + | |
| 3 | +import java.lang.reflect.Field; | |
| 4 | +import java.util.ArrayList; | |
| 5 | +import java.util.HashMap; | |
| 6 | +import java.util.List; | |
| 7 | +import java.util.Map; | |
| 8 | +import java.util.Set; | |
| 9 | + | |
| 10 | +import javax.ws.rs.GET; | |
| 11 | +import javax.ws.rs.Path; | |
| 12 | +import javax.ws.rs.Produces; | |
| 13 | +import javax.ws.rs.core.MediaType; | |
| 14 | + | |
| 15 | +import org.apache.commons.lang3.StringUtils; | |
| 16 | +import org.joda.time.format.DateTimeFormat; | |
| 17 | +import org.joda.time.format.DateTimeFormatter; | |
| 18 | +import org.slf4j.Logger; | |
| 19 | +import org.slf4j.LoggerFactory; | |
| 20 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 21 | +import org.springframework.stereotype.Component; | |
| 22 | + | |
| 23 | +import com.bsth.entity.DutyEmployee; | |
| 24 | +import com.bsth.entity.ScheduleRealInfo; | |
| 25 | +import com.bsth.redis.ScheduleRedisService; | |
| 26 | +import com.bsth.repository.DutyEmployeeRepository; | |
| 27 | +import com.bsth.server_ws.util.ScheduleCalculator; | |
| 28 | +import com.bsth.util.ConvertUtil; | |
| 29 | +import com.google.common.collect.ArrayListMultimap; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * @author Hill. | |
| 33 | + */ | |
| 34 | +@Component | |
| 35 | +@Path("/waybill") | |
| 36 | +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) | |
| 37 | +public class WaybillRestService { | |
| 38 | + | |
| 39 | + @Autowired | |
| 40 | + private ScheduleRedisService scheduleRedisService; | |
| 41 | + @Autowired | |
| 42 | + private DutyEmployeeRepository dutyEmployeeRepository; | |
| 43 | + | |
| 44 | + private static Logger logger = LoggerFactory.getLogger(WaybillRestService.class); | |
| 45 | + | |
| 46 | + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"), | |
| 47 | + fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd"); | |
| 48 | + | |
| 49 | + @GET | |
| 50 | + @Path("/") | |
| 51 | + public Map<String, Object> waybill(Map<String, Object> param) { | |
| 52 | + Map<String, Object> map = new HashMap<String, Object>(); | |
| 53 | + String rq = (String)param.get("date"), companyId = (String)param.get("companyCode"); | |
| 54 | + try { | |
| 55 | + //日期减一天,老接口是这样的 | |
| 56 | + String prveRq = fmtyyyyMMdd.print(fmtyyyyMMdd.parseDateTime(rq).minusDays(1)); | |
| 57 | + | |
| 58 | + //实际排班 | |
| 59 | + ArrayListMultimap<String, ScheduleRealInfo> listMap = scheduleRedisService.findByDateAndGroupByNbbm(prveRq, companyId); | |
| 60 | + //当班调派 | |
| 61 | + long st = fmtyyyyMMddHHmm.parseMillis(prveRq + "00:00"), et = fmtyyyyMMddHHmm.parseMillis(prveRq + "23:59"); | |
| 62 | + List<DutyEmployee> des = dutyEmployeeRepository.findByTime(st, et); | |
| 63 | + //转换成南汇路单需要的格式 | |
| 64 | + List<Waybill> data = toNhWaybill(listMap, des); | |
| 65 | + map.put("errCode", 0); | |
| 66 | + map.put("errMsg", ""); | |
| 67 | + map.put("data", data); | |
| 68 | + } catch (Exception e) { | |
| 69 | + logger.error("", e); | |
| 70 | + map.put("errCode", 1); | |
| 71 | + map.put("errMsg", "服务器出现异常!"); | |
| 72 | + } | |
| 73 | + | |
| 74 | + return map; | |
| 75 | + } | |
| 76 | + | |
| 77 | + private List<Waybill> toNhWaybill(ArrayListMultimap<String, ScheduleRealInfo> listMap, List<DutyEmployee> des) { | |
| 78 | + Set<String> nbbms = listMap.keySet(); | |
| 79 | + List<Waybill> result = new ArrayList<Waybill>(nbbms.size()); | |
| 80 | + Field jGhField = null; | |
| 81 | + try { | |
| 82 | + jGhField = ScheduleRealInfo.class.getDeclaredField("jGh"); | |
| 83 | + } catch (NoSuchFieldException | SecurityException e) { | |
| 84 | + // TODO Auto-generated catch block | |
| 85 | + e.printStackTrace(); | |
| 86 | + } | |
| 87 | + | |
| 88 | + List<ScheduleRealInfo> list; | |
| 89 | + ArrayListMultimap<String, ScheduleRealInfo> jGhListMap; | |
| 90 | + ScheduleRealInfo sch; | |
| 91 | + for (String nbbm : nbbms) { | |
| 92 | + list = listMap.get(nbbm); | |
| 93 | + if (list.size() == 0) | |
| 94 | + continue; | |
| 95 | + //班次信息 | |
| 96 | + Waybill wb = new Waybill(); | |
| 97 | + sch = list.get(0); | |
| 98 | + //日期 | |
| 99 | + wb.setDate(sch.getScheduleDateStr()); | |
| 100 | + //车辆自编号 | |
| 101 | + wb.setInsideCode(sch.getClZbh()); | |
| 102 | + //线路编码 | |
| 103 | + wb.setLineCode(sch.getXlBm()); | |
| 104 | + | |
| 105 | + //按 驾驶员 分组班次,构造路单子项 | |
| 106 | + jGhListMap = new ConvertUtil<ScheduleRealInfo>().groupMultiList(list, "_", jGhField); | |
| 107 | + for (String jGh : jGhListMap.keySet()) { | |
| 108 | + list = jGhListMap.get(jGh); | |
| 109 | + //营业公里 | |
| 110 | + wb.setMiles(ScheduleCalculator.calcYYLC(list)); | |
| 111 | + //驾驶员工号 | |
| 112 | + wb.setDriverJno(list.get(0).getjGh()); | |
| 113 | + wb.setDriverName(list.get(0).getjName()); | |
| 114 | + wb.setDriverId(list.get(0).getjId()); | |
| 115 | + //售票员工号 | |
| 116 | + wb.setConductorJno(list.get(0).getsGh()); | |
| 117 | + wb.setConductorName(list.get(0).getsName()); | |
| 118 | + wb.setConductorId(list.get(0).getsId()); | |
| 119 | + for (ScheduleRealInfo sri : list) { | |
| 120 | + if (StringUtils.isNotEmpty(sri.getsGh())) { | |
| 121 | + wb.setConductorJno(sri.getsGh()); | |
| 122 | + break; | |
| 123 | + } | |
| 124 | + } | |
| 125 | + } | |
| 126 | + result.add(wb); | |
| 127 | + } | |
| 128 | + | |
| 129 | + return result; | |
| 130 | + } | |
| 131 | + | |
| 132 | + final class Waybill { | |
| 133 | + // 日期 | |
| 134 | + private String date; | |
| 135 | + // 公司代码 | |
| 136 | + private String companyCode; | |
| 137 | + // 线路名称 | |
| 138 | + private String lineName; | |
| 139 | + // 线路代码 | |
| 140 | + private String lineCode; | |
| 141 | + // 车辆内部编码 | |
| 142 | + private String insideCode; | |
| 143 | + // 驾驶员工号 | |
| 144 | + private String driverJno; | |
| 145 | + // 驾驶员姓名 | |
| 146 | + private String driverName; | |
| 147 | + // 驾驶员身份证号 | |
| 148 | + private String driverId; | |
| 149 | + // 售票员工号 | |
| 150 | + private String conductorJno; | |
| 151 | + // 售票员姓名 | |
| 152 | + private String conductorName; | |
| 153 | + // 售票员身份证号 | |
| 154 | + private String conductorId; | |
| 155 | + // 营运公里 | |
| 156 | + private double miles; | |
| 157 | + | |
| 158 | + public String getDate() { | |
| 159 | + return date; | |
| 160 | + } | |
| 161 | + | |
| 162 | + public void setDate(String date) { | |
| 163 | + this.date = date; | |
| 164 | + } | |
| 165 | + | |
| 166 | + public String getCompanyCode() { | |
| 167 | + return companyCode; | |
| 168 | + } | |
| 169 | + | |
| 170 | + public void setCompanyCode(String companyCode) { | |
| 171 | + this.companyCode = companyCode; | |
| 172 | + } | |
| 173 | + | |
| 174 | + public String getLineName() { | |
| 175 | + return lineName; | |
| 176 | + } | |
| 177 | + | |
| 178 | + public void setLineName(String lineName) { | |
| 179 | + this.lineName = lineName; | |
| 180 | + } | |
| 181 | + | |
| 182 | + public String getLineCode() { | |
| 183 | + return lineCode; | |
| 184 | + } | |
| 185 | + | |
| 186 | + public void setLineCode(String lineCode) { | |
| 187 | + this.lineCode = lineCode; | |
| 188 | + } | |
| 189 | + | |
| 190 | + public String getInsideCode() { | |
| 191 | + return insideCode; | |
| 192 | + } | |
| 193 | + | |
| 194 | + public void setInsideCode(String insideCode) { | |
| 195 | + this.insideCode = insideCode; | |
| 196 | + } | |
| 197 | + | |
| 198 | + public String getDriverJno() { | |
| 199 | + return driverJno; | |
| 200 | + } | |
| 201 | + | |
| 202 | + public void setDriverJno(String driverJno) { | |
| 203 | + this.driverJno = driverJno; | |
| 204 | + } | |
| 205 | + | |
| 206 | + public String getDriverName() { | |
| 207 | + return driverName; | |
| 208 | + } | |
| 209 | + | |
| 210 | + public void setDriverName(String driverName) { | |
| 211 | + this.driverName = driverName; | |
| 212 | + } | |
| 213 | + | |
| 214 | + public String getDriverId() { | |
| 215 | + return driverId; | |
| 216 | + } | |
| 217 | + | |
| 218 | + public void setDriverId(String driverId) { | |
| 219 | + this.driverId = driverId; | |
| 220 | + } | |
| 221 | + | |
| 222 | + public String getConductorJno() { | |
| 223 | + return conductorJno; | |
| 224 | + } | |
| 225 | + | |
| 226 | + public void setConductorJno(String conductorJno) { | |
| 227 | + this.conductorJno = conductorJno; | |
| 228 | + } | |
| 229 | + | |
| 230 | + public String getConductorName() { | |
| 231 | + return conductorName; | |
| 232 | + } | |
| 233 | + | |
| 234 | + public void setConductorName(String conductorName) { | |
| 235 | + this.conductorName = conductorName; | |
| 236 | + } | |
| 237 | + | |
| 238 | + public String getConductorId() { | |
| 239 | + return conductorId; | |
| 240 | + } | |
| 241 | + | |
| 242 | + public void setConductorId(String conductorId) { | |
| 243 | + this.conductorId = conductorId; | |
| 244 | + } | |
| 245 | + | |
| 246 | + public double getMiles() { | |
| 247 | + return miles; | |
| 248 | + } | |
| 249 | + | |
| 250 | + public void setMiles(double miles) { | |
| 251 | + this.miles = miles; | |
| 252 | + } | |
| 253 | + } | |
| 254 | +} | ... | ... |