diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeAuditFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeAuditFormDTO.java index f7d3deac7d..c3748fe49f 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeAuditFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeAuditFormDTO.java @@ -3,6 +3,7 @@ package com.epmet.dto.form; import lombok.Data; import lombok.NoArgsConstructor; +import javax.validation.constraints.NotBlank; import java.io.Serializable; /** @@ -14,7 +15,9 @@ import java.io.Serializable; @Data public class BadgeAuditFormDTO implements Serializable { private static final long serialVersionUID = 2209535364555130964L; + @NotBlank(message = "申请记录Id不能为空") private String recordId; + @NotBlank(message = "审核结果不能为空") private String auditStatus; private String auditRemark; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeFormDTO.java index 5a40b86f0f..66384607cf 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/BadgeFormDTO.java @@ -2,6 +2,7 @@ package com.epmet.dto.form; import lombok.Data; +import javax.validation.constraints.NotBlank; import java.io.Serializable; /** @@ -12,6 +13,9 @@ import java.io.Serializable; @Data public class BadgeFormDTO implements Serializable { private static final long serialVersionUID = 9156247659994638103L; + public interface ManageGroup {} + public interface AuditGroup {} + @NotBlank(message = "徽章id不能为空", groups = {ManageGroup.class}) private String badgeId; /** * 页码 @@ -24,5 +28,6 @@ public class BadgeFormDTO implements Serializable { /** * 网格Id */ + @NotBlank(message = "网格id不能为空", groups = {AuditGroup.class}) private String gridId; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditBadgeFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditBadgeFormDTO.java index e11d2e107c..7b8cc1fb4a 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditBadgeFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/EditBadgeFormDTO.java @@ -16,6 +16,7 @@ import java.util.List; @Data public class EditBadgeFormDTO implements Serializable { private static final long serialVersionUID = 1578890423002035200L; + @NotBlank(message = "徽章ID不能为空") private String badgeId; /** * 徽章名称 diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/BadgeController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/BadgeController.java index c284939571..cabe4b0a98 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/BadgeController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/BadgeController.java @@ -68,6 +68,7 @@ public class BadgeController { */ @PostMapping("detail") public Result detail(@LoginUser TokenDto tokenDto, @RequestBody BadgeFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, BadgeFormDTO.ManageGroup.class); BadgeDetailResultDTO result = badgeService.detail(tokenDto, formDTO); return new Result().ok(result); } @@ -97,6 +98,7 @@ public class BadgeController { */ @PostMapping("delete") public Result delete(@LoginUser TokenDto tokenDto, @RequestBody BadgeFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, BadgeFormDTO.ManageGroup.class); badgeService.deleteBadge(tokenDto, formDTO); return new Result(); } @@ -116,6 +118,7 @@ public class BadgeController { */ @PostMapping("auditinglist") public Result> auditingList(@LoginUser TokenDto tokenDto, @RequestBody BadgeFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, BadgeFormDTO.AuditGroup.class); List result = badgeService.auditingList(tokenDto, formDTO); return new Result>().ok(result); } @@ -130,6 +133,7 @@ public class BadgeController { */ @PostMapping("auditrecord") public Result> auditRecord(@LoginUser TokenDto tokenDto, @RequestBody BadgeFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, BadgeFormDTO.AuditGroup.class); List result = badgeService.auditRecord(tokenDto, formDTO); return new Result>().ok(result); } @@ -144,6 +148,7 @@ public class BadgeController { */ @PostMapping("audit") public Result audit(@LoginUser TokenDto tokenDto, @RequestBody BadgeAuditFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO); badgeService.audit(tokenDto, formDTO); return new Result(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/BadgeServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/BadgeServiceImpl.java index b66faf5095..b7f21c0845 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/BadgeServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/BadgeServiceImpl.java @@ -17,6 +17,7 @@ package com.epmet.service.impl; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; @@ -25,9 +26,11 @@ import com.epmet.commons.tools.constant.FieldConstant; 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.exception.ValidateException; import com.epmet.commons.tools.page.PageData; 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.constant.BadgeConstant; import com.epmet.constant.BadgeMessageConstant; import com.epmet.constant.UserConstant; @@ -42,9 +45,11 @@ import com.epmet.dto.result.BadgeDetailResultDTO; import com.epmet.dto.result.BadgeListResultDTO; import com.epmet.entity.BadgeCertificationConfigEntity; import com.epmet.entity.BadgeEntity; +import com.epmet.feign.EpmetMessageOpenFeignClient; import com.epmet.feign.MessageFeignClient; import com.epmet.redis.UserBadgeRedis; import com.epmet.service.*; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -60,6 +65,7 @@ import java.util.*; * @since v1.0.0 2020-11-03 */ @Service +@Slf4j public class BadgeServiceImpl extends BaseServiceImpl implements BadgeService { @Autowired @@ -74,6 +80,9 @@ public class BadgeServiceImpl extends BaseServiceImpl imp private ResiUserBadgeService resiUserBadgeService; @Autowired private MessageFeignClient messageFeignClient; + @Autowired + private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Override @@ -322,6 +331,11 @@ public class BadgeServiceImpl extends BaseServiceImpl imp */ @Override public void audit(TokenDto tokenDto, BadgeAuditFormDTO formDTO) { + if(BadgeConstant.REJECTED.equals(formDTO.getAuditStatus())) { + if (StringUtils.isEmpty(formDTO.getAuditRemark())) { + throw new ValidateException(EpmetErrorCode.CUSTOMER_VALIDATE_ERROR.getCode(), "驳回理由不能为空"); + } + } UserBadgeCertificateRecordDTO dto = userBadgeCertificateRecordService.get(formDTO.getRecordId()); BadgeDetailResultDTO detail = baseDao.selectDetail(dto.getCustomerId(), dto.getBadgeId()); dto.setAuditStatus(formDTO.getAuditStatus()); @@ -329,48 +343,71 @@ public class BadgeServiceImpl extends BaseServiceImpl imp dto.setStaffId(tokenDto.getUserId()); dto.setIsLast(BadgeConstant.YES); dto.setAuditTime(new Date()); - userBadgeCertificateRecordService.update(dto); - ResiUserBadgeDTO resiUserBadgeDTO = new ResiUserBadgeDTO(); - resiUserBadgeDTO.setCustomerId(dto.getCustomerId()); - resiUserBadgeDTO.setBadgeId(dto.getBadgeId()); - resiUserBadgeDTO.setGridId(dto.getGridId()); - resiUserBadgeDTO.setUserId(dto.getUserId()); - resiUserBadgeDTO.setIsOpened(NumConstant.ZERO); - resiUserBadgeDTO.setCertificationAutidStatus(dto.getAuditStatus()); - resiUserBadgeService.save(resiUserBadgeDTO); - List msgList = new ArrayList<>(); + List wxmpMsgList = new ArrayList<>(); if(BadgeConstant.APPROVED.equals(formDTO.getAuditStatus())) { + + ResiUserBadgeDTO resiUserBadgeDTO = new ResiUserBadgeDTO(); + resiUserBadgeDTO.setCustomerId(dto.getCustomerId()); + resiUserBadgeDTO.setBadgeId(dto.getBadgeId()); + resiUserBadgeDTO.setGridId(dto.getGridId()); + resiUserBadgeDTO.setUserId(dto.getUserId()); + resiUserBadgeDTO.setIsOpened(NumConstant.ONE); + resiUserBadgeDTO.setCertificationAutidStatus(dto.getAuditStatus()); + resiUserBadgeService.save(resiUserBadgeDTO); //更新Redis - OpenedOrClosedFormDTO openedOrClosedFormDTO = new OpenedOrClosedFormDTO(); - openedOrClosedFormDTO.setCustomerId(dto.getCustomerId()); - openedOrClosedFormDTO.setUserId(dto.getUserId()); - openedOrClosedFormDTO.setBadgeId(dto.getBadgeId()); - userBadgeService.openedOrClosed(openedOrClosedFormDTO); + badgeRedis.pushOrRemoveUserBadge4List(dto.getUserId(),dto.getBadgeId(),dto.getCustomerId()); //通知 + String msg = String.format(BadgeMessageConstant.APPROVED_MSG, detail.getBadgeName()); UserMessageFormDTO messageFormDTO = new UserMessageFormDTO(); messageFormDTO.setCustomerId(dto.getCustomerId()); messageFormDTO.setApp(UserConstant.APP_RESI); messageFormDTO.setGridId(dto.getGridId()); messageFormDTO.setUserId(dto.getUserId()); messageFormDTO.setTitle(BadgeMessageConstant.TITLE); - messageFormDTO.setMessageContent(String.format(BadgeMessageConstant.APPROVED_MSG, detail.getBadgeName())); + messageFormDTO.setMessageContent(msg); messageFormDTO.setReadFlag(Constant.UNREAD); + //微信消息 + WxSubscribeMessageFormDTO wxmp = new WxSubscribeMessageFormDTO(); + wxmp.setCustomerId(dto.getCustomerId()); + wxmp.setClientType(UserConstant.APP_RESI); + wxmp.setUserId(dto.getUserId()); + wxmp.setBehaviorType("徽章消息"); + wxmp.setMessageContent(msg); + wxmp.setMessageTime(new Date()); + wxmp.setGridId(dto.getGridId()); + wxmpMsgList.add(wxmp); } else { //通知 + String msg = String.format(BadgeMessageConstant.REJECTED_MSG, detail.getBadgeName(), formDTO.getAuditRemark()); UserMessageFormDTO messageFormDTO = new UserMessageFormDTO(); messageFormDTO.setCustomerId(dto.getCustomerId()); messageFormDTO.setApp(UserConstant.APP_RESI); messageFormDTO.setGridId(dto.getGridId()); messageFormDTO.setUserId(dto.getUserId()); messageFormDTO.setTitle(BadgeMessageConstant.TITLE); - messageFormDTO.setMessageContent(String.format(BadgeMessageConstant.REJECTED_MSG, detail.getBadgeName(), formDTO.getAuditRemark())); + messageFormDTO.setMessageContent(msg); messageFormDTO.setReadFlag(Constant.UNREAD); msgList.add(messageFormDTO); + //微信消息 + WxSubscribeMessageFormDTO wxmp = new WxSubscribeMessageFormDTO(); + wxmp.setCustomerId(dto.getCustomerId()); + wxmp.setClientType(UserConstant.APP_RESI); + wxmp.setUserId(dto.getUserId()); + wxmp.setBehaviorType("徽章消息"); + wxmp.setMessageContent(msg); + wxmp.setMessageTime(new Date()); + wxmp.setGridId(dto.getGridId()); + wxmpMsgList.add(wxmp); } messageFeignClient.saveUserMessageList(msgList); + log.info("徽章消息,开始推送微信订阅消息"); + Result result = epmetMessageOpenFeignClient.sendWxSubscribeMessage(wxmpMsgList); + if (!result.success()) { + log.error("徽章消息,发送微信订阅消息失败" + JSON.toJSONString(result)); + } } @Override