Commit 29879135947f24016e427a95db84df42af1a11cc

Authored by 潘钊
1 parent 0d4dd0dc

update...

src/main/java/com/bsth/CXFConfig.java
1 package com.bsth; 1 package com.bsth;
2 2
  3 +import com.bsth.ws_server.attendance.AttendanceServiceSoap;
3 import com.bsth.ws_server.park_station.CompanyServiceSoap; 4 import com.bsth.ws_server.park_station.CompanyServiceSoap;
4 import com.bsth.ws_server.waybill.LD_ServiceSoap; 5 import com.bsth.ws_server.waybill.LD_ServiceSoap;
5 import org.apache.cxf.Bus; 6 import org.apache.cxf.Bus;
@@ -32,6 +33,10 @@ public class CXFConfig { @@ -32,6 +33,10 @@ public class CXFConfig {
32 return new LD_ServiceSoap(); 33 return new LD_ServiceSoap();
33 } 34 }
34 35
  36 + public AttendanceServiceSoap attendanceService(){
  37 + return new AttendanceServiceSoap();
  38 + }
  39 +
35 @Bean 40 @Bean
36 public Endpoint companyEndpoint() { 41 public Endpoint companyEndpoint() {
37 EndpointImpl endpoint = new EndpointImpl(springBus(), companyService()); 42 EndpointImpl endpoint = new EndpointImpl(springBus(), companyService());
@@ -49,6 +54,14 @@ public class CXFConfig { @@ -49,6 +54,14 @@ public class CXFConfig {
49 } 54 }
50 55
51 @Bean 56 @Bean
  57 + public Endpoint attendanceServiceEndpoint() {
  58 + EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceService());
  59 + endpoint.publish("/attendanceService");
  60 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  61 + return endpoint;
  62 + }
  63 +
  64 + @Bean
52 public ServletRegistrationBean servletRegistrationBean() { 65 public ServletRegistrationBean servletRegistrationBean() {
53 ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*"); 66 ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
54 bean.setLoadOnStartup(0); 67 bean.setLoadOnStartup(0);
src/main/java/com/bsth/entity/DDYAuthority.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +/**
  4 + * 调度员对应的线路权限
  5 + * Created by panzhao on 2017/3/27.
  6 + */
  7 +public class DDYAuthority {
  8 +
  9 + /** 调度员编号 */
  10 + private String ddy_id;
  11 +
  12 + /** 可调度的线路编码 ,号分隔多个 */
  13 + private String idx;
  14 +
  15 + /**
  16 + * 调度模式 0: 监控模式 1:主调模式
  17 + */
  18 + private int pattern;
  19 +
  20 + public String getDdy_id() {
  21 + return ddy_id;
  22 + }
  23 +
  24 + public void setDdy_id(String ddy_id) {
  25 + this.ddy_id = ddy_id;
  26 + }
  27 +
  28 + public String getIdx() {
  29 + return idx;
  30 + }
  31 +
  32 + public void setIdx(String idx) {
  33 + this.idx = idx;
  34 + }
  35 +
  36 + public int getPattern() {
  37 + return pattern;
  38 + }
  39 +
  40 + public void setPattern(int pattern) {
  41 + this.pattern = pattern;
  42 + }
  43 +}
src/main/java/com/bsth/entity/SchedulePlanInfo.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.Entity;
  4 +import javax.persistence.Id;
  5 +import javax.persistence.Table;
  6 +import java.io.Serializable;
  7 +import java.util.Date;
  8 +
  9 +/**
  10 + * 计调 计划排班
  11 + * Created by panzhao on 2017/3/27.
  12 + */
  13 +@Entity
  14 +@Table(name = "bsth_c_s_sp_info")
  15 +public class SchedulePlanInfo implements Serializable {
  16 +
  17 + /** 主键Id */
  18 + @Id
  19 + private Long id;
  20 +
  21 + /** 排班计划日期 */
  22 + private Date scheduleDate;
  23 +
  24 + /** 关联的公司名称 */
  25 + private String gsName;
  26 + /** 关联的公司编码 */
  27 + private String gsBm;
  28 + /** 关联的分公司名称 */
  29 + private String fgsName;
  30 + /** 关联的分公司编码 */
  31 + private String fgsBm;
  32 + /** 出场顺序号 */
  33 + private Integer ccno;
  34 +
  35 + /** 关联 bsth_c_line 主键,不做mapping */
  36 + private Integer xl;
  37 + /** 线路名称 */
  38 + private String xlName;
  39 + /** 线路编码 */
  40 + private String xlBm;
  41 +
  42 + /** 关联 bsth_c_s_gbi 主键,不做mapping */
  43 + private Long lp;
  44 + /** 路牌名称 */
  45 + private String lpName;
  46 +
  47 + /** 关联 bsth_c_cars 主键,不做mapping */
  48 + private Integer cl;
  49 + /** 车辆自编号 */
  50 + private String clZbh;
  51 +
  52 + /** 当分班的时候,驾驶员会不一样,具体根据规则,还有时刻表决定 */
  53 + /** 报道时间(格式 HH:mm) */
  54 + private String bdTime;
  55 + /** 出场时间(格式 HH:mm) */
  56 + private String ccTime;
  57 + /** 关联的驾驶员 bsth_c_personnel 主键,不做mapping */
  58 + private Integer j;
  59 + /** 驾驶员工号 */
  60 + private String jGh;
  61 + /** 驾驶员名字 */
  62 + private String jName;
  63 + /** 关联的售票员 bsth_c_personnel 主键,不做mapping */
  64 + private Integer s;
  65 + /** 售票员工号 */
  66 + private String sGh;
  67 + /** 售票员名字 */
  68 + private String sName;
  69 +
  70 + // 冗余的时刻明细信息,不做mapping
  71 + /** 线路方向(TODO:上下行,上行,下行,这个以后用枚举还是字典再议,现在先用文字) */
  72 + private String xlDir;
  73 + /** 起点站id,根据班次类型,会关联 bsth_c_station,或 bsth_c_car_park,不做mapping */
  74 + private Integer qdz;
  75 + /** 起点站code */
  76 + private String qdzCode;
  77 + /** 起点站名字 */
  78 + private String qdzName;
  79 + /** 终点站id,根据班次类型,会关联 bsth_c_station,或 bsth_c_car_park,不做mapping */
  80 + private Integer zdz;
  81 + /** 终点站code */
  82 + private String zdzCode;
  83 + /** 终点站名字 */
  84 + private String zdzName;
  85 +
  86 + /** 发车时间(格式 HH:mm) */
  87 + private String fcsj;
  88 + /** 发车顺序号 */
  89 + private Integer fcno;
  90 + /** 对应班次数 */
  91 + private Integer bcs;
  92 + /** 计划里程 */
  93 + private Double jhlc;
  94 + /** 班次历时 */
  95 + private Integer bcsj;
  96 +
  97 + /** 班次类型 字典type=ScheduleType */
  98 + private String bcType;
  99 +
  100 + /** 关联的时刻表id */
  101 + private Long ttInfo;
  102 + /** 关联的时刻表名字 */
  103 + private String ttInfoName;
  104 +
  105 + public Long getId() {
  106 + return id;
  107 + }
  108 +
  109 + public void setId(Long id) {
  110 + this.id = id;
  111 + }
  112 +
  113 + public Date getScheduleDate() {
  114 + return scheduleDate;
  115 + }
  116 +
  117 + public void setScheduleDate(Date scheduleDate) {
  118 + this.scheduleDate = scheduleDate;
  119 + }
  120 +
  121 + public String getGsName() {
  122 + return gsName;
  123 + }
  124 +
  125 + public void setGsName(String gsName) {
  126 + this.gsName = gsName;
  127 + }
  128 +
  129 + public String getGsBm() {
  130 + return gsBm;
  131 + }
  132 +
  133 + public void setGsBm(String gsBm) {
  134 + this.gsBm = gsBm;
  135 + }
  136 +
  137 + public String getFgsName() {
  138 + return fgsName;
  139 + }
  140 +
  141 + public void setFgsName(String fgsName) {
  142 + this.fgsName = fgsName;
  143 + }
  144 +
  145 + public String getFgsBm() {
  146 + return fgsBm;
  147 + }
  148 +
  149 + public void setFgsBm(String fgsBm) {
  150 + this.fgsBm = fgsBm;
  151 + }
  152 +
  153 + public Integer getCcno() {
  154 + return ccno;
  155 + }
  156 +
  157 + public void setCcno(Integer ccno) {
  158 + this.ccno = ccno;
  159 + }
  160 +
  161 + public Integer getXl() {
  162 + return xl;
  163 + }
  164 +
  165 + public void setXl(Integer xl) {
  166 + this.xl = xl;
  167 + }
  168 +
  169 + public String getXlName() {
  170 + return xlName;
  171 + }
  172 +
  173 + public void setXlName(String xlName) {
  174 + this.xlName = xlName;
  175 + }
  176 +
  177 + public String getXlBm() {
  178 + return xlBm;
  179 + }
  180 +
  181 + public void setXlBm(String xlBm) {
  182 + this.xlBm = xlBm;
  183 + }
  184 +
  185 + public Long getLp() {
  186 + return lp;
  187 + }
  188 +
  189 + public void setLp(Long lp) {
  190 + this.lp = lp;
  191 + }
  192 +
  193 + public String getLpName() {
  194 + return lpName;
  195 + }
  196 +
  197 + public void setLpName(String lpName) {
  198 + this.lpName = lpName;
  199 + }
  200 +
  201 + public Integer getCl() {
  202 + return cl;
  203 + }
  204 +
  205 + public void setCl(Integer cl) {
  206 + this.cl = cl;
  207 + }
  208 +
  209 + public String getClZbh() {
  210 + return clZbh;
  211 + }
  212 +
  213 + public void setClZbh(String clZbh) {
  214 + this.clZbh = clZbh;
  215 + }
  216 +
  217 + public String getBdTime() {
  218 + return bdTime;
  219 + }
  220 +
  221 + public void setBdTime(String bdTime) {
  222 + this.bdTime = bdTime;
  223 + }
  224 +
  225 + public String getCcTime() {
  226 + return ccTime;
  227 + }
  228 +
  229 + public void setCcTime(String ccTime) {
  230 + this.ccTime = ccTime;
  231 + }
  232 +
  233 + public Integer getJ() {
  234 + return j;
  235 + }
  236 +
  237 + public void setJ(Integer j) {
  238 + this.j = j;
  239 + }
  240 +
  241 + public String getjGh() {
  242 + return jGh;
  243 + }
  244 +
  245 + public void setjGh(String jGh) {
  246 + this.jGh = jGh;
  247 + }
  248 +
  249 + public String getjName() {
  250 + return jName;
  251 + }
  252 +
  253 + public void setjName(String jName) {
  254 + this.jName = jName;
  255 + }
  256 +
  257 + public Integer getS() {
  258 + return s;
  259 + }
  260 +
  261 + public void setS(Integer s) {
  262 + this.s = s;
  263 + }
  264 +
  265 + public String getsGh() {
  266 + return sGh;
  267 + }
  268 +
  269 + public void setsGh(String sGh) {
  270 + this.sGh = sGh;
  271 + }
  272 +
  273 + public String getsName() {
  274 + return sName;
  275 + }
  276 +
  277 + public void setsName(String sName) {
  278 + this.sName = sName;
  279 + }
  280 +
  281 + public String getXlDir() {
  282 + return xlDir;
  283 + }
  284 +
  285 + public void setXlDir(String xlDir) {
  286 + this.xlDir = xlDir;
  287 + }
  288 +
  289 + public Integer getQdz() {
  290 + return qdz;
  291 + }
  292 +
  293 + public void setQdz(Integer qdz) {
  294 + this.qdz = qdz;
  295 + }
  296 +
  297 + public String getQdzCode() {
  298 + return qdzCode;
  299 + }
  300 +
  301 + public void setQdzCode(String qdzCode) {
  302 + this.qdzCode = qdzCode;
  303 + }
  304 +
  305 + public String getQdzName() {
  306 + return qdzName;
  307 + }
  308 +
  309 + public void setQdzName(String qdzName) {
  310 + this.qdzName = qdzName;
  311 + }
  312 +
  313 + public Integer getZdz() {
  314 + return zdz;
  315 + }
  316 +
  317 + public void setZdz(Integer zdz) {
  318 + this.zdz = zdz;
  319 + }
  320 +
  321 + public String getZdzCode() {
  322 + return zdzCode;
  323 + }
  324 +
  325 + public void setZdzCode(String zdzCode) {
  326 + this.zdzCode = zdzCode;
  327 + }
  328 +
  329 + public String getZdzName() {
  330 + return zdzName;
  331 + }
  332 +
  333 + public void setZdzName(String zdzName) {
  334 + this.zdzName = zdzName;
  335 + }
  336 +
  337 + public String getFcsj() {
  338 + return fcsj;
  339 + }
  340 +
  341 + public void setFcsj(String fcsj) {
  342 + this.fcsj = fcsj;
  343 + }
  344 +
  345 + public Integer getFcno() {
  346 + return fcno;
  347 + }
  348 +
  349 + public void setFcno(Integer fcno) {
  350 + this.fcno = fcno;
  351 + }
  352 +
  353 + public Integer getBcs() {
  354 + return bcs;
  355 + }
  356 +
  357 + public void setBcs(Integer bcs) {
  358 + this.bcs = bcs;
  359 + }
  360 +
  361 + public Double getJhlc() {
  362 + return jhlc;
  363 + }
  364 +
  365 + public void setJhlc(Double jhlc) {
  366 + this.jhlc = jhlc;
  367 + }
  368 +
  369 + public Integer getBcsj() {
  370 + return bcsj;
  371 + }
  372 +
  373 + public void setBcsj(Integer bcsj) {
  374 + this.bcsj = bcsj;
  375 + }
  376 +
  377 + public String getBcType() {
  378 + return bcType;
  379 + }
  380 +
  381 + public void setBcType(String bcType) {
  382 + this.bcType = bcType;
  383 + }
  384 +
  385 + public Long getTtInfo() {
  386 + return ttInfo;
  387 + }
  388 +
  389 + public void setTtInfo(Long ttInfo) {
  390 + this.ttInfo = ttInfo;
  391 + }
  392 +
  393 + public String getTtInfoName() {
  394 + return ttInfoName;
  395 + }
  396 +
  397 + public void setTtInfoName(String ttInfoName) {
  398 + this.ttInfoName = ttInfoName;
  399 + }
  400 +}
src/main/java/com/bsth/redis/PlanScheduleRedisService.java 0 → 100644
  1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.entity.SchedulePlanInfo;
  4 +import com.bsth.repository.SchedulePlanInfoRepository;
  5 +import com.bsth.util.ConfigUtil;
  6 +import com.bsth.util.ConvertUtil;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.joda.time.DateTime;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.core.annotation.Order;
  14 +import org.springframework.data.redis.core.ListOperations;
  15 +import org.springframework.data.redis.core.RedisTemplate;
  16 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  17 +import org.springframework.stereotype.Service;
  18 +
  19 +import java.util.ArrayList;
  20 +import java.util.Date;
  21 +import java.util.Iterator;
  22 +import java.util.List;
  23 +
  24 +/**
  25 + * 计调的 计划排班redis缓存
  26 + * Created by panzhao on 2017/3/27.
  27 + */
  28 +@Service
  29 +@Order(6)
  30 +public class PlanScheduleRedisService implements CommandLineRunner {
  31 +
  32 + @Autowired
  33 + private RedisTemplate redisTemplate;
  34 +
  35 + @Autowired
  36 + SchedulePlanInfoRepository planInfoRepository;
  37 +
  38 + Logger logger = LoggerFactory.getLogger(this.getClass());
  39 +
  40 + private final static String REDIS_KEY_PREFIX = "plan:";
  41 +
  42 + /**
  43 + * 将一批计划写入redis
  44 + *
  45 + * @param list
  46 + */
  47 + public void wirte(List<SchedulePlanInfo> list) {
  48 + ArrayListMultimap<String, SchedulePlanInfo> multimap;
  49 + try {
  50 + if (list.size() == 0)
  51 + return;
  52 + //按日期和线路分组数据
  53 + Class clazz = SchedulePlanInfo.class;
  54 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDate"));
  55 +
  56 + //写入redis
  57 + Iterator<String> iterator = multimap.keySet().iterator();
  58 + String key;
  59 + while (iterator.hasNext()) {
  60 + key = iterator.next();
  61 + mergeData(key, multimap.get(key));
  62 + }
  63 + } catch (Exception e) {
  64 + logger.error("", e);
  65 + }
  66 + }
  67 +
  68 + /**
  69 + * 将 list 与redis里的数据合并
  70 + *
  71 + * @param key
  72 + * @param list
  73 + */
  74 + public void mergeData(String key, List<SchedulePlanInfo> list) {
  75 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  76 +
  77 + ListOperations<String, SchedulePlanInfo> ops = redisTemplate.opsForList();
  78 + List<SchedulePlanInfo> cacheList = ops.range(key, 0, -1);
  79 +
  80 + for (SchedulePlanInfo plan : cacheList) {
  81 + if (!list.contains(plan))
  82 + list.add(plan);
  83 + }
  84 + //删除redis数据
  85 + redisTemplate.delete(key);
  86 + //重新写入
  87 + ops.leftPushAll(key, list);
  88 + }
  89 +
  90 + /**
  91 + * 根据日期和线路编码从redis获取计划
  92 + *
  93 + * @param dateStr
  94 + * @param lineCode
  95 + * @return
  96 + */
  97 + public List<SchedulePlanInfo> read(String dateStr, String lineCode) {
  98 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
  99 + }
  100 +
  101 + @Override
  102 + public void run(String... strings) throws Exception {
  103 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  104 + //设置key 序列化器
  105 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  106 +
  107 + DateTime dt = new DateTime();
  108 + dt = dt.minusDays(cacheDays);
  109 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  110 + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(dt.toDate(), new Date());
  111 +
  112 + //写入redis
  113 + wirte(list);
  114 + }
  115 +
  116 + public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) {
  117 + rq = rq.replaceAll("-", "");
  118 + List<SchedulePlanInfo> rs = new ArrayList<>();
  119 + for(String lineCode : lineArray){
  120 + rs.addAll(read(rq, lineCode));
  121 + }
  122 + return rs;
  123 + }
  124 +}
src/main/java/com/bsth/redis/ScheduleRedisService.java
@@ -17,6 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate; @@ -17,6 +17,7 @@ import org.springframework.data.redis.core.RedisTemplate;
17 import org.springframework.data.redis.serializer.StringRedisSerializer; 17 import org.springframework.data.redis.serializer.StringRedisSerializer;
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
19 19
  20 +import java.util.ArrayList;
20 import java.util.Iterator; 21 import java.util.Iterator;
21 import java.util.List; 22 import java.util.List;
22 23
@@ -84,7 +85,7 @@ public class ScheduleRedisService implements CommandLineRunner { @@ -84,7 +85,7 @@ public class ScheduleRedisService implements CommandLineRunner {
84 list.add(sch); 85 list.add(sch);
85 } 86 }
86 //删除redis数据 87 //删除redis数据
87 - redisTemplate.delete(key); 88 + redisTemplate.delete(key);
88 //重新写入 89 //重新写入
89 ops.leftPushAll(key, list); 90 ops.leftPushAll(key, list);
90 } 91 }
@@ -183,4 +184,13 @@ public class ScheduleRedisService implements CommandLineRunner { @@ -183,4 +184,13 @@ public class ScheduleRedisService implements CommandLineRunner {
183 //写入redis 184 //写入redis
184 wirte(list); 185 wirte(list);
185 } 186 }
  187 +
  188 + public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {
  189 + rq = rq.replaceAll("-", "");
  190 + List<ScheduleRealInfo> rs = new ArrayList<>();
  191 + for(String lineCode : lineArray){
  192 + rs.addAll(read(rq, lineCode));
  193 + }
  194 + return rs;
  195 + }
