package com.minpay.shouhuo.deliveryaction; import com.min.base64.Base64; import com.min.des.DesUtils; import com.min.util.OffSetUtil; import com.minpay.common.bean.DrawDto; import com.minpay.common.bean.User; import com.minpay.common.exception.BusinessCodeException; import com.minpay.common.format.IFormatService; import com.minpay.common.service.IPropertiesService; import com.minpay.common.service.IPublicService; import com.minpay.common.util.CommonUtil; import com.minpay.common.util.DateUtil; import com.minpay.common.util.HttpPostUtil; import com.minpay.db.table.mapper.*; import com.minpay.db.table.model.*; import com.minpay.db.table.own.mapper.DeliveryMapper; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.data.format.MINCopyFormat; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; import com.startup.minpay.util.Log; import io.netty.util.internal.StringUtil; import net.sf.json.JSONObject; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 售货机提货相关接口 * @author Zhumq * */ @MINComponent public class DeliveryAction implements IMINAction{ /**查询提货信息*/ public static final String QUERY_DELIVERY_INFO = "queryDeliveryInfo"; /**修改提货信息*/ public static final String MODIFY_DELIVERY_INFO = "modifyDeliveryInfo"; /**提货接口*/ public static final String MAKE_DELIVERY_FOR_MACHINE = "makeDeliveryForMachine"; /**提货回调*/ public static final String BACK_DELIVERY_FOR_MACHINE = "backDeliveryForMachine"; /**提货(无需session)*/ public static final String MAKE_DELIVERY_FOR_MACHINE_NOSESSION = "makeDeliveryForMachineNoSession"; /**提货(测试专用)*/ public static final String MAKE_DELIVERY_FOR_MACHINE_TEST = "makeDeliveryForMachineTest"; /** * 查询提货信息 * @param equNo 售货机编号 * @param dates 创建时间 * @param userNo 商户编号 * @param status 提货状态 * @param orderNo 订单编号 * @param personNo 会员编号 * @param page * @param limit * @param session * @return * @throws MINBusinessException */ @MINAction(value = QUERY_DELIVERY_INFO) public MINActionResult queryDeliveryInfo( @MINParam(key = "equNo")String equNo, @MINParam(key = "dates")String dates, @MINParam(key = "userNo")String userNo, @MINParam(key = "status")String status, @MINParam(key = "orderNo")String orderNo, @MINParam(key = "personNo")String personNo, @MINParam(key = "page",defaultValue = "1")int page, @MINParam(key = "limit",defaultValue = "10")int limit, MINSession session) throws MINBusinessException{ MINActionResult res = new MINActionResult(); if(CommonUtil.isEmpty(equNo)){ throw new BusinessCodeException("JINM1101");//售货机异常,请联系工作人员 } //解密售货机编号 String equNoNew = OffSetUtil.deScanCode(equNo); //获取操作员信息 User user = session.getUser(); //创建分页对象 MINRowBounds row = new MINRowBounds(page, limit); //初始化查询条件 Map map = new HashMap(); map.put("orderNo", orderNo);//订单编号 map.put("status", status);//提货状态 map.put("userNo", userNo);//商户编号 map.put("equNo", equNoNew);//售货机编号 if(CommonUtil.isEmpty(personNo)){ personNo = user.getId(); } map.put("personNo", personNo);//会员编号 map.put("dates", dates);//创建时间 //传入渠道验证 map.put("channel", user.getChannel()); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(DeliveryMapper.class) .queryDeliveryInfo(map,row); //格式花时间和状态 list = Service.lookup(IFormatService.class).formatDateTime(list, "createTime"); list = new MINCopyFormat("{status:'statusDesc',proType:'proTypeDesc'}").format(list); list = Service.lookup(IFormatService.class).formatEnum(list,"{statusDesc:'VM_DELIVERY_STATUS',proTypeDesc:'PRO_TYPE'}"); //传递返回值 res.set(IMINBusinessConstant.F_PAGING_LAY, list); res.set(IMINBusinessConstant.F_PAGING_COUNT, row.getMaxRows()); return res; } /** * 提货接口 * @param orderNo 订单编号 * @param deliveryNo 提货单编号 * @param session * @return * @throws Exception */ @MINAction(value = MAKE_DELIVERY_FOR_MACHINE) public MINActionResult makeDeliveryForMachine( @MINParam ( key = "orderNo")String orderNo, @MINParam ( key = "deliveryNo")String deliveryNo, MINSession session) throws Exception{ MINActionResult res = new MINActionResult(); User user = session.getUser(); /**获取售货机推送地址*/ String url = Service.lookup(IPropertiesService.class) .getSystemProperties().get(user.getChannel() + "_GET_MACHINE_ADDRESS").getKey(); String retUrl = Service.lookup(IPropertiesService.class) .getSystemProperties().get(user.getChannel() + "_RETURN_MACHINE_ADDRESS").getKey(); //组装推送接口 String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON"); String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine"); /**查询数据(提货单号是否存在)*/ //初始化查询条件 Map map = new HashMap(); map.put("deliveryNo", deliveryNo);//提货编号 map.put("orderNo", orderNo);//订单编号 //传入渠道验证 map.put("channel", user.getChannel()); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(DeliveryMapper.class) .queryDeliverys(map); if(list == null || list.size() != 1 ){ throw new MINBusinessException("没有提货信息!"); } String equType = list.get(0).get("equType"); if(!"00".equals(equType) && !"01".equals(equType)){ throw new MINBusinessException("机器类型不支持推货!"); } VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo); if(delInf == null){ throw new MINBusinessException("没有提货信息!"); } if(delInf.getProNums().equals(delInf.getDeliveryNums())){ throw new MINBusinessException("提货已完成!"); } if(!delInf.getStatus().equals("0") && !delInf.getStatus().equals("1") && !delInf.getStatus().equals("5")){ throw new MINBusinessException("提货处理中,请稍后!"); } //改变提货状态为5处理中.... delInf.setStatus("5"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); Map mapNew = new HashMap(); mapNew.put("imeiAddr", list.get(0).get("equIMEI")); mapNew.put("cargoNo", list.get(0).get("cargoWay")); mapNew.put("deliveryNo", deliveryNo); mapNew.put("channel", user.getChannel()); mapNew.put("returnUrl", returnUrl); mapNew.put("orderNo", orderNo); mapNew.put("MINView", "JSON"); JSONObject jsonOb = JSONObject.fromObject(mapNew); String str = jsonOb.toString(); Log.info("通知售货机推货:".concat(str)); String passwardKey = Service.lookup(IPropertiesService.class) .getSystemProperties().get(user.getChannel() +"_TO_MACHINE_PASSWORD_KEY").getKey(); //数据加密 String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null)); String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe); // //获取转义后响应信息 JSONObject detail = JSONObject.fromObject(results); String code = String.valueOf(detail.get("code")); if(!"0".equals(code)){ Log.info("售货机退货失败:".concat(code)); //改变提货状态为3卡货(提货失败).... delInf.setStatus("3"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); throw new BusinessCodeException("JINM0011");//操作失败! } //获取处理状态 String state = String.valueOf(detail.get("returnData")); JSONObject stateNew = JSONObject.fromObject(state); if(stateNew != null && !"200".equals(String.valueOf(stateNew.get("code")))){ Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg")))); //改变提货状态为3卡货.... delInf.setStatus("3"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); String msg = String.valueOf(stateNew.get("msg")); throw new MINBusinessException(msg);//操作失败! }else if("200".equals(String.valueOf(stateNew.get("code")))){ } return res; } /** * 提货回调 * @param response * @param deliveryNo * @param outNums * @param status * @param failReason * @throws MINBusinessException */ @MINAction(value = BACK_DELIVERY_FOR_MACHINE,session = false) public void backDeliveryForMachine(HttpServletResponse response, String deliveryNo, String outNums, String status, String failReason) throws MINBusinessException { // 给第三方传递回调成功信息 try { if(response != null) { response.getOutputStream().write("Success".getBytes()); response.flushBuffer(); } } catch (IOException e) { e.printStackTrace(); } // 出货后维护销量 VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo); //处理数量 if(CommonUtil.isEmpty(outNums)){ outNums = "0"; } String newDelNUms = CommonUtil.add(delInf.getDeliveryNums(), outNums); int compare = CommonUtil.compare(delInf.getProNums(), newDelNUms); if(0 == compare ){ delInf.setStatus("2");//已出货 }else if(compare > 0){ delInf.setStatus("1");//部分出货 } delInf.setDeliveryNums(newDelNUms); //维护出货状态和数量 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); } /** * 创建提货信息 * @return * @throws BusinessCodeException * @throws MINBusinessException */ //@MINAction(value = "createDeliveryInfo",session = false) public static void createDeliveryInfo( List drawDtoList ) throws BusinessCodeException, MINBusinessException{ String nowTime = DateUtil.getCurrentDateTimeString(); for (int i = 0; i < drawDtoList.size(); i++) { DrawDto drawDto = drawDtoList.get(i); String orderId = drawDto.getOrderId(); String orderDetailsId = drawDto.getOrderDetailsId(); //获取订单信息 VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderInfMapper.class) .selectByPrimaryKey(orderId); if(ordInf == null){ throw new BusinessCodeException("JINM0114");//订单信息不存在 }else{ if(!"00".equals(ordInf.getState())){ throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货 } } VmOrderDetails detInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .selectByPrimaryKey(orderDetailsId); //中奖的 if(drawDto.isDraw()){ //创建提货对象 VmDeliveryInf dlInf = new VmDeliveryInf(); //获取提货表主键 String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID"); dlInf.setDeliveryId(dlId); //提货编号 dlInf.setChannel(ordInf.getChannel()); //渠道 dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号 dlInf.setPersonId(ordInf.getPersonId()); //会员编号 dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号 dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品 dlInf.setProName(detInf.getProName()); //商品名称 dlInf.setProPrice(detInf.getProPrice()); //单价 dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量 dlInf.setAmount(detInf.getAmount()); //金额 dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零 dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0 dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道 dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注 dlInf.setCreateUser(ordInf.getPersonId()); //创建人 dlInf.setCreateTime(nowTime); //创建时间 dlInf.setModifyUser(ordInf.getPersonId()); //修改人 dlInf.setModifyTime(nowTime); //修改时间 dlInf.setBranchid(ordInf.getBranchid()); dlInf.setProEquRelId(detInf.getProEquRelId()); //执行新增提货信息 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .insertSelective(dlInf); //更新订单详情 detInf.setDeliveryId(dlId); detInf.setIsWinning("01"); detInf.setIsDelivery("00"); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .updateByPrimaryKeySelective(detInf); /**没有中奖的*/ }else{ detInf.setIsWinning("00"); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .updateByPrimaryKeySelective(detInf); } } } /** * 创建提货信息 * @param orderNo 订单编号 * @return * @throws BusinessCodeException * @throws MINBusinessException */ //@MINAction(value = "createDeliveryInfo",session = false) public MINActionResult createDeliveryInfoTwo( // @MINParam(key = "orderNo") String orderNo ) throws BusinessCodeException, MINBusinessException{ MINActionResult res = new MINActionResult(); String nowTime = DateUtil.getCurrentDateTimeString(); //获取订单信息 VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderInfMapper.class) .selectByPrimaryKey(orderNo); if(ordInf == null){ throw new BusinessCodeException("JINM0114");//订单信息不存在 }else{ if(!"00".equals(ordInf.getState())){ throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货 } } //获取已支付的,待提货的订单商品信息 VmOrderDetailsExample examp = new VmOrderDetailsExample(); examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo); List ordetList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .selectByExample(examp); for (int i = 0; i < ordetList.size(); i++) { VmOrderDetails detInf = ordetList.get(i); if(detInf != null){ //创建提货对象 VmDeliveryInf dlInf = new VmDeliveryInf(); //获取提货表主键 String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID"); res.set("dlId", dlId); dlInf.setDeliveryId(dlId); //提货编号 dlInf.setChannel(ordInf.getChannel()); //渠道 dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号 dlInf.setPersonId(ordInf.getPersonId()); //会员编号 dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号 dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品 dlInf.setProName(detInf.getProName()); //商品名称 dlInf.setProPrice(detInf.getProPrice()); //单价 dlInf.setProNums(detInf.getProNums()); //数量 dlInf.setAmount(detInf.getAmount()); //金额 dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零 dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0 dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道 dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注 dlInf.setCreateUser(ordInf.getPersonId()); //创建人 dlInf.setCreateTime(nowTime); //创建时间 dlInf.setModifyUser(ordInf.getPersonId()); //修改人 dlInf.setModifyTime(nowTime); //修改时间 //执行新增提货信息 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .insert(dlInf); } } return res; } /** * 创建提货信息 * @param orderNo 订单编号 * @return * @throws BusinessCodeException * @throws MINBusinessException */ //@MINAction(value = "createDeliveryInfo",session = false) public static void purchaseCreateDeliveryInfo( String orderNo,String drawNumber ) throws BusinessCodeException, MINBusinessException{ String nowTime = DateUtil.getCurrentDateTimeString(); //获取订单信息 VmOrderInf ordInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderInfMapper.class) .selectByPrimaryKey(orderNo); if(ordInf == null){ throw new BusinessCodeException("JINM0114");//订单信息不存在 }else{ if(!"00".equals(ordInf.getState())){ throw new BusinessCodeException("JINM1105");//当前商品未支付,请支付后才可以提货 } } //获取已支付的,待提货的订单商品信息 VmOrderDetailsExample examp = new VmOrderDetailsExample(); examp.createCriteria().andChannelEqualTo(ordInf.getChannel()).andOrderIdEqualTo(orderNo); List ordetList = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .selectByExample(examp); for (int i = 0; i < ordetList.size(); i++) { VmOrderDetails detInf = ordetList.get(i); if(detInf != null){ //创建提货对象 VmDeliveryInf dlInf = new VmDeliveryInf(); //获取提货表主键 String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_INF_ID"); dlInf.setDeliveryId(dlId); //提货编号 dlInf.setChannel(ordInf.getChannel()); //渠道 dlInf.setEquipmentId(ordInf.getEquipmentId());//售货机编号 dlInf.setPersonId(ordInf.getPersonId()); //会员编号 dlInf.setOrdDetId(detInf.getDetailsId()); //订单详情编号 dlInf.setProType(detInf.getProType()); //商品交易类别:00正常商品01抽奖商品 dlInf.setProName(detInf.getProName()); //商品名称 dlInf.setProPrice(detInf.getProPrice()); //单价 if(!CommonUtil.isEmpty(drawNumber)){ dlInf.setProNums(drawNumber); //数量 }else{ dlInf.setProNums(detInf.getProNums()); //为空取订单中的数量 } dlInf.setAmount(detInf.getAmount()); //金额 dlInf.setStatus("0"); //0未提货1部分提货2已提货3卡货4清零 dlInf.setDeliveryNums("0"); //默认未提货/提货数量为0 dlInf.setCargoWay(detInf.getCargoWay()); //商品所在货道 dlInf.setRemarks("会员下单,售货机编号:"+ordInf.getEquipmentId());//备注 dlInf.setCreateUser(ordInf.getPersonId()); //创建人 dlInf.setCreateTime(nowTime); //创建时间 dlInf.setModifyUser(ordInf.getPersonId()); //修改人 dlInf.setModifyTime(nowTime); //修改时间 dlInf.setProEquRelId(detInf.getProEquRelId()); //货道编号 //执行新增提货信息 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .insertSelective(dlInf); //订单明细表set提货单编号 detInf.setDeliveryId(dlId); detInf.setIsDelivery("00"); Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmOrderDetailsMapper.class) .updateByPrimaryKeySelective(detInf); } } } /** * 提货接口 * @param orderNo 订单编号 * @param deliveryNo 提货单编号 * @return * @throws Exception */ @MINAction(value = MAKE_DELIVERY_FOR_MACHINE_NOSESSION ,session = false) public MINActionResult makeDeliveryForMachineNoSession( @MINParam ( key = "orderNo")String orderNo, @MINParam ( key = "deliveryNo")String deliveryNo ) throws Exception{ MINActionResult res = new MINActionResult(); /**获取售货机推送地址*/ String url = Service.lookup(IPropertiesService.class) .getSystemProperties().get("V01_GET_MACHINE_ADDRESS").getKey(); String retUrl = Service.lookup(IPropertiesService.class) .getSystemProperties().get( "V01_RETURN_MACHINE_ADDRESS").getKey(); //组装推送接口 String sendUrl = url.concat("/VendingMachineAction/pushGoods").concat("?MINView=JSON"); String returnUrl = retUrl.concat("/DeliveryAction/backDeliveryForMachine"); /**查询数据(提货单号是否存在)*/ //初始化查询条件 Map map = new HashMap(); map.put("deliveryNo", deliveryNo);//提货编号 map.put("orderNo", orderNo);//订单编号 //传入渠道验证 map.put("channel", "V01"); List> list = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(DeliveryMapper.class) .queryDeliverys(map); if(list == null || list.size() != 1 ){ throw new MINBusinessException("没有提货信息!"); } String equType = list.get(0).get("equType"); if(!"00".equals(equType) && !"01".equals(equType)){ throw new MINBusinessException("机器类型不支持推货!"); } VmDeliveryInf delInf = Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class).selectByPrimaryKey(deliveryNo); if(delInf == null){ throw new MINBusinessException("没有提货信息!"); } if(delInf.getProNums().equals(delInf.getDeliveryNums())){ throw new MINBusinessException("提货已完成!"); } //改变提货状态为5处理中.... delInf.setStatus("5"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); Map mapNew = new HashMap(); mapNew.put("imeiAddr", list.get(0).get("equIMEI")); mapNew.put("cargoNo", list.get(0).get("cargoWay")); mapNew.put("deliveryNo", deliveryNo); mapNew.put("channel", "V01"); mapNew.put("returnUrl", returnUrl); mapNew.put("orderNo", orderNo); mapNew.put("MINView", "JSON"); JSONObject jsonOb = JSONObject.fromObject(mapNew); String str = jsonOb.toString(); Log.info("通知售货机推货:".concat(str)); String passwardKey = Service.lookup(IPropertiesService.class) .getSystemProperties().get("V01_TO_MACHINE_PASSWORD_KEY").getKey(); //数据加密 String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null)); String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe); // //获取转义后响应信息 JSONObject detail = JSONObject.fromObject(results); String code = String.valueOf(detail.get("code")); if(!"0".equals(code)){ Log.info("售货机退货失败:".concat(code)); //改变提货状态为3卡货(提货失败).... delInf.setStatus("3"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); throw new BusinessCodeException("JINM0011");//操作失败! } //获取处理状态 String state = String.valueOf(detail.get("returnData")); JSONObject stateNew = JSONObject.fromObject(state); if(stateNew != null && !"200".equals(String.valueOf(stateNew.get("code")))){ Log.info("售货机退货卡货:".concat(CommonUtil.objToString(stateNew.get("msg")))); //改变提货状态为3卡货.... delInf.setStatus("3"); //处理提货状态 Service.lookup(IMINDataBaseService.class) .getMybatisMapper(VmDeliveryInfMapper.class) .updateByPrimaryKeySelective(delInf); String msg = String.valueOf(stateNew.get("msg")); throw new MINBusinessException(msg);//操作失败! }else if("200".equals(String.valueOf(stateNew.get("code")))){ } return res; } /** * 提货接口(测试专用) * @param equNo * @param startAisle * @return * @throws Exception */ @MINAction(value = MAKE_DELIVERY_FOR_MACHINE_TEST) public MINActionResult makeDeliveryForMachineTest( @MINParam ( key = "equNo")String equNo, @MINParam ( key = "startAisle")String startAisle, @MINParam ( key = "endAisle")String endAisle, MINSession session ) throws Exception{ if(CommonUtil.isEmpty(equNo)){ throw new MINBusinessException("售货机编号不能为空!"); } MINActionResult res = new MINActionResult(); User user = session.getUser(); String personId = user.getId(); String branchid = user.getBranchId(); /**校验用户是否是商户的补货员*/ VmPersonRoleInfExample vmPersonRoleInfExample = new VmPersonRoleInfExample(); vmPersonRoleInfExample.createCriteria().andBranchIdEqualTo(branchid) .andStateEqualTo("00").andPersonIdEqualTo(personId).andRoleEqualTo("01"); List vmPersonRoleInfList = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmPersonRoleInfMapper.class).selectByExample(vmPersonRoleInfExample); System.out.println("vmPersonRoleInfList数量:" + vmPersonRoleInfList.size()); if(vmPersonRoleInfList.size() != 1){ throw new MINBusinessException("权限不足!"); } VmEquipmentInf vmEquipmentInf = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmEquipmentInfMapper.class).selectByPrimaryKey(equNo); if(vmEquipmentInf == null){ throw new MINBusinessException("机器不存在!"); } String imeiAddr = vmEquipmentInf.getImeiAddr(); /**获取售货机推送地址*/ String url = Service.lookup(IPropertiesService.class) .getSystemProperties().get(user.getChannel() + "_GET_MACHINE_ADDRESS").getKey(); //组装推送接口 String sendUrl = url.concat("/VendingMachineAction/cePushGoods").concat("?MINView=JSON"); int endAisleNum = Integer.valueOf(endAisle); for (int startAisleNum = Integer.valueOf(startAisle); startAisleNum < (endAisleNum+1); startAisleNum++) { if(Integer.valueOf(startAisle) != startAisleNum){ Thread.sleep(5 * 1000); //设置暂停的时间 5 秒 System.out.println("==============="+"延迟5秒后执行"); } String cargoNo = ""; if(startAisleNum < 10){ cargoNo = "0".concat(String.valueOf(startAisleNum)); }else{ cargoNo = String.valueOf(startAisleNum); } //获取提货表主键 String dlId = Service.lookup(IPublicService.class).getSequence("VM_DELIVERY_TEST_ID"); Map mapNew = new HashMap(); mapNew.put("imeiAddr", imeiAddr); mapNew.put("cargoNo", cargoNo); mapNew.put("deliveryNo", "T".concat(dlId)); mapNew.put("channel", "V01"); mapNew.put("returnUrl", ""); mapNew.put("branchid", vmEquipmentInf.getBranchid()); mapNew.put("MINView", "JSON"); JSONObject jsonOb = JSONObject.fromObject(mapNew); String str = jsonOb.toString(); Log.info("通知售货机推货:".concat(str)); String passwardKey = Service.lookup(IPropertiesService.class) .getSystemProperties().get("V01_TO_MACHINE_PASSWORD_KEY").getKey(); //数据加密 String desDe = Base64.encode(DesUtils.getInstance().encrypt(Base64.encode(str).getBytes(),passwardKey.getBytes(),null)); String results = HttpPostUtil.sendPostFormachine(sendUrl, desDe); // //获取转义后响应信息 JSONObject detail = JSONObject.fromObject(results); String code = String.valueOf(detail.get("code")); } return res; } }