Commit 2a5abfd9 by 田超

Merge branch 'feature/1006126' into 'master'

feat: [1006126] 广告管理CPA模块优化

See merge request rays/pcloud-book!1469
parents df01a0a7 0ec8d56b
......@@ -73,6 +73,12 @@ public interface BmBiz {
* @return
*/
Long userSubmit(AdvertisingBmRegister bmRegister, Long wechatUserId);
/**
* 通过cpa链接预览提交
*/
Long userSubmit4Cpa(AdvertisingBmRegister bmRegister, Long wechatUserId);
/**
* 微信端获取个人报名详情
* @param adId 应用ID
......@@ -80,7 +86,7 @@ public interface BmBiz {
* @return
* @throws BizException
*/
List<BmRegisterDTO> getDetail4Wechat(Long adId, Long wechatUserId, Long qrcodeId) throws BizException;
List<BmRegisterDTO> getDetail4Wechat(Long adId, Long wechatUserId, Long qrcodeId,Long cpaId) throws BizException;
/**
* 获取报名次数
......@@ -127,4 +133,10 @@ public interface BmBiz {
* @return
*/
public Long getRegisterCountByBookId(Long bookId, Long adviserId, Long channelId, Long adId, String statisMonth);
/**
* cpa内容管理报名信息导出
* @param cpaId
*/
Map<String, Object> exportRegisterInfoByCpaId(Long cpaId, String statisMonth);
}
package com.pcloud.book.advertising.biz.impl;
import com.pcloud.book.advertising.biz.BmBiz;
import com.pcloud.book.advertising.dao.AdvertisingCpaDao;
import com.pcloud.book.advertising.dao.AdvertisingDistributionBookDao;
import com.pcloud.book.advertising.dao.AdvertisingSpaceDao;
import com.pcloud.book.advertising.dao.BmOptionDao;
......@@ -15,6 +16,7 @@ import com.pcloud.book.advertising.entity.AdvertisingBmOption;
import com.pcloud.book.advertising.entity.AdvertisingBmOptionItem;
import com.pcloud.book.advertising.entity.AdvertisingBmRegister;
import com.pcloud.book.advertising.entity.AdvertisingBmRegisterItem;
import com.pcloud.book.advertising.entity.AdvertisingCpa;
import com.pcloud.book.advertising.entity.AdvertisingDistributionBook;
import com.pcloud.book.advertising.entity.AdvertisingSpace;
import com.pcloud.book.advertising.enums.AdPositionEnum;
......@@ -87,6 +89,8 @@ public class BmBizImpl implements BmBiz {
private ChannelConsr channelConsr;
@Autowired
private AdvertisingDistributionBookDao distributionBookDao;
@Autowired
private AdvertisingCpaDao advertisingCpaDao;
/**
* 获取报名商品选项类型
......@@ -302,7 +306,37 @@ public class BmBizImpl implements BmBiz {
bmRegisterDao.insert(bmRegister);
Long registerId = bmRegister.getId();
// 添加用户选项
addRegisterItem(items, adId, wechatUserId, registerId);
addRegisterItem(items, adId, wechatUserId, registerId,null);
return registerId;
}
@Override
public Long userSubmit4Cpa(AdvertisingBmRegister bmRegister, Long wechatUserId) {
// 检测参数
Long cpaId = bmRegister.getCpaId();
List<AdvertisingBmRegisterItem> items = bmRegister.getBmRegisterItemList();
if (ListUtils.isEmpty(items)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "请填写表单");
}
Long mobilePhoneOptionId = bmOptionDao.getMobilePhoneOptionIdByCPA(cpaId);
Optional<AdvertisingBmRegisterItem> itemOptional = items.stream().filter(s -> s != null && s.getOptionId() == mobilePhoneOptionId).findFirst();
if (itemOptional.isPresent()) {// 存在
AdvertisingBmRegisterItem registerItem = itemOptional.get();
if (null != registerItem && !StringUtil.isEmpty(registerItem.getOptionValue())) {
Integer count = bmRegisterItemDao.checkMobilePhone4Cpa(cpaId, bmRegister.getFromType(), bmRegister.getFromId(), registerItem.getOptionValue());
if (count > 0) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "手机号已存在");
}
}
}
Long agentId = channelConsr.getParentId(bmRegister.getChannelId());
bmRegister.setAgentId(agentId);
WechatUser wechat = readerConsr.getWechatUser(wechatUserId);
bmRegister.setNickName(wechat == null ? "" : wechat.getWechatUserNickname());
bmRegisterDao.insert(bmRegister);
Long registerId = bmRegister.getId();
// 添加用户选项
addRegisterItem(items, null, wechatUserId, registerId,cpaId);
return registerId;
}
......@@ -314,13 +348,14 @@ public class BmBizImpl implements BmBiz {
* @param registerId
* @throws BizException
*/
public void addRegisterItem(List<AdvertisingBmRegisterItem> items, Long adId, Long wechatUserId, Long registerId) throws BizException {
public void addRegisterItem(List<AdvertisingBmRegisterItem> items, Long adId, Long wechatUserId, Long registerId,Long cpaId) throws BizException {
if (ListUtils.isEmpty(items)) {
return;
}
for (AdvertisingBmRegisterItem item : items) {
item.setUserId(wechatUserId);
item.setAdId(adId);
item.setCpaId(cpaId);
item.setRegisterId(registerId);
//多选单选选项id
List<Long> optionItems = item.getOptionItemIds();
......@@ -345,11 +380,12 @@ public class BmBizImpl implements BmBiz {
* 微信端获取个人报名详情
*/
@Override
public List<BmRegisterDTO> getDetail4Wechat(Long adId, Long wechatUserId, Long qrcodeId) throws BizException {
public List<BmRegisterDTO> getDetail4Wechat(Long adId, Long wechatUserId, Long qrcodeId,Long cpaId) throws BizException {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("adId", adId);
paramMap.put("wechatUserId", wechatUserId);
paramMap.put("qrcodeId", qrcodeId);
paramMap.put("cpaId", cpaId);
List<BmRegisterDTO> result = bmRegisterDao.getDetailByUser(paramMap);
return result;
......@@ -523,4 +559,41 @@ public class BmBizImpl implements BmBiz {
public Long getRegisterCountByBookId(Long bookId, Long adviserId, Long channelId, Long adId, String statisMonth) {
return bmRegisterDao.getRegisterCountByBookId(bookId, adviserId, channelId, adId, statisMonth);
}
@Override
public Map<String, Object> exportRegisterInfoByCpaId(Long cpaId, String statisMonth) {
AdvertisingCpa cpa = advertisingCpaDao.getById(cpaId);
if (null == cpa) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "CPA不存在!");
}
List<BmRegisterDTO> registerDtos = bmRegisterDao.getRegisterInfoListByCpaId(cpaId, statisMonth);
if (ListUtils.isEmpty(registerDtos)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "无报名信息!");
}
Map<String, Object> result = new HashMap<>();
try {
String title = cpa.getDetailName() + "-客户信息";
List<AdvertisingBmOption> optionList = bmOptionDao.getByCPAId(cpaId);
List<String> rowsNameList = new ArrayList<>();
rowsNameList.add("序号");
rowsNameList.add("报名人");
rowsNameList.add("报名时间");
for (int t = 0; t < optionList.size(); t++) {
AdvertisingBmOption option = optionList.get(t);
rowsNameList.add(option.getItemTitle());
}
String[] rowsName = rowsNameList.toArray(new String[0]);
String filePath = exportRegisterInfo(title, rowsName, optionList, registerDtos);
result.put("fileName", title);
result.put("filePath", filePath);
return result;
} catch (DataAccessException e) {
LOGGER.error("导出用户信息时【exportRegisterInfoByCpaId】" + e.getMessage(), e);
throw new BookBizException(BookBizException.ERROR, "导出注册用户相关信息时出现异常");
} catch (Exception e) {
LOGGER.error("调用commoncenter生成Excel异常:" + e.getMessage(), e);
throw new BookBizException(BookBizException.ERROR, "导出失败,请稍后重试");
}
}
}
......@@ -82,4 +82,6 @@ public interface BmRegisterDao extends BaseDao<AdvertisingBmRegister> {
* @return
*/
public Long getRegisterCountByBookId(Long bookId, Long adviserId, Long channelId, Long adId, String statisMonth);
List<BmRegisterDTO> getRegisterInfoListByCpaId(Long cpaId, String statisMonth);
}
......@@ -19,4 +19,6 @@ public interface BmRegisterItemDao extends BaseDao<AdvertisingBmRegisterItem> {
* @return
*/
Integer checkMobilePhone(Long adId, String fromType, Long fromId, String optionValue);
Integer checkMobilePhone4Cpa(Long cpaId, String fromType, Long fromId, String optionValue);
}
......@@ -89,5 +89,11 @@ public class BmRegisterDaoImpl extends BaseDaoImpl<AdvertisingBmRegister> implem
return getSessionTemplate().selectOne(getStatement("getRegisterCountByBookId"), map);
}
@Override
public List<BmRegisterDTO> getRegisterInfoListByCpaId(Long cpaId, String statisMonth) {
Map<String, Object> map = new HashMap<>();
map.put("cpaId", cpaId);
map.put("statisMonth", statisMonth);
return getSessionTemplate().selectList(getStatement("getRegisterInfoListByCpaId"),map);
}
}
......@@ -27,4 +27,14 @@ public class BmRegisterItemDaoImpl extends BaseDaoImpl<AdvertisingBmRegisterItem
map.put("optionValue", optionValue);
return getSessionTemplate().selectOne(getStatement("checkMobilePhone"), map);
}
@Override
public Integer checkMobilePhone4Cpa(Long cpaId, String fromType, Long fromId, String optionValue) {
Map<String, Object> map = new HashMap<>();
map.put("cpaId", cpaId);
map.put("fromType", fromType);
map.put("fromId",fromId);
map.put("optionValue", optionValue);
return getSessionTemplate().selectOne(getStatement("checkMobilePhone4Cpa"), map);
}
}
......@@ -90,6 +90,19 @@ public class AdvertisingBmRegister extends BaseEntity{
*/
private Long bookGroupId;
/**
* cpa内容id
*/
private Long cpaId;
public Long getCpaId() {
return cpaId;
}
public void setCpaId(Long cpaId) {
this.cpaId = cpaId;
}
public Long getUserId() {
return userId;
}
......
......@@ -46,6 +46,19 @@ public class AdvertisingBmRegisterItem extends BaseEntity{
*/
private List<Long> optionItemIds;
/**
* cpa内容id
*/
private Long cpaId;
public Long getCpaId() {
return cpaId;
}
public void setCpaId(Long cpaId) {
this.cpaId = cpaId;
}
public Long getUserId() {
return userId;
}
......
......@@ -69,7 +69,9 @@ public interface BmFacade {
@ApiOperation(value = "微信端获取个人报名详情", httpMethod = "GET")
@ApiImplicitParam(name = "adId", value = "广告id", dataType = "long", paramType = "query")
@RequestMapping(value = "/getDetail4Wechat", method = RequestMethod.GET)
ResponseDto<?> getDetail4Wechat(@CookieValue("userInfo") String userInfo, @RequestParam(value = "adId") Long adId)
ResponseDto<?> getDetail4Wechat(@CookieValue("userInfo") String userInfo,
@RequestParam(value = "adId",required = false) Long adId,
@RequestParam(value = "cpaId",required = false) Long cpaId)
throws PermissionException, BizException, JsonParseException;
/**
......
......@@ -62,12 +62,14 @@ public class BmFacadeImpl implements BmFacade {
@RequestMapping(value = "/userSubmit4Wechat",method = RequestMethod.POST)
public ResponseDto<?> userSubmit4Wechat(@CookieValue("userInfo") String userInfo, @RequestBody AdvertisingBmRegister bmRegister)
throws PermissionException, BizException, JsonParseException {
if (null == bmRegister || null == bmRegister.getAdId()) {
if (null == bmRegister || (null == bmRegister.getAdId() && null==bmRegister.getCpaId())) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数有误!");
}
if(null!=bmRegister.getAdId()) {
if (StringUtil.isEmpty(bmRegister.getFromType()) || null == bmRegister.getFromId()) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数有误!");
}
}
Long qrcodeId = Cookie.getId(userInfo, Cookie.QRCODE_ID);
Long sceneId = Cookie.getId(userInfo, Cookie._SCENE_ID);
Long adviserId = Cookie.getId(userInfo, Cookie._ADVISER_ID);
......@@ -75,10 +77,12 @@ public class BmFacadeImpl implements BmFacade {
Long officialAccountsId = Cookie.getId(userInfo, Cookie._OFFICIAL_ACCOUNTS_ID);
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
Long bookGroupId = Cookie.getId(userInfo, Cookie.BOOK_GROUP_ID);
if(null!=bmRegister.getAdId()) {
if ((null == bmRegister.getBookId() && !"WECHAT_GROUP".equals(bmRegister.getFromType()))
|| (null == bookGroupId && "WECHAT_GROUP".equals(bmRegister.getFromType()))) {
throw new BookBizException(BookBizException.PARAM_IS_NULL, "参数有误!");
}
}
bmRegister.setQrcodeId(qrcodeId);
bmRegister.setSceneId(sceneId);
bmRegister.setAdviserId(adviserId);
......@@ -86,7 +90,13 @@ public class BmFacadeImpl implements BmFacade {
bmRegister.setOfficialAccountId(officialAccountsId);
bmRegister.setUserId(wechatUserId);
bmRegister.setBookGroupId(bookGroupId);
Long result = bmBiz.userSubmit(bmRegister, wechatUserId);
Long result = null;
if(null!=bmRegister.getAdId()){
result=bmBiz.userSubmit(bmRegister, wechatUserId);
}
if(null!=bmRegister.getCpaId()){
result=bmBiz.userSubmit4Cpa(bmRegister, wechatUserId);
}
return new ResponseDto<>(result);
}
......@@ -95,14 +105,16 @@ public class BmFacadeImpl implements BmFacade {
*/
@Override
@RequestMapping(value = "/getDetail4Wechat",method = RequestMethod.GET)
public ResponseDto<?> getDetail4Wechat(@CookieValue("userInfo") String userInfo, @RequestParam(value = "adId") Long adId)
public ResponseDto<?> getDetail4Wechat(@CookieValue("userInfo") String userInfo,
@RequestParam(value = "adId",required = false) Long adId,
@RequestParam(value = "cpaId",required = false) Long cpaId)
throws PermissionException, BizException, JsonParseException {
Long wechatUserId = Cookie.getId(userInfo, Cookie._WECHAT_USER_ID);
Long qrcodeId = Cookie.getId(userInfo, Cookie.QRCODE_ID);
if (null == adId) {
if ((null == adId && null==cpaId)) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数有误!");
}
return new ResponseDto<>(bmBiz.getDetail4Wechat(adId, wechatUserId,qrcodeId));
return new ResponseDto<>(bmBiz.getDetail4Wechat(adId, wechatUserId,qrcodeId,cpaId));
}
/**
......@@ -124,4 +136,19 @@ public class BmFacadeImpl implements BmFacade {
return new ResponseDto<>(map);
}
/**
* cpa内容管理报名信息导出
*/
@RequestMapping(value = "/exportRegisterInfoByCpaId", method = RequestMethod.GET)
public ResponseDto<Map<String, Object>> exportRegisterInfoByCpaId(
@RequestHeader("token") String token, @RequestParam("cpaId") Long cpaId,
@RequestParam(value = "statisMonth", required = false) String statisMonth) throws PermissionException, BizException, JsonParseException {
if (null == cpaId) {
throw new BookBizException(BookBizException.PARAM_IS_ERROR, "参数有误!");
}
SessionUtil.getInfoToken4Redis(token);
Map<String, Object> map = bmBiz.exportRegisterInfoByCpaId(cpaId, statisMonth);
return new ResponseDto<>(map);
}
}
......@@ -10,6 +10,7 @@
<result column="option_item_id" property="optionItemId" jdbcType="BIGINT" />
<result column="option_value" property="optionValue" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="cpa_id" property="cpaId" jdbcType="BIGINT" />
</resultMap>
<resultMap id="registerItemDtoMap" type="BmRegisterItemDTO" >
......@@ -27,10 +28,10 @@
<insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingBmRegisterItem" useGeneratedKeys="true" keyProperty="id">
insert into advertising_bm_register_item (user_id, ad_id,
register_id, option_id, option_item_id,
option_value, create_time)
option_value, create_time,cpa_id)
values (#{userId,jdbcType=BIGINT}, #{adId,jdbcType=BIGINT},
#{registerId,jdbcType=BIGINT}, #{optionId,jdbcType=BIGINT}, #{optionItemId,jdbcType=BIGINT},
#{optionValue,jdbcType=VARCHAR}, NOW())
#{optionValue,jdbcType=VARCHAR}, NOW(),#{cpaId})
</insert>
<select id="getRegisterItemByUser" resultMap="registerItemDtoMap" parameterType="java.lang.Long" >
......@@ -66,4 +67,19 @@
AND i.option_value = #{optionValue}
</select>
<select id="checkMobilePhone4Cpa" resultType="Integer" parameterType="map">
SELECT
COUNT(1)
FROM
advertising_bm_register_item i
LEFT JOIN advertising_bm_register r ON i.register_id = r.id
LEFT JOIN advertising_bm_option o ON i.option_id = o.id
WHERE
i.cpa_id = #{cpaId}
AND r.from_type = #{fromType}
AND r.from_id = #{fromId}
AND o.item_title = '手机号'
AND i.option_value = #{optionValue}
</select>
</mapper>
\ No newline at end of file
......@@ -18,6 +18,7 @@
<result column="book_id" property="bookId" jdbcType="BIGINT"/>
<result column="create_day" property="createDay" jdbcType="DATE"/>
<result column="create_month" property="createMonth" jdbcType="VARCHAR"/>
<result column="cpa_id" property="cpaId" jdbcType="BIGINT"/>
</resultMap>
<!-- 微信端用户详细信息 -->
......@@ -36,7 +37,7 @@
<sql id="Base_Column_List" >
id, user_id, ad_id, nick_name, create_time, qrcode_id, scene_id, adviser_id, agent_id, channel_id, official_account_id, from_type,
from_id,book_id,create_day, create_month
from_id,book_id,create_day, create_month,cpa_id
</sql>
<insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingBmRegister" useGeneratedKeys="true" keyProperty="id">
......@@ -55,7 +56,8 @@
from_id,
book_id,
create_day,
create_month
create_month,
cpa_id
)
VALUES
(
......@@ -73,7 +75,8 @@
#{fromId,jdbcType=BIGINT},
#{bookId,jdbcType=BIGINT},
NOW(),
DATE_FORMAT(NOW(), '%Y-%m')
DATE_FORMAT(NOW(), '%Y-%m'),
#{cpaId}
)
</insert>
......@@ -82,8 +85,14 @@
select
<include refid="Base_Column_List" />
from advertising_bm_register
where ad_id = #{adId,jdbcType=BIGINT}
and user_id = #{wechatUserId}
where
user_id = #{wechatUserId}
<if test="adId !=null">
and ad_id = #{adId,jdbcType=BIGINT}
</if>
<if test="cpaId !=null">
and cpa_id = #{cpaId}
</if>
<if test="qrcodeId != null">
AND qrcode_id = #{qrcodeId}
</if>
......@@ -201,4 +210,16 @@
</if>
</select>
<select id="getRegisterInfoListByCpaId" parameterType="map" resultMap="wechatDetailMap">
SELECT
<include refid="Base_Column_List" />
FROM advertising_bm_register
WHERE
cpa_id = #{cpaId}
<if test="statisMonth != null">
AND create_month = #{statisMonth}
</if>
ORDER BY create_time DESC
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment