Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity
| | |
| | | private String cashierId; |
| | | private String cashierName; |
| | | |
| | | private String receiptCode; |
| | | |
| | | |
| | | public String getDetailId() { |
| | |
| | | this.cashierName = cashierName; |
| | | } |
| | | |
| | | public String getReceiptCode() { |
| | | return receiptCode; |
| | | } |
| | | |
| | | public void setReceiptCode(String receiptCode) { |
| | | this.receiptCode = receiptCode; |
| | | } |
| | | } |
| | |
| | | public final static int defaultExpireTime = 5 * 60; |
| | | public final static int RESEND_DEFAULT_EXPIRETIME = 1 * 60; |
| | | |
| | | public final static int DEFAULT_EXPIRETIME_TWO_MIN = 1 * 60; |
| | | |
| | | |
| | | //支付默认回话 |
| | | public final static int PAY_DEFAULT_EXPIRE_TIME = 2 * 60 * 60; |
| | | |
| | | public static final String RECEIPT_CODE = "_RECEIPT_CODE";// 收据编号 |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | private ResponseEntity<String> getStoreEnterCommunitys(IPageData pd, String storeId, String storeTypeCd, RestTemplate restTemplate) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | /** |
| | | * 查询商户信息 |
| | |
| | | */ |
| | | protected void checkStoreEnterCommunity(IPageData pd, String storeId, String storeTypeCd, String communityId, RestTemplate restTemplate) { |
| | | Assert.hasLength(pd.getUserId(), "用户未登录请先登录"); |
| | | ResponseEntity<String> responseEntity = null; |
| | | responseEntity = getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (resultVo.getCode() != ResultVo.CODE_OK) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | | } |
| | | |
| | | Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "data", "还未入驻小区,请先入驻小区"); |
| | | |
| | | JSONObject community = JSONObject.parseObject(responseEntity.getBody().toString()); |
| | | |
| | | JSONArray communitys = community.getJSONArray("data"); |
| | | JSONArray communitys = JSONArray.parseArray(resultVo.getData().toString()); |
| | | |
| | | if (communitys == null || communitys.size() == 0) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | |
| | | throw new IllegalArgumentException(responseEntity.getBody()); |
| | | } |
| | | |
| | | if(!StringUtil.isJsonObject(responseEntity.getBody())){ |
| | | // return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody()); |
| | | if (!StringUtil.isJsonObject(responseEntity.getBody())) { |
| | | // return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody()); |
| | | throw new IllegalArgumentException(responseEntity.getBody()); |
| | | } |
| | | |
| | | JSONObject paramJson = JSONObject.parseObject(responseEntity.getBody()); |
| | | if(paramJson.containsKey("code") && paramJson.getIntValue("code") != 0){ |
| | | if (paramJson.containsKey("code") && paramJson.getIntValue("code") != 0) { |
| | | throw new IllegalArgumentException(paramJson.getString("msg")); |
| | | } |
| | | |
| | |
| | | throw new IllegalArgumentException(responseEntity.getBody()); |
| | | } |
| | | JSONObject paramOut = JSONObject.parseObject(responseEntity.getBody()); |
| | | if(paramOut.containsKey("code") && ResultVo.CODE_OK != paramOut.getIntValue("code")){ |
| | | if (paramOut.containsKey("code") && ResultVo.CODE_OK != paramOut.getIntValue("code")) { |
| | | throw new IllegalArgumentException(paramOut.getString("msg")); |
| | | } |
| | | return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody()); |
| | | return new ResultVo(paramOut.getIntValue("code"), paramOut.getString("msg"), paramOut.get("data")); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | JSONArray privileges = data.getJSONArray("privileges"); |
| | | |
| | | if(!SecureInvocation.secure(this.getClass())){ |
| | | return new ResultVo(ResultVo.CODE_OK,privileges.toJSONString(),ResultVo.EMPTY_ARRAY); |
| | | if (!SecureInvocation.secure(this.getClass())) { |
| | | return new ResultVo(ResultVo.CODE_OK, privileges.toJSONString(), ResultVo.EMPTY_ARRAY); |
| | | } |
| | | |
| | | return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, privileges.toJSONString()); |
| | |
| | | import com.java110.po.fee.PayFeePo; |
| | | import com.java110.po.fee.FeeReceiptPo; |
| | | import com.java110.po.fee.FeeReceiptDetailPo; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.constant.*; |
| | | import com.java110.utils.exception.ListenerExecuteException; |
| | | import com.java110.utils.util.Assert; |
| | |
| | | payFeeDetail.setPayableAmount("0.0"); |
| | | } |
| | | payFeeDetail.setPayOrderId(paramInJson.getString("oId")); |
| | | payFeeDetail.setReceiptCode(receiptCode); |
| | | //todo 缓存收据编号 |
| | | CommonCache.setValue(payFeeDetail.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN); |
| | | // todo 刷入收银人员信息 |
| | | freshCashierInfo(payFeeDetail, paramInJson); |
| | | |
| | |
| | | import com.java110.po.fee.PayFeePo; |
| | | import com.java110.po.owner.RepairPoolPo; |
| | | import com.java110.po.owner.RepairUserPo; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.constant.FeeFlagTypeConstant; |
| | | import com.java110.utils.constant.FeeConfigConstant; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | |
| | | throw new IllegalArgumentException("费用项不存在"); |
| | | } |
| | | Date maxEndTime = feeDtos.get(0).getDeadlineTime(); |
| | | if (!FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) { |
| | | try { |
| | | maxEndTime = DateUtil.getDateFromString(feeConfigDtos.get(0).getEndTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | } catch (ParseException e) { |
| | | logger.error("比较费用日期失败", e); |
| | | } |
| | | Date newDate = DateUtil.stepMonth(endTime, paramInObj.getInteger("cycles") - 1); |
| | | //周期性费用 |
| | | if (maxEndTime == null || FeeDto.FEE_FLAG_CYCLE.equals(feeConfigDtos.get(0).getFeeFlag())) { |
| | | maxEndTime = DateUtil.getDateFromStringA(feeConfigDtos.get(0).getEndTime()); |
| | | } |
| | | |
| | | if (maxEndTime != null && endTime != null && !FeeDto.FEE_FLAG_ONCE.equals(feeConfigDtos.get(0).getFeeFlag())) { |
| | | Date newDate = DateUtil.stepMonth(endTime, reqJson.getDouble("cycles").intValue()); |
| | | if (newDate.getTime() > maxEndTime.getTime()) { |
| | | throw new IllegalArgumentException("缴费周期超过 缴费结束时间"); |
| | | throw new IllegalArgumentException("缴费周期超过 缴费结束时间,请用按结束时间方式缴费"); |
| | | } |
| | | } |
| | | |
| | |
| | | payFeeDetailPo.setPayOrderId(oId); |
| | | payFeeDetailPo.setCashierId(userDto.getUserId()); |
| | | payFeeDetailPo.setCashierName(userDto.getName()); |
| | | payFeeDetailPo.setReceiptCode(receiptCode); |
| | | //todo 缓存收据编号 |
| | | CommonCache.setValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN); |
| | | int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("缴费失败"); |
| | |
| | | payFeePo = BeanConvertUtil.covertBean(fee, PayFeePo.class); |
| | | PayFeeDetailPo payFeeDetailPo = BeanConvertUtil.covertBean(feeDetail, PayFeeDetailPo.class); |
| | | payFeeDetailPo.setReceivableAmount(feeDetail.getString("totalFeePrice")); |
| | | payFeeDetailPo.setReceiptCode(receiptCode); |
| | | //判断是否有赠送规则 |
| | | //todo 缓存收据编号 |
| | | CommonCache.setValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN); |
| | | |
| | | //todo 判断是否有赠送规则 |
| | | hasDiscount(paramObj, payFeePo, payFeeDetailPo); |
| | | |
| | | // todo 处理用户账户 |
| | |
| | | import com.java110.po.fee.PayFeePo; |
| | | import com.java110.po.owner.RepairPoolPo; |
| | | import com.java110.po.owner.RepairUserPo; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.constant.FeeConfigConstant; |
| | | import com.java110.utils.constant.FeeFlagTypeConstant; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | |
| | | @Autowired |
| | | private IRepairInnerServiceSMO repairInnerServiceSMO; |
| | | |
| | | @Autowired |
| | | private IFeeReceiptInnerServiceSMO feeReceiptInnerServiceSMOImpl; |
| | | |
| | | |
| | | @Override |
| | | public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException { |
| | |
| | | List<UserDto> userDtos = userV1InnerServiceSMOImpl.queryUsers(userDto); |
| | | Assert.listOnlyOne(userDtos, "用户未登录"); |
| | | |
| | | |
| | | //todo 生成收据编号 |
| | | String receiptCode = feeReceiptInnerServiceSMOImpl.generatorReceiptCode(reqJson.getString("communityId")); |
| | | |
| | | List<PayFeeDetailMonthDto> payFeeDetailMonthDtos = (List<PayFeeDetailMonthDto>) reqJson.get("payFeeDetailMonthDtos"); |
| | | |
| | | Calendar createTimeCal = Calendar.getInstance(); |
| | |
| | | } |
| | | createTimeCal.add(Calendar.SECOND, 1); |
| | | try { |
| | | doMonthFee(payFeeDetailMonthDto, context, userDtos.get(0), reqJson, createTimeCal.getTime(), feeDtoMap); |
| | | doMonthFee(payFeeDetailMonthDto, context, userDtos.get(0), reqJson, createTimeCal.getTime(), feeDtoMap,receiptCode); |
| | | } catch (Exception e) { |
| | | logger.error("处理异常", e); |
| | | throw new CmdException(e.getMessage()); |
| | |
| | | * @param userDto |
| | | * @param reqJson |
| | | */ |
| | | private void doMonthFee(PayFeeDetailMonthDto payFeeDetailMonthDto, ICmdDataFlowContext context, UserDto userDto, JSONObject reqJson, Date createTime, Map<String, FeeDto> feeDtoMap) { |
| | | private void doMonthFee(PayFeeDetailMonthDto payFeeDetailMonthDto, ICmdDataFlowContext context, UserDto userDto, JSONObject reqJson, Date createTime, Map<String, FeeDto> feeDtoMap,String receiptCode) { |
| | | //todo 计算结束时间 |
| | | Date startTime = DateUtil.getDateFromStringB(payFeeDetailMonthDto.getCurMonthTime()); |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | payFeeDetailPo.setEndTime(endTime); |
| | | // todo 按月交费时 主要按时间顺序排序时 能够整齐 |
| | | payFeeDetailPo.setCreateTime(DateUtil.getFormatTimeStringA(createTime)); |
| | | |
| | | //todo 缓存收据编号 |
| | | CommonCache.setValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE,receiptCode,CommonCache.DEFAULT_EXPIRETIME_TWO_MIN); |
| | | int flag = payFeeDetailNewV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("缴费失败"); |
| | |
| | | import com.java110.po.fee.FeeReceiptDetailPo; |
| | | import com.java110.po.owner.RepairPoolPo; |
| | | import com.java110.po.owner.RepairUserPo; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.constant.ResponseConstant; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.exception.ListenerExecuteException; |
| | |
| | | Assert.hasKeyAndValue(feeObject, "startTime", "未包含开始时间"); |
| | | Assert.hasKeyAndValue(feeObject, "endTime", "未包含结束时间"); |
| | | Assert.hasKeyAndValue(feeObject, "receivedAmount", "未包含实收金额"); |
| | | |
| | | //计算 应收金额 |
| | | FeeDto feeDto = new FeeDto(); |
| | | feeDto.setFeeId(feeObject.getString("feeId")); |
| | | feeDto.setCommunityId(feeObject.getString("communityId")); |
| | | Date pageEndTime = null; |
| | | List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto); |
| | | if (feeDtos == null || feeDtos.size() != 1) { |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "查询费用信息失败,未查到数据或查到多条数据"); |
| | | } |
| | | feeDto = feeDtos.get(0); |
| | | |
| | | pageEndTime = DateUtil.getDateFromStringB(feeObject.getString("endTime")); |
| | | if (pageEndTime.getTime() <= feeDto.getEndTime().getTime()) { |
| | | throw new IllegalArgumentException("可能存在重复缴费,请刷新页面重新缴费"); |
| | | } |
| | | |
| | | feeObject.put("feeDto", feeDto); |
| | | } |
| | | } |
| | | |
| | |
| | | businessFeeDetail.putAll(paramInJson); |
| | | businessFeeDetail.put("detailId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_detailId)); |
| | | businessFeeDetail.put("primeRate", paramInJson.getString("primeRate")); |
| | | //计算 应收金额 |
| | | FeeDto feeDto = new FeeDto(); |
| | | feeDto.setFeeId(paramInJson.getString("feeId")); |
| | | feeDto.setCommunityId(paramInJson.getString("communityId")); |
| | | List<FeeDto> feeDtos = feeInnerServiceSMOImpl.queryFees(feeDto); |
| | | if (feeDtos == null || feeDtos.size() != 1) { |
| | | throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR, "查询费用信息失败,未查到数据或查到多条数据"); |
| | | } |
| | | FeeDto feeDto = (FeeDto) paramInJson.get("feeDto"); |
| | | if (!businessFeeDetail.containsKey("state") || StringUtil.isEmpty(businessFeeDetail.getString("state"))) { |
| | | businessFeeDetail.put("state", "1400"); |
| | | } |
| | | feeDto = feeDtos.get(0); |
| | | |
| | | businessFeeDetail.put("startTime", paramInJson.getString("startTime")); |
| | | BigDecimal cycles = null; |
| | | Map feePriceAll = computeFeeSMOImpl.getFeePrice(feeDto); |
| | |
| | | } |
| | | payFeeDetailPo.setCashierId(userDto.getUserId()); |
| | | payFeeDetailPo.setCashierName(userDto.getName()); |
| | | payFeeDetailPo.setReceiptCode(receiptCode); |
| | | |
| | | //todo 缓存收据编号 |
| | | CommonCache.setValue(payFeeDetailPo.getDetailId() + CommonCache.RECEIPT_CODE, receiptCode, CommonCache.DEFAULT_EXPIRETIME_TWO_MIN); |
| | | int flag = payFeeDetailV1InnerServiceSMOImpl.savePayFeeDetailNew(payFeeDetailPo); |
| | | |
| | | if (flag < 1) { |
| | |
| | | |
| | | |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.PageDto; |
| | | import com.java110.dto.community.CommunitySettingDto; |
| | | import com.java110.dto.fee.FeeReceiptDto; |
| | |
| | | communitySettingDtos = communitySettingInnerServiceSMOImpl.queryCommunitySettings(communitySettingDto); |
| | | } |
| | | |
| | | preReceiptCode = communitySettingDtos.get(0).getSettingValue(); |
| | | preReceiptCode = communitySettingDtos.get(0).getSettingValue().trim(); |
| | | if (!StringUtil.isNumber(preReceiptCode)) { |
| | | return startCode + preReceiptCode; |
| | | } |
| | | |
| | | if(preReceiptCode.length() > 24){ |
| | | if (preReceiptCode.length() > 24) { |
| | | receiptCode = String.format("%024d", (Long.parseLong(preReceiptCode) + 1)); |
| | | }else{ |
| | | } else { |
| | | receiptCode = String.format("%0" + preReceiptCode.length() + "d", (Long.parseLong(preReceiptCode) + 1)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | private void saveReceiptCode(String communityId) { |
| | | CommunitySettingPo communitySettingPo = new CommunitySettingPo(); |
| | | communitySettingPo.setCommunityId(communityId); |
| | | communitySettingPo.setCsId(GenerateCodeFactory.getGeneratorId("10")); |
| | | communitySettingPo.setSettingType(CommunitySettingDto.SETTING_TYPE_FEE); |
| | | communitySettingPo.setSettingKey(CommunitySettingDto.SETTING_KEY_RECEIPT_CODE); |
| | | communitySettingPo.setSettingValue("001"); |
| | | communitySettingPo.setSettingName("收据开始编号"); |
| | | communitySettingPo.setRemark("系统自动生成"); |
| | | communitySettingInnerServiceSMOImpl.saveCommunitySetting(communitySettingPo); |
| | | } |
| | | |
| | | public IFeeReceiptServiceDao getFeeReceiptServiceDaoImpl() { |
| | |
| | | private void doDealFeeDto(FeeDto tmpFeeDto, OwnerDto ownerDto) { |
| | | |
| | | //判断是否存在 业主名称 |
| | | |
| | | FeeAttrDto ownerNameAttr = getOwnerFeeAttr(tmpFeeDto, FeeAttrDto.SPEC_CD_OWNER_NAME); |
| | | FeeAttrPo tmpFeeAttrPo = new FeeAttrPo(); |
| | | if (ownerNameAttr == null) { |
| | |
| | | feeAttrInnerServiceSMOImpl.updateFeeAttr(tmpFeeAttrPo); |
| | | } |
| | | |
| | | // todo 是否存在 业主ID |
| | | ownerNameAttr = getOwnerFeeAttr(tmpFeeDto, FeeAttrDto.SPEC_CD_OWNER_ID); |
| | | tmpFeeAttrPo = new FeeAttrPo(); |
| | | if (ownerNameAttr == null) { |
| | | tmpFeeAttrPo.setAttrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_attrId)); |
| | | tmpFeeAttrPo.setCommunityId(ownerDto.getCommunityId()); |
| | | tmpFeeAttrPo.setFeeId(tmpFeeDto.getFeeId()); |
| | | tmpFeeAttrPo.setSpecCd(FeeAttrDto.SPEC_CD_OWNER_ID); |
| | | tmpFeeAttrPo.setValue(ownerDto.getOwnerId()); |
| | | feeAttrInnerServiceSMOImpl.saveFeeAttr(tmpFeeAttrPo); |
| | | } else { |
| | | tmpFeeAttrPo.setAttrId(ownerNameAttr.getAttrId()); |
| | | tmpFeeAttrPo.setValue(ownerDto.getOwnerId()); |
| | | feeAttrInnerServiceSMOImpl.updateFeeAttr(tmpFeeAttrPo); |
| | | } |
| | | |
| | | } |
| | | |
| | | private FeeAttrDto getOwnerFeeAttr(FeeDto tmpFeeDto, String specCd) { |
| | |
| | | import com.java110.po.fee.FeeReceiptDetailPo; |
| | | import com.java110.po.log.LogSystemErrorPo; |
| | | import com.java110.service.smo.ISaveSystemErrorSMO; |
| | | import com.java110.utils.cache.CommonCache; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.factory.ApplicationContextFactory; |
| | | import com.java110.utils.util.Assert; |
| | |
| | | && businessPayFeeDetail.getDoubleValue("receivedAmount") < 0) { |
| | | return; |
| | | } |
| | | |
| | | String receiptCode = CommonCache.getValue(payFeeDetailPo.getDetailId()+CommonCache.RECEIPT_CODE); |
| | | //todo 如果为空重新生成收据编号 |
| | | if(StringUtil.isEmpty(receiptCode)){ |
| | | receiptCode = feeReceiptInnerServiceSMOImpl.generatorReceiptCode(payFeeDetailPo.getCommunityId()); |
| | | } |
| | | |
| | | //添加收据和收据详情 |
| | | FeeReceiptPo feeReceiptPo = new FeeReceiptPo(); |
| | | FeeReceiptDetailPo feeReceiptDetailPo = new FeeReceiptDetailPo(); |
| | |
| | | feeReceiptPo.setPayObjId(ownerDto.getOwnerId()); |
| | | feeReceiptPo.setPayObjName(ownerDto.getName()); |
| | | feeReceiptPo.setCreateTime(payFeeDetailPo.getCreateTime()); |
| | | feeReceiptPo.setReceiptCode(businessPayFeeDetail.getString("receiptCode")); |
| | | feeReceiptPo.setReceiptCode(receiptCode); |
| | | //这里只是写入 收据表,暂不考虑 事务一致性问题,就算写入失败 也只是影响 收据打印,如果 贵公司对 收据要求 比较高,不能有失败的情况 请加入事务管理 |
| | | feeReceiptDetailInnerServiceSMOImpl.saveFeeReceiptDetail(feeReceiptDetailPo); |
| | | feeReceiptInnerServiceSMOImpl.saveFeeReceipt(feeReceiptPo); |
| New file |
| | |
| | | package com.java110.user.cmd.wechat; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Cmd; |
| | | import com.java110.core.context.ICmdDataFlowContext; |
| | | import com.java110.core.event.cmd.Cmd; |
| | | import com.java110.core.event.cmd.CmdEvent; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.dto.user.UserAttrDto; |
| | | import com.java110.dto.wechat.SmallWeChatDto; |
| | | import com.java110.intf.store.ISmallWechatV1InnerServiceSMO; |
| | | import com.java110.intf.user.IUserAttrV1InnerServiceSMO; |
| | | import com.java110.po.user.UserAttrPo; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.MappingConstant; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.vo.ResultVo; |
| | | import org.slf4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 根据小程序code 获取openId |
| | | */ |
| | | |
| | | @Java110Cmd(serviceCode = "wechat.getOpenIdByCode") |
| | | public class GetOpenIdByCodeCmd extends Cmd { |
| | | private final static Logger logger = LoggerFactory.getLogger(GetOpenIdByCodeCmd.class); |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Autowired |
| | | private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IUserAttrV1InnerServiceSMO userAttrV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException { |
| | | Assert.hasKeyAndValue(reqJson, "code", "未包含code"); |
| | | Assert.hasKeyAndValue(reqJson, "appId", "未包含小程序ID"); |
| | | } |
| | | |
| | | @Override |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException { |
| | | |
| | | String userId = context.getReqHeaders().get("user-id"); |
| | | |
| | | String appId = ""; |
| | | String appSecret = ""; |
| | | if ("MALL".equals(reqJson.getString("appId"))) { |
| | | appId = MappingCache.getValue(MappingConstant.MALL_WECHAT_DOMAIN, "appId"); |
| | | appSecret = MappingCache.getValue(MappingConstant.MALL_WECHAT_DOMAIN, "appSecret"); |
| | | } else { |
| | | SmallWeChatDto smallWeChatDto = new SmallWeChatDto(); |
| | | smallWeChatDto.setAppId(reqJson.getString("appId")); |
| | | List<SmallWeChatDto> smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto); |
| | | |
| | | if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) { |
| | | throw new IllegalArgumentException("未配置小程序信息"); |
| | | } |
| | | |
| | | appId = smallWeChatDtos.get(0).getAppId(); |
| | | appSecret = smallWeChatDtos.get(0).getAppSecret(); |
| | | } |
| | | |
| | | |
| | | ResponseEntity<String> responseEntity; |
| | | String code = reqJson.getString("code"); |
| | | String urlString = "https://api.weixin.qq.com/sns/jscode2session?appid={appId}&secret={secret}&js_code={code}&grant_type={grantType}"; |
| | | String response = outRestTemplate.getForObject( |
| | | urlString, String.class, |
| | | appId, |
| | | appSecret, |
| | | code, |
| | | "authorization_code"); |
| | | |
| | | logger.debug("微信返回报文:" + response); |
| | | |
| | | //Assert.jsonObjectHaveKey(response, "errcode", "返回报文中未包含 错误编码,接口出错"); |
| | | JSONObject responseObj = JSONObject.parseObject(response); |
| | | |
| | | if (responseObj.containsKey("errcode") && !"0".equals(responseObj.getString("errcode"))) { |
| | | throw new IllegalArgumentException("微信验证失败,可能是code失效" + responseObj); |
| | | } |
| | | |
| | | String openId = responseObj.getString("openid"); |
| | | |
| | | UserAttrDto userAttrDto = new UserAttrDto(); |
| | | userAttrDto.setUserId(userId); |
| | | userAttrDto.setSpecCd(UserAttrDto.SPEC_MALL_OPEN_ID); |
| | | List<UserAttrDto> userAttrDtos = userAttrV1InnerServiceSMOImpl.queryUserAttrs(userAttrDto); |
| | | if(userAttrDtos == null || userAttrDtos.size() < 1){ |
| | | UserAttrPo userAttrPo = new UserAttrPo(); |
| | | userAttrPo.setAttrId(GenerateCodeFactory.getAttrId()); |
| | | userAttrPo.setUserId(userId); |
| | | userAttrPo.setSpecCd(UserAttrDto.SPEC_MALL_OPEN_ID); |
| | | userAttrPo.setValue(openId); |
| | | userAttrV1InnerServiceSMOImpl.saveUserAttr(userAttrPo); |
| | | }else { |
| | | UserAttrPo userAttrPo = new UserAttrPo(); |
| | | userAttrPo.setAttrId(userAttrDtos.get(0).getAttrId()); |
| | | userAttrPo.setValue(openId); |
| | | userAttrV1InnerServiceSMOImpl.updateUserAttr(userAttrPo); |
| | | } |
| | | context.setResponseEntity(ResultVo.createResponseEntity(openId)); |
| | | |
| | | } |
| | | } |
| | |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | private ResponseEntity<String> getStoreEnterCommunitys(IPageData pd, String storeId, String storeTypeCd, RestTemplate restTemplate) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | return new ResponseEntity<String>(resultVo.getMsg(), resultVo.getCode() == ResultVo.CODE_OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | /** |
| | | * 查询商户信息 |
| | |
| | | */ |
| | | protected void checkStoreEnterCommunity(IPageData pd, String storeId, String storeTypeCd, String communityId, RestTemplate restTemplate) { |
| | | Assert.hasLength(pd.getUserId(), "用户未登录请先登录"); |
| | | ResponseEntity<String> responseEntity = null; |
| | | responseEntity = getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (responseEntity.getStatusCode() != HttpStatus.OK) { |
| | | ResultVo resultVo = getCommunityStoreInfoSMOImpl.getStoreEnterCommunitys(pd, storeId, storeTypeCd, restTemplate); |
| | | if (resultVo.getCode() != ResultVo.CODE_OK) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | | } |
| | | |
| | | Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "data", "还未入驻小区,请先入驻小区"); |
| | | |
| | | JSONObject community = JSONObject.parseObject(responseEntity.getBody().toString()); |
| | | |
| | | JSONArray communitys = community.getJSONArray("data"); |
| | | JSONArray communitys = JSONArray.parseArray(resultVo.getData().toString()); |
| | | |
| | | if (communitys == null || communitys.size() == 0) { |
| | | throw new SMOException(ResponseConstant.RESULT_CODE_ERROR, "还未入驻小区,请先入驻小区"); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private JSONObject getCurrentCommunity(JSONArray communitys, String communityId) { |
| | | for (int communityIndex = 0; communityIndex < communitys.size(); communityIndex++) { |
| | |
| | | throw new IllegalArgumentException(paramJson.getString("msg")); |
| | | } |
| | | |
| | | return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody()); |
| | | return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody(),responseEntity.getBody()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if(paramOut.containsKey("code") && ResultVo.CODE_OK != paramOut.getIntValue("code")){ |
| | | throw new IllegalArgumentException(paramOut.getString("msg")); |
| | | } |
| | | return new ResultVo(responseEntity.getStatusCode() == HttpStatus.OK ? ResultVo.CODE_OK : ResultVo.CODE_ERROR, responseEntity.getBody()); |
| | | return new ResultVo(paramOut.getIntValue("code"), paramOut.getString("msg"), paramOut.get("data")); |
| | | } |
| | | |
| | | @Override |