@ -46,7 +46,7 @@ import java.util.List;
import java.util.Map ;
/ * *
* 党群表
* 党群表
*
* @author elink elink @elink - cn . com
* @since v1 . 0 . 0 2020 - 05 - 29
@ -83,8 +83,8 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
return ConvertUtils . sourceToTarget ( entityList , PartyGroupDTO . class ) ;
}
private QueryWrapper < PartyGroupEntity > getWrapper ( Map < String , Object > params ) {
String id = ( String ) params . get ( FieldConstant . ID_HUMP ) ;
private QueryWrapper < PartyGroupEntity > getWrapper ( Map < String , Object > params ) {
String id = ( String ) params . get ( FieldConstant . ID_HUMP ) ;
QueryWrapper < PartyGroupEntity > wrapper = new QueryWrapper < > ( ) ;
wrapper . eq ( StringUtils . isNotBlank ( id ) , FieldConstant . ID , id ) ;
@ -94,24 +94,49 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
@Override
public PartyGroupDTO get ( String id ) {
return baseDao . selectDetailById ( id ) ;
return baseDao . selectDetailById ( id ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void save ( PartyGroupDTO dto ) {
//确认党群名字是否重复
this . isPartyGroupNameExists ( dto ) ;
//保存部门信息
this . saveDeptInfo ( dto ) ;
PartyGroupEntity entity = ConvertUtils . sourceToTarget ( dto , PartyGroupEntity . class ) ;
insert ( entity ) ;
//保存群主信息
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
}
private void isPartyGroupNameExists ( PartyGroupDTO dto ) {
//先判断党群名是否重复
if ( StringUtils . isNotBlank ( dto . getId ( ) ) ) {
//代表更新党群
PartyGroupDTO oldPartyGroupDTO = get ( dto . getId ( ) ) ;
if ( oldPartyGroupDTO = = null ) {
throw new RenException ( "该党群不存在" ) ;
}
//若是改名则判断新名字是否重复
if ( ! dto . getPartyGroupName ( ) . equals ( oldPartyGroupDTO . getPartyGroupName ( ) ) ) {
PartyGroupDTO partyGroupDTO = getPartyGroupDTOByName ( dto . getPartyGroupName ( ) ) ;
if ( partyGroupDTO ! = null ) {
throw new RenException ( "该党群名名字已存在" ) ;
}
}
} else {
PartyGroupDTO partyGroupDTO = getPartyGroupDTOByName ( dto . getPartyGroupName ( ) ) ;
if ( partyGroupDTO ! = null ) {
throw new RenException ( "该党群名名字已存在" ) ;
}
}
}
private void saveDeptInfo ( PartyGroupDTO dto ) {
//赋值部门名称
Result < SysDeptDTO > sysDeptDTO = adminFeignClient . getSysDeptDTO ( Long . parseLong ( dto . getDeptId ( ) ) ) ;
if ( ! sysDeptDTO . success ( ) | | sysDeptDTO . getData ( ) = = null ) {
if ( ! sysDeptDTO . success ( ) | | sysDeptDTO . getData ( ) = = null ) {
throw new RenException ( sysDeptDTO . getMsg ( ) ) ;
}
SysDeptDTO dept = sysDeptDTO . getData ( ) ;
@ -129,31 +154,32 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
}
}
private void insertUserGroup ( String userId , String partyGroupId ) {
private void insertUserGroup ( String userId , String partyGroupId ) {
Result < UserDTO > userInfoById = userFeignClient . getUserInfoById ( userId ) ;
if ( ! userInfoById . success ( ) | | userInfoById . getData ( ) = = null ) {
if ( ! userInfoById . success ( ) | | userInfoById . getData ( ) = = null ) {
throw new RenException ( "获取用户信息失败" ) ;
}
UserDTO userDto = userInfoById . getData ( ) ;
PartyUserGroupEntity partyUserGroupEntity = new PartyUserGroupEntity ( ) ;
partyUserGroupEntity . setIdentityFlag ( userDto . getPartyFlag ( ) ) ;
partyUserGroupEntity . setPartyMember ( userDto . getPartyFlag ( ) ) ;
partyUserGroupEntity . setUserId ( userDto . getId ( ) ) ;
partyUserGroupEntity . setNickname ( userDto . getNickname ( ) ) ;
partyUserGroupEntity . setUserAvatar ( userDto . getFaceImg ( ) ) ;
partyUserGroupEntity . setMobile ( userDto . getMobile ( ) ) ;
partyUserGroupEntity . setPartyGroupId ( partyGroupId ) ;
partyUserGroupEntity . setIdentityFlag ( "1" ) ;
//身份标识为群主
partyUserGroupEntity . setIdentityFlag ( "0" ) ;
//网格信息
if ( userDto . getGridId ( ) ! = null & & userDto . getGridId ( ) ! = 0 ) {
if ( userDto . getGridId ( ) ! = null & & userDto . getGridId ( ) ! = 0 ) {
partyUserGroupEntity . setGrid ( userDto . getGrid ( ) ) ;
partyUserGroupEntity . setGridId ( userDto . getGridId ( ) ) ;
partyUserGroupEntity . setAllDeptIds ( userDto . getAllDeptIds ( ) ) ;
partyUserGroupEntity . setAllDeptNames ( userDto . getAllDeptNames ( ) ) ;
partyUserGroupEntity . setParentDeptIds ( userDto . getParentDeptIds ( ) ) ;
partyUserGroupEntity . setParentDeptNames ( userDto . getParentDeptNames ( ) ) ;
} else {
} else {
Result < UserGridRelationDTO > userFirstScanGird = userFeignClient . getUserFirstScanGird ( userId ) ;
if ( ! userFirstScanGird . success ( ) | | userFirstScanGird . getData ( ) = = null ) {
if ( ! userFirstScanGird . success ( ) | | userFirstScanGird . getData ( ) = = null ) {
throw new RenException ( "获取用户网格关联信息失败" ) ;
}
UserGridRelationDTO userGridRelationDTO = userFirstScanGird . getData ( ) ;
@ -171,6 +197,7 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
@Override
@Transactional ( rollbackFor = Exception . class )
public void update ( PartyGroupDTO dto ) {
this . isPartyGroupNameExists ( dto ) ;
//保存部门信息
this . saveDeptInfo ( dto ) ;
PartyGroupEntity entity = ConvertUtils . sourceToTarget ( dto , PartyGroupEntity . class ) ;
@ -178,19 +205,20 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
//判断是否更新群主
PartyUserGroupDTO managerByGroupId = partyUserGroupService . getManagerByGroupId ( dto . getId ( ) ) ;
//存在群主且如过改变群主信息 则之前群主为群成员
if ( managerByGroupId ! = null & & ! managerByGroupId . getUserId ( ) . equals ( dto . getUserId ( ) ) ) {
if ( managerByGroupId ! = null & & ! managerByGroupId . getUserId ( ) . equals ( dto . getUserId ( ) ) ) {
//先更新之前的群主为群成员
managerByGroupId . setIdentityFlag ( "0 " ) ;
managerByGroupId . setIdentityFlag ( "2 " ) ;
partyUserGroupService . update ( managerByGroupId ) ;
}
//判断新指定的群主是否已存在党群成员中
PartyUserGroupDTO userByGroupIdAndUserId = partyUserGroupService . getUserByGroupIdAndUserId ( dto . getId ( ) , dto . getUserId ( ) ) ;
//新指定群主不存在则直接新增
if ( userByGroupIdAndUserId = = null ) {
if ( userByGroupIdAndUserId = = null ) {
//保存群主信息
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
} else { //存在则只更新身份标识
userByGroupIdAndUserId . setIdentityFlag ( "1" ) ;
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
} else { //存在则只更新身份标识
//身份标识为群主
userByGroupIdAndUserId . setIdentityFlag ( "0" ) ;
partyUserGroupService . update ( userByGroupIdAndUserId ) ;
}
}
@ -211,7 +239,7 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
@Override
public List < UserDTO > getUserList ( Long deptId ) {
Result < List < UserDTO > > userList = userFeignClient . getUserList ( deptId ) ;
if ( ! userList . success ( ) | | userList . getData ( ) = = null ) {
if ( ! userList . success ( ) | | userList . getData ( ) = = null ) {
throw new RenException ( "获取用户列表信息失败" ) ;
}
return userList . getData ( ) ;
@ -233,15 +261,20 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
public Result joinGroup ( PartyUserJoinGroupFormDTO partyUserJoinGroupFormDTO ) {
//判断是够已加入党群
PartyUserGroupDTO userByGroupIdAndUserId = partyUserGroupService . getUserByGroupIdAndUserId ( partyUserJoinGroupFormDTO . getPartyGroupId ( ) , partyUserJoinGroupFormDTO . getUserId ( ) ) ;
if ( userByGroupIdAndUserId ! = null ) {
if ( userByGroupIdAndUserId ! = null ) {
return new Result ( ) . error ( "用户已加入此群!" ) ;
}
PartyUserGroupDTO partyUserGroupDTO = ConvertUtils . sourceToTarget ( partyUserJoinGroupFormDTO , PartyUserGroupDTO . class ) ;
partyUserGroupDTO . setIdentityFlag ( "0" ) ;
PartyUserGroupDTO partyUserGroupDTO = ConvertUtils . sourceToTarget ( partyUserJoinGroupFormDTO , PartyUserGroupDTO . class ) ;
//身份标识为群成员
partyUserGroupDTO . setIdentityFlag ( "2" ) ;
partyUserGroupDTO . setState ( 0 ) ;
partyUserGroupService . save ( partyUserGroupDTO ) ;
return new Result ( ) ;
}
@Override
public PartyGroupDTO getPartyGroupDTOByName ( String partyGroupName ) {
return baseDao . getPartyGroupDTOByName ( partyGroupName ) ;
}
}