|
|
@@ -4,13 +4,13 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.MirrorNoticeMapper;
|
|
|
+import com.cyksj.mapper.mirrorshop.MirrorNoticeUserMapper;
|
|
|
import com.cyksj.mapper.mirrorshop.MirrorNoticeUserReviewRecordMapper;
|
|
|
-import com.cyksj.mapper.mirrorshop.MirrorNoticeUserStatusRelateMapper;
|
|
|
import com.cyksj.model.entity.MirrorNotice;
|
|
|
+import com.cyksj.model.entity.MirrorNoticeUser;
|
|
|
import com.cyksj.model.entity.MirrorNoticeUserReviewRecord;
|
|
|
-import com.cyksj.model.entity.MirrorNoticeUserStatusRelate;
|
|
|
import com.cyksj.service.mange.RefreshCacheService;
|
|
|
-import com.cyksj.service.sys.MirrorNoticeService;
|
|
|
import com.cyksj.web.util.StpUserMirrorShopManageUser;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
@@ -21,6 +21,7 @@ import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
@@ -39,11 +40,11 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
|
|
|
private final HttpServletRequest request;
|
|
|
|
|
|
- private final MirrorNoticeService mirrorNoticeService;
|
|
|
+ private final MirrorNoticeUserMapper noticeUserMapper;
|
|
|
|
|
|
private final RefreshCacheService refreshCacheService;
|
|
|
|
|
|
- private final MirrorNoticeUserStatusRelateMapper MirrorNoticeUserStatusRelateMapper;
|
|
|
+ private final MirrorNoticeMapper mirrorNoticeMapper;
|
|
|
|
|
|
private final MirrorNoticeUserReviewRecordMapper mirrorNoticeUserReviewRecordMapper;
|
|
|
|
|
|
@@ -51,23 +52,15 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
* 店铺公告列表
|
|
|
*/
|
|
|
@GetMapping("/get")
|
|
|
- public Result<SearchResult<MirrorNotice>> get(@RequestParam(defaultValue = "1") Boolean self) {
|
|
|
+ public Result<SearchResult> get(@RequestParam(defaultValue = "1") Boolean self) {
|
|
|
long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
- if (self) {
|
|
|
- builder.put("uid", String.format("ua.user_id in (0,%s)", userId));
|
|
|
- } else {
|
|
|
- builder.field(MirrorNotice::getUserId, 0);
|
|
|
+ if (true) {
|
|
|
+ SearchResult<MirrorNoticeUser> search = beanSearcher.search(MirrorNoticeUser.class, builder.field(MirrorNoticeUser::getUserId, userId).orderBy(MirrorNoticeUser::getUpdateTime).desc().build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
builder.put("ruid", String.format(" and myr.user_id = %s", userId));
|
|
|
SearchResult<MirrorNotice> search = beanSearcher.search(MirrorNotice.class, builder.orderBy(MirrorNotice::getUpdateTime).desc().build());
|
|
|
- search.getDataList().forEach(data -> {
|
|
|
- if (data.getUserId() == 0) {
|
|
|
- Optional.ofNullable(MirrorNoticeUserStatusRelateMapper.selectOne(Wrappers.lambdaQuery(MirrorNoticeUserStatusRelate.class).eq(MirrorNoticeUserStatusRelate::getNoticeId, data.getId())
|
|
|
- .eq(MirrorNoticeUserStatusRelate::getUserId, userId)
|
|
|
- .last("limit 1"))).ifPresent(e -> data.setStatus(e.getStatus()));
|
|
|
- }
|
|
|
- });
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
@@ -76,10 +69,10 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
* 新增店铺公告
|
|
|
*/
|
|
|
@PostMapping("/post")
|
|
|
- public Result<String> post(@RequestBody MirrorNotice notice) {
|
|
|
+ public Result<String> post(@RequestBody MirrorNoticeUser notice) {
|
|
|
long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
notice.setUserId(userId);
|
|
|
- mirrorNoticeService.saveOrUpdate(notice);
|
|
|
+ noticeUserMapper.insert(notice);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
@@ -88,13 +81,13 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
* 编辑店铺公告
|
|
|
*/
|
|
|
@PutMapping("/update")
|
|
|
- public Result<String> update(@RequestBody MirrorNotice notice) {
|
|
|
+ public Result<String> update(@RequestBody MirrorNoticeUser notice) {
|
|
|
Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
- MirrorNotice byId = mirrorNoticeService.getById(notice.getId());
|
|
|
+ MirrorNoticeUser byId = noticeUserMapper.selectById(notice.getId());
|
|
|
if (byId == null || !ObjectUtil.equal(userId, byId.getUserId())) {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
- mirrorNoticeService.saveOrUpdate(notice);
|
|
|
+ noticeUserMapper.updateById(notice);
|
|
|
refreshCacheService.refreshUserMirrorShopAdvertiseCache(userId);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
@@ -106,30 +99,10 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
@PutMapping("/update/status/{id}")
|
|
|
public Result<String> updateStatusById(@PathVariable Long id) {
|
|
|
Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
- Optional.ofNullable(mirrorNoticeService.getById(id))
|
|
|
+ Optional.ofNullable(noticeUserMapper.selectById(id))
|
|
|
.ifPresent(en -> {
|
|
|
- if (en.getUserId() != 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- //官方公告
|
|
|
- if (!en.getUserId().equals(userId)) {
|
|
|
- MirrorNoticeUserStatusRelate mirrorNoticeUserStatusRelate = Optional.ofNullable(MirrorNoticeUserStatusRelateMapper.selectOne(Wrappers.lambdaQuery(MirrorNoticeUserStatusRelate.class)
|
|
|
- .eq(MirrorNoticeUserStatusRelate::getUserId, userId)
|
|
|
- .eq(MirrorNoticeUserStatusRelate::getNoticeId, id).last("limit 1"))).orElse(new MirrorNoticeUserStatusRelate());
|
|
|
-
|
|
|
- mirrorNoticeUserStatusRelate.setNoticeId(id);
|
|
|
- mirrorNoticeUserStatusRelate.setUserId(userId);
|
|
|
- if (mirrorNoticeUserStatusRelate.getId() == null) {
|
|
|
- mirrorNoticeUserStatusRelate.setStatus(!en.getStatus());
|
|
|
- MirrorNoticeUserStatusRelateMapper.insert(mirrorNoticeUserStatusRelate);
|
|
|
- } else {
|
|
|
- mirrorNoticeUserStatusRelate.setStatus(!mirrorNoticeUserStatusRelate.getStatus());
|
|
|
- MirrorNoticeUserStatusRelateMapper.updateById(mirrorNoticeUserStatusRelate);
|
|
|
- }
|
|
|
- } else {
|
|
|
- en.setStatus(!en.getStatus());
|
|
|
- mirrorNoticeService.updateById(en);
|
|
|
- }
|
|
|
+ en.setStatus(!en.getStatus());
|
|
|
+ noticeUserMapper.updateById(en);
|
|
|
refreshCacheService.refreshUserMirrorShopAdvertiseCache(userId);
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
@@ -141,9 +114,9 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
@PutMapping("/delete/{id}")
|
|
|
public Result<String> deleteById(@PathVariable Long id) {
|
|
|
Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
- mirrorNoticeService.remove(Wrappers.lambdaQuery(MirrorNotice.class)
|
|
|
- .eq(MirrorNotice::getId, id)
|
|
|
- .eq(MirrorNotice::getUserId, userId));
|
|
|
+ noticeUserMapper.delete(Wrappers.lambdaQuery(MirrorNoticeUser.class)
|
|
|
+ .eq(MirrorNoticeUser::getId, id)
|
|
|
+ .eq(MirrorNoticeUser::getUserId, userId));
|
|
|
refreshCacheService.refreshUserMirrorShopAdvertiseCache(userId);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
@@ -154,7 +127,6 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
@PostMapping("/mark/{id}")
|
|
|
public Result<String> markNotice(@PathVariable Long id) {
|
|
|
Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
- MirrorNotice byId = mirrorNoticeService.getById(id);
|
|
|
MirrorNoticeUserReviewRecord mirrorNoticeUserReviewRecord = Optional.ofNullable(mirrorNoticeUserReviewRecordMapper.selectOne(Wrappers.lambdaQuery(MirrorNoticeUserReviewRecord.class)
|
|
|
.eq(MirrorNoticeUserReviewRecord::getNoticeId, id)
|
|
|
.eq(MirrorNoticeUserReviewRecord::getUserId, userId)
|
|
|
@@ -171,4 +143,31 @@ public class CmsUserMirrorAdvertiseController {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量同步银河后台公告
|
|
|
+ */
|
|
|
+ @PostMapping("/sync/background/notice")
|
|
|
+ public Result<String> syncBackgroundNotice(@RequestBody List<Long> ids) {
|
|
|
+ Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ mirrorNoticeMapper.selectBatchIds(ids).forEach(backNotice -> {
|
|
|
+ MirrorNoticeUser mirrorNoticeUser = noticeUserMapper.selectOne(Wrappers.lambdaQuery(MirrorNoticeUser.class)
|
|
|
+ .eq(MirrorNoticeUser::getNoticeId, backNotice.getId())
|
|
|
+ .eq(MirrorNoticeUser::getUserId, userId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (mirrorNoticeUser == null) {
|
|
|
+ try {
|
|
|
+ mirrorNoticeUser = new MirrorNoticeUser();
|
|
|
+ mirrorNoticeUser.setNoticeId(backNotice.getId());
|
|
|
+ mirrorNoticeUser.setPlatform(backNotice.getPlatform());
|
|
|
+ mirrorNoticeUser.setTitle(backNotice.getTitle());
|
|
|
+ mirrorNoticeUser.setText(backNotice.getText());
|
|
|
+ noticeUserMapper.insert(mirrorNoticeUser);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
}
|