This commit is contained in:
wangjinlei
2023-09-20 16:14:49 +08:00
parent 2bfc0f7919
commit c39ce41ce9
5 changed files with 92 additions and 1 deletions

View File

@@ -3,13 +3,19 @@ package com.peanut.modules.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.peanut.common.utils.R; import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.ShopProductLabelEntity; import com.peanut.modules.book.entity.ShopProductLabelEntity;
import com.peanut.modules.book.entity.ShopProductToLabelEntity;
import com.peanut.modules.book.service.ShopProductLabelService; import com.peanut.modules.book.service.ShopProductLabelService;
import com.peanut.modules.book.service.ShopProductToLabelService;
import org.springframework.beans.factory.annotation.Autowired; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("book/label") @RequestMapping("book/label")
public class ShopProductLabelController { public class ShopProductLabelController {
@@ -17,6 +23,9 @@ public class ShopProductLabelController {
@Autowired @Autowired
private ShopProductLabelService shopProductLabelService; private ShopProductLabelService shopProductLabelService;
@Autowired
private ShopProductToLabelService shopProductToLabelService;
@RequestMapping("/addLabel") @RequestMapping("/addLabel")
public R addLabel(@RequestParam String labelName){ public R addLabel(@RequestParam String labelName){
@@ -37,7 +46,36 @@ public class ShopProductLabelController {
@RequestMapping("/delLabel") @RequestMapping("/delLabel")
public R delLabel(@RequestParam Integer splId){ public R delLabel(@RequestParam Integer splId){
//确定删除前是否已不存在项目
QueryWrapper<ShopProductToLabelEntity> shopProductToLabelEntityQueryWrapper = new QueryWrapper<>();
shopProductToLabelEntityQueryWrapper.eq("spl_id",splId);
shopProductToLabelEntityQueryWrapper.eq("del_flag",0);
ShopProductToLabelEntity shopProductToLabelEntity_check = shopProductToLabelService.getBaseMapper().selectOne(shopProductToLabelEntityQueryWrapper);
if(shopProductToLabelEntity_check!=null){
return R.error("还有书籍用此标签");
}
//更新
shopProductLabelService.removeById(splId);
return R.ok(); return R.ok();
} }
@RequestMapping("/updateLabel")
public R updateLabel(@RequestParam String labelName,@RequestParam Integer splId){
ShopProductLabelEntity byId = shopProductLabelService.getById(splId);
byId.setLabelName(labelName);
shopProductLabelService.updateById(byId);
return R.ok();
}
@RequestMapping("/getLabels")
public R getLabels(){
List<ShopProductLabelEntity> shopProductLabelEntities = shopProductLabelService.getBaseMapper().selectList(new QueryWrapper<ShopProductLabelEntity>()
.eq("del_flag",0));
Map re = new HashMap();
re.put("labels",shopProductLabelEntities);
return R.ok().put("result",re);
}
} }

View File

@@ -0,0 +1,9 @@
package com.peanut.modules.book.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peanut.modules.book.entity.ShopProductToLabelEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ShopProductToLabelDao extends BaseMapper<ShopProductToLabelEntity> {
}

View File

@@ -0,0 +1,26 @@
package com.peanut.modules.book.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
@Data
@TableName("shop_product_to_label")
public class ShopProductToLabelEntity {
@TableId
private Integer ptlId;
private Integer productId;
private Integer splId;
@TableField("del_flag")
@TableLogic
private Integer delFlag;
}

View File

@@ -0,0 +1,7 @@
package com.peanut.modules.book.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.peanut.modules.book.entity.ShopProductToLabelEntity;
public interface ShopProductToLabelService extends IService<ShopProductToLabelEntity> {
}

View File

@@ -0,0 +1,11 @@
package com.peanut.modules.book.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.book.dao.ShopProductToLabelDao;
import com.peanut.modules.book.entity.ShopProductToLabelEntity;
import com.peanut.modules.book.service.ShopProductToLabelService;
import org.springframework.stereotype.Service;
@Service("ShopProductToLabelService")
public class ShopProductToLabelServiceImpl extends ServiceImpl<ShopProductToLabelDao, ShopProductToLabelEntity> implements ShopProductToLabelService {
}