|
|
@@ -295,7 +295,9 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
|
|
|
//查询是否保存为草稿
|
|
|
Integer isDraft = dto.getIsDraft();
|
|
|
- if (isDraft == 1) {
|
|
|
+ boolean draft = Objects.equals(isDraft, 1);
|
|
|
+ String cityCode = validatePublishCityCode(dto, draft);
|
|
|
+ if (draft) {
|
|
|
//只校验标题
|
|
|
if (dto.getTitle() == null || dto.getTitle().trim().isEmpty()) {
|
|
|
throw new ServiceException("动态标题不能为空");
|
|
|
@@ -341,6 +343,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setLongitude(dto.getLongitude());
|
|
|
moment.setLocation(dto.getLocation());
|
|
|
moment.setAddress(dto.getAddress());
|
|
|
+ moment.setCityCode(cityCode);
|
|
|
|
|
|
if(Objects.nonNull(dto.getMediaType())){
|
|
|
// 设置封面图
|
|
|
@@ -356,7 +359,7 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
}
|
|
|
|
|
|
// 设置审核状态和发布时间
|
|
|
- if (dto.getIsDraft() != null && dto.getIsDraft() == 1) {
|
|
|
+ if (draft) {
|
|
|
// 保存草稿
|
|
|
moment.setAuditStatus(0);
|
|
|
moment.setPublishTime(null);
|
|
|
@@ -370,7 +373,6 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
moment.setIsDelete(0);
|
|
|
moment.setViewCount(0);
|
|
|
moment.setCreateTime(LocalDateTime.now());
|
|
|
- moment.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
// 8. 保存动态到数据库
|
|
|
int insertResult = momentMapper.insert(moment);
|
|
|
@@ -413,6 +415,28 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
|
|
|
return momentId;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证发布的城市code
|
|
|
+ *
|
|
|
+ * @param dto 发布动态请求对象
|
|
|
+ * @param draft 是否草稿
|
|
|
+ * @return String 城市编码
|
|
|
+ */
|
|
|
+ private String validatePublishCityCode(PublishMomentDTO dto, boolean draft) {
|
|
|
+ String cityCode = StringUtils.trimToNull(dto.getCityCode());
|
|
|
+ if (draft && StringUtils.isBlank(cityCode)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(cityCode)) {
|
|
|
+ throw new ServiceException("城市编码不能为空");
|
|
|
+ }
|
|
|
+ Boolean cityOpened = maTechnicianMapper.isHasMerchantCity(cityCode);
|
|
|
+ if (!Boolean.TRUE.equals(cityOpened)) {
|
|
|
+ throw new ServiceException("当前城市暂未开通服务");
|
|
|
+ }
|
|
|
+ return cityCode;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 编辑动态
|
|
|
*
|