Commit 117c68c8 by xunj

优化

1 parent b0ac7c0d
Showing 20 changed files with 242 additions and 58 deletions
package com.polysoft.activity.controller;
import com.polysoft.activity.model.param.IdQueryParam;
import com.polysoft.activity.model.param.ShareLinkParam;
import com.polysoft.activity.model.param.UserInfoParam;
import com.polysoft.activity.service.UserInfoService;
......@@ -41,4 +42,9 @@ public class UserController {
public ApiResult saveUserSign(@RequestBody UserInfoParam param) {
return userInfoService.saveUserSign(param);
}
@PostMapping("/queryUserSign")
@ResponseBody
public ApiResult queryUserSign(@RequestBody IdQueryParam param) {
return userInfoService.queryUserSignByUserId(param.getId(),null);
}
}
......@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/wish")
......@@ -32,10 +33,16 @@ public class WishController {
public ApiResult addWish(@Validated AddWishParam param) {
return wishService.addWish(param);
}
@GetMapping("/queryWishList" )
@PostMapping("/queryWishList" )
@ResponseBody
public ApiResult queryWishList(@RequestBody QueryWishParam param) {
return wishService.queryWishList(param);
}
@GetMapping("/queryPrizeUser" )
@ResponseBody
public ApiResult queryPrizeUser() {
return wishService.getPrizeUserName();
}
}
......@@ -8,6 +8,7 @@ import com.polysoft.activity.model.dto.WechatTokenDto;
import com.polysoft.activity.model.param.UserInfoParam;
import com.polysoft.activity.model.vo.FirstLoginRedVO;
import com.polysoft.activity.model.vo.UserInfoVO;
import com.polysoft.activity.model.vo.UserSignVO;
import com.polysoft.activity.model.vo.WechatToken;
import org.mapstruct.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -28,4 +29,5 @@ public interface UserInfoMapper {
int getFirstoginYesOrNo(@Param("userId") Long userId);
int updateFirstLoginStatus(@Param("userId") Long userId);
UserInfoVO getUserByComposeStatus(UserInfoForComposeStatusDto dto);
List<UserSignVO> queryUserSignByUserId(@Param("userId") Long userId,@Param("signDate") String signDate);
}
......@@ -17,5 +17,6 @@ public interface WishMapper extends BaseMapper<AddWishDto> {
List<QueryLuckDrawWishVO> queryLuckDrawWish();
QueryRealPrizeVO querRealPrize();
int getWishFirstPushOnDay(@Param("userId") Long userId,@Param("pushDate") String pushDate);
List<String> getPrizeUserName();
}
package com.polysoft.activity.model.param;
import lombok.Data;
/**
* @author lvyp
* @date 2021/1/30
*/
@Data
public class IdQueryParam {
private Long id;
}
package com.polysoft.activity.model.param;
import lombok.Data;
/**
* @author lvyp
* @date 2021/1/30
*/
@Data
public class UserSignParam {
private Long userId;
private Long signId;
}
......@@ -28,4 +28,5 @@ public class UserInfoVO implements Serializable {
@ApiModelProperty("牛牌合成时间")
private String composeCattleTime;
private String sysCurretTime;
private String hammerStatus;
}
package com.polysoft.activity.model.vo;
import lombok.Data;
/**
* @author lvyp
* @date 2021/1/30
*/
@Data
public class UserSignVO {
private Long id;
private Long userId;
private String signDate;
private String signStatus;
}
......@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @author lvyp
......@@ -30,5 +31,6 @@ public class WishVO {
private String pushDate ;
@ApiModelProperty("0 未删除 1 已删除")
private String deleteFalg ;
private List<String> picList;
private String picUrl;
}
......@@ -5,9 +5,12 @@ import com.polysoft.activity.model.param.ShareLinkParam;
import com.polysoft.activity.model.param.UserInfoParam;
import com.polysoft.activity.utils.ApiResult;
import java.util.List;
public interface UserInfoService {
ApiResult queryAuthUser(UserInfoParam param);
ApiResult getShareLink(ShareLinkParam param);
ApiResult saveUserSign(UserInfoParam param);
ApiResult getFirsetLgoinRed(Long userId);
ApiResult queryUserSignByUserId(Long userId,String signDate);
}
......@@ -16,4 +16,5 @@ public interface WishService {
ApiResult queryWishList(QueryWishParam pageNum);
List<QueryLuckDrawWishVO> queryLuckDrawWish();
QueryRealPrizeVO querRealPrize();
ApiResult getPrizeUserName();
}
......@@ -102,30 +102,43 @@ public class UserInfoServiceImpl implements UserInfoService {
@Override
public ApiResult saveUserSign(UserInfoParam param) {
try {
String today = DateUtil.format(new Date(),"yyyy-MM-dd");
List<UserSignVO> list2 = mapper.queryUserSignByUserId(param.getUserId(),today);
if(list2 != null && list2.size() > 0 ){
return ApiResult.ok();
}
UserSignDto userSignDto = new UserSignDto();
CattleBrandConfVO confVO = cattleBrandMapper.queryCattleBrandConf(DateUtil.format(new Date(),"yyyy-MM-dd"));
// CattleBrandConfVO confVO = cattleBrandMapper.queryCattleBrandConf("2021-02-11");
CattleBrandVO cattleBrandVO = null;
CattleBrandConfVO confVO = cattleBrandMapper.queryCattleBrandConf(today);
if(param.getSignId() != null){
userSignDto.setId(param.getSignId());
userSignDto.setCreateTime(new Date());
userSignDto.setSignStatus("2");
userSignDto.setSignStatus("1");
mapper.updateUserSign(userSignDto);
}else {
MathRandom a = new MathRandom(confVO.getRate1(),confVO.getRate2(),confVO.getRate3(),confVO.getRate4(),confVO.getRate5());
}else{
userSignDto.setId(SnowFlakeUtil.nextId());
userSignDto.setUserId(param.getUserId());
userSignDto.setSignStatus("1");
userSignDto.setSignDate(new Date());
userSignDto.setCreateTime(new Date());
mapper.saveUserSign(userSignDto);
}
MathRandom random = new MathRandom(confVO.getRate1(),confVO.getRate2(),confVO.getRate3(),confVO.getRate4(),confVO.getRate5());
List<SaveUserCattleDto> list = new ArrayList<>();
SaveUserCattleDto dto = new SaveUserCattleDto();
dto.setId(SnowFlakeUtil.nextId());
dto.setUserId(param.getUserId());
dto.setCattleBrandId(cattleBrandMapper.queryCattleBrandList((a.PercentageRandom()+"")).get(0).getCattleId());
String barandType = random.PercentageRandom()+"";
cattleBrandVO = cattleBrandMapper.queryCattleBrandList(barandType).get(0);
dto.setCattleBrandId(cattleBrandVO.getCattleId());
list.add(dto);
mapper.saveCattleBrand(list);
return ApiResult.ok(cattleBrandVO);
} catch (Exception e) {
e.printStackTrace();
return ApiResult.error(e.getMessage());
}
return ApiResult.ok();
}
@Override
......@@ -167,4 +180,10 @@ public class UserInfoServiceImpl implements UserInfoService {
}
return ApiResult.ok();
}
@Override
public ApiResult queryUserSignByUserId(Long userId,String signDate) {
return ApiResult.ok(mapper.queryUserSignByUserId(userId,null));
}
}
......@@ -78,12 +78,13 @@ public class WishServiceImpl implements WishService {
//发放牛牌
if(i > 0 && firstPushNum == 0){
CattleBrandConfVO confVO = cattleBrandMapper.queryCattleBrandConf(DateUtil.format(new Date(),"yyyy-MM-dd"));
MathRandom a = new MathRandom(confVO.getRate1(),confVO.getRate2(),confVO.getRate3(),confVO.getRate4(),confVO.getRate5());
MathRandom random = new MathRandom(confVO.getRate1(),confVO.getRate2(),confVO.getRate3(),confVO.getRate4(),confVO.getRate5());
List<SaveUserCattleDto> list = new ArrayList<>();
SaveUserCattleDto saveUserCattleDto = new SaveUserCattleDto();
saveUserCattleDto.setId(SnowFlakeUtil.nextId());
saveUserCattleDto.setUserId(param.getUserId());
cattleBrandVO = cattleBrandMapper.queryCattleBrandList((a.PercentageRandom()+"")).get(0);
String barandType = random.PercentageRandom()+"";
cattleBrandVO = cattleBrandMapper.queryCattleBrandList(barandType).get(0);
saveUserCattleDto.setCattleBrandId(cattleBrandVO.getCattleId());
list.add(saveUserCattleDto);
userInfoMapper.saveCattleBrand(list);
......@@ -99,7 +100,9 @@ public class WishServiceImpl implements WishService {
@Override
public ApiResult queryWishList(QueryWishParam param) {
if(param.getIsPage()){
PageHelper.startPage(param.getPageNum(),param.getPageSize());
}
PageResult<WishVO> result = BeanTransferUtils.toPagedResult(mapper.queryWishList(param),WishVO.class);
return ApiResult.ok(result);
}
......@@ -113,4 +116,9 @@ public class WishServiceImpl implements WishService {
public QueryRealPrizeVO querRealPrize() {
return mapper.querRealPrize();
}
@Override
public ApiResult getPrizeUserName() {
return ApiResult.ok(mapper.getPrizeUserName());
}
}
package com.polysoft.activity.task;
import com.polysoft.activity.common.log.LoggerHelper;
import com.polysoft.activity.mapper.WishRealPrizeMapper;
import com.polysoft.activity.model.dto.WishRealPrizeDto;
import com.polysoft.activity.model.vo.QueryLuckDrawWishVO;
import com.polysoft.activity.model.vo.QueryRealPrizeVO;
import com.polysoft.activity.service.WishService;
import com.polysoft.activity.utils.SnowFlakeUtil;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
/**
* @author lvyp
* @date 2021/1/21
*/
@Component
@EnableScheduling
public class UserSignTask {
@Resource
private WishService wishService;
@Resource
private WishRealPrizeMapper wishRealPrizeMapper;
@Scheduled( cron = "0 21 20 * * ? ")
// @Scheduled( cron = "0 55 10 * * ? ")
public void execute() {
try {
sendWechat();
} catch (Exception e) {
LoggerHelper.err(this.getClass(), "EpidemicForSendWechatp休眠异常:{}", e);
}
}
private void sendWechat(){
//查询疫情回访数据基础表
LoggerHelper.info(this.getClass(),"任务开始");
List<QueryLuckDrawWishVO> wishForToday = wishService.queryLuckDrawWish();
QueryRealPrizeVO realPrizeVO = wishService.querRealPrize();
List<WishRealPrizeDto> dtos = new ArrayList<>();
Date date = new Date();
if(wishForToday !=null && wishForToday.size() >0 && realPrizeVO != null) {
if (wishForToday.size() < 10) {
wishForToday.forEach(item -> {
WishRealPrizeDto dto = new WishRealPrizeDto();
dto.setId(SnowFlakeUtil.nextId());
dto.setUserId(item.getUserId());
dto.setWishId(item.getWishId());
dto.setPrizeId(realPrizeVO.getPrizeId());
dto.setCreateTime(date);
dtos.add(dto);
});
}else {
HashSet<Integer> has = getLuckUser(10, wishForToday.size());
for (Integer n : has) {
QueryLuckDrawWishVO item = wishForToday.get(n);
WishRealPrizeDto dto = new WishRealPrizeDto();
dto.setId(SnowFlakeUtil.nextId());
dto.setUserId(item.getUserId());
dto.setWishId(dto.getWishId());
dto.setPrizeId(realPrizeVO.getPrizeId());
dto.setCreateTime(date);
dtos.add(dto);
}
}
wishRealPrizeMapper.saveWishRealPrizeForList(dtos);
}else {
LoggerHelper.info(this.getClass(),"无抽奖");
}
}
private HashSet<Integer> getLuckUser(int count,int random){
HashSet<Integer> has = new HashSet<Integer>();
Integer i = 0;
for (int j = 1; j != 0; j++) {
i = new Random().nextInt(random);
has.add(i);
if (count == has.size()) {
break;
}
}
return has;
}
}
......@@ -67,9 +67,8 @@ public class WishLuckDrawTask {
});
}else {
HashSet<Integer> has = getLuckUser(10, wishForToday.size());
List<QueryLuckDrawWishVO> luckWish = wishService.queryLuckDrawWish();
for (Integer n : has) {
QueryLuckDrawWishVO item = luckWish.get(n);
QueryLuckDrawWishVO item = wishForToday.get(n);
WishRealPrizeDto dto = new WishRealPrizeDto();
dto.setId(SnowFlakeUtil.nextId());
dto.setUserId(item.getUserId());
......
......@@ -12,10 +12,11 @@
cattle_id,
brand_type,
brand_name
from t_cattle_brand where
from t_cattle_brand
where
1=1
<if test="brandType != null and brandType != '' ">
and brand_name#{brandType}
and brand_type = #{brandType}
</if>
</select>
<select id="queryCattleBrandByUserId" resultType="com.polysoft.activity.model.vo.CattleBrandFroUserVO">
......@@ -55,7 +56,7 @@
SELECT
t2.brand_type,
t2.brand_name ,
t1.cattle_brand_id,
t1.id as cattleBrandId,
t1.user_id
FROM
t_user_cattle t1 LEFT join t_cattle_brand t2 ON ( t2.cattle_id = t1.cattle_brand_id )
......
......@@ -11,7 +11,8 @@
dept_name,
is_first,
compose_cattle_status,
compose_cattle_time
compose_cattle_time,
hammer_status
from
t_user where
1=1
......@@ -91,7 +92,7 @@
UPDATE t_user_sign
SET
sign_status =#{signStatus},
create_time =#{#{createTime}
create_time =#{createTime}
where id = #{id}
</insert>
<select id="getUserByComposeStatus" parameterType="com.polysoft.activity.model.dto.UserInfoForComposeStatusDto"
......@@ -101,6 +102,21 @@
from t_user
where
user_id=#{userId}
</select>
<select id="queryUserSignByUserId" resultType="com.polysoft.activity.model.vo.UserSignVO">
select
t.id,
t.sign_date,
t.sign_status,
t.user_id
from
t_user_sign t
where
user_id = #{userId}
<if test="signDate != null and signDate != '' ">
and sign_date = #{signDate}
</if>
order by t.sign_date asc
</select>
</mapper>
......@@ -13,23 +13,15 @@
t1.prize_falg,
t1.create_time,
t1.push_date,
t2.pic_url
( SELECT GROUP_CONCAT(t.pic_url) FROM t_wish_pic t WHERE t.wish_id = t1.wish_id ) as pic_url
FROM
t_wish t1
left join t_wish_pic t2 on(t1.wish_id = t2.wish_id)
<where>
1=1
<if test="pushDate !=null and pushDate != '' ">
and push_date = #{pushDate}
order by create_time desc
<if test="isPage == false">
limit 20
</if>
<if test="wishId != null ">
and wish_id = #{wishId}
</if>
<if test="userId != null ">
and user_id = #{userId}
</if>
</where>
</select>
<select id="queryLuckDrawWish" resultType="com.polysoft.activity.model.vo.QueryLuckDrawWishVO">
SELECT
......@@ -64,4 +56,13 @@
user_id = #{userId}
and push_date =#{pushDate}
</select>
<select id="getPrizeUserName" resultType="java.lang.String">
SELECT
t2.user_name
FROM
t_wish_real_prize t
LEFT JOIN t_user t2 ON ( t2.user_id = t.user_id )
WHERE
DATE_FORMAT( t.create_time, '%Y-%m-%d' ) = DATE_FORMAT( NOW(), '%Y-%m-%d' )
</select>
</mapper>
package com.polysoft.activity.common.utils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author by zhangbr
* @date 2020/6/24.
*/
@Data
public class PageQuery {
@ApiModelProperty("当前页码")
private Integer pageNum = 1;
@ApiModelProperty("每页显示条数,默认30")
private Integer pageSize = 30;
@ApiModelProperty("每页显示条数,默认20")
private Integer pageSize = 20;
@ApiModelProperty(value = "是否分页,默认:true")
private Boolean isPage = true;
public Integer getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Boolean getPage() {
return isPage;
}
public void setPage(Boolean page) {
isPage = page;
}
}
......@@ -31,17 +31,23 @@ public class FileUtils {
File dest = null;
try {
// String path=uploadpath+File.separator+date+File.separator+uuid+fileName;
String path=uploadpath+"/"+date+"/"+uuid+fileName;
String fileType = fileName.substring(fileName.indexOf("."),fileName.length());
String path=uploadpath+"/"+date+"/"+uuid+fileType;
dest = new File(path);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
file.transferTo(dest);
log.info("上传成功");
return ApiResult.ok("/"+date+"/"+uuid+fileName);
return ApiResult.ok("/"+date+"/"+uuid+fileType);
}catch (Exception e){
e.printStackTrace();
return ApiResult.error();
}
}
public static void main(String[] args) {
String ss = "0ab520bfbbcd4ca8b3c66c7b4dbd8e3eF5A3F540-D6A3-404F-807C-A55D5D2FBE1E.jpeg";
System.out.println(ss.substring(ss.indexOf("."),ss.length()));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!