186 } 196 }
src/main/java/com/bsth/repository/SchedulePlanInfoRepository.java 0 → 100644
  1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.SchedulePlanInfo;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.PagingAndSortingRepository;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import java.util.Date;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/27.
  13 + */
  14 +@Repository
  15 +public interface SchedulePlanInfoRepository extends PagingAndSortingRepository<SchedulePlanInfo, Long> {
  16 +
  17 +
  18 + /**
  19 + * 获取大于指定日期的班次信息
  20 + * @param schDate
  21 + * @return
  22 + */
  23 + @Query("select s from SchedulePlanInfo s where s.scheduleDate>?1 and s.scheduleDate<=?2")
  24 + List<SchedulePlanInfo> findByDateRange(Date s, Date e);
  25 +}
src/main/java/com/bsth/service/DDYAuthorityService.java 0 → 100644
  1 +package com.bsth.service;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +import java.util.Set;
  6 +
  7 +/**
  8 + * Created by panzhao on 2017/3/27.
  9 + */
  10 +public interface DDYAuthorityService {
  11 +
  12 + /**
  13 + * 获取调度员分管的线路集合
  14 + * @param ddy_id
  15 + * @return
  16 + */
  17 + List<String> findLinesByDDY(String ddy_id);
  18 +
  19 + /**
  20 + * 根据驾驶员工号获取班型
  21 + * @param jGh
  22 + * @return
  23 + */
  24 + String findPlanType(String jGh);
  25 +
  26 +
  27 + public void loadPlanTypes();
  28 +
  29 + Map<String,String> findMultiType(Set<String> jsySet);
  30 +}
