| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserCustomSettingsMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.UserCustomSettings;
|
| | | import com.yeshi.fanli.entity.bus.user.UserCustomSettings.UserSettingTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.exception.user.UserCustomSettingsException;
|
| | | import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
|
| | | import com.yeshi.fanli.vo.user.UserSettingsVO;
|
| | |
|
| | | @Service
|
| | | public class UserCustomSettingsServiceImpl implements UserCustomSettingsService {
|
| | |
|
| | | @Resource
|
| | | private UserCustomSettingsMapper userCustomSettingsMapper;
|
| | | |
| | | @Override
|
| | | public void saveModuleState(Long uid, String type, Integer state) throws UserCustomSettingsException{
|
| | | if (uid == null || type == null || state == null || state > 1 || state < 0) {
|
| | | throw new UserCustomSettingsException(1, "传递参数不正确");
|
| | | }
|
| | | |
| | | |
| | | UserSettingTypeEnum mineTypeNum = null;
|
| | | if (type.equals(UserSettingTypeEnum.cancelNotice.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.cancelNotice;
|
| | | } else if (type.equals(UserSettingTypeEnum.noNewsRedDot.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.noNewsRedDot;
|
| | | } else if (type.equals(UserSettingTypeEnum.noBonusCount.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.noBonusCount;
|
| | | } else if (type.equals(UserSettingTypeEnum.noShareRecordAndStorage.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.noShareRecordAndStorage;
|
| | | } else if (type.equals(UserSettingTypeEnum.noInvitationBonus.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.noInvitationBonus;
|
| | | } else if (type.equals(UserSettingTypeEnum.openSpreadHongBao.name())) {
|
| | | mineTypeNum = UserSettingTypeEnum.openSpreadHongBao;
|
| | | } else {
|
| | | throw new UserCustomSettingsException(1, "参数类型不匹配"); |
| | | }
|
| | | |
| | | |
| | | UserCustomSettings settings = userCustomSettingsMapper.getSettingsByUidAndType(uid, type);
|
| | | if (settings != null) { |
| | | // 更新
|
| | | UserCustomSettings record = new UserCustomSettings();
|
| | | record.setId(settings.getId());
|
| | | record.setState(state);
|
| | | record.setUpdateTime(new Date());
|
| | | userCustomSettingsMapper.updateByPrimaryKeySelective(record);
|
| | | } else { |
| | | // 插入
|
| | | settings = new UserCustomSettings();
|
| | | settings.setState(state);
|
| | | settings.setType(mineTypeNum);
|
| | | settings.setUserInfo(new UserInfo(uid));
|
| | | settings.setUpdateTime(new Date());
|
| | | settings.setCreateTime(new Date());
|
| | | userCustomSettingsMapper.insertSelective(settings);
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserCustomSettings> getSettingsByUid(Long uid) throws UserCustomSettingsException{
|
| | | if (uid == null) {
|
| | | throw new UserCustomSettingsException(1, "uid不能为空");
|
| | | }
|
| | | |
| | | return userCustomSettingsMapper.getSettingsByUid(uid);
|
| | | }
|
| | | |
| | | @Override
|
| | | public UserCustomSettings getSettingsByUidAndType(Long uid, String type) throws UserCustomSettingsException{
|
| | | |
| | | if (uid == null || type == null || type.trim().length() == 0 ) {
|
| | | throw new UserCustomSettingsException(1, "传递的参数不能为空");
|
| | | }
|
| | | |
| | | return userCustomSettingsMapper.getSettingsByUidAndType(uid, type);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public UserSettingsVO getMySettings(Long uid) throws UserCustomSettingsException{
|
| | | |
| | | UserSettingsVO userSettingsVO = new UserSettingsVO();
|
| | | |
| | | List<UserCustomSettings> list = getSettingsByUid(uid);
|
| | | |
| | | if (list != null && list.size() > 0) {
|
| | | |
| | | for (UserCustomSettings userCustomSettings: list) {
|
| | | |
| | | Integer state = userCustomSettings.getState();
|
| | | if (state == null) {
|
| | | continue;
|
| | | }
|
| | | |
| | | UserSettingTypeEnum typeEnum = userCustomSettings.getType();
|
| | | |
| | | if (typeEnum.equals(UserSettingTypeEnum.cancelNotice) ) {
|
| | | userSettingsVO.setCancelNotice(state);
|
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noNewsRedDot)){
|
| | | userSettingsVO.setNoNewsRedDot(state);
|
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noBonusCount)){
|
| | | userSettingsVO.setNoBonusCount(state);
|
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noShareRecordAndStorage)){
|
| | | userSettingsVO.setNoShareRecordAndStorage(state);
|
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noInvitationBonus)){
|
| | | userSettingsVO.setNoInvitationBonus(state);
|
| | | } else if (typeEnum.equals(UserSettingTypeEnum.openSpreadHongBao)){
|
| | | userSettingsVO.setOpenSpreadHongBao(state);
|
| | | } |
| | | |
| | | }
|
| | | }
|
| | | |
| | | return userSettingsVO;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<Long> getCancelNoticeUsers(){
|
| | | return userCustomSettingsMapper.getUserID(UserSettingTypeEnum.cancelNotice.name());
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public boolean validateCancelNoticeByUid(Long uid){
|
| | | boolean ispush = true;
|
| | | |
| | | UserCustomSettings settings = userCustomSettingsMapper.getSettingsByUidAndType(uid,
|
| | | UserSettingTypeEnum.cancelNotice.name());
|
| | | |
| | | if (settings != null && settings.getState() != null && settings.getState() == 1) {
|
| | | ispush = false;
|
| | | }
|
| | | |
| | | return ispush;
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.user; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.aliyun.openservices.ons.api.Message; |
| | | import com.aliyun.openservices.ons.api.Producer; |
| | | import com.yeshi.fanli.dao.mybatis.user.UserCustomSettingsMapper; |
| | | import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; |
| | | import com.yeshi.fanli.dto.mq.user.body.UserPhoneOpenMQMsg; |
| | | import com.yeshi.fanli.entity.bus.user.UserCustomSettings; |
| | | import com.yeshi.fanli.entity.bus.user.UserCustomSettings.UserSettingTypeEnum; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.exception.user.UserCustomSettingsException; |
| | | import com.yeshi.fanli.service.inter.user.UserCustomSettingsService; |
| | | import com.yeshi.fanli.service.manger.msg.RocketMQManager; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; |
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName; |
| | | import com.yeshi.fanli.vo.user.UserSettingsVO; |
| | | |
| | | @Service |
| | | public class UserCustomSettingsServiceImpl implements UserCustomSettingsService { |
| | | |
| | | @Resource |
| | | private UserCustomSettingsMapper userCustomSettingsMapper; |
| | | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void saveModuleState(Long uid, String type, Integer state) throws UserCustomSettingsException { |
| | | if (uid == null || type == null || state == null || state > 1 || state < 0) { |
| | | throw new UserCustomSettingsException(1, "传递参数不正确"); |
| | | } |
| | | |
| | | UserSettingTypeEnum mineTypeNum = null; |
| | | if (type.equals(UserSettingTypeEnum.cancelNotice.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.cancelNotice; |
| | | } else if (type.equals(UserSettingTypeEnum.noNewsRedDot.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.noNewsRedDot; |
| | | } else if (type.equals(UserSettingTypeEnum.noBonusCount.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.noBonusCount; |
| | | } else if (type.equals(UserSettingTypeEnum.noShareRecordAndStorage.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.noShareRecordAndStorage; |
| | | } else if (type.equals(UserSettingTypeEnum.noInvitationBonus.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.noInvitationBonus; |
| | | } else if (type.equals(UserSettingTypeEnum.openSpreadHongBao.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.openSpreadHongBao; |
| | | } else if (type.equals(UserSettingTypeEnum.noDisplayPhoneNum.name())) { |
| | | mineTypeNum = UserSettingTypeEnum.noDisplayPhoneNum; |
| | | } else { |
| | | throw new UserCustomSettingsException(1, "参数类型不匹配"); |
| | | } |
| | | |
| | | UserCustomSettings settings = userCustomSettingsMapper.getSettingsByUidAndType(uid, type); |
| | | if (settings != null) { |
| | | // 更新 |
| | | UserCustomSettings record = new UserCustomSettings(); |
| | | record.setId(settings.getId()); |
| | | record.setState(state); |
| | | record.setUpdateTime(new Date()); |
| | | userCustomSettingsMapper.updateByPrimaryKeySelective(record); |
| | | } else { |
| | | // 插入 |
| | | settings = new UserCustomSettings(); |
| | | settings.setState(state); |
| | | settings.setType(mineTypeNum); |
| | | settings.setUserInfo(new UserInfo(uid)); |
| | | settings.setUpdateTime(new Date()); |
| | | settings.setCreateTime(new Date()); |
| | | userCustomSettingsMapper.insertSelective(settings); |
| | | } |
| | | |
| | | if (mineTypeNum == UserSettingTypeEnum.noDisplayPhoneNum && !Constant.IS_TEST) { |
| | | UserPhoneOpenMQMsg msg = new UserPhoneOpenMQMsg(uid, state == 1? false: true, new Date()); |
| | | Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userPhoneOpen, msg); |
| | | rocketMQManager.sendNormalMsg(message, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<UserCustomSettings> getSettingsByUid(Long uid) throws UserCustomSettingsException { |
| | | if (uid == null) { |
| | | throw new UserCustomSettingsException(1, "uid不能为空"); |
| | | } |
| | | return userCustomSettingsMapper.getSettingsByUid(uid); |
| | | } |
| | | |
| | | @Override |
| | | public UserCustomSettings getSettingsByUidAndType(Long uid, String type) throws UserCustomSettingsException { |
| | | if (uid == null || type == null || type.trim().length() == 0) { |
| | | throw new UserCustomSettingsException(1, "传递的参数不能为空"); |
| | | } |
| | | |
| | | return userCustomSettingsMapper.getSettingsByUidAndType(uid, type); |
| | | } |
| | | |
| | | @Override |
| | | public UserSettingsVO getMySettings(Long uid) throws UserCustomSettingsException { |
| | | |
| | | UserSettingsVO userSettingsVO = new UserSettingsVO(); |
| | | |
| | | List<UserCustomSettings> list = getSettingsByUid(uid); |
| | | |
| | | if (list != null && list.size() > 0) { |
| | | |
| | | for (UserCustomSettings userCustomSettings : list) { |
| | | |
| | | Integer state = userCustomSettings.getState(); |
| | | if (state == null) { |
| | | continue; |
| | | } |
| | | |
| | | UserSettingTypeEnum typeEnum = userCustomSettings.getType(); |
| | | |
| | | if (typeEnum.equals(UserSettingTypeEnum.cancelNotice)) { |
| | | userSettingsVO.setCancelNotice(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noNewsRedDot)) { |
| | | userSettingsVO.setNoNewsRedDot(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noBonusCount)) { |
| | | userSettingsVO.setNoBonusCount(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noShareRecordAndStorage)) { |
| | | userSettingsVO.setNoShareRecordAndStorage(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noInvitationBonus)) { |
| | | userSettingsVO.setNoInvitationBonus(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.openSpreadHongBao)) { |
| | | userSettingsVO.setOpenSpreadHongBao(state); |
| | | } else if (typeEnum.equals(UserSettingTypeEnum.noDisplayPhoneNum)) { |
| | | userSettingsVO.setNoDisplayPhoneNum(state); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return userSettingsVO; |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> getCancelNoticeUsers() { |
| | | return userCustomSettingsMapper.getUserID(UserSettingTypeEnum.cancelNotice.name()); |
| | | } |
| | | |
| | | @Override |
| | | public boolean validateCancelNoticeByUid(Long uid) { |
| | | boolean ispush = true; |
| | | |
| | | UserCustomSettings settings = userCustomSettingsMapper.getSettingsByUidAndType(uid, |
| | | UserSettingTypeEnum.cancelNotice.name()); |
| | | |
| | | if (settings != null && settings.getState() != null && settings.getState() == 1) { |
| | | ispush = false; |
| | | } |
| | | |
| | | return ispush; |
| | | } |
| | | |
| | | @Override |
| | | public List<UserCustomSettings> listByUidListAndTypeAndState(List<Long> uidList, String type, Integer state) { |
| | | return userCustomSettingsMapper.listByUidListAndTypeAndState(uidList, type, state); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean validateDisplayPhoneByUid(Long uid) { |
| | | UserCustomSettings settings = userCustomSettingsMapper.getSettingsByUidAndType(uid, |
| | | UserSettingTypeEnum.noDisplayPhoneNum.name()); |
| | | if (settings != null && settings.getState() != null && settings.getState() == 1) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | } |