diff --git a/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java b/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java index 896b06e5..360a0968 100644 --- a/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java +++ b/src/main/java/com/peanut/modules/book/controller/ShopProductLabelController.java @@ -3,13 +3,19 @@ package com.peanut.modules.book.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peanut.common.utils.R; 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.ShopProductToLabelService; 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.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + @RestController @RequestMapping("book/label") public class ShopProductLabelController { @@ -17,6 +23,9 @@ public class ShopProductLabelController { @Autowired private ShopProductLabelService shopProductLabelService; + @Autowired + private ShopProductToLabelService shopProductToLabelService; + @RequestMapping("/addLabel") public R addLabel(@RequestParam String labelName){ @@ -37,7 +46,36 @@ public class ShopProductLabelController { @RequestMapping("/delLabel") public R delLabel(@RequestParam Integer splId){ + //确定删除前是否已不存在项目 + QueryWrapper 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(); } + @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 shopProductLabelEntities = shopProductLabelService.getBaseMapper().selectList(new QueryWrapper() + .eq("del_flag",0)); + Map re = new HashMap(); + re.put("labels",shopProductLabelEntities); + return R.ok().put("result",re); + } + } diff --git a/src/main/java/com/peanut/modules/book/dao/ShopProductToLabelDao.java b/src/main/java/com/peanut/modules/book/dao/ShopProductToLabelDao.java new file mode 100644 index 00000000..6c89745a --- /dev/null +++ b/src/main/java/com/peanut/modules/book/dao/ShopProductToLabelDao.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/book/entity/ShopProductToLabelEntity.java b/src/main/java/com/peanut/modules/book/entity/ShopProductToLabelEntity.java new file mode 100644 index 00000000..bcee7bbd --- /dev/null +++ b/src/main/java/com/peanut/modules/book/entity/ShopProductToLabelEntity.java @@ -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; +} diff --git a/src/main/java/com/peanut/modules/book/service/ShopProductToLabelService.java b/src/main/java/com/peanut/modules/book/service/ShopProductToLabelService.java new file mode 100644 index 00000000..41145ad0 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/ShopProductToLabelService.java @@ -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 { +} diff --git a/src/main/java/com/peanut/modules/book/service/impl/ShopProductToLabelServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/ShopProductToLabelServiceImpl.java new file mode 100644 index 00000000..76475001 --- /dev/null +++ b/src/main/java/com/peanut/modules/book/service/impl/ShopProductToLabelServiceImpl.java @@ -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 implements ShopProductToLabelService { +}