|
@@ -11,18 +11,20 @@ import com.txz.mall.model.SystemGroupData;
|
|
import com.txz.mall.model.UserSign;
|
|
import com.txz.mall.model.UserSign;
|
|
import com.txz.mall.service.SystemGroupDataService;
|
|
import com.txz.mall.service.SystemGroupDataService;
|
|
import com.txz.mall.service.UserSignService;
|
|
import com.txz.mall.service.UserSignService;
|
|
|
|
+import com.txz.operating.dto.ConfigDTO;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
import tk.mybatis.mapper.entity.Example;
|
|
import tk.mybatis.mapper.entity.Example;
|
|
-import vo.GroupDataFormCheckVO;
|
|
|
|
-import vo.GroupDataFormItemCheckVO;
|
|
|
|
|
|
+import vo.UserSignDetailVO;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@@ -32,7 +34,10 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
@Transactional
|
|
@Transactional
|
|
public class UserSignServiceImpl extends AbstractService<UserSign> implements UserSignService {
|
|
public class UserSignServiceImpl extends AbstractService<UserSign> implements UserSignService {
|
|
|
|
+
|
|
private static final long USER_ID = 1;
|
|
private static final long USER_ID = 1;
|
|
|
|
+ private static final String SIGN_CODE = "user_code";
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private UserSignMapper userSignMapper;
|
|
private UserSignMapper userSignMapper;
|
|
@Resource
|
|
@Resource
|
|
@@ -41,31 +46,9 @@ public class UserSignServiceImpl extends AbstractService<UserSign> implements Us
|
|
private OperatingConfigDubboServiceClient configDubboServiceClient;
|
|
private OperatingConfigDubboServiceClient configDubboServiceClient;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public HashMap<String, Object> todayDetail() {
|
|
|
|
- HashMap<String, Object> map = new HashMap<>();
|
|
|
|
-
|
|
|
|
- boolean hasSignedToday = hasSignedToday(USER_ID);
|
|
|
|
- map.put("today", hasSignedToday);
|
|
|
|
-
|
|
|
|
- // 3. 查询用户的连续签到天数
|
|
|
|
- int continuousDays = getContinuousDays(USER_ID);
|
|
|
|
- map.put("continuous", continuousDays);
|
|
|
|
-
|
|
|
|
- ArrayList<GroupDataFormItemCheckVO> list = new ArrayList<>();
|
|
|
|
- List<SystemGroupData> systemGroupData = groupData();
|
|
|
|
- for (SystemGroupData groupData : systemGroupData) {
|
|
|
|
- if (StringUtils.isNotBlank(groupData.getValue())) {
|
|
|
|
- List<GroupDataFormItemCheckVO> fields = JSONObject.parseObject(groupData.getValue(), GroupDataFormCheckVO.class).getFields();
|
|
|
|
- GroupDataFormItemCheckVO vo = new GroupDataFormItemCheckVO();
|
|
|
|
- List<String> dayCollect = fields.stream().filter(field -> field.getName().equals(Constants.SIGN_TYPE_DAY_TITLE)).map(GroupDataFormItemCheckVO::getValue).collect(Collectors.toList());
|
|
|
|
- Integer gold = fields.stream().filter(field -> field.getName().equals(Constants.SIGN_TYPE_GOLD_TITLE)).map(GroupDataFormItemCheckVO::getValue).map(Integer::valueOf).reduce(0, Integer::sum);
|
|
|
|
- vo.setName(dayCollect.get(0));
|
|
|
|
- vo.setValue(gold.toString());
|
|
|
|
- list.add(vo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- map.put("fields", list);
|
|
|
|
- return map;
|
|
|
|
|
|
+ public List<UserSignDetailVO> todayDetail() {
|
|
|
|
+ ConfigDTO configByCode = configDubboServiceClient.getConfigByCode(SIGN_CODE);
|
|
|
|
+ return JSONObject.parseArray(configByCode.getValueInfo(), UserSignDetailVO.class);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -106,9 +89,8 @@ public class UserSignServiceImpl extends AbstractService<UserSign> implements Us
|
|
private boolean hasSignedToday(Long USER_ID) {
|
|
private boolean hasSignedToday(Long USER_ID) {
|
|
Condition condition = new Condition(UserSign.class);
|
|
Condition condition = new Condition(UserSign.class);
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
|
criteria.andEqualTo("uid", USER_ID);
|
|
criteria.andEqualTo("uid", USER_ID);
|
|
- criteria.andLike("signDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "%");
|
|
|
|
|
|
+ criteria.andLike("createDay", new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "%");
|
|
return !userSignMapper.selectByCondition(condition).isEmpty();
|
|
return !userSignMapper.selectByCondition(condition).isEmpty();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,9 +99,8 @@ public class UserSignServiceImpl extends AbstractService<UserSign> implements Us
|
|
Date yesterday = DateUtils.addDays(new Date(), -1);
|
|
Date yesterday = DateUtils.addDays(new Date(), -1);
|
|
Condition condition = new Condition(UserSign.class);
|
|
Condition condition = new Condition(UserSign.class);
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
|
criteria.andEqualTo("uid", USER_ID);
|
|
criteria.andEqualTo("uid", USER_ID);
|
|
- criteria.andLike("signDate", new SimpleDateFormat("yyyy-MM-dd").format(yesterday) + "%");
|
|
|
|
|
|
+ criteria.andLike("createDay", new SimpleDateFormat("yyyy-MM-dd").format(yesterday) + "%");
|
|
List<UserSign> list = userSignMapper.selectByCondition(condition);
|
|
List<UserSign> list = userSignMapper.selectByCondition(condition);
|
|
return list.isEmpty() ? null : list.get(0);
|
|
return list.isEmpty() ? null : list.get(0);
|
|
}
|
|
}
|
|
@@ -140,7 +121,6 @@ public class UserSignServiceImpl extends AbstractService<UserSign> implements Us
|
|
// 获取最新的签到记录
|
|
// 获取最新的签到记录
|
|
Condition condition = new Condition(UserSign.class);
|
|
Condition condition = new Condition(UserSign.class);
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
Example.Criteria criteria = condition.createCriteria();
|
|
- criteria.andEqualTo("isDelete", 0);
|
|
|
|
criteria.andEqualTo("uid", userId);
|
|
criteria.andEqualTo("uid", userId);
|
|
condition.orderBy("id").desc();
|
|
condition.orderBy("id").desc();
|
|
List<UserSign> list = userSignMapper.selectByCondition(condition);
|
|
List<UserSign> list = userSignMapper.selectByCondition(condition);
|
|
@@ -156,18 +136,21 @@ public class UserSignServiceImpl extends AbstractService<UserSign> implements Us
|
|
// 根据连续签到天数发放奖励
|
|
// 根据连续签到天数发放奖励
|
|
private void giveReward(int continuousDays) {
|
|
private void giveReward(int continuousDays) {
|
|
int reward = 0;
|
|
int reward = 0;
|
|
- List<SystemGroupData> systemGroupData = groupData();
|
|
|
|
- for (SystemGroupData groupData : systemGroupData) {
|
|
|
|
- if (StringUtils.isNotBlank(groupData.getValue())) {
|
|
|
|
- List<GroupDataFormItemCheckVO> fields = com.alibaba.fastjson.JSONObject.parseObject(groupData.getValue(), GroupDataFormCheckVO.class).getFields();
|
|
|
|
- reward += fields.stream().filter(field -> field.getName().equals(Constants.SIGN_TYPE_GOLD_TITLE)).map(GroupDataFormItemCheckVO::getValue).map(Integer::valueOf).reduce(0, Integer::sum);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+// List<SystemGroupData> systemGroupData = groupData();
|
|
|
|
+// for (SystemGroupData groupData : systemGroupData) {
|
|
|
|
+// if (StringUtils.isNotBlank(groupData.getValue())) {
|
|
|
|
+// List<GroupDataFormItemCheckVO> fields = com.alibaba.fastjson.JSONObject.parseObject(groupData.getValue(), GroupDataFormCheckVO.class).getFields();
|
|
|
|
+// reward += fields.stream().filter(field -> field.getName().equals(Constants.SIGN_TYPE_GOLD_TITLE)).map(GroupDataFormItemCheckVO::getValue).map(Integer::valueOf).reduce(0, Integer::sum);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
|
|
// todo 发到个人用户
|
|
// todo 发到个人用户
|
|
}
|
|
}
|
|
|
|
|
|
private List<SystemGroupData> groupData() {
|
|
private List<SystemGroupData> groupData() {
|
|
|
|
+ ConfigDTO configByCode = configDubboServiceClient.getConfigByCode(SIGN_CODE);
|
|
|
|
+
|
|
|
|
+
|
|
List<SystemGroupData> systemGroupData = systemGroupDataService.configDetail(Constants.GROUP_DATA_ID_SIGN.longValue(), Constants.GROUP_DATA_STATUS_NORMAL);
|
|
List<SystemGroupData> systemGroupData = systemGroupDataService.configDetail(Constants.GROUP_DATA_ID_SIGN.longValue(), Constants.GROUP_DATA_STATUS_NORMAL);
|
|
if (CollectionUtils.isEmpty(systemGroupData)) {
|
|
if (CollectionUtils.isEmpty(systemGroupData)) {
|
|
throw new ServiceException("系统配置异常");
|
|
throw new ServiceException("系统配置异常");
|