主页-我的课程

This commit is contained in:
wuchunlei
2024-04-11 09:05:34 +08:00
parent fe14ece2a3
commit b705aec11d
68 changed files with 1772 additions and 4 deletions

View File

@@ -0,0 +1,4 @@
package com.peanut.modules.master.controller;
public class MedicineLabelAndMarketController {
}

View File

@@ -0,0 +1,359 @@
package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.master.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* 众妙之门国学商品标签、营销标签管理
*/
@Slf4j
@RestController("masterSociologyLabelAndMarket")
@RequestMapping("master/sociologyLabelAndMarket")
public class SociologyLabelAndMarketController {
@Autowired
private ShopProductSociologyLabelService labelService;
@Autowired
private ShopProductSociologyMarketService marketService;
@Autowired
private ShopProductToSociologyLabelService toLabelService;
@Autowired
private ShopProductToSociologyMarketService toMarketService;
@Autowired
private ShopProductService productService;
/**
* 标签树
*/
@RequestMapping(path = "/labelTree")
public R labelTree() {
List<ShopProductSociologyLabel> labelsTree = labelService.labelTree();
return R.ok().put("result", labelsTree);
}
/**
* 获取标签列表
*/
@RequestMapping(path = "/getLabelListByPid")
public R getLabelListByPid(String pid) {
LambdaQueryWrapper<ShopProductSociologyLabel> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductSociologyLabel::getPid,pid);
wrapper.orderByAsc(ShopProductSociologyLabel::getSort);
wrapper.orderByAsc(ShopProductSociologyLabel::getCreateTime);
List<ShopProductSociologyLabel> labelTopList = labelService.list(wrapper);
return R.ok().put("result", labelTopList);
}
/**
* 营销标签树
*/
@RequestMapping(path = "/marketTree")
public R marketTree() {
List<ShopProductSociologyMarket> marketsTree = marketService.marketTree();
return R.ok().put("result", marketsTree);
}
/**
* 获取营销标签列表
*/
@RequestMapping(path = "/getMakertListByPid")
public R getMakertListByPid(String pid) {
LambdaQueryWrapper<ShopProductSociologyMarket> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductSociologyMarket::getPid,pid);
wrapper.orderByAsc(ShopProductSociologyMarket::getSort);
wrapper.orderByAsc(ShopProductSociologyMarket::getCreateTime);
List<ShopProductSociologyMarket> marketTopList = marketService.list(wrapper);
return R.ok().put("result", marketTopList);
}
@RequestMapping(path = "/getLabelById")
public R getLabelById(String id) {
return R.ok().put("result",labelService.getById(id));
}
@RequestMapping(path = "/saveOrUpdateLabel")
public R saveOrUpdateLabel(@RequestBody ShopProductSociologyLabel label) {
if (label.getId()==null){
if(label.getPid()==0){
labelService.save(label);
return R.ok().put("result",label);
}else {
ShopProductSociologyLabel l = labelService.getById(label.getPid());
if (l.getIsLast()==1){
return R.error("请将父标签设置为非最后一集");
}else {
labelService.save(label);
return R.ok().put("result",label);
}
}
}else {
if (label.getIsLast() == 1){
List llast = labelService.list(new LambdaQueryWrapper<ShopProductSociologyLabel>()
.eq(ShopProductSociologyLabel::getPid,label.getId()));
if (llast.size()>0){
return R.error("请先删除子集,再设置为最后一集");
}else {
labelService.saveOrUpdate(label);
return R.ok().put("result",label);
}
}else {
labelService.saveOrUpdate(label);
return R.ok().put("result",label);
}
}
}
@RequestMapping(path = "/delLabel")
public R delLabel(String id) {
ShopProductSociologyLabel label = labelService.getById(id);
if (label.getIsLast()==1){
MPJLambdaWrapper<ShopProductToSociologyLabel> wrapper = new MPJLambdaWrapper();
wrapper.eq(ShopProductToSociologyLabel::getSociologyLabelId,id);
List<ShopProductToSociologyLabel> tolables = toLabelService.list(wrapper);
if (tolables.size()>0){
return R.error("请先移除商品");
}else {
labelService.removeById(id);
return R.ok();
}
}else {
List<ShopProductSociologyLabel> labelList = labelService.list(new LambdaQueryWrapper<ShopProductSociologyLabel>().eq(ShopProductSociologyLabel::getPid,id));
if (labelList.size() > 0) {
return R.error("请先删除子集");
}else {
labelService.removeById(id);
return R.ok();
}
}
}
@RequestMapping(path = "/getMarketById")
public R getMarketById(String id) {
return R.ok().put("result",marketService.getById(id));
}
@RequestMapping(path = "/saveOrUpdateMarket")
public R saveOrUpdateMarket(@RequestBody ShopProductSociologyMarket market) {
if (market.getId()==null){
if(market.getPid()==0){
marketService.save(market);
return R.ok().put("result",market);
}else {
ShopProductSociologyMarket m = marketService.getById(market.getPid());
if (m.getIsLast()==1){
return R.error("请将父标签设置为非最后一集");
}else {
marketService.save(market);
return R.ok().put("result",market);
}
}
}else {
if (market.getIsLast() == 1){
List mList = marketService.list(new LambdaQueryWrapper<ShopProductSociologyMarket>()
.eq(ShopProductSociologyMarket::getPid,market.getId()));
if (mList.size()>0){
return R.error("请先删除子集,再设置为最后一集");
}else {
marketService.saveOrUpdate(market);
return R.ok().put("result",market);
}
}else {
marketService.saveOrUpdate(market);
return R.ok().put("result",market);
}
}
}
@RequestMapping(path = "/delMarket")
public R delMarket(String id) {
ShopProductSociologyMarket market = marketService.getById(id);
if (market.getIsLast()==1){
MPJLambdaWrapper<ShopProductToSociologyMarket> wrapper = new MPJLambdaWrapper();
wrapper.eq(ShopProductToSociologyMarket::getSociologyMarketId,id);
List<ShopProductToSociologyMarket> tomarkets = toMarketService.list(wrapper);
if (tomarkets.size()>0){
return R.error("请先移除商品");
}else {
marketService.removeById(id);
return R.ok();
}
}else {
List<ShopProductSociologyMarket> marketList = marketService.list(new LambdaQueryWrapper<ShopProductSociologyMarket>().eq(ShopProductSociologyMarket::getPid,id));
if (marketList.size() > 0) {
return R.error("请先删除子集");
}else {
marketService.removeById(id);
return R.ok();
}
}
}
/**
* 获取未关联商品列表
*/
@RequestMapping("/getNotToLabelList")
public R getNotToLabelList(@RequestBody Map params){
LambdaQueryWrapper<ShopProduct> wrapper = new LambdaQueryWrapper();
if (params.containsKey("goodsType")&&!"".equals(params.get("goodsType").toString())){
wrapper.eq(ShopProduct::getGoodsType,params.get("goodsType").toString());
}
if (params.containsKey("productName")&&!"".equals(params.get("productName").toString())){
wrapper.like(ShopProduct::getProductName,params.get("productName").toString());
}
if (params.containsKey("sociologyLabelId")&&!"".equals(params.get("sociologyLabelId").toString())){
String sql = "select product_id from shop_product_to_sociology_label where del_flag = 0 and sociology_label_id = "+params.get("sociologyLabelId");
wrapper.notInSql(ShopProduct::getProductId,sql);
}
if (params.containsKey("bookMarketId")&&!"".equals(params.get("bookMarketId").toString())){
String sql = "select product_id from shop_product_to_sociology_market where del_flag = 0 and sociology_market_id = "+params.get("sociologyMarketId");
wrapper.notInSql(ShopProduct::getProductId,sql);
}
Page<ShopProduct> page = productService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
return R.ok().put("result", page);
}
/**
* 获取书标签列表
*/
@RequestMapping("/getToLabelList")
public R getToLabelList(@RequestBody Map params){
MPJLambdaWrapper<ShopProductToSociologyLabel> wrapper = new MPJLambdaWrapper();
wrapper.selectAll(ShopProductToSociologyLabel.class);
wrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductToSociologyLabel::getProductId);
if (params.containsKey("productName")&&!"".equals(params.get("productName").toString())){
wrapper.like(ShopProduct::getProductName,params.get("productName").toString());
}
if (params.containsKey("goodsType")&&!"".equals(params.get("goodsType").toString())){
wrapper.eq(ShopProduct::getGoodsType,params.get("goodsType").toString());
}
if (params.containsKey("productId")&&!"".equals(params.get("productId").toString())){
wrapper.eq(ShopProductToSociologyLabel::getProductId,params.get("productId").toString());
}
if (params.containsKey("sociologyLabelId")&&!"".equals(params.get("sociologyLabelId").toString())){
wrapper.eq(ShopProductToSociologyLabel::getSociologyLabelId,params.get("sociologyLabelId").toString());
}
Page<ShopProductToSociologyLabel> page = toLabelService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
List<ShopProductToSociologyLabel> res = page.getRecords();
if (res.size() > 0) {
for (ShopProductToSociologyLabel item : res) {
item.setProduct(productService.getById(item.getProductId()));
item.setLabel(labelService.getById(item.getSociologyLabelId()));
}
}
page.setRecords(res);
return R.ok().put("result", page);
}
/**
* 获取营销标签列表
*/
@RequestMapping("/getToMarketList")
public R getToMarketList(@RequestBody Map params){
MPJLambdaWrapper<ShopProductToSociologyMarket> wrapper = new MPJLambdaWrapper();
wrapper.selectAll(ShopProductToSociologyMarket.class);
wrapper.leftJoin(ShopProduct.class,ShopProduct::getProductId,ShopProductToSociologyMarket::getProductId);
if (params.containsKey("productName")&&!"".equals(params.get("productName").toString())){
wrapper.like(ShopProduct::getProductName,params.get("productName").toString());
}
if (params.containsKey("goodsType")&&!"".equals(params.get("goodsType").toString())){
wrapper.eq(ShopProduct::getGoodsType,params.get("goodsType").toString());
}
if (params.containsKey("productId")&&!"".equals(params.get("productId").toString())){
wrapper.eq(ShopProductToBookMarket::getProductId,params.get("productId").toString());
}
if (params.containsKey("sociologyMarketId")&&!"".equals(params.get("sociologyMarketId").toString())){
wrapper.eq(ShopProductToSociologyMarket::getSociologyMarketId,params.get("sociologyMarketId").toString());
}
Page<ShopProductToSociologyMarket> page = toMarketService.page(new Page<>(
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())),wrapper);
List<ShopProductToSociologyMarket> res = page.getRecords();
if (res.size() > 0) {
for (ShopProductToSociologyMarket item : res) {
item.setProduct(productService.getById(item.getProductId()));
item.setMarket(marketService.getById(item.getSociologyMarketId()));
}
}
page.setRecords(res);
return R.ok().put("result", page);
}
@RequestMapping(path = "/saveToLabel")
public R saveToLabel(@RequestBody Map params) {
if (!StringUtils.isEmpty(params.get("productId").toString())){
String[] ids = params.get("productId").toString().split(",");
if (ids.length > 0) {
for (String id : ids) {
ShopProductToSociologyLabel toLabel = new ShopProductToSociologyLabel();
toLabel.setSociologyLabelId(Integer.parseInt(params.get("sociologyLabelId").toString()));
toLabel.setProductId(Integer.parseInt(id));
toLabelService.save(toLabel);
}
}
}
return R.ok();
}
@RequestMapping(path = "/saveToMarket")
public R saveToMarket(@RequestBody Map params) {
if (!StringUtils.isEmpty(params.get("productId").toString())){
String[] ids = params.get("productId").toString().split(",");
if (ids.length > 0) {
for (String id : ids) {
ShopProductToSociologyMarket toMarket = new ShopProductToSociologyMarket();
toMarket.setSociologyMarketId(Integer.parseInt(params.get("sociologyMarketId").toString()));
toMarket.setProductId(Integer.parseInt(id));
toMarketService.save(toMarket);
}
}
}
return R.ok();
}
@RequestMapping(path = "/delToLable")
public R delToLable(String lableId,String productId) {
if(StringUtils.isNotEmpty(productId)){
String[] productIds = productId.split(",");
for(String id : productIds){
LambdaQueryWrapper<ShopProductToSociologyLabel> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductToSociologyLabel::getSociologyLabelId,lableId);
wrapper.eq(ShopProductToSociologyLabel::getProductId,id);
toLabelService.remove(wrapper);
}
}
return R.ok();
}
@RequestMapping(path = "/delToMarket")
public R delToMarket(String marketId,String productId) {
if(StringUtils.isNotEmpty(productId)){
String[] productIds = productId.split(",");
for(String id : productIds){
LambdaQueryWrapper<ShopProductToSociologyMarket> wrapper = new LambdaQueryWrapper();
wrapper.eq(ShopProductToSociologyMarket::getSociologyMarketId,marketId);
wrapper.eq(ShopProductToSociologyMarket::getProductId,id);
toMarketService.remove(wrapper);
}
}
return R.ok();
}
}