/* * 修改浏览次数 */ @Override public DealerInfo modifyViewContact(String brandId, String dealerId) throws BusinessException { DealerInfoModel dealerInfo = dealerInfoService.findById(dealerId); if (null == dealerInfo) { throw new BusinessException(CommonConst.DATA_NOT_EXISTS); } UserInfo userInfo = userInfoService.selectByPrimaryKey(dealerId); Integer contactIsExistInt = brandViewContactMapper.isExist(brandId, dealerId, null); Short viewType = BrandConstant.BrandViewContact.VIEW_TYPE_INITIATIVE; if (contactIsExistInt > 0) { Integer groomIsExistInt = dealerGroomMapper.isExist(brandId, dealerId); if (groomIsExistInt > 0) { viewType = BrandConstant.BrandViewContact.VIEW_TYPE__RECOMMEND; } else { Integer inviteIsExistInt = brandInviteMapper.isExist(brandId, dealerId); if (inviteIsExistInt > 0) { viewType = BrandConstant.BrandViewContact.VIEW_TYPE_APPLICATION; } } } BrandViewContact brandViewContact = new BrandViewContact(); brandViewContact.setBrandId(brandId); brandViewContact.setDealerId(dealerId); brandViewContact.setViewType(viewType); if (contactIsExistInt == 0) { brandViewContact.setRefrenceId(com.zttx.sdk.utils.SerialnoUtils.buildPrimaryKey()); brandViewContact.setViewTime(CalendarUtils.getCurrentLong()); brandViewContactMapper.insert(brandViewContact); } BrandCount brandCount = brandCountService.selectByPrimaryKey(brandId); Integer viewCount = brandCountService.getViewDealerTotal(brandId); boolean brandCountisExist = true; if (null != brandCount) { if (viewCount.intValue() <= brandCount.getViewDealerCount().intValue()) { throw new BusinessException(BrandConst.VIEW_CONTACT_LACK_POINTS); } } else { brandCountisExist = false; brandCount = new BrandCount(); brandCount.setRefrenceId(com.zttx.sdk.utils.SerialnoUtils.buildPrimaryKey()); } // 查看经销商联系信息数量 Long count = brandViewContactMapper.getBrandViewContactCount(brandViewContact); brandCount.setViewDealerCount(count.intValue()); if (brandCountisExist) { brandCountService.updateByPrimaryKey(brandCount); } else { brandCountService.insert(brandCount); } Boolean isExits = false; if (contactIsExistInt > 0) { isExits = true; } dealerInfo.setIsViewAdd(isExits); dealerInfo.setUserMobile(userInfo.getUserMobile()); return dealerInfo; }
private Integer getViewDealerTotal(BrandCount brandCount) { Integer viewCount = BrandConstant.BrandCountConst.BRAND_VIEW_COUNT; if (null != brandCount.getViewDealerTotal() && 0 < brandCount.getViewDealerTotal()) { viewCount = brandCount.getViewDealerTotal(); } return viewCount; }
public Boolean insertWithCheck( String brandId, String dealerId, Boolean isAdd, BrandViewContact brandViewContact) throws BusinessException { Short viewType = BrandConstant.BrandViewContact.VIEW_TYPE_INITIATIVE; Boolean isExist = this.isExist(brandId, dealerId, null); if (brandViewContact == null) { brandViewContact = new BrandViewContact(); } if (!isExist) { isExist = dealerGroomMapper.isExist(brandId, dealerId) > 0; if (!isExist) { isExist = brandInviteMapper.isExist(brandId, dealerId) > 0; if (isExist) { viewType = BrandConstant.BrandViewContact.VIEW_TYPE_APPLICATION; } } else { viewType = BrandConstant.BrandViewContact.VIEW_TYPE__RECOMMEND; } if (isExist || isAdd) { brandViewContact.setRefrenceId(com.zttx.sdk.utils.SerialnoUtils.buildPrimaryKey()); brandViewContact.setBrandId(brandId); brandViewContact.setDealerId(dealerId); brandViewContact.setViewTime(CalendarUtils.getCurrentLong()); brandViewContact.setViewType(viewType); brandViewContactMapper.insert(brandViewContact); if (!isExist) { BrandCount brandCount = brandCountMapper.selectByPrimaryKey(brandId); Integer viewCount = getViewDealerTotal(brandCount); if (null != brandCount && viewCount.intValue() > brandCount.getViewDealerCount().intValue()) { List<Integer> countTypeList = Lists.newArrayList(); // 已铺货产品数量和未铺货产品数量只需放入一个类型就可以了 countTypeList.add(BrandConstant.BrandCountConst.BRANDCOUNT_VIEWDEALERCOUNT); brandCountService.modifyBrandCount(brandId, countTypeList.toArray(new Integer[] {})); } } } } return isExist; }
@ResponseBody @RequestMapping(value = "", method = RequestMethod.POST) public JsonMessage brandCount(HttpServletRequest request, ClientParameter parameter) throws BusinessException { Map<String, String> map = ParameterUtils.getMapFromParameter(parameter); String brandId = MapUtils.getString(map, "brandId"); String count = MapUtils.getString(map, "viewDealerTotal"); // 品牌商id 不允许为空 if (StringUtils.isEmpty(brandId)) { throw new BusinessException("品牌商ID不能为空!"); } // 找不到品牌商 BrandCount brandCount = brandCountService.selectByPrimaryKey(brandId); if (brandCount == null) { throw new BusinessException("该品牌商ID不存在!"); } int total = brandCount.getViewDealerTotal() == null ? 0 : brandCount.getViewDealerTotal(); total = total == 0 ? BrandConstant.BrandCount.VIEW_TOTAL_COUNT : total; int used = brandCount.getViewDealerCount() == null ? 0 : brandCount.getViewDealerCount(); if (StringUtils.isEmpty(count)) { // ||StringUtils.equals(count, "0") Map<String, Object> retMap = Maps.newHashMap(); retMap.put("total", total); retMap.put("brandId", brandId); retMap.put("rest", total - used); return this.getJsonMessage(CommonConst.SUCCESS, retMap); } // 数据为空 就返回该品牌商的 if (!StringUtils.isNumeric(count) || Integer.parseInt(count) < 0) { throw new BusinessException("Count 格式不合法 or 值小于等于0"); } brandCount.setViewDealerTotal(Integer.parseInt(count)); total = Integer.parseInt(count); brandCountService.updateByPrimaryKey(brandCount); Map<String, Object> retMap = Maps.newHashMap(); retMap.put("total", total); retMap.put("brandId", brandId); retMap.put("rest", total - used); return this.getJsonMessage(CommonConst.SUCCESS, retMap); }