|
|
@@ -1,10 +1,105 @@
|
|
|
package com.cyksj.web.controller.manage.mirrorshop.manage;
|
|
|
|
|
|
+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.model.entity.UserMirrorShopManageAdvertise;
|
|
|
+import com.cyksj.service.mirrorshop.UserMirrorShopAdvertiseService;
|
|
|
+import com.cyksj.web.util.StpUserMirrorShopManageUser;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
/**
|
|
|
* 项目名: yhlxj2
|
|
|
* 文件名: CmsUserMirrorAdvertiseController
|
|
|
* 创建者: JavaZou
|
|
|
* 创建时间:2024/11/7 12:04
|
|
|
*/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/mirrorShop/manage/ad")
|
|
|
+@RequiredArgsConstructor
|
|
|
public class CmsUserMirrorAdvertiseController {
|
|
|
+
|
|
|
+ private final UserMirrorShopAdvertiseService userMirrorShopAdvertiseService;
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final HttpServletRequest request;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 店铺公告列表
|
|
|
+ */
|
|
|
+ @GetMapping("/get")
|
|
|
+ public Result<SearchResult<UserMirrorShopManageAdvertise>> get() {
|
|
|
+ long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ SearchResult<UserMirrorShopManageAdvertise> search = beanSearcher.search(UserMirrorShopManageAdvertise.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(UserMirrorShopManageAdvertise::getUserId, userId)
|
|
|
+ .orderBy(UserMirrorShopManageAdvertise::getUpdateTime).desc()
|
|
|
+ .build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增店铺公告
|
|
|
+ */
|
|
|
+ @PostMapping("/post")
|
|
|
+ public Result<String> post(@RequestBody UserMirrorShopManageAdvertise advertise) {
|
|
|
+ long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ advertise.setUserId(userId);
|
|
|
+ userMirrorShopAdvertiseService.saveOrUpdate(advertise);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑店铺公告
|
|
|
+ */
|
|
|
+ @PutMapping("/update")
|
|
|
+ public Result<String> update(@RequestBody UserMirrorShopManageAdvertise advertise) {
|
|
|
+ Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ UserMirrorShopManageAdvertise byId = userMirrorShopAdvertiseService.getById(advertise.getId());
|
|
|
+ if (byId == null || !ObjectUtil.equal(userId, byId.getUserId())) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+ userMirrorShopAdvertiseService.saveOrUpdate(advertise);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上下架店铺公告
|
|
|
+ */
|
|
|
+ @PutMapping("/update/status/{id}")
|
|
|
+ public Result<String> updateStatusById(@PathVariable Long id) {
|
|
|
+ Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ Optional.ofNullable(userMirrorShopAdvertiseService.getById(id))
|
|
|
+ .ifPresent(en -> {
|
|
|
+ if (!en.getUserId().equals(userId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ en.setStatus(!en.getStatus());
|
|
|
+ userMirrorShopAdvertiseService.updateById(en);
|
|
|
+ });
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除店铺公告
|
|
|
+ */
|
|
|
+ @PutMapping("/delete/{id}")
|
|
|
+ public Result<String> deleteById(@PathVariable Long id) {
|
|
|
+ Long userId = StpUserMirrorShopManageUser.getLoginIdAsLong();
|
|
|
+ userMirrorShopAdvertiseService.remove(Wrappers.lambdaQuery(UserMirrorShopManageAdvertise.class)
|
|
|
+ .eq(UserMirrorShopManageAdvertise::getId, id)
|
|
|
+ .eq(UserMirrorShopManageAdvertise::getUserId, userId));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
}
|