diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3e06d99..951372d 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,6 +6,11 @@ + + + + + diff --git a/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java b/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java index f8a1eaf..20f60f4 100644 --- a/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java +++ b/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java @@ -35,6 +35,16 @@ public class MyApiController extends BaseController @Resource private IMyApiService myApiService; + @PostMapping("/upd") + public Result updByUserIdAndApiId(@RequestBody MyApi myApi) { + if(myApi.getMyNum()==0){ + return Result.error("次数不足"); + } + Long userId = SecurityUtils.getUserId(); + myApi.setUserId(userId); + return Result.success(myApiService.updByUserIdAndApiId(myApi)); + } + /** * 查询我的api列表 */ diff --git a/cloud-market-server/src/main/java/com/muyu/market/mapper/MyApiMapper.java b/cloud-market-server/src/main/java/com/muyu/market/mapper/MyApiMapper.java index 24a324a..7bbeb54 100644 --- a/cloud-market-server/src/main/java/com/muyu/market/mapper/MyApiMapper.java +++ b/cloud-market-server/src/main/java/com/muyu/market/mapper/MyApiMapper.java @@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface MyApiMapper extends BaseMapper{ - + Integer updByUserIdAndApiId(MyApi myApi); } diff --git a/cloud-market-server/src/main/java/com/muyu/market/service/IMyApiService.java b/cloud-market-server/src/main/java/com/muyu/market/service/IMyApiService.java index 4c6feee..6afd516 100644 --- a/cloud-market-server/src/main/java/com/muyu/market/service/IMyApiService.java +++ b/cloud-market-server/src/main/java/com/muyu/market/service/IMyApiService.java @@ -11,6 +11,8 @@ import com.baomidou.mybatisplus.extension.service.IService; * @date 2024-09-06 */ public interface IMyApiService extends IService { + + public Integer updByUserIdAndApiId(MyApi myApi); /** * 精确查询我的api * diff --git a/cloud-market-server/src/main/java/com/muyu/market/service/impl/MyApiServiceImpl.java b/cloud-market-server/src/main/java/com/muyu/market/service/impl/MyApiServiceImpl.java index e52c9fe..923d9de 100644 --- a/cloud-market-server/src/main/java/com/muyu/market/service/impl/MyApiServiceImpl.java +++ b/cloud-market-server/src/main/java/com/muyu/market/service/impl/MyApiServiceImpl.java @@ -3,6 +3,7 @@ package com.muyu.market.service.impl; import java.util.List; import com.muyu.market.domain.SysDatawarehouse; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.muyu.market.mapper.MyApiMapper; import com.muyu.market.domain.MyApi; @@ -23,6 +24,13 @@ public class MyApiServiceImpl extends ServiceImpl implements IMyApiService { + @Autowired + private MyApiMapper mapper; + @Override + public Integer updByUserIdAndApiId(MyApi myApi) { + return mapper.updByUserIdAndApiId(myApi); + } + /** * 精确查询我的api * diff --git a/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml b/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml index a15b1ca..30942ae 100644 --- a/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml +++ b/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml @@ -3,7 +3,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - + insert into my_api @@ -62,15 +62,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where my_id = #{myId} + + UPDATE my_api SET `my_num` = my_num-1 ,`my_states` = 'N' WHERE `user_id` = #{userId} and `api_id` = #{apiId}; + delete from my_api where my_id = #{myId} - delete from my_api where my_id in + delete from my_api where my_id in #{myId} - \ No newline at end of file +