johnswang
2021-04-13 5dc0cf507a81af71096ffdc80e14b2dcbcb4c5af
重建拉取用户头像接口;新增与活动相关的直播商品接口
1个文件已添加
12个文件已修改
1171 ■■■■■ 已修改文件
src/com/yc/sdk/miniapp/api/WxMaLiveService.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/miniapp/api/impl/WxMaLiveServiceImpl.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/miniapp/service/MaLiveIfc.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/miniapp/service/MaLiveImpl.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/action/api/LiveRoomVideo.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuying.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingBalance.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingLiveGoods.java 584 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingLogon.java 349 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/service/balance/BalanceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/service/panicBuying/PanicBuyingIfc.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/shopping/service/panicBuying/PanicBuyingImpl.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/weixincp/util/AvatarFile.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/com/yc/sdk/miniapp/api/WxMaLiveService.java
@@ -68,9 +68,15 @@
     * 调用接口往指定直播间导入已入库的商品
     */
    String ADD_GOODS_TO_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods" ;
    /**
     * 删除直播间商品
     */
    String DELETE_GOODS_IN_ROOM = "https://api.weixin.qq.com/wxaapi/broadcast/goods/deleteInRoom" ;
    
    /**
     * 商品添加并提审
     * 添加商品并提审
     * @param goodsEntity
     * @return
     */