src/main/java/com/bsth/service/impl/DDYAuthorityServiceImpl.java 0 → 100644
  1 +package com.bsth.service.impl;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.service.DDYAuthorityService;
  5 +import com.google.common.base.Splitter;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.boot.CommandLineRunner;
  10 +import org.springframework.core.annotation.Order;
  11 +import org.springframework.jdbc.core.JdbcTemplate;
  12 +import org.springframework.stereotype.Component;
  13 +import org.springframework.stereotype.Service;
  14 +
  15 +import java.util.*;
  16 +import java.util.concurrent.TimeUnit;
  17 +
  18 +/**
  19 + * Created by panzhao on 2017/3/27.
  20 + */
  21 +@Service
  22 +@Order(5)
  23 +public class DDYAuthorityServiceImpl implements DDYAuthorityService, CommandLineRunner {
  24 +
  25 + @Autowired
  26 + JdbcTemplate jdbcTemplate;
  27 +
  28 + /**
  29 + * 驾驶员班型对照
  30 + * 1: 做1休1
  31 + * 1,1,1,1,1,0,0 : 做5休2
  32 + */
  33 + static Map<String, String> planTypesMap;
  34 +
  35 + Logger logger = LoggerFactory.getLogger(this.getClass());
  36 +
  37 + @Override
  38 + public List<String> findLinesByDDY(String ddy_id) {
  39 + List<String> rs;
  40 + try {
  41 + Map<String, Object> map = jdbcTemplate.queryForMap("select LINE_CODE_STR from bsth_c_real_control_authority a left join bsth_c_sys_user u on a.user_id=u.id where u.user_name=?", ddy_id);
  42 + String idx = map.get("LINE_CODE_STR").toString();
  43 +
  44 + rs = Splitter.on(",").trimResults().splitToList(idx);
  45 + }catch (Exception e){
  46 + logger.error("", e);
  47 + rs = new ArrayList<>();
  48 + }
  49 + return rs;
  50 + }
  51 +
  52 + @Override
  53 + public String findPlanType(String jGh) {
  54 + return planTypesMap.get(jGh);
  55 + }
  56 +
  57 + /**
  58 + * 加载驾驶员班型数据
  59 + */
  60 + @Override
  61 + public void loadPlanTypes(){
  62 + Map<String, String> rsMap = new HashMap<>();
  63 + //线路_搭班编码 ——> 班型
  64 + Map<String, String> ddbm2bxMap = new HashMap<>();
  65 + List<Map<String, Object>> listMap = jdbcTemplate.queryForList("select IFNULL(FBGS, '1') as FBGS, RY_DBBMS, XL from bsth_c_s_sr1_flat where ry_dbbms is not null and xl is not null");
  66 + List<String> fbList, dbList;
  67 + String xl, fbgs;
  68 + for(Map<String, Object> map : listMap){
  69 + xl = map.get("XL").toString();
  70 + fbgs = map.get("FBGS").toString();
  71 + //拆分分班
  72 + fbList = Splitter.on("-").trimResults().splitToList(map.get("RY_DBBMS").toString());
  73 + for(String fb : fbList){
  74 + //拆分搭班编码
  75 + dbList = Splitter.on(",").trimResults().splitToList(fb);
  76 +
  77 + for(String db : dbList)
  78 + ddbm2bxMap.put(xl + "_" + db, fbgs);
  79 + }
  80 + }
  81 +
  82 + //线路_搭班编码 ——> 驾驶员
  83 + Map<String, String> ddbm2jsyMap = new HashMap<>();
  84 + listMap = jdbcTemplate.queryForList("select ec.DBBM,ec.XL,p.JOB_CODE from bsth_c_s_ecinfo ec LEFT JOIN bsth_c_personnel p on ec.jsy=p.id where ec.dbbm is not null and ec.xl is not null and p.job_code is not null");
  85 + for(Map<String, Object> map : listMap){
  86 + ddbm2jsyMap.put(map.get("XL") + "_" + map.get("DBBM"), map.get("JOB_CODE").toString());
  87 + }
  88 +
  89 + Set<String> dbms = ddbm2jsyMap.keySet();
  90 + for(String bm : dbms){
  91 + if(ddbm2bxMap.containsKey(bm))
  92 + rsMap.put(ddbm2jsyMap.get(bm), ddbm2bxMap.get(bm));
  93 + }
  94 + planTypesMap = rsMap;
  95 + }
  96 +
  97 + @Override
  98 + public Map<String, String> findMultiType(Set<String> jsySet) {
  99 + Map<String, String> rs = new HashMap<>();
  100 + for(String jGh: jsySet){
  101 + rs.put(jGh, planTypesMap.get(jGh));
  102 + }
  103 + return rs;
  104 + }
  105 +
  106 +
  107 + @Autowired
  108 + RefreshPlanTypesThread refreshPlanTypesThread;
  109 +
  110 + @Override
  111 + public void run(String... strings) throws Exception {
  112 + //加载驾驶员班型数据
  113 + Application.mainServices.scheduleWithFixedDelay(refreshPlanTypesThread, 30, 60 * 120, TimeUnit.SECONDS);
  114 + }
  115 +
  116 + @Component
  117 + public static class RefreshPlanTypesThread extends Thread{
  118 +
  119 + @Autowired
  120 + DDYAuthorityService ddyAuthorityService;
  121 +
  122 + @Override
  123 + public void run() {
  124 + ddyAuthorityService.loadPlanTypes();
  125 + }
  126 + }
  127 +}
