|
|
@ -28,9 +28,16 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.scan.param.ImgScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.ImgTaskDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextScanParamDTO; |
|
|
|
import com.epmet.commons.tools.scan.param.TextTaskDTO; |
|
|
|
import com.epmet.commons.tools.scan.result.SyncScanResult; |
|
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.ScanContentUtils; |
|
|
|
import com.epmet.constant.ReadFlagConstant; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.UserResiInfoResultDTO; |
|
|
@ -40,8 +47,10 @@ import com.epmet.modules.constant.UserMessageConstant; |
|
|
|
import com.epmet.modules.feign.EpmetMessageFeignClient; |
|
|
|
import com.epmet.modules.feign.EpmetUserFeignClient; |
|
|
|
import com.epmet.modules.feign.GovOrgFeignClient; |
|
|
|
import com.epmet.modules.group.dao.GroupEditSubmitRecordDao; |
|
|
|
import com.epmet.modules.group.dao.ResiGroupDao; |
|
|
|
import com.epmet.modules.group.dao.ResiGroupOperationDao; |
|
|
|
import com.epmet.modules.group.entity.GroupEditSubmitRecordEntity; |
|
|
|
import com.epmet.modules.group.entity.ResiGroupEntity; |
|
|
|
import com.epmet.modules.group.entity.ResiGroupOperationEntity; |
|
|
|
import com.epmet.modules.group.redis.ResiGroupRedis; |
|
|
@ -54,10 +63,7 @@ import com.epmet.modules.member.redis.ResiGroupMemberRedis; |
|
|
|
import com.epmet.modules.member.service.GroupMemeberOperationService; |
|
|
|
import com.epmet.modules.member.service.ResiGroupMemberService; |
|
|
|
import com.epmet.modules.utils.ModuleConstant; |
|
|
|
import com.epmet.resi.group.constant.EnterGroupTypeConstant; |
|
|
|
import com.epmet.resi.group.constant.GroupStateConstant; |
|
|
|
import com.epmet.resi.group.constant.LeaderFlagConstant; |
|
|
|
import com.epmet.resi.group.constant.MemberStateConstant; |
|
|
|
import com.epmet.resi.group.constant.*; |
|
|
|
import com.epmet.resi.group.dto.UserRoleDTO; |
|
|
|
import com.epmet.resi.group.dto.group.*; |
|
|
|
import com.epmet.resi.group.dto.group.form.*; |
|
|
@ -71,8 +77,10 @@ import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
@ -127,6 +135,24 @@ public class ResiGroupServiceImpl extends BaseServiceImpl<ResiGroupDao, ResiGrou |
|
|
|
@Autowired |
|
|
|
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ResiGroupDao resiGroupDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GroupEditSubmitRecordDao groupEditSubmitRecordDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private LoginUserUtil loginUserUtil; |
|
|
|
|
|
|
|
@Value("${openapi.scan.server.url}") |
|
|
|
private String scanApiUrl; |
|
|
|
|
|
|
|
@Value("${openapi.scan.method.textSyncScan}") |
|
|
|
private String textSyncScanMethod; |
|
|
|
|
|
|
|
@Value("${openapi.scan.method.imgSyncScan}") |
|
|
|
private String imgSyncScanMethod; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<ResiGroupDTO> page(Map<String, Object> params) { |
|
|
|
IPage<ResiGroupEntity> page = baseDao.selectPage( |
|
|
@ -574,18 +600,6 @@ public class ResiGroupServiceImpl extends BaseServiceImpl<ResiGroupDao, ResiGrou |
|
|
|
if(!epmetMessageFeignClient.saveUserMessage(userMessageFormDTO).success()){ |
|
|
|
logger.warn(String.format(ModuleConstant.FAILED_SEND_MESSAGE,String.format(UserMessageConstant.AGREE_CREATING_GROUP_MSG_TEMPLATE,resiGroupDTO.getGroupName()))); |
|
|
|
} |
|
|
|
//发送微信订阅消息
|
|
|
|
WxSubscribeMessageFormDTO wxSubscribeMessageFormDTO = new WxSubscribeMessageFormDTO(); |
|
|
|
wxSubscribeMessageFormDTO.setCustomerId(resiGroupDTO.getCustomerId()); |
|
|
|
wxSubscribeMessageFormDTO.setUserId(resiGroupDTO.getCreatedBy()); |
|
|
|
wxSubscribeMessageFormDTO.setClientType(AppClientConstant.APP_RESI); |
|
|
|
wxSubscribeMessageFormDTO.setGridId(resiGroupDTO.getGridId()); |
|
|
|
wxSubscribeMessageFormDTO.setBehaviorType(UserMessageConstant.WX_APPLY_CREATE_GROUP_BEHAVIOR); |
|
|
|
wxSubscribeMessageFormDTO.setMessageContent(String.format(UserMessageConstant.AGREE_CREATING_GROUP_MSG_TEMPLATE,resiGroupDTO.getGroupName())); |
|
|
|
wxSubscribeMessageFormDTO.setMessageTime(new Date()); |
|
|
|
List<WxSubscribeMessageFormDTO> msgList = new ArrayList<>(); |
|
|
|
msgList.add(wxSubscribeMessageFormDTO); |
|
|
|
epmetMessageOpenFeignClient.sendWxSubscribeMessage(msgList); |
|
|
|
//更新政府端:工作-基层治理-党员认证reddot
|
|
|
|
resiGroupRedis.subtractWorkGrassrootsPartyAuthRedDotValue(resiGroupDTO.getGridId()); |
|
|
|
return new Result(); |
|
|
@ -1016,4 +1030,216 @@ public class ResiGroupServiceImpl extends BaseServiceImpl<ResiGroupDao, ResiGrou |
|
|
|
logger.warn(String.format(ModuleConstant.FAILED_SEND_MESSAGE,msg)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public GroupDetailResultDTO getGroupDetail(String groupId) { |
|
|
|
GroupDetailResultDTO groupDetail = new GroupDetailResultDTO(); |
|
|
|
|
|
|
|
// 1.拼装组基本信息
|
|
|
|
GroupEditSubmitRecordEntity ler = groupEditSubmitRecordDao.getLatestEditSubmitRecord(groupId); |
|
|
|
|
|
|
|
if (ler != null) { |
|
|
|
groupDetail.setAuditStatus(ler.getAuditStatus()); |
|
|
|
groupDetail.setRemark(ler.getRemark()); |
|
|
|
} |
|
|
|
|
|
|
|
if (ler != null && GroupAuditStatusConstant.UNDER_AUDITING.equals(ler.getAuditStatus())) { |
|
|
|
// 审核中,显示待审核内容
|
|
|
|
groupDetail.setGroupHeadPhoto(ler.getGroupHeadPhoto()); |
|
|
|
groupDetail.setGroupName(ler.getGroupName()); |
|
|
|
groupDetail.setGroupIntroduction(ler.getGroupIntroduction()); |
|
|
|
} else { |
|
|
|
// 不在审核中,直接显示组信息
|
|
|
|
ResiGroupEntity resiGroupEntity = resiGroupDao.selectById(groupId); |
|
|
|
if (resiGroupEntity == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
groupDetail.setGroupHeadPhoto(resiGroupEntity.getGroupHeadPhoto()); |
|
|
|
groupDetail.setGroupName(resiGroupEntity.getGroupName()); |
|
|
|
groupDetail.setGroupIntroduction(resiGroupEntity.getGroupIntroduction()); |
|
|
|
} |
|
|
|
|
|
|
|
// 2.编辑次数及其限制
|
|
|
|
groupDetail.setEditNumLimit(GroupLimitConstant.EDIT_NUM_LIMIT_MONTH); |
|
|
|
Date now = new Date(); |
|
|
|
int usedEditNum = groupEditSubmitRecordDao.countEditNum(groupId, DateUtils.getMonthStart(now), DateUtils.getMonthEnd(now)); |
|
|
|
groupDetail.setAvaliableEditNum(GroupLimitConstant.EDIT_NUM_LIMIT_MONTH - usedEditNum); |
|
|
|
|
|
|
|
// 审核状态
|
|
|
|
// 是否可编辑
|
|
|
|
boolean editable = true; |
|
|
|
|
|
|
|
if (GroupLimitConstant.EDIT_NUM_LIMIT_MONTH <= usedEditNum) { |
|
|
|
// 达到最大编辑次数了
|
|
|
|
editable = false; |
|
|
|
} |
|
|
|
|
|
|
|
if (ler != null && GroupAuditStatusConstant.UNDER_AUDITING.equals(ler.getAuditStatus())) { |
|
|
|
// 提交了,还没审核完
|
|
|
|
editable = false; |
|
|
|
} |
|
|
|
|
|
|
|
groupDetail.setEditable(editable); |
|
|
|
return groupDetail; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void submitGroupEdit(String groupId, String groupName, String groupHeadPhoto, String groupIntroduction) { |
|
|
|
// 1.判断小组是否存在,判断是否已经在"待审核"状态
|
|
|
|
ResiGroupEntity group = resiGroupDao.selectById(groupId); |
|
|
|
if (group == null) { |
|
|
|
throw new RenException(EpmetErrorCode.GROUP_EDIT_ERROR.getCode(), "组信息不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
GroupEditSubmitRecordEntity lre = groupEditSubmitRecordDao.getLatestEditSubmitRecord(groupId); |
|
|
|
if (lre != null && GroupAuditStatusConstant.UNDER_AUDITING.equals(lre.getAuditStatus())) { |
|
|
|
// 在待审核状态,不允许再次提交编辑
|
|
|
|
throw new RenException(EpmetErrorCode.GROUP_EDIT_ERROR.getCode(), "该组已提交编辑,处于待审核状态,完成审核前不可再次提交"); |
|
|
|
} |
|
|
|
|
|
|
|
if (resiGroupDao.countExistsGroupNameBeforeEdit(groupId, group.getGridId(), groupName) > 0) { |
|
|
|
// 已存在组名,拒绝提交
|
|
|
|
throw new RenException(EpmetErrorCode.GROUP_EDIT_ERROR.getCode(), "组名已存在"); |
|
|
|
} |
|
|
|
|
|
|
|
// 2.内容检查
|
|
|
|
//scanGroupEditContent(groupName, groupIntroduction, groupHeadPhoto);
|
|
|
|
|
|
|
|
String app = loginUserUtil.getLoginUserApp(); |
|
|
|
String userId = loginUserUtil.getLoginUserId(); |
|
|
|
String messageText = generateGroupEditMessageText(app, userId, group.getCustomerId(), group.getGridId(), groupName); |
|
|
|
|
|
|
|
// 3.创建编辑提交记录
|
|
|
|
GroupEditSubmitRecordEntity editRecord = new GroupEditSubmitRecordEntity(); |
|
|
|
editRecord.setAuditStatus(GroupAuditStatusConstant.UNDER_AUDITING); |
|
|
|
editRecord.setCustomerId(group.getCustomerId()); |
|
|
|
editRecord.setGridId(group.getGridId()); |
|
|
|
editRecord.setGroupHeadPhoto(groupHeadPhoto); |
|
|
|
editRecord.setGroupIntroduction(groupIntroduction); |
|
|
|
editRecord.setGroupId(groupId); |
|
|
|
editRecord.setGroupName(groupName); |
|
|
|
editRecord.setReadFlag(ReadFlagConstant.UN_READ); |
|
|
|
editRecord.setMessageText(messageText); |
|
|
|
|
|
|
|
if (groupEditSubmitRecordDao.insert(editRecord) == 0) { |
|
|
|
throw new RenException(EpmetErrorCode.GROUP_EDIT_ERROR.getCode(), EpmetErrorCode.GROUP_EDIT_ERROR.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成组信息编辑简介文本:xxx申请编辑组信息,请审核 |
|
|
|
* @param app |
|
|
|
* @param userId |
|
|
|
* @param customerId |
|
|
|
* @param gridId |
|
|
|
* @param groupName |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String generateGroupEditMessageText(String app, String userId, String customerId, String gridId, String groupName) { |
|
|
|
List<UserRoleResultDTO> resiRoles = getResiRoles(app, customerId, userId, gridId); |
|
|
|
boolean isPartymember = false; |
|
|
|
boolean isWarmhearted = false; |
|
|
|
for (UserRoleResultDTO role : resiRoles) { |
|
|
|
if (EpmetRoleKeyConstant.WARMHEARTED.equals(role.getRoleKey())) { |
|
|
|
isWarmhearted = true; |
|
|
|
} |
|
|
|
if (EpmetRoleKeyConstant.PARTYMEMBER.equals(role.getRoleKey())) { |
|
|
|
isPartymember = true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!isWarmhearted && isPartymember) { |
|
|
|
throw new RenException(EpmetErrorCode.CANNOT_CREATE_GROUP.getCode(), "只有党员和热心居民才能创建和编辑小组"); |
|
|
|
} |
|
|
|
String roleName = ""; |
|
|
|
if (isPartymember) { |
|
|
|
roleName = ModuleConstant.PARTYMEMBER; |
|
|
|
} else if (isWarmhearted) { |
|
|
|
roleName = ModuleConstant.WAREMHEARTED_RESI; |
|
|
|
} |
|
|
|
|
|
|
|
//3.获取居民注册信息
|
|
|
|
UserResiInfoFormDTO resiParam = new UserResiInfoFormDTO(); |
|
|
|
resiParam.setCustomerId(customerId); |
|
|
|
resiParam.setUserId(userId); |
|
|
|
Result<UserResiInfoResultDTO> resiResult = |
|
|
|
epmetUserFeignClient.getUserResiInfoDTO(resiParam); |
|
|
|
String userName = ""; |
|
|
|
if (resiResult.success() && null != resiResult.getData()) { |
|
|
|
userName = (StringUtils.isBlank(resiResult.getData().getSurname()) ? "" : resiResult.getData().getSurname()) |
|
|
|
+ (StringUtils.isBlank(resiResult.getData().getName()) ? "" : resiResult.getData().getName()); |
|
|
|
} |
|
|
|
userName = StringUtils.isBlank(userName) ? ModuleConstant.UNKNOWN : userName; |
|
|
|
return String.format(UserMessageConstant.EDIT_OF_GROUP_MESSAGE_TEMPLATE, roleName, userName, groupName); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询居民的角色列表 |
|
|
|
* @param app |
|
|
|
* @param customerId |
|
|
|
* @param userId |
|
|
|
* @param gridId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<UserRoleResultDTO> getResiRoles(String app, String customerId, String userId, String gridId) { |
|
|
|
UserRoleFormDTO userRoleFormDTO = new UserRoleFormDTO(); |
|
|
|
userRoleFormDTO.setApp(app); |
|
|
|
userRoleFormDTO.setCustomerId(customerId); |
|
|
|
userRoleFormDTO.setUserId(userId); |
|
|
|
userRoleFormDTO.setGridId(gridId); |
|
|
|
Result<List<UserRoleResultDTO>> rolesResult = epmetUserFeignClient.getUserRoleInfo(userRoleFormDTO); |
|
|
|
|
|
|
|
if (! rolesResult.success()) { |
|
|
|
logger.error("修改组信息:查询居民角色失败,详情:{}", rolesResult.getInternalMsg()); |
|
|
|
throw new RenException(EpmetErrorCode.GROUP_EDIT_ERROR.getCode(), "查询居民角色失败"); |
|
|
|
} else { |
|
|
|
List<UserRoleResultDTO> roles = rolesResult.getData(); |
|
|
|
if (CollectionUtils.isEmpty(roles)) { |
|
|
|
roles = new ArrayList<>(); |
|
|
|
} |
|
|
|
return roles; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 内容检查 |
|
|
|
* @param groupName |
|
|
|
* @param groupIntroduction |
|
|
|
* @param groupHeadPhoto |
|
|
|
*/ |
|
|
|
private void scanGroupEditContent(String groupName, String groupIntroduction, String groupHeadPhoto) { |
|
|
|
// 文本内容审核
|
|
|
|
TextScanParamDTO textScanParamDTO = new TextScanParamDTO(); |
|
|
|
TextTaskDTO taskDTO = new TextTaskDTO(); |
|
|
|
String content = groupName.concat("-").concat(groupIntroduction); |
|
|
|
taskDTO.setContent(content); |
|
|
|
taskDTO.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
textScanParamDTO.getTasks().add(taskDTO); |
|
|
|
Result<SyncScanResult> textSyncScanResult = ScanContentUtils.textSyncScan(scanApiUrl.concat(textSyncScanMethod), textScanParamDTO); |
|
|
|
if (!textSyncScanResult.success()) { |
|
|
|
logger.error("调用内容审核服务审核文本发生错误:{}", textSyncScanResult.getInternalMsg()); |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
} else { |
|
|
|
if (!textSyncScanResult.getData().isAllPass()) { |
|
|
|
throw new RenException(EpmetErrorCode.TEXT_SCAN_FAILED.getCode(), EpmetErrorCode.TEXT_SCAN_FAILED.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 图片内容审核
|
|
|
|
ImgScanParamDTO imgScanParamDTO = new ImgScanParamDTO(); |
|
|
|
ImgTaskDTO task = new ImgTaskDTO(); |
|
|
|
task.setDataId(UUID.randomUUID().toString().replace("-", "")); |
|
|
|
task.setUrl(groupHeadPhoto); |
|
|
|
imgScanParamDTO.getTasks().add(task); |
|
|
|
|
|
|
|
Result<SyncScanResult> imgScanResult = ScanContentUtils.imgSyncScan(scanApiUrl.concat(imgSyncScanMethod), imgScanParamDTO); |
|
|
|
if (!imgScanResult.success()){ |
|
|
|
logger.error("调用内容审核服务审核图片发生错误:{}", textSyncScanResult.getInternalMsg()); |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
} else { |
|
|
|
if (!textSyncScanResult.getData().isAllPass()) { |
|
|
|
throw new RenException(EpmetErrorCode.IMG_SCAN_FAILED.getCode(), EpmetErrorCode.IMG_SCAN_FAILED.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|