MQTask.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. package com.iamberry.rst.controllers.mq;
  2. import com.iamberry.rst.controllers.sys.SysController;
  3. import com.iamberry.rst.core.cm.CompanyInfo;
  4. import com.iamberry.rst.core.cm.Postage;
  5. import com.iamberry.rst.core.cm.PostageAuthority;
  6. import com.iamberry.rst.core.cm.SalesOrder;
  7. import com.iamberry.rst.core.fm.ComplaintDetectInfo;
  8. import com.iamberry.rst.core.order.ProductType;
  9. import com.iamberry.rst.core.sms.OrderMessage;
  10. import com.iamberry.rst.core.sms.SmsMessage;
  11. import com.iamberry.rst.core.sys.Admin;
  12. import com.iamberry.rst.core.tools.KuaiDi100;
  13. import com.iamberry.rst.core.tools.LogisticsInfo;
  14. import com.iamberry.rst.faces.address.AddressService;
  15. import com.iamberry.rst.faces.cm.*;
  16. import com.iamberry.rst.faces.fm.ComplaintDetectInfoService;
  17. import com.iamberry.rst.faces.order.EfastOrderService;
  18. import com.iamberry.rst.faces.order.LogisticsInfoService;
  19. import com.iamberry.rst.faces.sms.MessageService;
  20. import com.iamberry.rst.faces.sms.SmsService;
  21. import com.iamberry.rst.faces.sys.SysConfigService;
  22. import com.iamberry.rst.faces.sys.SysService;
  23. import com.iamberry.rst.util.SmsConfig;
  24. import com.iamberry.rst.utils.EfastUtil;
  25. import com.iamberry.wechat.tools.ResponseJson;
  26. import net.sf.json.JSONArray;
  27. import net.sf.json.JSONObject;
  28. import org.apache.poi.hssf.model.InternalWorkbook;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.springframework.beans.factory.InitializingBean;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.context.annotation.Lazy;
  34. import org.springframework.scheduling.annotation.Scheduled;
  35. import org.springframework.stereotype.Component;
  36. import java.text.MessageFormat;
  37. import java.text.SimpleDateFormat;
  38. import java.util.*;
  39. import static com.iamberry.rst.util.SmsConfig.*;
  40. @Component(value="mqTask")
  41. @Lazy(false)
  42. public class MQTask implements InitializingBean {
  43. private static Logger logger = LoggerFactory.getLogger(MQTask.class);
  44. @Autowired
  45. private MessageService messageService;
  46. @Autowired
  47. private SmsService smsService;
  48. @Autowired
  49. private EfastOrderService efastOrderService;
  50. @Autowired
  51. private SalesOrderService salesOrderService;
  52. @Autowired
  53. private SysService sysService;
  54. @Autowired
  55. private AddressService addressService;
  56. @Autowired
  57. private CustomerService customerService;
  58. @Autowired
  59. private SysConfigService sysConfigService;
  60. @Autowired
  61. private KuaiDi100 kuaidi100;
  62. @Autowired
  63. private LogisticsInfoService logisticsInfoService;
  64. @Autowired
  65. private PostageAuthorityService postageAuthorityService;
  66. @Autowired
  67. private PostageService postageService;
  68. @Autowired
  69. private CompanyInfoService companyInfoService;
  70. @Autowired
  71. private ComplaintDetectInfoService complaintDetectInfoService;
  72. @Autowired
  73. private EfastUtil efastUtil;
  74. private Object lock = new Object();
  75. private Object lock1 = new Object();
  76. public void afterPropertiesSet() throws Exception {
  77. }
  78. //@Scheduled(cron = "*/10 * * * * ?")
  79. //@Scheduled(cron = "0 0 9,11,14,16,18,20 * * ? ")//推送时间分别为每天早上九点、中午十一点、下午三点、下午六点、晚上八点
  80. //@Scheduled(cron = "0 0 */1 * * ?")//每小时执行一次
  81. // @Scheduled(cron = "0 0/3 * * * ?")//每三分钟执行一次
  82. public void auditMessagePush(){
  83. logger.info("------------执行消息提醒,推送待处理订单短信 start-----------");
  84. List<SmsMessage> smsMessageList = messageService.listOrderMessages();
  85. if(smsMessageList != null && smsMessageList.size() > 0){
  86. //循环推送短信
  87. for(SmsMessage smsMessage : smsMessageList){
  88. ResponseJson json = smsService.sms(smsMessage.getTel(),smsMessage.getTypes(),smsMessage.getCounts());
  89. if(json.getReturnCode() == 200){
  90. logger.info("------------推送到+"+smsMessage.getTel()+"一条"+(smsMessage.getTypes() == 1?"待处理":"驳回")+"短信成功");
  91. //设置审核通过记录为无效
  92. if(smsMessage.getTypes() == 3){
  93. OrderMessage orderMessage = new OrderMessage();
  94. orderMessage.setMessageStatus(2);
  95. orderMessage.setMessageType(3);
  96. messageService.updateOrderMessageStatus(orderMessage);
  97. }
  98. }else{
  99. logger.info("------------推送到+"+smsMessage.getTel()+"一条"+(smsMessage.getTypes() == 1?"待处理":"驳回")+"短信失败"+json.getReturnMsg());
  100. }
  101. }
  102. }
  103. }
  104. /**
  105. * 批量同步百胜订单信息 -- 客诉系统 -- 作废
  106. * @throws Exception
  107. */
  108. //@Scheduled(cron = "0 0 */1 * * ?")//每小时执行一次
  109. //@Scheduled(cron = "0 0/3 * * * ?")//每三分钟执行一次
  110. //@Scheduled(cron = "*/10 * * * * ?")
  111. public void syncEfastOrderList() throws Exception {
  112. logger.info("---------------- 批量同步百胜订单开始 ---------------");
  113. int pageNo = 1;
  114. int pageSize = 20;
  115. boolean flag = false; //控制是否还需要获取百胜订单信息
  116. String date = "";
  117. synchronized (lock) {
  118. String configParameter = sysConfigService.getSysConfig(1);
  119. do {
  120. //批量获取百胜订单信息
  121. JSONObject obj = null;
  122. try{
  123. obj = efastOrderService.listOrderInfoFormEfast(pageNo, pageSize, configParameter);
  124. }catch (Exception e){
  125. logger.info("Efast订单获取失败,失败原因:"+e.getMessage());
  126. }
  127. if (obj == null) {
  128. return;
  129. }
  130. int totalResults = obj.getInt("total_results"); //百胜返回总页数
  131. if (pageNo < totalResults) {
  132. flag = true;
  133. pageNo++;
  134. } else {
  135. flag = false;
  136. }
  137. salesOrderService.addSalesOrderList(obj);
  138. } while (flag); //百胜返回条目数如果等于设置的分页条目数,则继续查询下一页
  139. }
  140. logger.info("---------------- 批量同步百胜订单结束 ---------------");
  141. }
  142. /**
  143. * 同步百胜订单状态等信息----客诉系统 -- 作废
  144. * @throws Exception
  145. */
  146. //@Scheduled(cron = "0 0 */1 * * ?")//每小时执行一次
  147. // @Scheduled(cron = "0 0/3 * * * ?")//每三分钟执行一次
  148. //@Scheduled(cron = "*/10 * * * * ?")
  149. public void syncEfastOrderStatus() throws Exception {
  150. int pageNo = 1;
  151. int pageSize = 20;
  152. boolean flag = false; //控制是否还需要获取百胜订单信息
  153. /*int returnPageNo = 1;
  154. int returnPageSize = 20;
  155. boolean returnFlag = false; //控制是否还需要获取百胜退单信息*/
  156. synchronized (lock1) {
  157. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  158. Date beginDate = new Date();
  159. SalesOrder order = new SalesOrder();
  160. Calendar date = Calendar.getInstance();
  161. //获取同步百胜订单的开始时间
  162. String configParameter = sysConfigService.getSysConfig(2); //获取客诉订单同步百胜订单状态时间间隔
  163. date.setTime(beginDate);
  164. date.set(Calendar.DATE, date.get(Calendar.DATE) - Integer.valueOf(configParameter));
  165. order.setStartDate(format.parse(format.format(date.getTime())));
  166. order.setSalesCreateTime(format.parse(format.format(date.getTime())));
  167. //根据创建时间获取订单信息
  168. List<SalesOrder> orderlist = salesOrderService.listSalesOrder(order);
  169. logger.info("需要同步订单状态的订单有:" + orderlist.size() + "个;");
  170. if (orderlist == null || orderlist.size() == 0) {
  171. return;
  172. }
  173. do {
  174. //批量获取百胜订单信息
  175. JSONObject obj = efastOrderService.listOrderInfoFormEfast(pageNo, pageSize, format.format(order.getSalesCreateTime()));
  176. if (obj == null) {
  177. return;
  178. }
  179. JSONArray orderList = obj.getJSONArray("list");
  180. if (orderList == null || orderList.size() == 0) {
  181. return;
  182. }
  183. salesOrderService.updateOrderList(orderList, orderlist);
  184. int totalResults = obj.getInt("total_results"); //百胜返回总页数
  185. if (pageNo < totalResults) {
  186. flag = true;
  187. pageNo++;
  188. } else {
  189. flag = false;
  190. }
  191. } while (flag); //百胜返回条目数如果等于设置的分页条目数,则继续查询下一页
  192. //无法实现获取退单信息,只能查出已确认未收货的订单
  193. /*do {
  194. //批量获取百胜退单信息
  195. JSONObject obj = efastOrderService.listReturnOrderFormEfast(returnPageNo, returnPageSize, format.format(date.getTime()));
  196. if (obj == null) {
  197. return;
  198. }
  199. JSONArray orderList = obj.getJSONArray("list");
  200. System.out.println("orderList="+orderList);
  201. if (orderList == null || orderList.size() == 0) {
  202. return;
  203. }
  204. salesOrderService.updateReturnOrderList(orderList, orderlist);
  205. int totalResults = obj.getInt("total_results"); //百胜返回总页数
  206. if (returnPageNo < totalResults) {
  207. returnFlag = true;
  208. returnPageNo++;
  209. } else {
  210. returnFlag = false;
  211. }
  212. } while (returnFlag); //百胜返回条目数如果等于设置的分页条目数,则继续查询下一页*/
  213. }
  214. }
  215. /**客诉系统 自动追踪发货信息**/
  216. // @Scheduled(cron = "0 0/30 * * * ?")//每30分钟执行一次
  217. /*@Scheduled(cron = "0 0/3 * * * ?")//每三分钟执行一次*/
  218. // public void synchronousDelivery()throws Exception{
  219. //
  220. //
  221. // /*同步维修订单*/
  222. // Repair repair = new Repair();
  223. // List<Repair> listRepair = repairService.listSynchronizingRepair(repair);
  224. // if(listRepair.size() > 0){
  225. // for(Repair re:listRepair){
  226. // JSONObject respData = efastOrderService.getOrderFormEfastByOrderId(re.getRepairBackEfastOrderId());
  227. // EfastOrder efastOrder = efastUtil.respDataConversion(respData);
  228. // if(efastOrder == null){
  229. // return;
  230. // }
  231. // if (efastOrder.getOrderStatus() == 1){//1代表已发货 发货状态: 0(未发货)1(已发货,即已扫描出库)3(备货中)
  232. // re.setRepairSendName(efastOrder.getOrderAddressName());
  233. // re.setRepairSendTel(efastOrder.getOrderAddressTel());
  234. // //查询省市县id
  235. // /*Map<String,String> pccMap = provincesCitiesCounties(efastOrder);
  236. // re.setProvinceNumber(Integer.valueOf(pccMap.get("provinceId")));
  237. // re.setCityNumber(Integer.valueOf(pccMap.get("cityId")));
  238. // re.setAreaNumber(Integer.valueOf(pccMap.get("districtId")));*/
  239. // /*re.setRepairSendMergeAddress(pccMap.get("province")+"-"+pccMap.get("city")+"-"+pccMap.get("district"));*/
  240. // /*re.setRepairSendAddress(efastOrder.getOrderAddress());*/
  241. // re.setRepairSendLogisticsCompany(efastOrder.getOrderPostFirm());
  242. // re.setRepairSendLogisticsNo(efastOrder.getOrderPostNum());
  243. // /*re.setRepairSendStatus(2);*/
  244. // Integer msg = repairService.updateRepairInfo(re,null,null);
  245. // if(msg > 0){
  246. // //发送维修发货通知短信
  247. // sendSMS("<维修业务>",efastOrder.getOrderPostFirm(),efastOrder.getOrderPostNum(),re.getCustomerId(),re.getRepairBackTel());
  248. // }
  249. // }
  250. //
  251. // }
  252. // }
  253. //
  254. // /*同步换货订单*/
  255. // Renewed renewed = new Renewed();
  256. // List<Renewed> listRenewed = renewedService.listSynchronizingRenewed(renewed);
  257. // if(listRenewed.size() > 0){
  258. // for(Renewed re:listRenewed){
  259. // JSONObject respData = efastOrderService.getOrderFormEfastByOrderId(re.getRenewedBackEfastOrderId());
  260. // EfastOrder efastOrder = efastUtil.respDataConversion(respData);
  261. // if(efastOrder == null){
  262. // return;
  263. // }
  264. // if (efastOrder.getOrderStatus() == 1){//1代表已发货 发货状态: 0(未发货)1(已发货,即已扫描出库)3(备货中)
  265. // re.setRenewedSendName(efastOrder.getOrderAddressName());
  266. // re.setRenewedSendTel(efastOrder.getOrderAddressTel());
  267. // /*//查询省市县id
  268. // Map<String,String> pccMap = provincesCitiesCounties(efastOrder);
  269. // re.setProvinceNumber(Integer.valueOf(pccMap.get("provinceId")));
  270. // re.setCityNumber(Integer.valueOf(pccMap.get("cityId")));
  271. // re.setAreaNumber(Integer.valueOf(pccMap.get("districtId")));
  272. // re.setRenewedSendMergeAddress(pccMap.get("province")+"-"+pccMap.get("city")+"-"+pccMap.get("district"));
  273. // re.setRenewedSendAddress(efastOrder.getOrderAddress());*/
  274. // re.setRenewedSendLogisticsCompany(efastOrder.getOrderPostFirm());
  275. // re.setRenewedSendLogisticsNo(efastOrder.getOrderPostNum());
  276. // /*re.setRenewedSendStatus(2);*/
  277. // Integer msg = renewedService.updateRenewedInfo(re,null,null);
  278. // if(msg > 0){
  279. // //发送换货发货通知短信
  280. // sendSMS("<换货业务>",efastOrder.getOrderPostFirm(),efastOrder.getOrderPostNum(),re.getCustomerId(),re.getRenewedBackTel());
  281. // }
  282. // }
  283. // }
  284. // }
  285. // /*同步补发订单*/
  286. // Reissue reissue = new Reissue();
  287. // List<Reissue> listReissue = reissueService.listSynchronizingReissue(reissue);
  288. // if(listReissue.size() > 0){
  289. // for(Reissue re:listReissue){
  290. // JSONObject respData = efastOrderService.getOrderFormEfastByOrderId(re.getReissueBackEfastOrderId());
  291. // EfastOrder efastOrder = efastUtil.respDataConversion(respData);
  292. // if(efastOrder == null){
  293. // return;
  294. // }
  295. // if (efastOrder.getOrderStatus() == 1){//1代表已发货 发货状态: 0(未发货)1(已发货,即已扫描出库)3(备货中)
  296. // re.setReissueSendName(efastOrder.getOrderAddressName());
  297. // re.setReissueSendTel(efastOrder.getOrderAddressTel());
  298. // /*//查询省市县id
  299. // Map<String,String> pccMap = provincesCitiesCounties(efastOrder);
  300. // re.setProvinceNumber(Integer.valueOf(pccMap.get("provinceId")));
  301. // re.setCityNumber(Integer.valueOf(pccMap.get("cityId")));
  302. // re.setAreaNumber(Integer.valueOf(pccMap.get("districtId")));
  303. // re.setReissueSendMergeAddress(pccMap.get("province")+"-"+pccMap.get("city")+"-"+pccMap.get("district"));
  304. // re.setReissueSendAddress(efastOrder.getOrderAddress());*/
  305. // re.setReissueSendLogisticsCompany(efastOrder.getOrderPostFirm());
  306. // re.setReissueSendLogisticsNo(efastOrder.getOrderPostNum());
  307. // /*re.setReissueSendStatus(2);*/
  308. // Integer msg = reissueService.updateReissueInfo(re);
  309. // if(msg > 0){
  310. // //发送补发发货通知短信
  311. // sendSMS("<补发业务>",efastOrder.getOrderPostFirm(),efastOrder.getOrderPostNum(),re.getCustomerId(),re.getReissueSendTel());
  312. //
  313. // }
  314. // }
  315. // }
  316. // }
  317. // }
  318. /**
  319. * 发送发货通知
  320. * @param relation 维修 换货 补发
  321. * @param postFirm 物流公司代码
  322. * @param postNum 物流单号
  323. * @param customerId 客诉主键id
  324. * @param tel 手机号
  325. */
  326. public void sendSMS(String relation,String postFirm,String postNum,Integer customerId,String tel){
  327. if(postFirm != null && !postFirm.equals("") && postNum != null && !postNum.equals("")
  328. && customerId > 0 && !tel.equals("")){
  329. postFirm = KuaiDi100.replace(postFirm);
  330. if(!postFirm.equals("")){
  331. ProductType productType = customerService.getcompanyAffiliation(customerId);
  332. if(productType != null){
  333. String rejected_text = "";
  334. //1:美国watero; 2:上朵电动牙刷 3:优尼雅净水机
  335. if (productType.getTypeCompany() == 1){
  336. rejected_text = RELATION_SEND_WATERO;
  337. }
  338. if (productType.getTypeCompany() == 2){
  339. rejected_text = RELATION_SEND_SHANGDUO;
  340. }
  341. if (productType.getTypeCompany() == 3){
  342. rejected_text = RELATION_SEND_YULIA;
  343. }
  344. if (productType.getTypeCompany() == 4){
  345. rejected_text = RELATION_SEND_AIBERLE;
  346. }
  347. String text = MessageFormat.format(rejected_text, relation,postFirm+","+postNum);
  348. smsService.sendOtherCMS(tel,text);
  349. }
  350. }
  351. }
  352. }
  353. /**
  354. * 查询省市县id
  355. * @param
  356. */
  357. // public Map<String,String> provincesCitiesCounties(EfastOrder efastOrder){
  358. // Map<String,String> map = new HashMap<String, String>();
  359. // String province = "";
  360. // String city = "";
  361. // String zone = "";
  362. // //省
  363. // if(efastOrder.getOrderProvince().substring(efastOrder.getOrderProvince().length() - 1,efastOrder.getOrderProvince().length()).equals("省")){
  364. // province = efastOrder.getOrderProvince().substring(0,efastOrder.getOrderProvince().length() - 1);
  365. // }else{
  366. // province = efastOrder.getOrderProvince();
  367. // }
  368. // Province provinceinfo = new Province();
  369. // provinceinfo.setProvince(province);
  370. // List<Province> provinceList = addressService.listProvince(provinceinfo);
  371. // if(provinceList.size() < 1){
  372. // provinceinfo.setProvince(null);
  373. // provinceList = addressService.listProvince(provinceinfo);
  374. // }
  375. // map.put("provinceId",String.valueOf(provinceList.get(0).getProvinceId()));
  376. // map.put("province",provinceList.get(0).getProvince());
  377. //
  378. //
  379. // //市
  380. // city = efastOrder.getOrderCity().substring(0,efastOrder.getOrderCity().length() - 1);
  381. // City cityInfo = new City();
  382. // cityInfo.setCity(city);
  383. // List<City> cityList = addressService.listCity(cityInfo);
  384. // if(cityList.size() < 1){
  385. // cityInfo.setCity(null);
  386. // cityInfo.setProvinceId(provinceList.get(0).getProvinceId());
  387. // cityList = addressService.listCity(cityInfo);
  388. // }
  389. // map.put("cityId",String.valueOf(cityList.get(0).getCityId()));
  390. // map.put("city",cityList.get(0).getCity());
  391. //
  392. // //区
  393. // zone = efastOrder.getOrderArea().substring(0,efastOrder.getOrderArea().length() - 1);
  394. // District district = new District();
  395. // district.setDistrict(zone);
  396. // List<District> districtList = addressService.listDistrict(district);
  397. // if(districtList.size() < 1){
  398. // district.setDistrict(null);
  399. // district.setCityId(cityList.get(0).getCityId());
  400. // districtList = addressService.listDistrict(district);
  401. // }
  402. // map.put("districtId",String.valueOf(districtList.get(0).getDistrictId()));
  403. // map.put("district",districtList.get(0).getDistrict());
  404. // return map;
  405. // }
  406. /**客诉系统 自动追踪发货信息**/
  407. // @Scheduled(cron = "0 0/60 * * * ?")//每60分钟执行一次
  408. // @Scheduled(cron = "0 0/1 * * * ?")//每1分钟执行一次
  409. // public void syncSendBackCustomer()throws Exception{
  410. // CmRelation cmRelation = new CmRelation();
  411. // cmRelation.setRelationBackStatus(2);
  412. // List<CmRelation> cmRelationList = cmRelationService.getCmRelationList(cmRelation);
  413. // for(int i=0;i<cmRelationList.size();i++){
  414. // CmRelation cc = cmRelationList.get(i);
  415. // if(!StringUtils.isEmpty(cc.getRelationBackLogisticsCompany()) && !StringUtils.isEmpty(cc.getRelationBackLogisticsNo())){
  416. // JSONObject rst = kuaidi100.getExpressInfo(cc.getRelationBackLogisticsCompany(),cc.getRelationBackLogisticsNo());
  417. // if(rst.has("state") && rst.getInt("state") == 3){ //当快递状态为已签收的时候
  418. // Integer flag = 0;
  419. // try{
  420. // flag = cmRelationService.updateStatus(cc);
  421. // }catch (RuntimeException e){
  422. // logger.info("====== 客诉寄回签收报错 :客诉id:"+cc.getCustomerId()+" ======"+e.getMessage());
  423. // }
  424. // if(flag < 1){
  425. // logger.info("====== 客诉寄回签收失败 :客诉id:"+cc.getCustomerId()+" ======");
  426. // }else{
  427. // logger.info("====== 客诉寄回签收成功 :客诉id:"+cc.getCustomerId()+" ======");
  428. // }
  429. // }
  430. // }
  431. // }
  432. // }
  433. /**客诉系统 自动追踪发货信息**/
  434. // @Scheduled(cron = "0 0/2 * * * ?")//每2分钟执行一次
  435. @Scheduled(cron = "0 0 9 * * ?")//每天上午午9点触发
  436. public void postageRemind()throws Exception{
  437. Map<Integer,Integer> map = new HashMap<Integer,Integer>();
  438. List<CompanyInfo> companyInfoList = companyInfoService.listCompanyInfo(new CompanyInfo());
  439. for (CompanyInfo ci: companyInfoList ) {
  440. /*权限去重*/
  441. Set<Integer> authorityCustomerManagerSet = new HashSet();
  442. Set<Integer> authorityFinancialManagerSet = new HashSet();
  443. Set<Integer> authorityFinancialPaymentSet = new HashSet();
  444. PostageAuthority postageAuthority = new PostageAuthority();
  445. postageAuthority.setAuthorityStatus(1);
  446. postageAuthority.setCompanyId(ci.getCompanyId());
  447. List<PostageAuthority> postageAuthorityList = postageAuthorityService.getPostageAuthorityList(postageAuthority);
  448. for (int j=0;j<postageAuthorityList.size();j++){
  449. PostageAuthority pa = postageAuthorityList.get(j);
  450. if(pa.getAuthorityCustomerManager() != null && pa.getAuthorityCustomerManager() != 0){
  451. authorityCustomerManagerSet.add(pa.getAuthorityCustomerManager());
  452. }
  453. if(pa.getAuthorityFinancialManager() != null && pa.getAuthorityFinancialManager() != 0){
  454. authorityFinancialManagerSet.add(pa.getAuthorityFinancialManager());
  455. }
  456. if(pa.getAuthorityFinancialPayment() != null && pa.getAuthorityFinancialPayment() != 0){
  457. authorityFinancialPaymentSet.add(pa.getAuthorityFinancialPayment());
  458. }
  459. }
  460. Postage pt = new Postage();
  461. pt.setCompanyId(ci.getCompanyId());
  462. pt.setPostageManagerStatus(1); //客服经理审核 1:审核中
  463. for (Integer customerManager: authorityCustomerManagerSet) { //customerManager 为id
  464. Integer postageNumber = postageService.getPostageNumber(pt);
  465. if(map.get(customerManager) == null){
  466. map.put(customerManager,postageNumber);
  467. }else{
  468. Integer number = map.get(customerManager);
  469. map.put(customerManager,number + postageNumber);
  470. }
  471. }
  472. pt = new Postage();
  473. pt.setCompanyId(ci.getCompanyId());
  474. pt.setPostageFinanceStatus(1); //状态(财务审核) 1:审核中
  475. for (Integer financialManager: authorityFinancialManagerSet) { //financialManager 为id
  476. Integer postageNumber = postageService.getPostageNumber(pt);
  477. if(map.get(financialManager) == null){
  478. map.put(financialManager,postageNumber);
  479. }else{
  480. Integer number = map.get(financialManager);
  481. map.put(financialManager,number + postageNumber);
  482. }
  483. }
  484. pt = new Postage();
  485. pt.setCompanyId(ci.getCompanyId());
  486. pt.setPostageTransferStatus(1); //是否转账:1待转 2:已转
  487. for (Integer financialPayment: authorityFinancialPaymentSet) { //financialPayment 为id
  488. Integer postageNumber = postageService.getPostageNumber(pt);
  489. if(map.get(financialPayment) == null){
  490. map.put(financialPayment,postageNumber);
  491. }else{
  492. Integer number = map.get(financialPayment);
  493. map.put(financialPayment,number + postageNumber);
  494. }
  495. }
  496. }
  497. for (Map.Entry<Integer,Integer> m: map.entrySet()) {
  498. Integer number = m.getValue();
  499. Admin admin = new Admin();
  500. admin.setAdminId(m.getKey());
  501. admin = sysService.get(admin);
  502. String tel = admin.getAdminTel();
  503. if(admin == null || tel == null || "".equals(tel)){
  504. logger.info("邮费转账发送待处理短信,手机号码为空,"+ tel+"===id为"+m.getKey());
  505. continue;
  506. }
  507. if(number == null || number == 0){
  508. continue;
  509. }
  510. String text = MessageFormat.format(REMIND_POSTAGE_PENDING,number);
  511. smsService.sendOtherCMS(tel,text);
  512. }
  513. }
  514. /**
  515. * 查询维修超时数据并短信通知
  516. */
  517. @Scheduled(cron = "0 50 8 * * ?")//每天上午午9点触发
  518. /* @Scheduled(cron = "0 0/1 * * * ?")//每2分钟执行一次*/
  519. public void detectTimeoutNotice() throws Exception {
  520. logger.info("---------------- 询维修超时数据并短信通知开始 ---------------");
  521. //待检测即将超时数据
  522. List<ComplaintDetectInfo> listMaintenanceCut = complaintDetectInfoService.listMaintenanceCutNotice();
  523. //待维修即将超时数据
  524. List<ComplaintDetectInfo> listCompleteCut = complaintDetectInfoService.listCompleteCutNotice();
  525. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  526. if(listMaintenanceCut != null && listMaintenanceCut.size() > 0){
  527. for(ComplaintDetectInfo info : listMaintenanceCut){
  528. if(info.getDetectNumber() != null && info.getMaintenanceCutTime() != null){
  529. //发送短信通知维修检测人员
  530. String text = MessageFormat.format(SmsConfig.DETECTION_TIMEOUT_NOTIFICATION, info.getDetectNumber(),"检测超时",format.format(info.getMaintenanceCutTime()));
  531. String result = smsService.sendOtherCMS(SmsConfig.CUSTOMER_PHONE, text);
  532. logger.info("给 " + SmsConfig.CUSTOMER_PHONE + " 手机用户发送短信:" + text+"发送检测即将超时数据维修人员:"+result);
  533. }
  534. }
  535. }
  536. if(listCompleteCut != null && listCompleteCut.size() > 0){
  537. for(ComplaintDetectInfo info : listCompleteCut){
  538. //发送短信通知维修检测人员
  539. if(info.getDetectNumber() != null && info.getCompleteCutTime() != null){
  540. String text = MessageFormat.format(SmsConfig.DETECTION_TIMEOUT_NOTIFICATION, info.getDetectNumber(),"维修超时",format.format(info.getCompleteCutTime()));
  541. String result = smsService.sendOtherCMS(SmsConfig.CUSTOMER_PHONE, text);
  542. logger.info("给 " + SmsConfig.CUSTOMER_PHONE + " 手机用户发送短信:" + text+"发送维修即将超时数据维修人员:"+result);
  543. }
  544. }
  545. }
  546. logger.info("---------------- 询维修超时数据并短信通知结束 ---------------");
  547. }
  548. //@Scheduled(cron = "*/10 * * * * ?")
  549. //@Scheduled(cron = "0 0 9,11,14,16,18,20 * * ? ")//推送时间分别为每天早上九点、中午十一点、下午三点、下午六点、晚上八点
  550. //@Scheduled(cron = "0 0 */1 * * ?")//每小时执行一次
  551. // @Scheduled(cron = "0 0/3 * * * ?")//每三分钟执行一次
  552. @Scheduled(cron = "0 0/30 * * * ?")//每半个小时执行一次
  553. public void orderCaseDate(){
  554. logger.info("查询订单揽件时间");
  555. List<SalesOrder> salesOrderList = salesOrderService.orderAfterCaseDate();
  556. if (salesOrderList == null || salesOrderList.isEmpty()) {
  557. return;
  558. }
  559. for (SalesOrder salesOrder:salesOrderList) {
  560. // 查询订单对应的物流公司
  561. LogisticsInfo log = new LogisticsInfo();
  562. log.setLogisticsRstCode(salesOrder.getSalesPostFirm());
  563. List<LogisticsInfo> listlog = logisticsInfoService.getLogisticsInfoList(log);
  564. // 调用第三方接口查询物流信息
  565. Date date = kuaidi100.selectCourierSignCaseTime(listlog.get(0).getLogisticsEfastCode(),salesOrder.getSalesPostNum());
  566. if(date == null){
  567. continue;
  568. }
  569. // 编辑订单的揽件时间
  570. SalesOrder so = new SalesOrder();
  571. so.setSalesId(salesOrder.getSalesId());
  572. so.setOrderCaseDate(date);
  573. if(salesOrderService.update(so) <= 0){
  574. logger.info("修改揽件时间异常,订单号:"+salesOrder.getSalesOrderId());
  575. }
  576. }
  577. }
  578. }