Browse Source

推广海报

zoujiajian 2 năm trước cách đây
mục cha
commit
d30ecca099

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/DistributePosterGoods.java

@@ -22,4 +22,6 @@ public class DistributePosterGoods extends BaseEntity{
 	private String skuIds;
 
 	private String img;
+
+	private Boolean status;
 }

+ 52 - 0
netflix-dao/src/main/java/com/cyksj/model/views/DistributePosterGoodsView.java

@@ -0,0 +1,52 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: DistributePosterGoodsView
+ * 创建者: JavaZou
+ * 创建时间:2024/6/24 15:48
+ */
+
+@Getter
+@Setter
+@SearchBean(tables = "distribute_poster_goods dp inner join goods_don g on g.id = dp.goods_id",
+		orderBy = "dp.update_time desc")
+public class DistributePosterGoodsView {
+	@DbField("dp.id")
+	private Long id;
+
+	@DbField("dp.name")
+	public String name;
+
+	@DbField("g.title")
+	private String title;
+
+	@DbField("g.id")
+	private Long goodsId;
+
+	@DbField("dp.sku_ids")
+	private String skuIds;
+
+	@DbIgnore
+	private String specVal;
+
+	@DbField("dp.img")
+	private String img;
+
+	@DbField("dp.status")
+	private Boolean status;
+
+	@DbField("dp.created_time")
+	private Date createdTIme;
+
+	@DbField("dp.update_time")
+	private Date updateTime;
+}

+ 14 - 0
netflix-service/src/main/java/com/cyksj/service/distribute/DistributePosterGoodsService.java

@@ -0,0 +1,14 @@
+package com.cyksj.service.distribute;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.cyksj.model.entity.DistributePosterGoods;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: DistributePosterGoodsService
+ * 创建者: JavaZou
+ * 创建时间:2024/6/24 15:41
+ */
+public interface DistributePosterGoodsService extends IService<DistributePosterGoods> {
+	void saveOrUpdatePo(DistributePosterGoods distributePosterGoods) throws Exception;
+}

+ 44 - 0
netflix-service/src/main/java/com/cyksj/service/distribute/impl/DistributePosterGoodsServiceImp.java

@@ -0,0 +1,44 @@
+package com.cyksj.service.distribute.impl;
+
+import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.mapper.GoodsDonMapper;
+import com.cyksj.mapper.manage.distribute.DistributePosterGoodsMapper;
+import com.cyksj.model.entity.DistributePosterGoods;
+import com.cyksj.model.entity.GoodsDon;
+import com.cyksj.service.distribute.DistributePosterGoodsService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: DistributePosterGoodsServiceImp
+ * 创建者: JavaZou
+ * 创建时间:2024/6/24 15:42
+ */
+@Service
+@RequiredArgsConstructor
+public class DistributePosterGoodsServiceImp extends ServiceImpl<DistributePosterGoodsMapper, DistributePosterGoods> implements DistributePosterGoodsService {
+
+	private final GoodsDonMapper goodsDonMapper;
+
+	@Override
+	public void saveOrUpdatePo(DistributePosterGoods distributePosterGoods) throws Exception {
+		Assert.notEmpty(distributePosterGoods.getImg(), "海报不为空");
+
+		Long goodsId = distributePosterGoods.getGoodsId();
+
+		GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
+
+		if (goodsDon.getIsSkuDistribute() && StrUtil.isEmpty(distributePosterGoods.getSkuIds())) {
+			throw BusinessRuntimeException.getInstance("请选择对应的规格");
+		}
+
+		distributePosterGoods.setSkuIds(Jsons.toJson(Jsons.parseList(distributePosterGoods.getSkuIds(), Long.class)));
+
+		this.saveOrUpdate(distributePosterGoods);
+	}
+}

+ 101 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/distribute/DistributePosterController.java

@@ -0,0 +1,101 @@
+package com.cyksj.web.controller.manage.distribute;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.GoodsDonSkuMapper;
+import com.cyksj.model.entity.DistributePosterGoods;
+import com.cyksj.model.entity.GoodsDonSku;
+import com.cyksj.model.views.DistributePosterGoodsView;
+import com.cyksj.service.distribute.DistributePosterGoodsService;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: DistributePosterController
+ * 创建者: JavaZou
+ * 创建时间:2024/6/24 15:38
+ */
+
+@RestController
+@RequestMapping("/manage/distribute/poster")
+@RequiredArgsConstructor
+public class DistributePosterController {
+	private final DistributePosterGoodsService distributePosterGoodsService;
+
+	private final BeanSearcher beanSearcher;
+
+	private final HttpServletRequest request;
+
+	private final GoodsDonSkuMapper skuMapper;
+
+	/**
+	 * 新增海报
+	 */
+	@PostMapping("/post")
+	public Result<String> post(@RequestBody DistributePosterGoods distributePosterGoods) throws Exception {
+		distributePosterGoodsService.saveOrUpdatePo(distributePosterGoods);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 删除海报
+	 */
+	@DeleteMapping("/del/{id}")
+	public Result<String> del(@PathVariable Long id) {
+		distributePosterGoodsService.removeById(id);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 编辑海报
+	 */
+	@PutMapping("/update")
+	public Result<String> update(@RequestBody DistributePosterGoods distributePosterGoods) throws Exception {
+		distributePosterGoodsService.saveOrUpdatePo(distributePosterGoods);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 海报列表
+	 */
+	@GetMapping("/get")
+	public Result<SearchResult<DistributePosterGoodsView>> get() {
+		SearchResult<DistributePosterGoodsView> search = beanSearcher.search(DistributePosterGoodsView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
+		search.getDataList().forEach(e -> {
+			if (StrUtil.isNotBlank(e.getSkuIds())) {
+				try {
+					String specVal = skuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
+									.in(GoodsDonSku::getId, Jsons.parseSet(e.getSkuIds(), Long.class)))
+							.stream().map(GoodsDonSku::getSpecVal).collect(Collectors.joining(","));
+					e.setSpecVal(specVal);
+				} catch (Exception ex) {
+				}
+			}
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
+
+	/**
+	 * 海报上下架
+	 */
+	@PutMapping("/update/status/{id}")
+	public Result<String> updateStatus(@PathVariable Long id) {
+		Optional.ofNullable(distributePosterGoodsService.getById(id))
+				.ifPresent(e -> {
+					e.setStatus(!e.getStatus());
+					distributePosterGoodsService.updateById(e);
+				});
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+}