@ -8,20 +8,22 @@ import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.Result ;
import com.epmet.commons.tools.validator.PhoneValidatorUtils ;
import com.epmet.commons.tools.validator.ValidatorUtils ;
import com.epmet.constant.BadgeConstant ;
import com.epmet.constant.ReadFlagConstant ;
import com.epmet.constant.SmsTemplateConstant ;
import com.epmet.dao.BadgeDao ;
import com.epmet.dao.ResiUserBadgeDao ;
import com.epmet.dao.UserBadgeDao ;
import com.epmet.dao.UserRoleDao ;
import com.epmet.dao.* ;
import com.epmet.dto.ResiUserBadgeDTO ;
import com.epmet.dto.UserBadgeCertificateRecordDTO ;
import com.epmet.dto.form.* ;
import com.epmet.dto.result.* ;
import com.epmet.feign.EpmetMessageOpenFeignClient ;
import com.epmet.feign.EpmetUserOpenFeignClient ;
import com.epmet.feign.GovOrgFeignClient ;
import com.epmet.redis.UserBadgeRedis ;
import com.epmet.service.UserBadgeService ;
import com.epmet.service.UserBaseInfoService ;
import com.epmet.util.ModuleConstant ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -57,6 +59,12 @@ public class UserBadgeServiceImpl implements UserBadgeService {
private ResiUserBadgeDao resiUserBadgeDao ;
@Autowired
private BadgeDao badgeDao ;
@Autowired
private GovOrgFeignClient govOrgFeignClient ;
@Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient ;
@Autowired
private BadgeCertificationConfigDao badgeCertificationConfigDao ;
/ * *
* @Description 查询已经点亮的徽章
@ -74,7 +82,7 @@ public class UserBadgeServiceImpl implements UserBadgeService {
List < UserBadgeListResultDTO > redisUserBadgeList = JSON . parseArray ( userBadge . toString ( ) , UserBadgeListResultDTO . class ) ;
List < UserBadgeListResultDTO > userBadgeListResultDTOS = userBadgeDao . selectBadgeList ( userBadgeListFormDTO ) ;
if ( CollectionUtils . isEmpty ( userBadgeListResultDTOS ) ) {
return redisUserBadgeList ;
return redisUserBadgeList . stream ( ) . sorted ( Comparator . comparing ( UserBadgeListResultDTO : : getSort ) ) . collect ( Collectors . toList ( ) ) ;
}
redisUserBadgeList . forEach ( u - > {
userBadgeListResultDTOS . forEach ( badge - > {
@ -84,11 +92,13 @@ public class UserBadgeServiceImpl implements UserBadgeService {
}
} ) ;
} ) ;
List < UserBadgeListResultDTO > noOpenBadge = new ArrayList < > ( ) ;
redisUserBadgeList . forEach ( u - > {
if ( ! u . getStatus ( ) ) {
userBadgeListResultDTOS . add ( u ) ;
noOpenBadge . add ( u ) ;
}
} ) ;
userBadgeListResultDTOS . addAll ( noOpenBadge . stream ( ) . sorted ( Comparator . comparing ( UserBadgeListResultDTO : : getSort ) ) . collect ( Collectors . toList ( ) ) ) ;
return userBadgeListResultDTOS ;
}
@ -121,7 +131,14 @@ public class UserBadgeServiceImpl implements UserBadgeService {
}
} ) ;
} ) ;
return userOperListResultDTOS . stream ( ) . sorted ( Comparator . comparing ( UserOperListResultDTO : : getBadgeName ) ) . collect ( Collectors . toList ( ) ) ;
Map < String , List < UserOperListResultDTO > > collect = userOperListResultDTOS . stream ( ) . collect ( Collectors . groupingBy ( UserOperListResultDTO : : getIsLighted ) ) ;
List < UserOperListResultDTO > result = collect . get ( BadgeConstant . YES ) ;
List < UserOperListResultDTO > noLight = collect . get ( BadgeConstant . NO ) ;
if ( CollectionUtils . isEmpty ( noLight ) ) {
return result ;
}
result . addAll ( noLight . stream ( ) . sorted ( Comparator . comparing ( UserOperListResultDTO : : getSort ) ) . collect ( Collectors . toList ( ) ) ) ;
return result ;
}
/ * *
@ -215,9 +232,14 @@ public class UserBadgeServiceImpl implements UserBadgeService {
@Transactional ( rollbackFor = Exception . class )
public Result authBadgeRecord ( CertificationAddFormDTO certificationAddFormDTO ) {
log . info ( JSON . toJSONString ( certificationAddFormDTO ) ) ;
if ( StringUtils . isNotBlank ( certificationAddFormDTO . getMobile ( ) ) ) {
AuthFieldFormDTO authFieldFormDTO = new AuthFieldFormDTO ( ) ;
authFieldFormDTO . setCustomerId ( certificationAddFormDTO . getCustomerId ( ) ) ;
authFieldFormDTO . setBadgeId ( certificationAddFormDTO . getBadgeId ( ) ) ;
validateParams ( certificationAddFormDTO , authFieldFormDTO ) ;
if ( StringUtils . isNotBlank ( certificationAddFormDTO . getMobile ( ) ) ) {
String smsCode = userBadgeRedis . getBadgeSmsCode ( certificationAddFormDTO . getMobile ( ) ) ;
if ( ! StringUtils . isNotBlank ( smsCode ) ) {
if ( ! StringUtils . isNotBlank ( smsCode ) ) {
return new Result ( ) . error ( EpmetErrorCode . MOBILE_CODE_ERROR . getCode ( ) ) ;
}
}
@ -225,7 +247,7 @@ public class UserBadgeServiceImpl implements UserBadgeService {
List < String > userIds = new ArrayList < > ( ) ;
userIds . add ( certificationAddFormDTO . getUserId ( ) ) ;
List < UserBaseInfoResultDTO > userBaseInfoResultDTOS = userBaseInfoService . queryUserBaseInfo ( userIds ) ;
if ( CollectionUtils . isEmpty ( userBaseInfoResultDTOS ) ) {
if ( CollectionUtils . isEmpty ( userBaseInfoResultDTOS ) ) {
throw new RenException ( "查询用户基本信息集合为空......" ) ;
}
userBadgeDao . updateCertificateRecordIsLast ( form . getBadgeId ( ) , form . getUserId ( ) ) ;
@ -236,19 +258,34 @@ public class UserBadgeServiceImpl implements UserBadgeService {
log . info ( JSON . toJSONString ( form ) ) ;
userBadgeDao . insertUserBadgeCertificateRecord ( form ) ;
//TODO 站内信发送 您好,您的xxx徽章因认证失败未成功点亮,请查看
this . sendMessageByUser ( form ) ;
//TODO 站内信发送
String badgeName = badgeDao . selectBadgeName ( form . getCustomerId ( ) , form . getBadgeId ( ) ) ;
sendMessage ( BadgeConstant . AUTH_TITLE , String . format ( BadgeConstant . READ_FLAG , userBaseInfoResultDTOS . get ( NumConstant . ZERO ) . getDistrict ( ) . concat ( userBaseInfoResultDTOS . get ( NumConstant . ZERO ) . getRealName ( ) ) , badgeName ) , form . getGridId ( ) , form . getUserId ( ) , form . getCustomerId ( ) ) ;
return new Result ( ) ;
}
private void validateParams ( CertificationAddFormDTO certificationAddFormDTO , AuthFieldFormDTO authFieldFormDTO ) {
List < AuthFieldResultDTO > authFieldResultDTOS = this . authField ( authFieldFormDTO ) ;
if ( CollectionUtils . isEmpty ( authFieldResultDTOS ) ) {
throw new RenException ( "该徽章配置配置错误" ) ;
}
Set < String > requiredColumns = authFieldResultDTOS . stream ( )
. filter ( o - > NumConstant . ONE_STR . equals ( o . getIsRequired ( ) ) )
. map ( AuthFieldResultDTO : : getEnName ) . collect ( Collectors . toSet ( ) ) ;
List < String > missColumns = ValidatorUtils . hasAllRequired ( JSON . toJSONString ( certificationAddFormDTO ) , requiredColumns ) ;
if ( ! CollectionUtils . isEmpty ( missColumns ) ) {
throw new RenException ( JSON . toJSONString ( missColumns ) . concat ( "不能为空" ) ) ;
}
}
/ * *
* @Description 站内信发送 — — 提交徽章认证
* @Param form
* @author zxc
* @date 2020 / 11 / 10 9 : 04 上午
* /
public void sendMessageByUser ( UserBadgeCertificateRecordDTO form ) {
public void sendMessageByUser ( UserBadgeCertificateRecordDTO form ) {
List < UserMessageFormDTO > msgList = new ArrayList < > ( ) ;
UserMessageFormDTO formDTO = new UserMessageFormDTO ( ) ;
formDTO . setApp ( BadgeConstant . RESI ) ;
@ -388,4 +425,69 @@ public class UserBadgeServiceImpl implements UserBadgeService {
return badges . stream ( ) . collect ( Collectors . groupingBy ( UserBadgeInfoResultDTO : : getUserId ) ) ;
}
/ * *
* @Description 发送站内信
* @Param title 标题
* @Param msg 信息
* @Param gridId 网格ID
* @Param userId 用户ID
* @Param customerId 客户ID
* @author zxc
* @date 2020 / 11 / 19 上午9 : 16
* /
public void sendMessage ( String title , String msg , String gridId , String userId , String customerId ) {
//1.查询加入当前网格下的人员 customer_staff_grid
CommonGridIdFormDTO commonGridIdFormDTO = new CommonGridIdFormDTO ( ) ;
commonGridIdFormDTO . setGridId ( gridId ) ;
commonGridIdFormDTO . setUserId ( userId ) ;
Result < List < String > > gridstaffs =
govOrgFeignClient . getGridStaffs ( commonGridIdFormDTO ) ;
//2.查询这些人是否有管理员身份且未被禁用 staff_role customer_staff
if ( gridstaffs . success ( ) & & null ! = gridstaffs . getData ( ) & & gridstaffs . getData ( ) . size ( ) > 0 ) {
RolesUsersListFormDTO rolesUsersListFormDTO = new RolesUsersListFormDTO ( ) ;
rolesUsersListFormDTO . setCustomerId ( customerId ) ;
List < String > roleKeys = new ArrayList < String > ( ) ;
roleKeys . add ( ModuleConstant . STAFF_ROLE_GRID_MANAGER ) ;
rolesUsersListFormDTO . setRoleKeys ( roleKeys ) ;
rolesUsersListFormDTO . setUserIds ( gridstaffs . getData ( ) ) ;
Result < List < String > > staffRoles =
epmetUserOpenFeignClient . specificRolesStaffs ( rolesUsersListFormDTO ) ;
//3.发送消息
if ( staffRoles . success ( ) & & null ! = staffRoles . getData ( ) & & staffRoles . getData ( ) . size ( ) > 0 ) {
List < UserMessageFormDTO > msgList = new ArrayList < > ( ) ;
List < WxSubscribeMessageFormDTO > subscribeList = new ArrayList < > ( ) ;
for ( String to : staffRoles . getData ( ) ) {
//站内信
UserMessageFormDTO msgObj = new UserMessageFormDTO ( ) ;
msgObj . setApp ( ModuleConstant . APP_GOV ) ;
msgObj . setCustomerId ( customerId ) ;
msgObj . setGridId ( gridId ) ;
msgObj . setMessageContent ( msg ) ;
msgObj . setReadFlag ( ReadFlagConstant . UN_READ ) ;
msgObj . setTitle ( title ) ;
msgObj . setUserId ( to ) ;
msgList . add ( msgObj ) ;
//微信订阅
WxSubscribeMessageFormDTO subscribeDTO = new WxSubscribeMessageFormDTO ( ) ;
subscribeDTO . setClientType ( ModuleConstant . APP_GOV ) ;
subscribeDTO . setGridId ( gridId ) ;
subscribeDTO . setCustomerId ( customerId ) ;
subscribeDTO . setUserId ( to ) ;
subscribeDTO . setBehaviorType ( ModuleConstant . BADGE_AUDIT_MESSAGE ) ;
subscribeDTO . setMessageContent ( msg ) ;
subscribeDTO . setMessageTime ( new Date ( ) ) ;
subscribeList . add ( subscribeDTO ) ;
}
if ( subscribeList . size ( ) > NumConstant . ZERO ) {
epmetMessageOpenFeignClient . sendWxSubscribeMessage ( subscribeList ) ;
}
Result result = epmetMessageOpenFeignClient . saveUserMessageList ( msgList ) ;
if ( result . success ( ) ) {
return ;
}
}
}
}
}