src/main/java/com/bsth/ws_server/attendance/AttendanceService.java 0 → 100644
  1 +package com.bsth.ws_server.attendance;
  2 +
  3 +import com.bsth.ws_server.attendance.entity.NH_jsy_attendance;
  4 +
  5 +import javax.jws.WebParam;
  6 +import javax.jws.WebService;
  7 +import javax.xml.ws.Holder;
  8 +
  9 +/**
  10 + * 考勤相关数据接口
  11 + * Created by panzhao on 2017/3/27.
  12 + */
  13 +@WebService(
  14 + name = "AttendanceServiceSoap",
  15 + targetNamespace = "http://control.bsth.com/")
  16 +public interface AttendanceService {
  17 +
  18 + /**
  19 + * 驾驶员考勤信息
  20 + * @param password
  21 + * @param rq
  22 + * @param ddy_id 调度员ID
  23 + * @param result
  24 + * @param fError
  25 + * @return
  26 + */
  27 + boolean jsy_attendance_NH(
  28 + @WebParam(name = "password") String password,
  29 + @WebParam(name = "rq") String rq,
  30 + @WebParam(name = "ddy_id") String ddy_id,
  31 + @WebParam(name = "resultArray", mode = WebParam.Mode.INOUT) Holder<NH_jsy_attendance[]> result,
  32 + @WebParam(name = "fError", mode = WebParam.Mode.INOUT) Holder<String> fError);
  33 +}
