@ -26,14 +26,14 @@ import com.elink.esua.epdc.commons.tools.utils.ConvertUtils;
import com.elink.esua.epdc.commons.tools.constant.FieldConstant ;
import com.elink.esua.epdc.commons.tools.utils.Result ;
import com.elink.esua.epdc.dao.PartyGroupDao ;
import com.elink.esua.epdc.dto.ParentAndAllDeptDTO ;
import com.elink.esua.epdc.dto.PartyGroupDTO ;
import com.elink.esua.epdc.dto.PartyGroupListDTO ;
import com.elink.esua.epdc.dto.SysDeptDTO ;
import com.elink.esua.epdc.dto.* ;
import com.elink.esua.epdc.entity.PartyGroupEntity ;
import com.elink.esua.epdc.entity.PartyUserGroupEntity ;
import com.elink.esua.epdc.feign.AdminFeignClient ;
import com.elink.esua.epdc.feign.UserFeignClient ;
import com.elink.esua.epdc.redis.PartyGroupRedis ;
import com.elink.esua.epdc.service.PartyGroupService ;
import com.elink.esua.epdc.service.PartyUserGroupService ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -58,6 +58,13 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
@Autowired
private AdminFeignClient adminFeignClient ;
@Autowired
private UserFeignClient userFeignClient ;
@Autowired
private PartyUserGroupService partyUserGroupService ;
@Override
public PageData < PartyGroupDTO > page ( Map < String , Object > params ) {
IPage < PartyGroupEntity > page = baseDao . selectPage (
@ -85,13 +92,21 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
@Override
public PartyGroupDTO get ( String id ) {
PartyGroupEntity entity = baseDao . selectById ( id ) ;
return ConvertUtils . sourceToTarget ( entity , PartyGroupDTO . class ) ;
return baseDao . selectDetailById ( id ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void save ( PartyGroupDTO dto ) {
//保存部门信息
this . saveDeptInfo ( dto ) ;
PartyGroupEntity entity = ConvertUtils . sourceToTarget ( dto , PartyGroupEntity . class ) ;
insert ( entity ) ;
//保存群主信息
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
}
private void saveDeptInfo ( PartyGroupDTO dto ) {
//赋值部门名称
Result < SysDeptDTO > sysDeptDTO = adminFeignClient . getSysDeptDTO ( Long . parseLong ( dto . getDeptId ( ) ) ) ;
if ( ! sysDeptDTO . success ( ) | | sysDeptDTO . getData ( ) = = null ) {
@ -110,15 +125,72 @@ public class PartyGroupServiceImpl extends BaseServiceImpl<PartyGroupDao, PartyG
dto . setParentDeptIds ( deptDTO . getParentDeptIds ( ) ) ;
dto . setParentDeptNames ( deptDTO . getParentDeptNames ( ) ) ;
}
PartyGroupEntity entity = ConvertUtils . sourceToTarget ( dto , PartyGroupEntity . class ) ;
insert ( entity ) ;
}
private void insertUserGroup ( String userId , String partyGroupId ) {
Result < UserDTO > userInfoById = userFeignClient . getUserInfoById ( userId ) ;
if ( ! userInfoById . success ( ) | | userInfoById . getData ( ) = = null ) {
throw new RenException ( "获取用户信息失败" ) ;
}
UserDTO userDto = userInfoById . getData ( ) ;
PartyUserGroupEntity partyUserGroupEntity = new PartyUserGroupEntity ( ) ;
partyUserGroupEntity . setIdentityFlag ( userDto . getPartyFlag ( ) ) ;
partyUserGroupEntity . setUserId ( userDto . getId ( ) ) ;
partyUserGroupEntity . setNickname ( userDto . getNickname ( ) ) ;
partyUserGroupEntity . setUserAvatar ( userDto . getFaceImg ( ) ) ;
partyUserGroupEntity . setMobile ( userDto . getMobile ( ) ) ;
partyUserGroupEntity . setPartyGroupId ( partyGroupId ) ;
partyUserGroupEntity . setIdentityFlag ( "1" ) ;
//网格信息
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 {
Result < UserGridRelationDTO > userFirstScanGird = userFeignClient . getUserFirstScanGird ( userId ) ;
if ( ! userFirstScanGird . success ( ) | | userFirstScanGird . getData ( ) = = null ) {
throw new RenException ( "获取用户网格关联信息失败" ) ;
}
UserGridRelationDTO userGridRelationDTO = userFirstScanGird . getData ( ) ;
partyUserGroupEntity . setGrid ( userGridRelationDTO . getGrid ( ) ) ;
partyUserGroupEntity . setGridId ( userGridRelationDTO . getGridId ( ) ) ;
partyUserGroupEntity . setAllDeptIds ( userGridRelationDTO . getAllDeptIds ( ) ) ;
partyUserGroupEntity . setAllDeptNames ( userGridRelationDTO . getAllDeptNames ( ) ) ;
partyUserGroupEntity . setParentDeptIds ( userGridRelationDTO . getParentDeptIds ( ) ) ;
partyUserGroupEntity . setParentDeptNames ( userGridRelationDTO . getParentDeptNames ( ) ) ;
}
partyUserGroupService . insert ( partyUserGroupEntity ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void update ( PartyGroupDTO dto ) {
//保存部门信息
this . saveDeptInfo ( dto ) ;
PartyGroupEntity entity = ConvertUtils . sourceToTarget ( dto , PartyGroupEntity . class ) ;
updateById ( entity ) ;
//判断是否更新群主
PartyUserGroupDTO managerByGroupId = partyUserGroupService . getManagerByGroupId ( dto . getId ( ) ) ;
//存在群主且如过改变群主信息 则之前群主为群成员
if ( managerByGroupId ! = null & & ! managerByGroupId . getUserId ( ) . equals ( dto . getUserId ( ) ) ) {
//先更新之前的群主为群成员
managerByGroupId . setIdentityFlag ( "0" ) ;
partyUserGroupService . update ( managerByGroupId ) ;
}
//判断新指定的群主是否已存在党群成员中
PartyUserGroupDTO userByGroupIdAndUserId = partyUserGroupService . getUserByGroupIdAndUserId ( dto . getId ( ) , dto . getUserId ( ) ) ;
//新指定群主不存在则直接新增
if ( userByGroupIdAndUserId = = null ) {
//保存群主信息
this . insertUserGroup ( dto . getUserId ( ) , entity . getId ( ) ) ;
} else { //存在则只更新身份标识
userByGroupIdAndUserId . setIdentityFlag ( "1" ) ;
partyUserGroupService . update ( userByGroupIdAndUserId ) ;
}
}
@Override
@ -134,4 +206,20 @@ 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 ) {
throw new RenException ( "获取用户列表信息失败" ) ;
}
return userList . getData ( ) ;
}
@Override
public PageData < PartyGroupDTO > listPage ( Map < String , Object > params ) {
IPage < PartyGroupDTO > page = getPage ( params ) ;
List < PartyGroupDTO > list = baseDao . selectListOfPartyGroupDTO ( params ) ;
return new PageData < > ( list , page . getTotal ( ) ) ;
}
}