DeliveryAction.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. package com.minpay.shouhuo.deliveryaction;
  2. import com.min.base64.Base64;
  3. import com.min.des.DesUtils;
  4. import com.min.util.OffSetUtil;
  5. import com.minpay.common.bean.DrawDto;
  6. import com.minpay.common.bean.User;
  7. import com.minpay.common.exception.BusinessCodeException;
  8. import com.minpay.common.format.IFormatService;
  9. import com.minpay.common.service.IPropertiesService;
  10. import com.minpay.common.service.IPublicService;
  11. import com.minpay.common.util.CommonUtil;
  12. import com.minpay.common.util.DateUtil;
  13. import com.minpay.common.util.HttpPostUtil;
  14. import com.minpay.db.table.mapper.*;
  15. import com.minpay.db.table.model.*;
  16. import com.minpay.db.table.own.mapper.DeliveryMapper;
  17. import com.startup.minpay.frame.business.IMINAction;
  18. import com.startup.minpay.frame.business.res.MINActionResult;
  19. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  20. import com.startup.minpay.frame.data.format.MINCopyFormat;
  21. import com.startup.minpay.frame.exception.MINBusinessException;
  22. import com.startup.minpay.frame.jdbc.MINRowBounds;
  23. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  24. import com.startup.minpay.frame.service.base.Service;
  25. import com.startup.minpay.frame.session.MINSession;
  26. import com.startup.minpay.frame.target.MINAction;
  27. import com.startup.minpay.frame.target.MINComponent;
  28. import com.startup.minpay.frame.target.MINParam;
  29. import com.startup.minpay.util.Log;
  30. import io.netty.util.internal.StringUtil;
  31. import net.sf.json.JSONObject;
  32. import javax.servlet.http.HttpServletResponse;
  33. import java.io.IOException;
  34. import java.util.HashMap;
  35. import java.util.List;
  36. import java.util.Map;
  37. /**
  38. * 售货机提货相关接口
  39. * @author Zhumq
  40. *
  41. */
  42. @MINComponent
  43. public class DeliveryAction implements IMINAction{
  44. /**查询提货信息*/
  45. public static final String QUERY_DELIVERY_INFO = "queryDeliveryInfo";
  46. /**修改提货信息*/
  47. public static final String MODIFY_DELIVERY_INFO = "modifyDeliveryInfo";
  48. /**提货接口*/
  49. public static final String MAKE_DELIVERY_FOR_MACHINE = "makeDeliveryForMachine";
  50. /**提货回调*/
  51. public static final String BACK_DELIVERY_FOR_MACHINE = "backDeliveryForMachine";
  52. /**提货(无需session)*/
  53. public static final String MAKE_DELIVERY_FOR_MACHINE_NOSESSION = "makeDeliveryForMachineNoSession";
  54. /**提货(测试专用)*/
  55. public static final String MAKE_DELIVERY_FOR_MACHINE_TEST = "makeDeliveryForMachineTest";
  56. /**
  57. * 查询提货信息
  58. * @param equNo 售货机编号
  59. * @param dates 创建时间
  60. * @param userNo 商户编号
  61. * @param status 提货状态
  62. * @param orderNo 订单编号
  63. * @param personNo 会员编号
  64. * @param page
  65. * @param limit
  66. * @param session
  67. * @return
  68. * @throws MINBusinessException
  69. */
  70. @MINAction(value = QUERY_DELIVERY_INFO)
  71. public MINActionResult queryDeliveryInfo(
  72. @MINParam(key = "equNo")String equNo,
  73. @MINParam(key = "dates")String dates,
  74. @MINParam(key = "userNo")String userNo,
  75. @MINParam(key = "status")String status,
  76. @MINParam(key = "orderNo")String orderNo,
  77. @MINParam(key = "personNo")String personNo,
  78. @MINParam(key = "page",defaultValue = "1")int page,
  79. @MINParam(key = "limit",defaultValue = "10")int limit,
  80. MINSession session) throws MINBusinessException{
  81. MINActionResult res = new MINActionResult();
  82. if(CommonUtil.isEmpty(equNo)){
  83. throw new BusinessCodeException("JINM1101");//售货机异常,请联系工作人员
  84. }
  85. //解密售货机编号
  86. String equNoNew = OffSetUtil.deScanCode(equNo);
  87. //获取操作员信息
  88. User user = session.getUser();
  89. //创建分页对象
  90. MINRowBounds row = new MINRowBounds(page, limit);
  91. //初始化查询条件
  92. Map<String,String> map = new HashMap<String,String>();
  93. map.put("orderNo", orderNo);//订单编号
  94. map.put("status", status);//提货状态
  95. map.put("userNo", userNo);//商户编号
  96. map.put("equNo", equNoNew);//售货机编号
  97. if(CommonUtil.isEmpty(personNo)){
  98. personNo = user.getId();
  99. }
  100. map.put("personNo", personNo);//会员编号
  101. map.put("dates", dates);//创建时间
  102. //传入渠道验证
  103. map.put("channel", user.getChannel());
  104. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  105. .getMybatisMapper(DeliveryMapper.class)
  106. .queryDeliveryInfo(map,row);
  107. //格式花时间和状态
  108. list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime");
  109. list = new MINCopyFormat("{status:'statusDesc',proType:'proTypeDesc'}").format(list);
  110. list = Service.lookup(IFormatService.class).formatEnum(list,"{statusDesc:'VM_DELIVERY_STATUS',proTypeDesc:'PRO_TYPE'}");
  111. //传递返回值
  112. res.set(IMINBusinessConstant.F_PAGING_LAY, list);
  113. res.set(IMINBusinessConstant.F_PAGING_COUNT, row.getMaxRows());
  114. return res;
  115. }
  116. /**
  117. * 提货接口
  118. * @param orderNo 订单编号
  119. * @param deliveryNo 提货单编号
  120. * @param session
  121. * @return
  122. * @throws Exception
  123. */
  124. @MINAction(value = MAKE_DELIVERY_FOR_MACHINE)
  125. public MINActionResult makeDeliveryForMachine(
  126. @MINParam ( key = "orderNo")String orderNo,
  127. @MINParam ( key = "deliveryNo")String deliveryNo,
  128. MINSession session) throws Exception{
  129. MINActionResult res = new MINActionResult();
  130. User user = session.getUser();
  131. /**获取售货机推送地址*/
  132. String url = Service.lookup(IPropertiesService.class)
  133. .getSystemProperties().get(user.getChannel() + "_GET_MACHINE_ADDRESS").getKey();
  134. String retUrl = Service.lookup(IPropertiesService.class)
  135. .getSystemProperties().get(user.getChannel() + "_RETURN_MACHINE_ADDRESS").getKey();
  136. //组装推送接口
  137. String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON");
  138. String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine");
  139. /**查询数据(提货单号是否存在)*/
  140. //初始化查询条件
  141. Map<String,String> map = new HashMap<String,String>();
  142. map.put("deliveryNo", deliveryNo);//提货编号
  143. map.put("orderNo", orderNo);//订单编号
  144. //传入渠道验证
  145. map.put("channel", user.getChannel());
  146. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  147. .getMybatisMapper(DeliveryMapper.class)
  148. .queryDeliverys(map);
  149. if(list == null || list.size() != 1 ){
  150. throw new MINBusinessException("没有提货信息!");
  151. }
  152. String equType = list.get(0).get("equType");
  153. if(!"00".equals(equType) && !"01".equals(equType)){
  154. throw new MINBusinessException("机器类型不支持推货!");
  155. }
  156. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  157. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo);
  158. if(delInf == null){
  159. throw new MINBusinessException("没有提货信息!");
  160. }
  161. if(delInf.getProNums().equals(delInf.getDeliveryNums())){
  162. throw new MINBusinessException("提货已完成!");
  163. }
  164. if(!delInf.getStatus().equals("0")
  165. && !delInf.getStatus().equals("1") && !delInf.getStatus().equals("5")){
  166. throw new MINBusinessException("提货处理中,请稍后!");
  167. }
  168. //改变提货状态为5处理中....
  169. delInf.setStatus("5");
  170. //处理提货状态
  171. Service.lookup(IMINDataBaseService.class)
  172. .getMybatisMapper(VmDeliveryInfMapper.class)
  173. .updateByPrimaryKeySelective(delInf);
  174. Map<String,String> mapNew = new HashMap<String,String>();
  175. mapNew.put("imeiAddr", list.get(0).get("equIMEI"));
  176. mapNew.put("cargoNo", list.get(0).get("cargoWay"));
  177. mapNew.put("deliveryNo", deliveryNo);
  178. mapNew.put("channel", user.getChannel());
  179. mapNew.put("returnUrl", returnUrl);
  180. mapNew.put("orderNo", orderNo);
  181. mapNew.put("MINView", "JSON");
  182. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  183. String str = jsonOb.toString();
  184. Log.info("通知售货机推货:".concat(str));
  185. String passwardKey = Service.lookup(IPropertiesService.class)
  186. .getSystemProperties().get(user.getChannel() +"_TO_MACHINE_PASSWORD_KEY").getKey();
  187. //数据加密
  188. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  189. String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe);
  190. // //获取转义后响应信息
  191. JSONObject detail = JSONObject.fromObject(results);
  192. String code = String.valueOf(detail.get("code"));
  193. if(!"0".equals(code)){
  194. Log.info("售货机退货失败:".concat(code));
  195. //改变提货状态为3卡货(提货失败)....
  196. delInf.setStatus("3");
  197. //处理提货状态
  198. Service.lookup(IMINDataBaseService.class)
  199. .getMybatisMapper(VmDeliveryInfMapper.class)
  200. .updateByPrimaryKeySelective(delInf);
  201. throw new BusinessCodeException("JINM0011");//操作失败!
  202. }
  203. //获取处理状态
  204. String state = String.valueOf(detail.get("returnData"));
  205. JSONObject stateNew = JSONObject.fromObject(state);
  206. if(stateNew != null
  207. && !"200".equals(String.valueOf(stateNew.get("code")))){
  208. Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg"))));
  209. //改变提货状态为3卡货....
  210. delInf.setStatus("3");
  211. //处理提货状态
  212. Service.lookup(IMINDataBaseService.class)
  213. .getMybatisMapper(VmDeliveryInfMapper.class)
  214. .updateByPrimaryKeySelective(delInf);
  215. String msg = String.valueOf(stateNew.get("msg"));
  216. throw new MINBusinessException(msg);//操作失败!
  217. }else if("200".equals(String.valueOf(stateNew.get("code")))){
  218. }
  219. return res;
  220. }
  221. /**
  222. * 提货回调
  223. * @param response
  224. * @param deliveryNo
  225. * @param outNums
  226. * @param status
  227. * @param failReason
  228. * @throws MINBusinessException
  229. */
  230. @MINAction(value = BACK_DELIVERY_FOR_MACHINE,session = false)
  231. public void backDeliveryForMachine(HttpServletResponse response,
  232. String deliveryNo,
  233. String outNums,
  234. String status,
  235. String failReason) throws MINBusinessException {
  236. // 给第三方传递回调成功信息
  237. try {
  238. if(response != null) {
  239. response.getOutputStream().write("Success".getBytes());
  240. response.flushBuffer();
  241. }
  242. } catch (IOException e) {
  243. e.printStackTrace();
  244. }
  245. // 出货后维护销量
  246. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  247. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo);
  248. //处理数量
  249. if(CommonUtil.isEmpty(outNums)){
  250. outNums = "0";
  251. }
  252. String newDelNUms = CommonUtil.add(delInf.getDeliveryNums(), outNums);
  253. int compare = CommonUtil.compare(delInf.getProNums(), newDelNUms);
  254. if(0 == compare ){
  255. delInf.setStatus("2");//已出货
  256. }else if(compare > 0){
  257. delInf.setStatus("1");//部分出货
  258. }
  259. delInf.setDeliveryNums(newDelNUms);
  260. //维护出货状态和数量
  261. Service.lookup(IMINDataBaseService.class)
  262. .getMybatisMapper(VmDeliveryInfMapper.class)
  263. .updateByPrimaryKeySelective(delInf);
  264. }
  265. /**
  266. * 创建提货信息
  267. * @return
  268. * @throws BusinessCodeException
  269. * @throws MINBusinessException
  270. */
  271. //@MINAction(value = "createDeliveryInfo",session = false)
  272. public static void createDeliveryInfo(
  273. List<DrawDto> drawDtoList
  274. ) throws BusinessCodeException, MINBusinessException{
  275. String nowTime = DateUtil.getCurrentDateTimeString();
  276. for (int i = 0; i < drawDtoList.size(); i++) {
  277. DrawDto drawDto = drawDtoList.get(i);
  278. String orderId = drawDto.getOrderId();
  279. String orderDetailsId = drawDto.getOrderDetailsId();
  280. //获取订单信息
  281. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  282. .getMybatisMapper(VmOrderInfMapper.class)
  283. .selectByPrimaryKey(orderId);
  284. if(ordInf == null){
  285. throw new BusinessCodeException("JINM0114");//订单信息不存在
  286. }else{
  287. if(!"00".equals(ordInf.getState())){
  288. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  289. }
  290. }
  291. VmOrderDetails detInf = Service.lookup(IMINDataBaseService.class)
  292. .getMybatisMapper(VmOrderDetailsMapper.class)
  293. .selectByPrimaryKey(orderDetailsId);
  294. //中奖的
  295. if(drawDto.isDraw()){
  296. //创建提货对象
  297. VmDeliveryInf dlInf = new VmDeliveryInf();
  298. //获取提货表主键
  299. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  300. dlInf.setDeliveryId(dlId); //提货编号
  301. dlInf.setChannel(ordInf.getChannel()); //渠道
  302. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  303. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  304. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  305. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  306. dlInf.setProName(detInf.getProName()); //商品名称
  307. dlInf.setProPrice(detInf.getProPrice()); //单价
  308. dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量
  309. dlInf.setAmount(detInf.getAmount()); //金额
  310. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  311. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  312. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  313. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  314. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  315. dlInf.setCreateTime(nowTime); //创建时间
  316. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  317. dlInf.setModifyTime(nowTime); //修改时间
  318. dlInf.setBranchid(ordInf.getBranchid());
  319. dlInf.setProEquRelId(detInf.getProEquRelId());
  320. //执行新增提货信息
  321. Service.lookup(IMINDataBaseService.class)
  322. .getMybatisMapper(VmDeliveryInfMapper.class)
  323. .insertSelective(dlInf);
  324. //更新订单详情
  325. detInf.setDeliveryId(dlId);
  326. detInf.setIsWinning("01");
  327. detInf.setIsDelivery("00");
  328. Service.lookup(IMINDataBaseService.class)
  329. .getMybatisMapper(VmOrderDetailsMapper.class)
  330. .updateByPrimaryKeySelective(detInf);
  331. /**没有中奖的*/
  332. }else{
  333. detInf.setIsWinning("00");
  334. Service.lookup(IMINDataBaseService.class)
  335. .getMybatisMapper(VmOrderDetailsMapper.class)
  336. .updateByPrimaryKeySelective(detInf);
  337. }
  338. }
  339. }
  340. /**
  341. * 创建提货信息
  342. * @param orderNo 订单编号
  343. * @return
  344. * @throws BusinessCodeException
  345. * @throws MINBusinessException
  346. */
  347. //@MINAction(value = "createDeliveryInfo",session = false)
  348. public MINActionResult createDeliveryInfoTwo(
  349. // @MINParam(key = "orderNo")
  350. String orderNo
  351. ) throws BusinessCodeException, MINBusinessException{
  352. MINActionResult res = new MINActionResult();
  353. String nowTime = DateUtil.getCurrentDateTimeString();
  354. //获取订单信息
  355. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  356. .getMybatisMapper(VmOrderInfMapper.class)
  357. .selectByPrimaryKey(orderNo);
  358. if(ordInf == null){
  359. throw new BusinessCodeException("JINM0114");//订单信息不存在
  360. }else{
  361. if(!"00".equals(ordInf.getState())){
  362. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  363. }
  364. }
  365. //获取已支付的,待提货的订单商品信息
  366. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  367. examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo);
  368. List<VmOrderDetails> ordetList = Service.lookup(IMINDataBaseService.class)
  369. .getMybatisMapper(VmOrderDetailsMapper.class)
  370. .selectByExample(examp);
  371. for (int i = 0; i < ordetList.size(); i++) {
  372. VmOrderDetails detInf = ordetList.get(i);
  373. if(detInf != null){
  374. //创建提货对象
  375. VmDeliveryInf dlInf = new VmDeliveryInf();
  376. //获取提货表主键
  377. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  378. res.set("dlId", dlId);
  379. dlInf.setDeliveryId(dlId); //提货编号
  380. dlInf.setChannel(ordInf.getChannel()); //渠道
  381. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  382. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  383. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  384. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  385. dlInf.setProName(detInf.getProName()); //商品名称
  386. dlInf.setProPrice(detInf.getProPrice()); //单价
  387. dlInf.setProNums(detInf.getProNums()); //数量
  388. dlInf.setAmount(detInf.getAmount()); //金额
  389. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  390. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  391. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  392. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  393. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  394. dlInf.setCreateTime(nowTime); //创建时间
  395. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  396. dlInf.setModifyTime(nowTime); //修改时间
  397. //执行新增提货信息
  398. Service.lookup(IMINDataBaseService.class)
  399. .getMybatisMapper(VmDeliveryInfMapper.class)
  400. .insert(dlInf);
  401. }
  402. }
  403. return res;
  404. }
  405. /**
  406. * 创建提货信息
  407. * @param orderNo 订单编号
  408. * @return
  409. * @throws BusinessCodeException
  410. * @throws MINBusinessException
  411. */
  412. //@MINAction(value = "createDeliveryInfo",session = false)
  413. public static void purchaseCreateDeliveryInfo(
  414. String orderNo,String drawNumber
  415. ) throws BusinessCodeException, MINBusinessException{
  416. String nowTime = DateUtil.getCurrentDateTimeString();
  417. //获取订单信息
  418. VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class)
  419. .getMybatisMapper(VmOrderInfMapper.class)
  420. .selectByPrimaryKey(orderNo);
  421. if(ordInf == null){
  422. throw new BusinessCodeException("JINM0114");//订单信息不存在
  423. }else{
  424. if(!"00".equals(ordInf.getState())){
  425. throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货
  426. }
  427. }
  428. //获取已支付的,待提货的订单商品信息
  429. VmOrderDetailsExample examp = new VmOrderDetailsExample();
  430. examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo);
  431. List<VmOrderDetails> ordetList = Service.lookup(IMINDataBaseService.class)
  432. .getMybatisMapper(VmOrderDetailsMapper.class)
  433. .selectByExample(examp);
  434. for (int i = 0; i < ordetList.size(); i++) {
  435. VmOrderDetails detInf = ordetList.get(i);
  436. if(detInf != null){
  437. //创建提货对象
  438. VmDeliveryInf dlInf = new VmDeliveryInf();
  439. //获取提货表主键
  440. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID");
  441. dlInf.setDeliveryId(dlId); //提货编号
  442. dlInf.setChannel(ordInf.getChannel()); //渠道
  443. dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号
  444. dlInf.setPersonId(ordInf.getPersonId()); //会员编号
  445. dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号
  446. dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品
  447. dlInf.setProName(detInf.getProName()); //商品名称
  448. dlInf.setProPrice(detInf.getProPrice()); //单价
  449. if(!CommonUtil.isEmpty(drawNumber)){
  450. dlInf.setProNums(drawNumber); //数量
  451. }else{
  452. dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量
  453. }
  454. dlInf.setAmount(detInf.getAmount()); //金额
  455. dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零
  456. dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0
  457. dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道
  458. dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注
  459. dlInf.setCreateUser(ordInf.getPersonId()); //创建人
  460. dlInf.setCreateTime(nowTime); //创建时间
  461. dlInf.setModifyUser(ordInf.getPersonId()); //修改人
  462. dlInf.setModifyTime(nowTime); //修改时间
  463. dlInf.setProEquRelId(detInf.getProEquRelId()); //货道编号
  464. //执行新增提货信息
  465. Service.lookup(IMINDataBaseService.class)
  466. .getMybatisMapper(VmDeliveryInfMapper.class)
  467. .insertSelective(dlInf);
  468. //订单明细表set提货单编号
  469. detInf.setDeliveryId(dlId);
  470. detInf.setIsDelivery("00");
  471. Service.lookup(IMINDataBaseService.class)
  472. .getMybatisMapper(VmOrderDetailsMapper.class)
  473. .updateByPrimaryKeySelective(detInf);
  474. }
  475. }
  476. }
  477. /**
  478. * 提货接口
  479. * @param orderNo 订单编号
  480. * @param deliveryNo 提货单编号
  481. * @return
  482. * @throws Exception
  483. */
  484. @MINAction(value = MAKE_DELIVERY_FOR_MACHINE_NOSESSION ,session = false)
  485. public MINActionResult makeDeliveryForMachineNoSession(
  486. @MINParam ( key = "orderNo")String orderNo,
  487. @MINParam ( key = "deliveryNo")String deliveryNo
  488. ) throws Exception{
  489. MINActionResult res = new MINActionResult();
  490. /**获取售货机推送地址*/
  491. String url = Service.lookup(IPropertiesService.class)
  492. .getSystemProperties().get("V01_GET_MACHINE_ADDRESS").getKey();
  493. String retUrl = Service.lookup(IPropertiesService.class)
  494. .getSystemProperties().get( "V01_RETURN_MACHINE_ADDRESS").getKey();
  495. //组装推送接口
  496. String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON");
  497. String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine");
  498. /**查询数据(提货单号是否存在)*/
  499. //初始化查询条件
  500. Map<String,String> map = new HashMap<String,String>();
  501. map.put("deliveryNo", deliveryNo);//提货编号
  502. map.put("orderNo", orderNo);//订单编号
  503. //传入渠道验证
  504. map.put("channel", "V01");
  505. List<Map<String,String>> list = Service.lookup(IMINDataBaseService.class)
  506. .getMybatisMapper(DeliveryMapper.class)
  507. .queryDeliverys(map);
  508. if(list == null || list.size() != 1 ){
  509. throw new MINBusinessException("没有提货信息!");
  510. }
  511. String equType = list.get(0).get("equType");
  512. if(!"00".equals(equType) && !"01".equals(equType)){
  513. throw new MINBusinessException("机器类型不支持推货!");
  514. }
  515. VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class)
  516. .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo);
  517. if(delInf == null){
  518. throw new MINBusinessException("没有提货信息!");
  519. }
  520. if(delInf.getProNums().equals(delInf.getDeliveryNums())){
  521. throw new MINBusinessException("提货已完成!");
  522. }
  523. //改变提货状态为5处理中....
  524. delInf.setStatus("5");
  525. //处理提货状态
  526. Service.lookup(IMINDataBaseService.class)
  527. .getMybatisMapper(VmDeliveryInfMapper.class)
  528. .updateByPrimaryKeySelective(delInf);
  529. Map<String,String> mapNew = new HashMap<String,String>();
  530. mapNew.put("imeiAddr", list.get(0).get("equIMEI"));
  531. mapNew.put("cargoNo", list.get(0).get("cargoWay"));
  532. mapNew.put("deliveryNo", deliveryNo);
  533. mapNew.put("channel", "V01");
  534. mapNew.put("returnUrl", returnUrl);
  535. mapNew.put("orderNo", orderNo);
  536. mapNew.put("MINView", "JSON");
  537. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  538. String str = jsonOb.toString();
  539. Log.info("通知售货机推货:".concat(str));
  540. String passwardKey = Service.lookup(IPropertiesService.class)
  541. .getSystemProperties().get("V01_TO_MACHINE_PASSWORD_KEY").getKey();
  542. //数据加密
  543. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  544. String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe);
  545. // //获取转义后响应信息
  546. JSONObject detail = JSONObject.fromObject(results);
  547. String code = String.valueOf(detail.get("code"));
  548. if(!"0".equals(code)){
  549. Log.info("售货机退货失败:".concat(code));
  550. //改变提货状态为3卡货(提货失败)....
  551. delInf.setStatus("3");
  552. //处理提货状态
  553. Service.lookup(IMINDataBaseService.class)
  554. .getMybatisMapper(VmDeliveryInfMapper.class)
  555. .updateByPrimaryKeySelective(delInf);
  556. throw new BusinessCodeException("JINM0011");//操作失败!
  557. }
  558. //获取处理状态
  559. String state = String.valueOf(detail.get("returnData"));
  560. JSONObject stateNew = JSONObject.fromObject(state);
  561. if(stateNew != null
  562. && !"200".equals(String.valueOf(stateNew.get("code")))){
  563. Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg"))));
  564. //改变提货状态为3卡货....
  565. delInf.setStatus("3");
  566. //处理提货状态
  567. Service.lookup(IMINDataBaseService.class)
  568. .getMybatisMapper(VmDeliveryInfMapper.class)
  569. .updateByPrimaryKeySelective(delInf);
  570. String msg = String.valueOf(stateNew.get("msg"));
  571. throw new MINBusinessException(msg);//操作失败!
  572. }else if("200".equals(String.valueOf(stateNew.get("code")))){
  573. }
  574. return res;
  575. }
  576. /**
  577. * 提货接口(测试专用)
  578. * @param equNo
  579. * @param startAisle
  580. * @return
  581. * @throws Exception
  582. */
  583. @MINAction(value = MAKE_DELIVERY_FOR_MACHINE_TEST)
  584. public MINActionResult makeDeliveryForMachineTest(
  585. @MINParam ( key = "equNo")String equNo,
  586. @MINParam ( key = "startAisle")String startAisle,
  587. @MINParam ( key = "endAisle")String endAisle,
  588. MINSession session
  589. ) throws Exception{
  590. if(CommonUtil.isEmpty(equNo)){
  591. throw new MINBusinessException("售货机编号不能为空!");
  592. }
  593. MINActionResult res = new MINActionResult();
  594. User user = session.getUser();
  595. String personId = user.getId();
  596. String branchid = user.getBranchId();
  597. /**校验用户是否是商户的补货员*/
  598. VmPersonRoleInfExample vmPersonRoleInfExample = new VmPersonRoleInfExample();
  599. vmPersonRoleInfExample.createCriteria().andBranchIdEqualTo(branchid)
  600. .andStateEqualTo("00").andPersonIdEqualTo(personId).andRoleEqualTo("01");
  601. List<VmPersonRoleInf> vmPersonRoleInfList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPersonRoleInfMapper.class).selectByExample(vmPersonRoleInfExample);
  602. System.out.println("vmPersonRoleInfList数量:" + vmPersonRoleInfList.size());
  603. if(vmPersonRoleInfList.size() != 1){
  604. throw new MINBusinessException("权限不足!");
  605. }
  606. VmEquipmentInf vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(equNo);
  607. if(vmEquipmentInf == null){
  608. throw new MINBusinessException("机器不存在!");
  609. }
  610. String imeiAddr = vmEquipmentInf.getImeiAddr();
  611. /**获取售货机推送地址*/
  612. String url = Service.lookup(IPropertiesService.class)
  613. .getSystemProperties().get(user.getChannel() + "_GET_MACHINE_ADDRESS").getKey();
  614. //组装推送接口
  615. String sendUrl = url.concat("/VendingMachineAction/cePushGoods").concat("?MINView=JSON");
  616. int endAisleNum = Integer.valueOf(endAisle);
  617. for (int startAisleNum = Integer.valueOf(startAisle); startAisleNum < (endAisleNum+1); startAisleNum++) {
  618. if(Integer.valueOf(startAisle) != startAisleNum){
  619. Thread.sleep(5 * 1000); //设置暂停的时间 5 秒
  620. System.out.println("==============="+"延迟5秒后执行");
  621. }
  622. String cargoNo = "";
  623. if(startAisleNum < 10){
  624. cargoNo = "0".concat(String.valueOf(startAisleNum));
  625. }else{
  626. cargoNo = String.valueOf(startAisleNum);
  627. }
  628. //获取提货表主键
  629. String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_TEST_ID");
  630. Map<String,String> mapNew = new HashMap<String,String>();
  631. mapNew.put("imeiAddr", imeiAddr);
  632. mapNew.put("cargoNo", cargoNo);
  633. mapNew.put("deliveryNo", "T".concat(dlId));
  634. mapNew.put("channel", "V01");
  635. mapNew.put("returnUrl", "");
  636. mapNew.put("branchid", vmEquipmentInf.getBranchid());
  637. mapNew.put("MINView", "JSON");
  638. JSONObject jsonOb = JSONObject.fromObject(mapNew);
  639. String str = jsonOb.toString();
  640. Log.info("通知售货机推货:".concat(str));
  641. String passwardKey = Service.lookup(IPropertiesService.class)
  642. .getSystemProperties().get("V01_TO_MACHINE_PASSWORD_KEY").getKey();
  643. //数据加密
  644. String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null));
  645. String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe);
  646. // //获取转义后响应信息
  647. JSONObject detail = JSONObject.fromObject(results);
  648. String code = String.valueOf(detail.get("code"));
  649. }
  650. return res;
  651. }
  652. }