123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- 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<String,String> map = new HashMap<String,String>();
- 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<Map<String,String>> 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<String,String> map = new HashMap<String,String>();
- map.put("deliveryNo", deliveryNo);//提货编号
- map.put("orderNo", orderNo);//订单编号
- //传入渠道验证
- map.put("channel", user.getChannel());
- List<Map<String,String>> 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<String,String> mapNew = new HashMap<String,String>();
- 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<DrawDto> 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<VmOrderDetails> 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<VmOrderDetails> 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<String,String> map = new HashMap<String,String>();
- map.put("deliveryNo", deliveryNo);//提货编号
- map.put("orderNo", orderNo);//订单编号
- //传入渠道验证
- map.put("channel", "V01");
- List<Map<String,String>> 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<String,String> mapNew = new HashMap<String,String>();
- 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<VmPersonRoleInf> 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<String,String> mapNew = new HashMap<String,String>();
- 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;
- }
- }
|