@Override // @Transactional public void createActAd(String actName, long rawAdId) throws ActAdInputException { Act act = actService.getActByName(actName); if (act == null) { throw new ActAdInputException(ActAdInputException.ACT_AD_NAME_IS_NOT_EXIST); } RawAd rawAd = rawAdService.getRawAd(rawAdId); if (rawAd == null) { throw new ActAdInputException(ActAdInputException.ACT_AD_RAW_AD_ID_IS_NULL); } if (isUrlExist(rawAd.getTargetUrl(), act.getId())) { throw new ActAdInputException(ActAdInputException.ACT_AD_URL_IS_EXIST); } try { ActAd actAd = rawAdIntoActAd(rawAd); int sequence = getAdCount(act.getId()); actAd.setSequence((sequence + 1)); actAd.setActId(act.getId()); actAdMapper.insert(actAd); String actIds = rawAd.getActIds(); if (StringUtils.isEmpty(actIds)) { rawAd.setActIds(String.valueOf(act.getId())); } else { String[] ids = actIds.split(","); List<String> list = new ArrayList<String>(); for (String id : ids) { list.add(id); } list.add(String.valueOf(act.getId())); rawAd.setActIds(StringUtils.join(list, ",")); } rawAd.setStatus(1); rawAdService.updateRawAd(rawAd); } catch (Exception e) { throw new ActAdInputException(ActAdInputException.CREATE_ACT_AD_IS_ERROR); } }
private ActAd rawAdIntoActAd(RawAd rawAd) { ActAd ad = new ActAd(); ad.setAddress(rawAd.getAddress()); ad.setCity(rawAd.getCity()); ad.setCreateTime(new Date()); ad.setDiscount(rawAd.getDiscount()); ad.setDistrict(rawAd.getCircle()); ad.setEndTime(rawAd.getEndDate()); ad.setLastModifyTime(new Date()); ad.setLink(rawAd.getTargetUrl()); ad.setName(rawAd.getTitle()); ad.setPicUrl(rawAd.getImg()); ad.setPrice(rawAd.getPrice()); ad.setPrimePrice(rawAd.getOriginal()); ad.setSource(rawAd.getSource()); ad.setSourceLink(getDomain(rawAd.getTargetUrl())); ad.setStartTime(rawAd.getStartDate()); return ad; }