src/main/java/com/bsth/ws_server/attendance/AttendanceServiceSoap.java 0 → 100644
  1 +package com.bsth.ws_server.attendance;
  2 +
  3 +import com.bsth.entity.SchedulePlanInfo;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +import com.bsth.redis.PlanScheduleRedisService;
  6 +import com.bsth.redis.ScheduleRedisService;
  7 +import com.bsth.service.DDYAuthorityService;
  8 +import com.bsth.service.UserService;
  9 +import com.bsth.ws_server.attendance.entity.NH_jsy_attendance;
  10 +import com.bsth.ws_server.util.WSDataConver;
  11 +import org.slf4j.Logger;
  12 +import org.springframework.beans.BeansException;
  13 +import org.springframework.context.ApplicationContext;
  14 +import org.springframework.context.ApplicationContextAware;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import javax.jws.WebService;
  18 +import javax.xml.ws.Holder;
  19 +import java.util.HashSet;
  20 +import java.util.List;
  21 +import java.util.Map;
  22 +import java.util.Set;
  23 +
  24 +/**
  25 + * Created by panzhao on 2017/3/27.
  26 + */
  27 +@Component
  28 +@WebService(
  29 + name = "AttendanceServiceSoap",
  30 + portName = "AttendanceServiceSoap",
  31 + serviceName = "AttendanceService",
  32 + targetNamespace = "http://control.bsth.com/",
  33 + endpointInterface = "com.bsth.ws_server.attendance.AttendanceService")
  34 +public class AttendanceServiceSoap implements AttendanceService, ApplicationContextAware {
  35 +
  36 + Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
  37 +
  38 + static DDYAuthorityService ddyAuthorityService;
  39 + static PlanScheduleRedisService planScheduleRedisService;
  40 + static ScheduleRedisService scheduleRedisService;
  41 +
  42 + static UserService userService;
  43 +
  44 + @Override
  45 + public boolean jsy_attendance_NH(String password, String rq, String ddy_id, Holder<NH_jsy_attendance[]> result, Holder<String> fError) {
  46 + try {
  47 + if(userService.get(password) == null){
  48 + fError.value = "无效的密码!";
  49 + return false;
  50 + }
  51 +
  52 + //该调度员分管的线路
  53 + List<String> lineArray = ddyAuthorityService.findLinesByDDY(ddy_id);
  54 + //计划排班
  55 + List<SchedulePlanInfo> plans = planScheduleRedisService.findByMultiLine(lineArray, rq);
  56 + //实际排班
  57 + List<ScheduleRealInfo> reals = scheduleRedisService.findByMultiLine(lineArray, rq);
  58 + //从计划和实际里提取出驾驶员
  59 + Set<String> jsySet = extractJsy(plans, reals);
  60 + //驾驶员班型对照
  61 + Map<String, String> types = ddyAuthorityService.findMultiType(jsySet);
  62 +
  63 + //转换成工资系统想要的数据
  64 + result.value = WSDataConver.to_jsyAttendanceNH(plans, reals, types, rq);
  65 + }catch (Exception e){
  66 + logger.error("", e);
  67 + fError.value = "服务器出现异常!";
  68 + return false;
  69 + }
  70 + return true;
  71 + }
  72 +
  73 +
  74 + private Set<String> extractJsy(List<SchedulePlanInfo> plans, List<ScheduleRealInfo> reals) {
  75 + Set<String> rs = new HashSet<>();
  76 + for (SchedulePlanInfo plan : plans) {
  77 + rs.add(plan.getjGh());
  78 + }
  79 +
  80 + for (ScheduleRealInfo sch : reals) {
  81 + rs.add(sch.getjGh());
  82 + }
  83 + return rs;
  84 + }
  85 +
  86 + @Override
  87 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  88 + ddyAuthorityService = applicationContext.getBean(DDYAuthorityService.class);
  89 + planScheduleRedisService = applicationContext.getBean(PlanScheduleRedisService.class);
  90 + scheduleRedisService = applicationContext.getBean(ScheduleRedisService.class);
  91 + userService = applicationContext.getBean(UserService.class);
  92 + }
  93 +}