@@ -93,7 +99,7 @@
    public Long goodsRepostAudit(Long goodsId)  throws WxErrorException;
    
    /**
     * 删除商品
     * 删除商品库中的商品
     * @param goodsId
     * @return
     * @throws WxErrorException
@@ -101,7 +107,7 @@
    public boolean goodsDelete(Long goodsId)throws WxErrorException;
    
    /**
     * 更新商品
     * 更新商品库中的商品
     * @param goodsEntity
     * @return
     * @throws WxErrorException
@@ -160,4 +166,13 @@
     * @throws WxErrorException
     */
    public boolean addGoodsToRoom(Integer roomId,String[] goodsId) throws WxErrorException;
    /**
     * 删除直播间商品
     * @param roomId
     * @param goodsId
     * @return
     * @throws WxErrorException
     */
    public boolean deleteGoodsInRoom(Integer roomId, Integer goodsId) throws WxErrorException;
}
src/com/yc/sdk/miniapp/api/impl/WxMaLiveServiceImpl.java
@@ -211,4 +211,15 @@
        Integer errCode = jsonElement.get("errcode").getAsInt();
        return(errCode!=null&& errCode.intValue() == 0) ;
    }
    @Override
    public boolean deleteGoodsInRoom(Integer roomId,Integer goodsId) throws WxErrorException{
        JsonObject json = new JsonObject();
        json.addProperty("roomId", roomId);
        json.addProperty("goodsId", goodsId);
        String responseText = this.wxMaService.post(DELETE_GOODS_IN_ROOM,json.toString());
        JsonObject jsonElement = new JsonParser().parse(responseText).getAsJsonObject();
        Integer errCode = jsonElement.get("errcode").getAsInt();
        return(errCode!=null&& errCode.intValue() == 0) ;
    }
}
src/com/yc/sdk/miniapp/service/MaLiveIfc.java
@@ -184,7 +184,7 @@
     * @param goodsIds
     * @return
     */
    public Integer saveGoodsToRoom(Integer roomId, String goodsIds);
    public Integer addGoodsToRoom(Integer roomId, String goodsIds);
    /**
     * 获取显示在首页的直播间广告
@@ -202,4 +202,19 @@
     * @return
     */
    public LiveRoomEntity getLiveRoomListForMe(Integer roomId, String shopCcCode, String userCode, String docCode);
    /**
     * 按活动单号获取商品库中的商品信息
     * @param docCode
     * @return
     */
    public LiveGoodsEntity getGoodsEntityForPanicBuying(String docCode);
    /**
     * 删除直播间商品
     * @param roomId
     * @param goodsId
     * @return
     */
    public Integer deleteGoodsInRoom(Integer roomId, Integer goodsId);
}
src/com/yc/sdk/miniapp/service/MaLiveImpl.java
@@ -190,7 +190,7 @@
    }
    
    @Override
    public Integer saveGoodsToRoom(Integer roomId,String goodsIds) {
    public Integer addGoodsToRoom(Integer roomId,String goodsIds) {
        Integer ret = null;
        try {
            String sql = " set nocount on ; \n"
@@ -207,6 +207,31 @@
                    + " select @myRowCount = isnull(@myRowCount,0) + @@rowcount \n"
                    + " select @myRowCount \n";
                    ret = this.jdbcTemplate.queryForObject(sql, new Object[]{roomId,goodsIds}, Integer.class) ;
        } catch(DataAccessException e){
            if (e  instanceof EmptyResultDataAccessException) {
                return 0 ;
            } else {
                //e.printStackTrace();
                throw e ;
            }
        }catch(Exception e){
            //e.printStackTrace();
            throw e ;
        }
        return ret ;
    }
    @Override
    public Integer deleteGoodsInRoom(Integer roomId,Integer goodsId) {
        Integer ret = null;
        try {
            String sql = " set nocount on ; \n"
                    + " declare @RoomId int = ?,@GoodsId int = ? \n"
                    + " delete from t710704 where RoomId = @RoomId and GoodsId = @GoodsId \n"
                    + " select @@rowcount \n";
                    ret = this.jdbcTemplate.queryForObject(sql, new Object[]{roomId,goodsId}, Integer.class) ;
        } catch(DataAccessException e){
            if (e  instanceof EmptyResultDataAccessException) {
                return 0 ;
@@ -929,6 +954,29 @@
    }
    
    @Override
    public LiveGoodsEntity getGoodsEntityForPanicBuying(String docCode ) {
        String sql = " set nocount on ; \n"
                + " declare @MatCode varchar(50) = ? \n"
                + " select top 1 a.GoodsId,a.MatCode,a.CoverImgUrl,\n"
                + "   a.PriceType,a.Price,a.Price2,a.URL,a.AuditId,a.AuditStatus,a.ThirdPartyTag,a.DepositDocCode,a.DepositRowId \n"
                + " from t710703 a  \n"
                + " where a.MatCode = isnull(@MatCode,'')  \n" ;
        try {
            Map<String,Object> map = this.jdbcTemplate.queryForMap(sql, new Object[]{docCode}) ;
            return getGoodsEntity(map) ;
        }catch(DataAccessException e){
            if (e  instanceof EmptyResultDataAccessException) {
                return null ;
            } else {
                throw e ;
            }
        }catch(Exception e){
            throw e ;
        }
    }
    @Override
    public LiveGoodsEntity getGoodsEntity(String matCode ,String depositDocCode,String depositRowId) {
        String sql = " set nocount on ; \n"
                + " declare @MatCode varchar(50) = ?,@DepositDocCode varchar(50) = ?, @DepositRowId varchar(20) = ? \n"
src/com/yc/sdk/shopping/action/api/LiveRoomVideo.java
@@ -1393,7 +1393,71 @@
            //刷新房间信息 , 定时作业 com.yc.sdk.miniapp.action.MaSyncLiveRoomTimer 每 20秒执行一次 
            
            //保存到数据库
            maLiveIfc.saveGoodsToRoom(Integer.valueOf(roomId), goodsIdStr) ;
            maLiveIfc.addGoodsToRoom(Integer.valueOf(roomId), goodsIdStr) ;
            json.addProperty("state", state? "success":"failed");
            this.printJson(response, json.toString());
        } catch (DataAccessException e) {
            this.logger.error(e.getMessage(), e);
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/addGoodsToRoom.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return ;
        }catch (Exception e) {
            this.logger.error(e.getMessage(), e);
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/shopping/live/addGoodsToRoom.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return ;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 删除直播间商品
     * @param request
     * @param response
     */
    @RequestMapping("/deleteGoodsInRoom.do")
    public void deleteGoodsInRoom(HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //CallBackMessage callBackMessage=new CallBackMessage();
        String roomId = request.getParameter("roomid") ;
        String goodsId = request.getParameter("goodsid") ;
        if (roomId == null || "".equals(roomId) || "null".equals(roomId)) {
            errJson.addProperty("warning","必须指定 roomid 参数【/shopping/live/deleteGoodsInRoom.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return ;
        }
        if (goodsId == null || "".equals(goodsId)) {
            errJson.addProperty("warning","必须指定 goodsid 参数【/shopping/live/deleteGoodsInRoom.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return ;
        }
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            //删除直播间商品
            boolean state = wxOpenMaService.getLiveService().deleteGoodsInRoom(Integer.parseInt(roomId), Integer.parseInt( goodsId));
            //刷新房间信息 , 定时作业 com.yc.sdk.miniapp.action.MaSyncLiveRoomTimer 每 20秒执行一次
            //保存到数据库
            maLiveIfc.deleteGoodsInRoom(Integer.parseInt(roomId), Integer.parseInt( goodsId)) ;
            
            json.addProperty("state", state? "success":"failed");            
            this.printJson(response, json.toString());
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuying.java
@@ -1632,8 +1632,8 @@
        orderEntityJsonObject.addProperty("isShowContinueButton", orderEntity.getStatus()!=null&&orderEntity.getStatus().intValue()==3);  //是否显示继续活动按钮
        orderEntityJsonObject.addProperty("isShowStopButton", orderEntity.getStatus()!=null&&orderEntity.getStatus().intValue()==2);    //是否显示停止活动按钮
        if (orderEntity.getFormId()!=null && orderEntity.getFormId().intValue() == 710804) {   //如果是团购活动,则显示 园购成功 和 团购失败
            orderEntityJsonObject.addProperty("isShowGroupBuyingSuccessButton", orderEntity.getGroupBuyingStatus()==null||orderEntity.getGroupBuyingStatus().intValue()==0); //是否显示团购成功按钮
            orderEntityJsonObject.addProperty("isShowGroupBuyingFailedButton", orderEntity.getGroupBuyingStatus()==null||orderEntity.getGroupBuyingStatus().intValue()==0);  //是否显示团购失败按钮
            orderEntityJsonObject.addProperty("isShowGroupBuyingSuccessButton", orderEntity.getStatus()!=null&&orderEntity.getStatus().intValue()==0?true:false); //是否显示团购成功按钮
            orderEntityJsonObject.addProperty("isShowGroupBuyingFailedButton", orderEntity.getStatus()!=null&&orderEntity.getStatus().intValue()==0?true:false);  //是否显示团购失败按钮
        }
        
        orderEntityJsonObject.addProperty("openId", orderEntity.getOpenId());    //openid
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingBalance.java
@@ -70,6 +70,7 @@
            json.addProperty("todayPayableAmount", balanceEntity != null ? balanceEntity.getTodayPayableAmount():0);  //今日订单金额
            json.addProperty("curentPeriodId", balanceEntity != null ? balanceEntity.getCurentPeriodId():"");  //当前期间
            
            //首页显示汇总数
            BalanceEntity balanceCountEntity = balanceIfc.getSummaryForHomePage(openId) ;
            json.addProperty("heXiaoCount", balanceCountEntity != null ? balanceCountEntity.getHeXiaoCount():0);  //可核销订单数量
            json.addProperty("orderCount", balanceCountEntity != null ? balanceCountEntity.getOrderCount():0);  // 我的订单次数(活动订单)
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingLiveGoods.java
New file
@@ -0,0 +1,584 @@
package com.yc.sdk.shopping.action.jiazhuang;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.google.gson.JsonObject;
import com.yc.action.BaseAction;
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.sdk.miniapp.entity.LiveGoodsEntity;
import com.yc.sdk.miniapp.service.MaLiveIfc;
import com.yc.sdk.shopping.entity.CustomerFeedbackParameterEntity;
import com.yc.sdk.shopping.entity.ImageEntity;
import com.yc.sdk.shopping.service.ShoppingImageIfc;
import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
import com.yc.sdk.shopping.service.panicBuying.PanicBuyingIfc;
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.sdk.weixinmp.action.MpServiceInit;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.open.api.WxOpenMaService;
import me.chanjar.weixin.open.api.WxOpenService;
@Controller
@Scope("prototype")
@RequestMapping("/shopping/panicBuyingLiveGoods.do")
public class PanicBuyingLiveGoods  extends BaseAction {
    @Autowired
    MaLiveIfc maLiveIfc ;
    @Autowired
    PanicBuyingIfc panicBuyingIfc ;
    @Autowired
    ShoppingImageDataIfc imgData ;
    @Autowired
    ShoppingImageDataIfc shoppingImageDataIfc;
    @Autowired
    ShoppingImageIfc shoppingImageIfc;
    /**
     * 新增直播商品
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=add")
    public void add(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = panicBuyingIfc.getPanicBuyingForLiveGoods(docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,添加商品失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            if (goodsEntity.getMatName()!=null && goodsEntity.getMatName().length() > 17) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +"】太长【最长17个字符】,请修改后重试该操作!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            // 开始处理图片 , 图片尺寸最大300像素*300像素
            if (goodsEntity.getPhotoPath()==null||"".equals(goodsEntity.getPhotoPath())) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +" 没有上传图片,添加商品或更新商品失败");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            ImageEntity image = shoppingImageDataIfc.getImageFile(goodsEntity.getPhotoPath().replaceAll(";",SettingKey.NAVSPLIT),300,300,false,request ,null,null);
            if (image == null) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +" 图片不存在,请重新上传图片后再重试该操作");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            WxMediaUploadResult wxMediaUploadResult  = null ;
            try {
                wxMediaUploadResult = wxOpenMaService.getMediaService().uploadMedia( "image",  image.getFile()) ;
            }catch (Exception e) {
                throw e ;
            }finally {
                if (image != null && image.getFile().exists()) {
                    image.getFile().delete();
                }
            }
            // 结束处理图片
            //设置小程序路径
            String url = "pages/detail/detail?doccode="+ goodsEntity.getMatCode();
            goodsEntity.setUrl(url) ;
            goodsEntity.setCoverImgUrl(wxMediaUploadResult.getMediaId()) ;   //图片尺寸最大300像素*300像素
            goodsEntity = wxOpenMaService.getLiveService().goodsAdd(goodsEntity) ;  //新增商品库
            if (goodsEntity!=null && goodsEntity.getGoodsId()!=null) {
                maLiveIfc.saveAddGoods(goodsEntity);   //保存到数据库
            }
            json.addProperty("msg", "添加商品成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 更新直播商品
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=update")
    public void update(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = panicBuyingIfc.getPanicBuyingForLiveGoods(docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,更新商品失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            if (goodsEntity.getMatName()!=null && goodsEntity.getMatName().length() > 17) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +"】太长【最长17个字符】,请修改后重试该操作!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            // 开始处理图片 , 图片尺寸最大300像素*300像素
            if (goodsEntity.getPhotoPath()==null||"".equals(goodsEntity.getPhotoPath())) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +" 没有上传图片,添加商品或更新商品失败");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            ImageEntity image = shoppingImageDataIfc.getImageFile(goodsEntity.getPhotoPath().replaceAll(";",SettingKey.NAVSPLIT),300,300,false,request ,null,null);
            if (image == null) {
                errJson.addProperty("warning", "活动名称【" +goodsEntity.getMatName() +" 图片不存在,请重新上传图片后再重试该操作");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            WxMediaUploadResult wxMediaUploadResult  = null ;
            try {
                wxMediaUploadResult = wxOpenMaService.getMediaService().uploadMedia( "image",  image.getFile()) ;
            }catch (Exception e) {
                throw e ;
            }finally {
                if (image != null && image.getFile().exists()) {
                    image.getFile().delete();
                }
            }
            // 结束处理图片
            //设置小程序路径
            String url = "pages/detail/detail?doccode="+ goodsEntity.getMatCode();
            goodsEntity.setUrl(url) ;
            goodsEntity.setCoverImgUrl(wxMediaUploadResult.getMediaId()) ;   //图片尺寸最大300像素*300像素
            boolean state = wxOpenMaService.getLiveService().goodsUpdate(goodsEntity)  ;   //更新商品库
            if (state) {
                maLiveIfc.saveUpdateGoods(goodsEntity);   //保存到数据库
            }
            json.addProperty("msg", "更新商品成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 撤回审核商品
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=reset")
    public void reset(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = maLiveIfc.getGoodsEntityForPanicBuying( docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,撤回审核失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            if (goodsEntity.getGoodsId() == null || goodsEntity.getAuditId() == null) {
                errJson.addProperty("warning", "该商品不是提审状态,不允许执行【撤回审核】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            boolean state = wxOpenMaService.getLiveService().goodsReset( goodsEntity) ;
            if (state) {
                maLiveIfc.saveResetGoods( goodsEntity.getGoodsId()) ;
            }
            json.addProperty("msg", "撤回审核成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 重新提审商品
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=repost")
    public void repost(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = maLiveIfc.getGoodsEntityForPanicBuying( docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,重新提审失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            if (goodsEntity.getGoodsId() == null || goodsEntity.getAuditId() != null) {
                errJson.addProperty("warning", "该商品已是提审状态,不允许【重新提交审核】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            Long myAuditId = wxOpenMaService.getLiveService().goodsRepostAudit( goodsEntity.getGoodsId()) ;
            if (myAuditId!=null) {
                maLiveIfc.saveRepostGoods( goodsEntity.getGoodsId(), myAuditId);
            }
            json.addProperty("msg", "重新提审成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 删除商品
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=delete")
    public void delete(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = maLiveIfc.getGoodsEntityForPanicBuying( docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,删除商品失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            boolean state = wxOpenMaService.getLiveService().goodsDelete(goodsEntity.getGoodsId())  ;
            if (state) {
                maLiveIfc.saveDeleteGoods( goodsEntity.getGoodsId());
            }
            json.addProperty("msg", "删除商品成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * 刷新商品状态
     * @param request
     * @param response
     */
    @RequestMapping(params = "m=inquire")
    public void inquire(@RequestBody CustomerFeedbackParameterEntity customerFeedbackParameter,HttpServletRequest request, HttpServletResponse response) {
        //HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        //String cltCode = (session.getAttribute(SettingKey.CLTCODE) == null?"": (String)session.getAttribute(SettingKey.CLTCODE)) ;
        //String cltName = (session.getAttribute(SettingKey.CLTNAME) == null?"": (String)session.getAttribute(SettingKey.CLTNAME)) ;
        //String openId = (session.getAttribute(SessionKey.WEIXIN_OPENID) == null ? "": (String) session.getAttribute(SessionKey.WEIXIN_OPENID));
        //String action = request.getParameter("action") ;
        String docCode = request.getParameter(SettingKey.DOCCODE);
        DataSourceEntity dataSourceEntity ;
        try {
            dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
        }catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        try {
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            //SettingEntity settingEntity = settingIfc.getSettingEntity();
            //小程序服务
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxOpenMaService wxOpenMaService = wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(dataSourceEntity.getMiniAppId()) ;
            LiveGoodsEntity goodsEntity = maLiveIfc.getGoodsEntityForPanicBuying( docCode);
            if (goodsEntity == null) {
                errJson.addProperty("warning", "活动不存在,刷新商品状态失败!");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            List<LiveGoodsEntity> goodsList = wxOpenMaService.getLiveService().goodsInquire(new Long[] { goodsEntity.getGoodsId()})  ;
            for(int i =0 ;goodsList != null && i < goodsList.size() ; i++) {
                goodsList.get(i).setMatCode(goodsEntity.getMatCode()) ;
                goodsList.get(i).setDepositDocCode(goodsEntity.getDepositDocCode()) ;
                goodsList.get(i).setDepositRowId(goodsEntity.getDepositRowId()) ;
                maLiveIfc.saveUpdateGoods(goodsList.get(i));   //保存到数据库
            }
            json.addProperty("msg", "刷新状态成功");
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch (Exception e ){
            errJson.addProperty("warning", (e.getCause()!=null?e.getCause().getMessage(): e.getMessage()));
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
}
src/com/yc/sdk/shopping/action/jiazhuang/PanicBuyingLogon.java
@@ -10,6 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,6 +20,7 @@
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.sdk.miniapp.action.MaServiceInit;
import com.yc.sdk.miniapp.service.MaUserIfc;
import com.yc.sdk.shopping.entity.CustomerEntity;
import com.yc.sdk.shopping.entity.CustomerSignupEntity;
@@ -29,7 +31,9 @@
import com.yc.sdk.weixinmp.entity.MyWxMpUser;
import com.yc.utils.SessionKey;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.open.api.WxOpenService;
import redis.clients.jedis.Jedis;
@@ -124,7 +128,7 @@
            WxOpenService wxOpenService = MpServiceInit.getWxOpenService();
            WxMaJscode2SessionResult result = wxOpenService.getWxOpenComponentService().miniappJscode2Session(corpEntity.getMiniAppId(), code);
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
            //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
            //SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
            //SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm") ;
            
@@ -155,76 +159,8 @@
                return;    
            }
            
            CustomerEntity customerEntity = accountIfc.getLoginInfoByMiniAppOpenId(result.getOpenid());
            if (customerEntity != null) {
                //session.setAttribute(SessionKey.USERCODE,customerEntity.getCltCode());
                //session.setAttribute(SessionKey.USERNAME,customerEntity.getCltName());
                //保存到会话
                if (customerEntity.getCltCode() != null && !"".equals(customerEntity.getCltCode())) {
                    session.setAttribute(SettingKey.CLTCODE, customerEntity.getCltCode());
                }else{
                    session.removeAttribute(SettingKey.CLTCODE);
                }
                session.setAttribute(SettingKey.CLTNAME, customerEntity.getCltName());
                session.setAttribute(SettingKey.CLTTEL, customerEntity.getTel());
                session.setAttribute(SettingKey.CLTEMAIL, customerEntity.getEmail());
                session.setAttribute(SettingKey.COUNTRY, customerEntity.getCountryZoneId());
                session.setAttribute(SettingKey.PROVINCE, customerEntity.getProvinceZoneId());
                session.setAttribute(SettingKey.POSTCODE, customerEntity.getPostCode());
                json.addProperty(SettingKey.CLTCODE, customerEntity.getCltCode());   //客户编号
                //json.addProperty(SettingKey.ReferralsType, customerEntity.getReferralsType());   //介绍人类别
                //json.addProperty(SettingKey.ReferralsCode, customerEntity.getReferralsCode());   //介绍人编号
                //json.addProperty(SettingKey.ReferralsName, customerEntity.getReferralsName());   //介绍人姓名
                //session.setAttribute(SettingKey.SELECTCITYAREAID,customerEntity.getAreaId() ) ;  //保存已经选择的城市
                //session.setAttribute(SettingKey.MEMBERLEVELDESC,customerEntity.getMemberLevelDesc() ) ;  //会员级别描述
                //session.setAttribute(SettingKey.SettlementByMonthly,customerEntity.isSettlementByMonthly() ) ;  //是否月结客户
            }
            json = getLoginJsonObject( request, result.getOpenid(), myWxMpUser, corpEntity) ;
            
            //保存到会话
            session.setAttribute(SessionKey.SHOPPING_DBID,corpEntity.getDbId() + "") ;
            session.setAttribute(SessionKey.WEIXIN_FROM,"3") ;
            session.setAttribute(SessionKey.WEIXIN_CORPID,corpEntity.getMiniAppId()) ;
            session.setAttribute(SessionKey.WEIXIN_OPENID,myWxMpUser.getOpenId()) ;
            session.setAttribute(SessionKey.WEIXIN_NICKNAME, myWxMpUser.getNickname()) ;
            session.setAttribute(SessionKey.WEIXIN_HEADIMGURL,myWxMpUser.getHeadImgUrl()) ;
            json.addProperty(SessionKey.WEIXIN_OPENID, result.getOpenid());
            json.addProperty("JSESSIONID", session.getId());
            json.addProperty("openId", myWxMpUser.getOpenId());
            json.addProperty("nickName",myWxMpUser.getNickname() );  //昵称
            json.addProperty("language", myWxMpUser.getLanguage());  //语言
            json.addProperty("city", myWxMpUser.getCity());  //城市
            json.addProperty("province", myWxMpUser.getProvince());   //省份
            json.addProperty("country", myWxMpUser.getCountry());   //国家
            json.addProperty("avatarUrl", myWxMpUser.getHeadImgUrl());   //原始头像
            json.addProperty("WeiXinAvatarUnid", myWxMpUser.getWeiXinAvatarUnid());   //头像UNID
            json.addProperty("unionId", myWxMpUser.getUnionId());
            //json.addProperty("watermark", erpWxMPUser.getWatermark().getAppid());
            json.addProperty("isPullUserInfo", myWxMpUser.isPullUserInfo());    //是否需要拉取用户信息
            json.addProperty(SettingKey.SESSIONKEY, result.getSessionKey());
            json.addProperty("isExpired", myWxMpUser.isExpired());   //个人认证是否过期
            json.addProperty("effectiveStartDate",myWxMpUser.getEffectiveStartDate()!=null?sdf.format(myWxMpUser.getEffectiveStartDate()):"");   //个人认证开始时间
            json.addProperty("effectiveEndDate",myWxMpUser.getEffectiveEndDate()!=null?sdf.format(myWxMpUser.getEffectiveEndDate()):"");   //个人认证结束时间
            json.addProperty("expiryDays",myWxMpUser.getExpiryDays());   //个人认证过期天数,正数表示已过期天数,负数表示即将过期天数,null 表示从未认证过
            //商家签约情况
            CustomerSignupEntity enterpriseSignupEntity = customerSignupIfc.getCustomerSignup(result.getOpenid());
            json.addProperty("isSignup", enterpriseSignupEntity!=null&&enterpriseSignupEntity.getTelephone()!=null&&!"".equals(enterpriseSignupEntity.getTelephone())?true:false);  //是否签约
            json.addProperty("isEnterpriceExpired", enterpriseSignupEntity!=null&&enterpriseSignupEntity.isExpired());   //企业认证是否过期
            json.addProperty("enterpriceEffectiveStartDate",enterpriseSignupEntity!=null&&enterpriseSignupEntity.getEffectiveStartDate()!=null?sdf.format(enterpriseSignupEntity.getEffectiveStartDate()):"");   //企业认证开始时间
            json.addProperty("enterpriceEffectiveEndDate",enterpriseSignupEntity!=null&&enterpriseSignupEntity.getEffectiveEndDate()!=null?sdf.format(enterpriseSignupEntity.getEffectiveEndDate()):"");   //企业认证结束时间
            json.addProperty("enterpriceExpiryDays",myWxMpUser.getExpiryDays());   //企业认证过期天数,正数表示已过期天数,负数表示即将过期天数,null 表示从未认证过
            json.addProperty("state", "success");
            this.printJson(response, json.toString());
            return;    
            //return JsonUtils.toJson(session);
@@ -251,4 +187,277 @@
            SpObserver.setDBtoInstance();
        }
    }
    private JsonObject getLoginJsonObject(HttpServletRequest request,String openId,MyWxMpUser myWxMpUser,DataSourceEntity corpEntity) {
        HttpSession session=request.getSession();
        JsonObject json = new JsonObject();
        //JsonObject errJson = new JsonObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
        CustomerEntity customerEntity = accountIfc.getLoginInfoByMiniAppOpenId(openId);
        if (customerEntity != null) {
            //session.setAttribute(SessionKey.USERCODE,customerEntity.getCltCode());
            //session.setAttribute(SessionKey.USERNAME,customerEntity.getCltName());
            //保存到会话
            if (customerEntity.getCltCode() != null && !"".equals(customerEntity.getCltCode())) {
                session.setAttribute(SettingKey.CLTCODE, customerEntity.getCltCode());
            }else{
                session.removeAttribute(SettingKey.CLTCODE);
            }
            session.setAttribute(SettingKey.CLTNAME, customerEntity.getCltName());
            session.setAttribute(SettingKey.CLTTEL, customerEntity.getTel());
            session.setAttribute(SettingKey.CLTEMAIL, customerEntity.getEmail());
            session.setAttribute(SettingKey.COUNTRY, customerEntity.getCountryZoneId());
            session.setAttribute(SettingKey.PROVINCE, customerEntity.getProvinceZoneId());
            session.setAttribute(SettingKey.POSTCODE, customerEntity.getPostCode());
            json.addProperty(SettingKey.CLTCODE, customerEntity.getCltCode());   //客户编号
            //json.addProperty(SettingKey.ReferralsType, customerEntity.getReferralsType());   //介绍人类别
            //json.addProperty(SettingKey.ReferralsCode, customerEntity.getReferralsCode());   //介绍人编号
            //json.addProperty(SettingKey.ReferralsName, customerEntity.getReferralsName());   //介绍人姓名
            //session.setAttribute(SettingKey.SELECTCITYAREAID,customerEntity.getAreaId() ) ;  //保存已经选择的城市
            //session.setAttribute(SettingKey.MEMBERLEVELDESC,customerEntity.getMemberLevelDesc() ) ;  //会员级别描述
            //session.setAttribute(SettingKey.SettlementByMonthly,customerEntity.isSettlementByMonthly() ) ;  //是否月结客户
        }
        //保存到会话
        session.setAttribute(SessionKey.SHOPPING_DBID,corpEntity.getDbId() + "") ;
        session.setAttribute(SessionKey.WEIXIN_FROM,"3") ;
        session.setAttribute(SessionKey.WEIXIN_CORPID,corpEntity.getMiniAppId()) ;
        session.setAttribute(SessionKey.WEIXIN_OPENID,myWxMpUser.getOpenId()) ;
        session.setAttribute(SessionKey.WEIXIN_NICKNAME, myWxMpUser.getNickname()) ;
        session.setAttribute(SessionKey.WEIXIN_HEADIMGURL,myWxMpUser.getHeadImgUrl()) ;
        json.addProperty(SessionKey.WEIXIN_OPENID, openId);
        json.addProperty("JSESSIONID", session.getId());
        json.addProperty("openId", myWxMpUser.getOpenId());
        json.addProperty("nickName",myWxMpUser.getNickname() );  //昵称
        json.addProperty("language", myWxMpUser.getLanguage());  //语言
        json.addProperty("city", myWxMpUser.getCity());  //城市
        json.addProperty("province", myWxMpUser.getProvince());   //省份
        json.addProperty("country", myWxMpUser.getCountry());   //国家
        json.addProperty("avatarUrl", myWxMpUser.getHeadImgUrl());   //原始头像
        json.addProperty("WeiXinAvatarUnid", myWxMpUser.getWeiXinAvatarUnid());   //头像UNID
        json.addProperty("unionId", myWxMpUser.getUnionId());
        //json.addProperty("watermark", erpWxMPUser.getWatermark().getAppid());
        json.addProperty("isPullUserInfo", myWxMpUser.isPullUserInfo());    //是否需要拉取用户信息
        //json.addProperty(SettingKey.SESSIONKEY, sessionKey);
        json.addProperty("isExpired", myWxMpUser.isExpired());   //个人认证是否过期
        json.addProperty("effectiveStartDate",myWxMpUser.getEffectiveStartDate()!=null?sdf.format(myWxMpUser.getEffectiveStartDate()):"");   //个人认证开始时间
        json.addProperty("effectiveEndDate",myWxMpUser.getEffectiveEndDate()!=null?sdf.format(myWxMpUser.getEffectiveEndDate()):"");   //个人认证结束时间
        json.addProperty("expiryDays",myWxMpUser.getExpiryDays());   //个人认证过期天数,正数表示已过期天数,负数表示即将过期天数,null 表示从未认证过
        //商家签约情况
        CustomerSignupEntity enterpriseSignupEntity = customerSignupIfc.getCustomerSignup(openId);
        json.addProperty("isSignup", enterpriseSignupEntity!=null&&enterpriseSignupEntity.getTelephone()!=null&&!"".equals(enterpriseSignupEntity.getTelephone())?true:false);  //是否签约
        json.addProperty("isEnterpriceExpired", enterpriseSignupEntity!=null&&enterpriseSignupEntity.isExpired());   //企业认证是否过期
        json.addProperty("enterpriceEffectiveStartDate",enterpriseSignupEntity!=null&&enterpriseSignupEntity.getEffectiveStartDate()!=null?sdf.format(enterpriseSignupEntity.getEffectiveStartDate()):"");   //企业认证开始时间
        json.addProperty("enterpriceEffectiveEndDate",enterpriseSignupEntity!=null&&enterpriseSignupEntity.getEffectiveEndDate()!=null?sdf.format(enterpriseSignupEntity.getEffectiveEndDate()):"");   //企业认证结束时间
        json.addProperty("enterpriceExpiryDays",myWxMpUser.getExpiryDays());   //企业认证过期天数,正数表示已过期天数,负数表示即将过期天数,null 表示从未认证过
        json.addProperty("state", "success");
        return json;
    }
    /**
     * 获取用户登录信息
     * @param request
     * @param response
     */
    @GetMapping("/getPanicBuyingUserInfo.do")
    public void getPanicBuyingUserInfo(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session=request.getSession();
        //String fromUserId = request.getParameter(SettingKey.FROMUSERID) ;
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        String openId = (String) session.getAttribute(SessionKey.WEIXIN_OPENID) ;
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
                MyWxMpUser myWxMpUser = maUserIfc.getUser(openId) ;
                json = getLoginJsonObject( request, openId, myWxMpUser, dataSourceEntity);
                this.printJson(response, json.toString());
                return;
       }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/info.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } catch (Exception e) {
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/info.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
    /**
     * <pre>
     * 获取用户信息接口
     * </pre>
     */
    @GetMapping("/panicBuyingInfo.do")
    public void info(String signature, String rawData, String encryptedData, String iv,
            HttpServletRequest request, HttpServletResponse response) {
        HttpSession session=request.getSession();
        String fromUserId = request.getParameter(SettingKey.FROMUSERID) ;
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        String corpId = request.getParameter(SessionKey.WEIXIN_CORPID) ;
        if (corpId == null || "".equals(corpId)) {
            corpId = request.getParameter(SessionKey.WEIXIN_APPID) ;
        }
        if (corpId == null || "".equals(corpId)) {
            corpId = (String) session.getAttribute(SessionKey.WEIXIN_CORPID);
        }
        if (corpId == null || "".equals(corpId)) {
            corpId = (String) session.getAttribute(SessionKey.WEIXIN_CORPID);
        }
        if (corpId == null || "".equals(corpId)) {
            errJson.addProperty("warning","必须传递 AppId 参数【/panicBuyingInfo.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        DataSourceEntity corpEntity = null ;
        try {
            corpEntity =  MultiDataSource.getDataSourceMapByMaAppId(corpId);
            if (corpEntity == null  ) {
                errJson.addProperty("warning","在数据源中没有找到该小程序的 AppId 参数设置,传递 AppId 【"+ corpId +"】参数不正确!【/panicBuyingInfo.do】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            if (SpObserver.isDemoInstance("_"+corpEntity.getDbId() )) {
                errJson.addProperty("warning", "未找到数据源【"+ corpEntity.getDbId() +"】【CorpId:"+ corpId+ "】,请在数据源中设置好【/panicBuyingInfo.do】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            session.setAttribute(SessionKey.WEIXIN_CORPID, corpId);
            session.setAttribute(SessionKey.WEIXIN_APPID, corpId);
        }catch (Exception e) {
            e.printStackTrace();
            errJson.addProperty("warning",e.getCause()!=null?e.getCause().getMessage(): e.getMessage()+"【/panicBuyingInfo.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        //String hostUrl = SettingKey.getHostUrl(request) ;
        //DataSourceEntity corpEntity = MultiDataSource.getDataSourceMapByCorpURL(hostUrl) ;
        //Map<String,String> map = new HashMap<String,String>() ;
        //System.out.println(this.getClass()+ " sessionId:"+ session.getId()+ ",sessionKey:" + sessionKey );
        /*
        final WxMaService wxService = MaServiceInit.getWxMaService(corpEntity, jedisPool);
        if (wxService == null) {
            throw new IllegalArgumentException(String.format("未找到对应appid的配置,请核实!"));
        }
        */
        //第三方托管方式写法
        WxMaService wxService = null;
        try {
            wxService = MaServiceInit.getWxMaServiceByOpenComponentByAppId(corpEntity.getMiniAppId()) ;
            if (wxService==null) {
                errJson.addProperty("warning","在数据源中没有找到该小程序的 AppId 参数设置(WxMaService),可能传递 AppId 【"+ corpId +"】参数不正确!【/panicBuyingInfo.do】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
        }catch (Exception e) {
            e.printStackTrace();
            errJson.addProperty("warning",e.getCause()!=null?e.getCause().getMessage(): e.getMessage()+"【/panicBuyingInfo.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }
        String openId = (String)session.getAttribute(SessionKey.WEIXIN_OPENID);
       try (Jedis jedis = this.jedisPool.getResource()){
           SpObserver.setDBtoInstance("_"+corpEntity.getDbId());//切换数据源
               String sessionKey = jedis.get(SettingKey.SESSIONKEY.concat(":"+corpEntity.getMiniAppId()).concat(":"+openId));
               if (sessionKey == null || "".equals(sessionKey)) {
                   sessionKey = request.getParameter(SettingKey.SESSIONKEY) ;
               }
               if (sessionKey == null || "".equals(sessionKey)) {
                errJson.addProperty("warning", "获取会话信息sessionKey失败,导致无法解密获取的用户信息,可能原因是会话已过期,请强制退出微信然后再重试【/wx/miniapp/user/panicBuyingInfo.do】");
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
               if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
                   errJson.addProperty("warning","user check failed【/panicBuyingInfo.do】");
                   json.add("error", errJson);
                   this.printJson(response, json.toString());
                   return;
               }
           // 用户信息校验
           //String unionId = (String)session.getAttribute(SessionKey.WEIXIN_MINIAPP_UNIONID);
          // WxMpUser erpWxMPUser = null ;
           // 解密用户信息
           WxMaUserInfo wxMaUserInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
           maUserIfc.saveUser(openId, wxMaUserInfo, request,fromUserId,true);
           MyWxMpUser myWxMpUser = maUserIfc.getUser(openId) ;
           json = getLoginJsonObject( request, openId, myWxMpUser, corpEntity);
           this.printJson(response, json.toString());
           return;
       }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/info.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } catch (Exception e) {
            e.printStackTrace();
            errJson.addProperty("warning",(e.getCause()!=null?e.getCause().getMessage(): e.getMessage())+"【/info.do】");
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
}
src/com/yc/sdk/shopping/service/balance/BalanceImpl.java
@@ -25,7 +25,7 @@
                + " declare @MyVisiteTraceCount int = 0 , @MyPanicBuyingTraceCount int = 0 \n"   //我的足迹,客户轨迹 
                
                //可核销订单数量,订单次数
                + " select @HeXiaoCount = sum(case when isnull(a.Digit,0) <> 0 and isnull(a.HeXiaoDigit,0) <> isnull(a.Digit,0) then 1 else 0 end )  \n"
                + " select @HeXiaoCount = sum(case when isnull(a.Digit,0) <> 0 and isnull(a.HeXiaoDigit,0) <> isnull(a.Digit,0) then 1 else 0 end ),  \n"
                + "    @OrderCount = count(1) \n"
                + " from  t710806H a \n"
                + " where a.OpenId = @OpenId  \n"
src/com/yc/sdk/shopping/service/panicBuying/PanicBuyingIfc.java
@@ -2,6 +2,7 @@
import java.util.List;
import com.yc.sdk.miniapp.entity.LiveGoodsEntity;
import com.yc.sdk.shopping.entity.PanicBuyingEntity;
import com.yc.sdk.shopping.entity.PanicBuyingPamareterEntity;
import com.yc.sdk.shopping.entity.PanicBuyingRelationEntity;
@@ -165,4 +166,11 @@
     * @return
     */
    public Integer saveRelationList(PanicBuyingRelationEntity panicBuyingRelationEntity);
    /**
     * 按活动单号获取直播所需要的商品信息
     * @param docCode
     * @return
     */
    public LiveGoodsEntity getPanicBuyingForLiveGoods(String docCode);
}
src/com/yc/sdk/shopping/service/panicBuying/PanicBuyingImpl.java
@@ -10,6 +10,7 @@
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import com.yc.sdk.miniapp.entity.LiveGoodsEntity;
import com.yc.sdk.shopping.entity.PanicBuyingEntity;
import com.yc.sdk.shopping.entity.PanicBuyingPamareterEntity;
import com.yc.sdk.shopping.entity.PanicBuyingRelationEntity;
@@ -363,7 +364,7 @@
                + "         when 1 then '昨天' when 2 then '前天' \n" 
                + "            else cast(datepart(month,d.LastAccessTime) as varchar(10)) + '月' + cast(datepart(day,d.LastAccessTime) as varchar(10))+'日' end \n" 
                + "            + ' ' + cast(datepart(hour,d.LastAccessTime) as varchar(10)) + ':' + cast(datepart(minute,d.LastAccessTime) as varchar(10)) \n" 
                + "            as LastAccessTimeDescription,a.ReadTimesByPanicBuyingAuthor \n"
                + "            as LastAccessTimeDescription,d.ReadTimesByPanicBuyingAuthor \n"
                + " from t710805 d \n"
                + " join t710802H a on d.RefCode = a.DocCode \n"
                + " left join t110601 b on a.CcCode = b.CcCode \n"
@@ -795,6 +796,50 @@
    }
    @Override
    public LiveGoodsEntity getPanicBuyingForLiveGoods(String docCode) {
        String sql = " set nocount on \n"
                + " declare @DocCode varchar(20) = ?  \n"
                + " select a.DocCode,a.OriginalPrice,a.SalesPrice,a.Title ,a.CoverImage,a.FormId \n"
                + " from t710802H a \n"
                + " where a.DocCode = @DocCode \n";
        try {
            Map<String, Object> map = this.jdbcTemplate.queryForMap(sql, new Object[] {docCode}) ;
            LiveGoodsEntity liveGoodsEntity = new LiveGoodsEntity();
            if (map != null) {
                liveGoodsEntity.setMatCode(map.get("DocCode")==null?"":(String)map.get("DocCode"));  //商品编号
                liveGoodsEntity.setMatName(map.get("Title")==null?"":(String)map.get("Title"));   //商品名称
                liveGoodsEntity.setPhotoPath(map.get("CoverImage")==null?"":(String)map.get("CoverImage"));   //商品图片
                Integer formId  = (Integer)map.get("FormId");
                // 710802 维护秒杀活动 ; 710804 维护拼团活动
                if (formId!=null&&(formId.intValue()==710802||formId.intValue()==710804)) {
                    //价格类型,1:一口价(只需要传入price,price2不传)
                    //        2:价格区间(price字段为左边界,price2字段为右边界,price和price2必传)
                    //        3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传)
                    liveGoodsEntity.setPriceType(3);  //3:显示折扣价(price字段为原价,price2字段为现价, price和price2必传)
                    liveGoodsEntity.setPrice(map.get("OriginalPrice")==null?0L:Double.parseDouble(map.get("OriginalPrice").toString()));   //原价
                    liveGoodsEntity.setPrice2(map.get("SalesPrice")==null?0L:Double.parseDouble(map.get("SalesPrice").toString()));   //现价
                }else {   //维护报名邀约 , 只需要显示“报名费”
                    liveGoodsEntity.setPriceType(1);   //一口价(只需要传入price,price2不传)
                    liveGoodsEntity.setPrice(map.get("SalesPrice")==null?0L:Double.parseDouble(map.get("SalesPrice").toString()));   //现价
                }
            }
            return liveGoodsEntity;
        }catch(DataAccessException e ) {
            if (e instanceof EmptyResultDataAccessException){
                return null ;
            }else {
                 throw e ;
            }
        }catch(Exception e){
            e.printStackTrace();
            throw e;
        }
    }
    @Override
    public Integer changePanicBuyingStatus(String docCode,Integer status) {
        String sql = " set nocount on \n"
                + " declare @DocCode varchar(20) = ?,@Status int = ? \n"
src/com/yc/sdk/weixincp/util/AvatarFile.java
@@ -27,7 +27,7 @@
public class AvatarFile {
    
    public static File getAvatarFile(String uri,String fileName,String filePath) {
    public static File getAvatarFile(String uri,String fileName,String filePath) throws ClientProtocolException,IOException,Exception {
        if (uri == null||"".equals(uri)) return null ;
        
        HttpGet httpGet = new HttpGet(uri); 
@@ -66,11 +66,16 @@
          File localFile = FileUtils.createTmpFile(inputStream,  path, extName, new File(filePath));
          return localFile ;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw e ;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IOException e) {
            throw e ;
        }catch (Exception e) {
            e.printStackTrace();
            throw e ;
        }
        return null ;
    }    
    
    public static UploadFiles getImages(File file) throws Exception {