Authored by mingdan.ge

cps4期

... ... @@ -55,8 +55,36 @@ public class ImagesHelper {
String subfileName = fileName.substring(fileName.indexOf(bucket));
return subfileName.substring(subfileName.indexOf("/"));
}
/**
* 场景:从uic获取到的不是原始图片相对路径,数据库存储是图片相对路径
* 获取图片相对路径
* @param urlWithwh 图片的相对地址 http://head.static.yhbimg.com/yhb-head/2018/1/25/13/01abb7f1473ffc711a154c01091c29d9.648116.jpg?imageView2/{mode}/w/{width}/h/{height}
*
*/
public static String getImageUrl(String urlWithwh) {
if (urlWithwh == null) {
return null;
}
if (urlWithwh.contains("?")) {
return urlWithwh.substring(0, urlWithwh.indexOf("?"));
}
return urlWithwh;
}
/**
* 场景:从uic获取到的头像,数据库存储是图片绝对路径,给前台需要加上后缀
* 获取图片相对路径
* @param urlWithwh 图片的地址 http://head.static.yhbimg.com/yhb-head/2018/1/25/13/01abb7f1473ffc711a154c01091c29d9.648116.jpg
* @return urlWithwh 图片的地址 http://head.static.yhbimg.com/yhb-head/2018/1/25/13/01abb7f1473ffc711a154c01091c29d9.648116.jpg?imageView2/{mode}/w/{width}/h/{height}
*
*/
public static String getHeadImageUrl(String url) {
if (url == null) {
return null;
}
return url + "?imageView2/{mode}/w/{width}/h/{height}";
}
/**
* 场景:数据库存储是图片相对路径,前台需要图片绝对路径
* 获取图片绝对路径
* @param fileName 图片的相对地址 /2016/03/07/13/01f0024f3dc6f0885f370281a2b41c8bfb.png
... ...
... ... @@ -102,7 +102,10 @@
<value>/UnionShareRest/resetApply</value>
<value>/UnionShareRest/queryActivityOrder</value>
<value>/UnionShareRest/queryRank</value>
<value>/UnionShareRest/updateMonthData</value>
<value>/UnionShareRest/addVirtual</value>
<value>/UnionShareRest/toAddVirtual</value>
<value>/UnionShareRest/dealExtraActivityTask</value>
<value>/UnionShareRest/clearActivity</value>
<value>/UnionShareRest/getStatisticsInfo</value>
... ...
... ... @@ -18,6 +18,8 @@ public interface UnionShareOrdersActivityLogsMapper {
List<UnionShareOrdersActivityLogs> selectByOrderCode(@Param("orderCode") String orderCode);
int updateByPrimaryKeySelective(UnionShareOrdersActivityLogs record);
List<UnionShareOrdersActivityLogs> selectByPrimaryKeySelective(UnionShareOrdersActivityLogs record);
int updateStatusByOrderId(UnionShareOrdersActivityLogs record);
int updateByPrimaryKey(UnionShareOrdersActivityLogs record);
... ...
... ... @@ -19,6 +19,6 @@ public interface UnionShareOrdersActivityMapper {
int updateByPrimaryKeySelective(UnionShareOrdersActivity record);
int updateByPrimaryKey(UnionShareOrdersActivity record);
int updateStatusById(@Param("id")int id,@Param("oldStatus")int oldStatus,@Param("newStatus")int newStatus,@Param("updateTime")int updateTime);
int updateStatusById(@Param("id")int id,@Param("oldProgress")int oldProgress,@Param("newProgress")int newProgress,@Param("updateTime")int updateTime);
}
\ No newline at end of file
... ...
... ... @@ -28,7 +28,7 @@ public interface UnionShareOrdersMapper {
List<UnionShareOrders> selectListByOrderCodesForActivity(@Param("orderCodes") List<String> orderCodes);
List<UnionShareOrders> selectAllListByUids(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("uid") Integer uid,@Param("orderCode") String orderCode);
List<UnionShareOrdersUidBo> selectUidList(@Param("beginTime") int beginTime, @Param("endTime") int endTime,@Param("num") Integer num);
List<UnionShareOrdersUidBo> selectUidList(@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrders> selectListByOrderUidForActivity(@Param("beginTime") int beginTime,@Param("endTime") int endTime,@Param("orderUid") Integer orderUid,@Param("promoteUid") Integer promoteUid);
UnionShareOrders selectActivityOrderByUid(@Param("activityId") int activityId,@Param("orderUid") Integer orderUid,@Param("promoteUid") Integer promoteUid);
... ... @@ -39,7 +39,7 @@ public interface UnionShareOrdersMapper {
BigDecimal selectAmountBySettleCode(@Param("promoteUid")int promoteUid,@Param("settlementCode")String settlementCode);
UnionShareOrdersMonth selectMonthData(@Param("beginTime") int beginTime, @Param("endTime") int endTime, @Param("promoteUid") Integer promoteUid);
UnionShareOrdersMonth selectMonthData( @Param("promoteUid") Integer promoteUid,@Param("beginTime") int beginTime, @Param("endTime") int endTime);
List<UnionShareOrders> selectListByCondition(@Param("promoteUid")int promoteUid, @Param("status")String status,@Param("updateTime")int updateTime, @Param("offset") int offset, @Param("rows") int rows);
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.math.BigDecimal;
public class UnionShareOrders {
public class UnionShareOrders extends BaseBO {
private Integer id;
private String orderCode;
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.math.BigDecimal;
public class UnionShareOrdersActivity {
public class UnionShareOrdersActivity extends BaseBO{
private Integer id;
private String activityName;
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.math.BigDecimal;
public class UnionShareOrdersActivityItem {
public class UnionShareOrdersActivityItem extends BaseBO {
private Integer id;
private Integer activityId;
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.math.BigDecimal;
public class UnionShareOrdersActivityLogs {
public class UnionShareOrdersActivityLogs extends BaseBO {
private Integer id;
private Integer activityId;
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.util.List;
/**
* Created by qing.zhao on 2018/5/17.
*/
public class UnionShareOrdersListBO {
public class UnionShareOrdersListBO extends BaseBO {
private List<UnionShareOrders> list;
public List<UnionShareOrders> getList() {
... ...
... ... @@ -2,10 +2,11 @@ package com.yoho.unions.dal.model;
import java.math.BigDecimal;
import com.yoho.service.model.union.request.BaseBO;
import com.yoho.unions.common.annotation.BatchExportField;
import com.yoho.unions.common.annotation.BatchImportField;
public class UnionShareOrdersMonth {
public class UnionShareOrdersMonth extends BaseBO {
private Integer id;
... ...
package com.yoho.unions.dal.model;
import com.yoho.service.model.union.request.BaseBO;
import java.math.BigDecimal;
public class UnionShareSettlement {
public class UnionShareSettlement extends BaseBO {
private Integer id;
private String settlementCode;
... ...
... ... @@ -47,6 +47,27 @@
from union_share_orders_activity_logs
where status=1 and orders like CONCAT('%', #{orderCode}, '%')
</select>
<select id="selectByPrimaryKeySelective" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from union_share_orders_activity_logs
where 1==1
<if test="status != null" >
and status=#{status,jdbcType=INTEGER}
</if>
<if test="orderUid != null" >
and order_uid=##{orderUid,jdbcType=INTEGER}
</if>
<if test="promoteUid != null" >
and promote_uid=#{promoteUid,jdbcType=INTEGER}
</if>
<if test="activityId != null" >
and activity_id=#{activityId,jdbcType=INTEGER}
</if>
<if test="id != null" >
and id = #{id,jdbcType=INTEGER}
</if>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from union_share_orders_activity_logs
where id = #{id,jdbcType=INTEGER}
... ...
... ... @@ -200,8 +200,8 @@
</update>
<update id="updateStatusById" >
update union_share_orders_activity
set status = #{newStatus,jdbcType=INTEGER},
set progress = #{newProgress,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and status = #{oldStatus,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and progress = #{oldProgress,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -338,15 +338,13 @@
select promote_uid as promoteUid,order_uid as orderUid,count(id) as num
from union_share_orders
where status in(10,20,30,40) and order_code is not null
<if test="num != null" >
and count(id) &gt;= #{num}
</if>
<if test="beginTime != null" >
and order_time &gt; #{beginTime}
and order_time &gt;= #{beginTime}
</if>
<if test="endTime != null" >
and order_time &lt;#{endTime}
and order_time &lt;= #{endTime}
</if>
group by promote_uid,order_uid
</select>
<select id="selectListByOrderUidForActivity" resultMap="BaseResultMap">
select
... ... @@ -364,12 +362,8 @@
select sum(amount) as amount,sum(extra_amount) as extraAmount,sum(order_amount) as orderAmount,count(order_code) as orderNum
from union_share_orders
where promote_uid = #{promoteUid} and status in (10,20,30,40)
<if test="beginTime != 0" >
and order_time &gt;= #{beginTime}
</if>
<if test="endTime != 0" >
and order_time &lt; #{endTime}
</if>
</select>
<select id="selectActivityOrderByUid" resultMap="BaseResultMap">
select
... ...
package com.yoho.unions.server.restapi;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.*;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.service.model.union.bo.*;
import com.yoho.unions.server.task.CpsOrderExtraActivityTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,15 +21,6 @@ import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.core.rest.annotation.ServiceDesc;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.union.bo.IdOrIdsBo;
import com.yoho.service.model.union.bo.ShareOrderBo;
import com.yoho.service.model.union.bo.ShareSettlementBo;
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
import com.yoho.service.model.union.bo.UninoShareIncomeRankBo;
import com.yoho.service.model.union.bo.UnionShareBankBo;
import com.yoho.service.model.union.bo.UnionShareOrdersActivityLogsBo;
import com.yoho.service.model.union.bo.UnionShareUserBankBo;
import com.yoho.service.model.union.bo.UnionShareUserBo;
import com.yoho.service.model.union.request.UninoShareIncomeRankReqBo;
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
... ... @@ -62,6 +55,9 @@ public class UnionShareRest {
@Autowired
IUnionShareService unionShareService;
@Autowired
CpsOrderExtraActivityTask cpsOrderExtraActivityTask;
@RequestMapping("/getShareInfoByUid")
@ResponseBody
public ShareUserSettlementInfoBo getShareInfoByUid(@RequestBody int uid){
... ... @@ -327,9 +323,31 @@ public class UnionShareRest {
UninoShareIncomeRankBo result = unionShareService.queryRank(bo);
return result;
}
/**
* 手动更新用户月预估数据
* */
@RequestMapping("/updateMonthData")
@ResponseBody
public UnionResponse updateMonthData(@RequestBody UnionShareOrdersMonthReqBO bo){
log.info("UnionShareRest.updateMonthData bo is {}", bo);
if (null == bo || null == bo.getUid()|| null == bo.getBeginDate()|| null == bo.getEndDate()) {
throw new ServiceException(ServiceError.PARAM_ERROR);
}
Set<String> dates = new HashSet<>();
for(int i=bo.getBeginDate();i<=bo.getEndDate();) {
dates.add(i + "");
if (i % 100 == 12) {
i = i - 11 + 100;
} else {
i++;
}
}
unionShareService.updateMonthData(bo.getUid(),dates);
return new UnionResponse(200, "updateMonthData success");
}
/**
* 后台操作向redis塞待执行任务
* 后台操作向redis塞待执行的马甲随机增任务
* */
@RequestMapping("/addVirtual")
@ResponseBody
... ... @@ -338,6 +356,28 @@ public class UnionShareRest {
unionShareService.setVirtualAddToRedis();
return new UnionResponse(200, "addVirtual success");
}
/**
* 手动执行一次马甲随机增
* */
@RequestMapping("/toAddVirtual")
@ResponseBody
public UnionResponse toAddVirtual(){
log.info("UnionShareRest.toAddVirtual.");
UnionShareVirtualAddBo addBo = new UnionShareVirtualAddBo();
addBo.setTime(DateUtil.getCurrentTimeSecond());
unionShareService.dealWithVirtualUserTask(addBo);
return new UnionResponse(200, "toAddVirtual success");
}
/**
* 手动执行一次活动奖励发放
* */
@RequestMapping("/dealExtraActivityTask")
@ResponseBody
public UnionResponse dealExtraActivityTask(){
log.info("UnionShareRest.dealExtraActivityTask.");
cpsOrderExtraActivityTask.run();
return new UnionResponse(200, "dealExtraActivityTask success");
}
/**
* 清活动缓存
... ...
... ... @@ -1254,6 +1254,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
uninoShareIncomeBo.setRankNum(i+1);
// uninoShareIncomeBo.setAmountStr("¥"+df.format(uninoShareIncomeBo.getAmount()));
uninoShareIncomeBo.setAmountStr("¥"+uninoShareIncomeBo.getAmount());
uninoShareIncomeBo.setImage(ImagesHelper.getHeadImageUrl(uninoShareIncomeBo.getImage()));
}
PageResponseBO<UninoShareIncomeBo> pageList = new PageResponseBO<>();
pageList.setList(list);
... ... @@ -1462,10 +1463,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("dealWithWaitActivity end,deal null,activity is {}",activity);
return;
}
int minNum = queryActivityItemMinNum(activity.getId());
// int minNum = queryActivityItemMinNum(activity.getId());
//查询可以参与活动的uid组
logger.info("dealWithWaitActivity,activity is {},selectUidList",activity);
List<UnionShareOrdersUidBo> uids=unionShareOrdersMapper.selectUidList(activity.getStartTime(), activity.getEndTime(), minNum);
List<UnionShareOrdersUidBo> uids=unionShareOrdersMapper.selectUidList(activity.getStartTime(), activity.getEndTime());
logger.info("dealWithWaitActivity,activity is {},selectUidList, uids is {}",activity,uids);
uids.forEach(u->{
joinExtraActivity(u.getOrderUid(), u.getPromoteUid(), activity.getId());
... ... @@ -1554,12 +1555,17 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* */
private List<UnionShareOrdersActivityItem> queryActivityItemList(int activityId) {
logger.info("queryActivityItemList,activityId is {}",activityId);
List<UnionShareOrdersActivityItem> items = getFromRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,List.class,"list","0");
if (CollectionUtils.isNotEmpty(items)) {
logger.info("queryActivityItemList,activityId is {},get chache {}",activityId,items);
return items;
List<JSONObject> itemsObj = getFromRedis(ShareOrdersKeyEnum.ACTIVITY,activityId,List.class,"list","0");
if (CollectionUtils.isNotEmpty(itemsObj)) {
logger.info("queryActivityItemList,activityId is {},get chache {}",activityId,itemsObj);
List<UnionShareOrdersActivityItem> cacheItems = new ArrayList<>();
itemsObj.forEach(it->{
String json=JsonUtil.objectToJSON(it);
cacheItems.add(JsonUtil.jsonToObject(json, UnionShareOrdersActivityItem.class));
});
return cacheItems;
}
items = unionShareOrdersActivityItemMapper.selectByActivityId(activityId);
List<UnionShareOrdersActivityItem> items = unionShareOrdersActivityItemMapper.selectByActivityId(activityId);
if (CollectionUtils.isEmpty(items)) {
return new ArrayList<>();
}
... ... @@ -1600,6 +1606,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
* */
public boolean joinExtraActivity(int orderUid ,int promoteUid ,int activityId){
logger.info("joinExtraActivity,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
//查询是否已参加过此活动
if (hasJoinActivity(orderUid, promoteUid, activityId)) {
//存在有效的参与数据,直接返回
logger.info("joinExtraActivity end,hasJoinActivity,orderUid is {},promoteUid is {},activityId is {}.",orderUid,promoteUid,activityId);
return true;
}
UnionShareOrdersActivity activity = queryActivity(activityId);
if (null == activity || activity.getType() != 3) {
return false;
... ... @@ -1662,6 +1676,28 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
return false;
}
//是否已参加过此活动
private boolean hasJoinActivity(int orderUid ,int promoteUid ,int activityId) {
UnionShareOrders unionShareOrders=queryOrderActivity(orderUid, promoteUid, activityId);
if (unionShareOrders == null) {
return false;
}
if (unionShareOrders.getStatus().equals(ShareOrdersStatusEnum.ACTIVITY_DISCARD.getCode())) {
return false;
}
return true;
}
private List<UnionShareOrdersActivityLogs> queryJoinLogs(int orderUid ,int promoteUid ,int activityId) {
UnionShareOrdersActivityLogs req = new UnionShareOrdersActivityLogs();
req.setOrderUid(orderUid);
req.setPromoteUid(promoteUid);
req.setActivityId(activityId);
req.setStatus(1);
List<UnionShareOrdersActivityLogs> list=unionShareOrdersActivityLogsMapper.selectByPrimaryKeySelective(req);
return list;
}
/**
* 参加加倍返活动
* */
... ... @@ -2279,10 +2315,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("updateOneMonthData promoteUid is {},date is {}.",promoteUid,date);
Integer dateInt = Integer.valueOf(date);
Calendar time = Calendar.getInstance();
time.setTime(DateUtil.stringToDate(date, "yyyyMM"));
int beginTime=(int) time.getTimeInMillis()/1000;
time.add(Calendar.DAY_OF_MONTH,1);
int endTime=((int) time.getTimeInMillis()/1000)-1;
time.setTime(DateUtil.stringToDate(date+"01 00:00:00", "yyyyMMdd HH:mm:ss"));
int beginTime=(int) (time.getTime().getTime()/1000);
time.add(Calendar.MONTH,1);
int endTime=(int) (time.getTime().getTime()/1000);
UnionShareOrdersMonth unionShareOrdersMonth = getMonthData(promoteUid,dateInt);
//查询cps订单表中此月的预估收益
UnionShareOrdersMonth month=unionShareOrdersMapper.selectMonthData(promoteUid, beginTime, endTime);
... ... @@ -2297,19 +2333,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
logger.info("updateOneMonthData,getUserInfoFromUic, promoteUid is {},date is {}.",promoteUid,date);
UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(promoteUid);
if (userInfoRspBO != null) {
month.setImage(userInfoRspBO.getHeadIco());
month.setImage(ImagesHelper.getImageUrl(userInfoRspBO.getHeadIco()));
month.setNickname(userInfoRspBO.getNickname());
}
month.setType(1);//类型:1-联盟用户,2-马甲用户
month.setDate(dateInt);
month.setUpdateTime(DateUtil.getCurrentTimeSecond());
month.setUid(promoteUid);
if (unionShareOrdersMonth != null) {
//月预估收益更新
month.setId(unionShareOrdersMonth.getId());
logger.info("updateOneMonthData,updateByUidAndMonth, promoteUid is {},date is {},update data is {}.",promoteUid,date,month);
int result=unionShareOrdersMonthMapper.updateByUidAndMonth(month);
if (result > 0) {
return;
if (result == 0) {
logger.info("updateOneMonthData,updateByUidAndMonth fail, promoteUid is {},date is {}");
}
return;
}
month.setCreateTime(month.getUpdateTime());
logger.info("updateOneMonthData,insertSelective, promoteUid is {},date is {},insert data is {}.",promoteUid,date,month);
... ... @@ -2320,7 +2359,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport
private UnionShareOrdersMonth getMonthData(int promoteUid, int date) {
logger.info("getMonthData promoteUid is {},date is {}.",promoteUid,date);
List<UnionShareOrdersMonth> unionShareOrdersMonth = unionShareOrdersMonthMapper.selectMonthData(date, promoteUid,1);
if (unionShareOrdersMonth == null ) {
if (CollectionUtils.isEmpty(unionShareOrdersMonth)) {
return null;
}
for (int i = 1; i < unionShareOrdersMonth.size(); i++) {
... ...