src/main/java/com/bsth/ws_server/attendance/entity/NH_jsy_attendance.java 0 → 100644
  1 +package com.bsth.ws_server.attendance.entity;
  2 +
  3 +/**
  4 + * 南汇驾驶员考勤
  5 + * Created by panzhao on 2017/3/27.
  6 + */
  7 +public class NH_jsy_attendance {
  8 +
  9 + /** 日期 */
  10 + private String rq;
  11 +
  12 + /** 线路编码 */
  13 + private String xlBm;
  14 +
  15 + /** 线路名称 */
  16 + private String xlName;
  17 +
  18 + /** 驾驶员工号 */
  19 + private String jGh;
  20 +
  21 + /** 驾驶员名称 */
  22 + private String jName;
  23 +
  24 + /** 售票员工号 */
  25 + private String sGh;
  26 +
  27 + /** 售票员名称 */
  28 + private String sName;
  29 +
  30 + /** 班型 */
  31 + private String planType;
  32 +
  33 + /**
  34 + * 出勤状态 应出,实出
  35 + * 1,0 应出未出
  36 + * 1,1 应出实出
  37 + * 0,1 无计划,临加出勤
  38 + */
  39 + private String status;
  40 +
  41 + public String getRq() {
  42 + return rq;
  43 + }
  44 +
  45 + public void setRq(String rq) {
  46 + this.rq = rq;
  47 + }
  48 +
  49 + public String getXlBm() {
  50 + return xlBm;
  51 + }
  52 +
  53 + public void setXlBm(String xlBm) {
  54 + this.xlBm = xlBm;
  55 + }
  56 +
  57 + public String getXlName() {
  58 + return xlName;
  59 + }
  60 +
  61 + public void setXlName(String xlName) {
  62 + this.xlName = xlName;
  63 + }
  64 +
  65 + public String getjGh() {
  66 + return jGh;
  67 + }
  68 +
  69 + public void setjGh(String jGh) {
  70 + this.jGh = jGh;
  71 + }
  72 +
  73 + public String getjName() {
  74 + return jName;
  75 + }
  76 +
  77 + public void setjName(String jName) {
  78 + this.jName = jName;
  79 + }
  80 +
  81 + public String getsGh() {
  82 + return sGh;
  83 + }
  84 +
  85 + public void setsGh(String sGh) {
  86 + this.sGh = sGh;
  87 + }
  88 +
  89 + public String getsName() {
  90 + return sName;
  91 + }
  92 +
  93 + public void setsName(String sName) {
  94 + this.sName = sName;
  95 + }
  96 +
  97 + public String getPlanType() {
  98 + return planType;
  99 + }
  100 +
  101 + public void setPlanType(String planType) {
  102 + this.planType = planType;
  103 + }
  104 +
  105 + public String getStatus() {
  106 + return status;
  107 + }
  108 +
  109 + public void setStatus(String status) {
  110 + this.status = status;
  111 + }
  112 +}
src/main/java/com/bsth/ws_server/util/WSDataConver.java
@@ -2,9 +2,11 @@ package com.bsth.ws_server.util; @@ -2,9 +2,11 @@ package com.bsth.ws_server.util;
2 2
3 import com.bsth.entity.DutyEmployee; 3 import com.bsth.entity.DutyEmployee;
4 import com.bsth.entity.OilInfo; 4 import com.bsth.entity.OilInfo;
  5 +import com.bsth.entity.SchedulePlanInfo;
5 import com.bsth.entity.ScheduleRealInfo; 6 import com.bsth.entity.ScheduleRealInfo;
6 import com.bsth.util.Arith; 7 import com.bsth.util.Arith;
7 import com.bsth.util.ConvertUtil; 8 import com.bsth.util.ConvertUtil;
  9 +import com.bsth.ws_server.attendance.entity.NH_jsy_attendance;
8 import com.bsth.ws_server.waybill.entity.*; 10 import com.bsth.ws_server.waybill.entity.*;
9 import com.google.common.collect.ArrayListMultimap; 11 import com.google.common.collect.ArrayListMultimap;
10 import org.apache.commons.lang3.StringUtils; 12 import org.apache.commons.lang3.StringUtils;
@@ -288,7 +290,7 @@ public class WSDataConver { @@ -288,7 +290,7 @@ public class WSDataConver {
288 290
289 //根据车辆获取油量信息 291 //根据车辆获取油量信息
290 oilArray = likeGet(oilInfoMap, sch.getClZbh() + "_"); 292 oilArray = likeGet(oilInfoMap, sch.getClZbh() + "_");
291 - if(oilArray.size() > 0){ 293 + if (oilArray.size() > 0) {
292 Collections.sort(oilArray, oilComp); 294 Collections.sort(oilArray, oilComp);
293 //出厂存油 295 //出厂存油
294 sn_waybill.setOut_oil(oilArray.get(0).getCzyl()); 296 sn_waybill.setOut_oil(oilArray.get(0).getCzyl());
@@ -344,6 +346,7 @@ public class WSDataConver { @@ -344,6 +346,7 @@ public class WSDataConver {
344 346
345 /** 347 /**
346 * 将实际排班转换成上南需要损失公里数据 348 * 将实际排班转换成上南需要损失公里数据
  349 + *
347 * @param listMap 350 * @param listMap
348 * @return 351 * @return
349 */ 352 */
@@ -439,7 +442,7 @@ public class WSDataConver { @@ -439,7 +442,7 @@ public class WSDataConver {
439 442
440 private static double countOilExpend(List<OilInfo> oilArray) { 443 private static double countOilExpend(List<OilInfo> oilArray) {
441 double sum = 0; 444 double sum = 0;
442 - for(OilInfo oilInfo : oilArray){ 445 + for (OilInfo oilInfo : oilArray) {
443 sum = Arith.add(sum, oilInfo.getYh()); 446 sum = Arith.add(sum, oilInfo.getYh());
444 } 447 }
445 return sum; 448 return sum;
@@ -447,8 +450,8 @@ public class WSDataConver { @@ -447,8 +450,8 @@ public class WSDataConver {
447 450
448 private static double countOilExpend(List<OilInfo> oilArray, String jGh) { 451 private static double countOilExpend(List<OilInfo> oilArray, String jGh) {
449 double sum = 0; 452 double sum = 0;
450 - for(OilInfo oilInfo : oilArray){  
451 - if(oilInfo.getJsy().equals(jGh)) 453 + for (OilInfo oilInfo : oilArray) {
  454 + if (oilInfo.getJsy().equals(jGh))
452 sum = Arith.add(sum, oilInfo.getYh()); 455 sum = Arith.add(sum, oilInfo.getYh());
453 } 456 }
454 return sum; 457 return sum;
@@ -469,7 +472,77 @@ public class WSDataConver { @@ -469,7 +472,77 @@ public class WSDataConver {
469 return list; 472 return list;
470 } 473 }
471 474
472 - public static class OilComp implements Comparator<OilInfo>{ 475 + /**
  476 + * 将数据转换成南汇工资系统需要的驾驶员考勤数据
  477 + *
  478 + * @param plans
  479 + * @param reals
  480 + * @param types
  481 + * @return
  482 + */
  483 + public static NH_jsy_attendance[] to_jsyAttendanceNH(List<SchedulePlanInfo> plans, List<ScheduleRealInfo> reals, Map<String, String> types, String rq) {
  484 + List<String> ghArray = new ArrayList<>(types.keySet());
  485 + NH_jsy_attendance[] rs = new NH_jsy_attendance[ghArray.size()];
  486 +
  487 + NH_jsy_attendance attendance;
  488 + SchedulePlanInfo plan;
  489 + ScheduleRealInfo real;
  490 + String jGh;
  491 + for(int i = 0; i < ghArray.size(); i ++){
  492 + jGh = ghArray.get(i);
  493 +
  494 + attendance = new NH_jsy_attendance();
  495 + attendance.setRq(rq);
  496 + //计划
  497 + plan = searchByJsy(plans, jGh);
  498 + //实际
  499 + real = searchRealByJsy(reals, jGh);
  500 + //考勤
  501 + attendance.setStatus((plan==null?"0":"1") + "," + (real==null?"0":"1"));
  502 + //班型
  503 + attendance.setPlanType(types.get(jGh)==null?"1":types.get(jGh));
  504 + //驾驶员工号
  505 + attendance.setjGh(jGh);
  506 +
  507 + if(real != null){
  508 + attendance.setXlBm(real.getXlBm());
  509 + attendance.setXlName(real.getXlName());
  510 + attendance.setjName(real.getjName());
  511 + attendance.setsGh(real.getsGh());
  512 + attendance.setsName(real.getsName());
  513 + }
  514 + else if(plan != null){
  515 + attendance.setXlBm(plan.getXlBm());
  516 + attendance.setXlName(plan.getXlName());
  517 + attendance.setjName(plan.getjName());
  518 + attendance.setsGh(plan.getsGh());
  519 + attendance.setsName(plan.getsName());
  520 + }
  521 +
  522 + rs[i] = attendance;
  523 + }
  524 + return rs;
  525 + }
  526 +
  527 + public static SchedulePlanInfo searchByJsy(List<SchedulePlanInfo> plans, String jGh){
  528 +
  529 + for(SchedulePlanInfo plan : plans){
  530 + if(plan.getjGh().equals(jGh))
  531 + return plan;
  532 + }
  533 + return null;
  534 + }
  535 +
  536 + public static ScheduleRealInfo searchRealByJsy(List<ScheduleRealInfo> reals, String jGh){
  537 +
  538 + for(ScheduleRealInfo sch : reals){
  539 + if(sch.getjGh().equals(jGh))
  540 + return sch;
  541 + }
  542 + return null;
  543 + }
  544 +
  545 + public static class OilComp implements Comparator<OilInfo> {
473 546
474 @Override 547 @Override
475 public int compare(OilInfo o1, OilInfo o2) { 548 public int compare(OilInfo o1, OilInfo o2) {