diff --git a/cloud-market-common/src/main/java/com/muyu/market/domain/MyApi.java b/cloud-market-common/src/main/java/com/muyu/market/domain/MyApi.java new file mode 100644 index 0000000..4091d76 --- /dev/null +++ b/cloud-market-common/src/main/java/com/muyu/market/domain/MyApi.java @@ -0,0 +1,70 @@ +package com.muyu.market.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muyu.common.core.annotation.Excel; +import com.muyu.common.core.web.domain.BaseEntity; +import lombok.*; +import lombok.experimental.SuperBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; + +/** + * 我的api对象 my_api + * + * @author 2112A + * @date 2024-09-06 + */ + +@Data +@Setter +@Getter +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@TableName("my_api") +public class MyApi { + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + @TableId( type = IdType.AUTO) + private Long myId; + + /** 用户ID */ + @Excel(name = "用户ID") + private Long userId; + + /** 商品ID */ + @Excel(name = "商品ID") + private Long apiId; + + /** 剩余次数 */ + @Excel(name = "剩余次数") + private Long myNum; + + /** 购买时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "购买时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date myTime; + + /** 使用状态 */ + @Excel(name = "使用状态") + private Long myStates; + + + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("myId", getMyId()) + .append("userId", getUserId()) + .append("apiId", getApiId()) + .append("myNum", getMyNum()) + .append("myTime", getMyTime()) + .append("myStates", getMyStates()) + .toString(); + } +} 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 new file mode 100644 index 0000000..2e22d0b --- /dev/null +++ b/cloud-market-server/src/main/java/com/muyu/market/controller/MyApiController.java @@ -0,0 +1,110 @@ +package com.muyu.market.controller; + +import java.util.Arrays; +import java.util.List; +import jakarta.servlet.http.HttpServletResponse; +import javax.annotation.Resource; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.muyu.common.security.annotation.RequiresPermissions; +import com.muyu.market.domain.MyApi; +import com.muyu.market.service.IMyApiService; +import com.muyu.common.core.web.controller.BaseController; +import com.muyu.common.core.domain.Result; +import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.security.utils.SecurityUtils; +import org.springframework.validation.annotation.Validated; +import com.muyu.common.core.web.page.TableDataInfo; + +/** + * 我的apiController + * + * @author 2112A + * @date 2024-09-06 + */ +@RestController +@RequestMapping("/api") +public class MyApiController extends BaseController +{ + @Resource + private IMyApiService myApiService; + + /** + * 查询我的api列表 + */ + @RequiresPermissions("api:api:list") + @GetMapping("/list") + public Result> list(MyApi myApi) + { + startPage(); + List list = myApiService.selectMyApiList(myApi); + return getDataTable(list); + } + + /** + * 导出我的api列表 + */ + @RequiresPermissions("api:api:export") + @PostMapping("/export") + public void export(HttpServletResponse response, MyApi myApi) + { + List list = myApiService.selectMyApiList(myApi); + ExcelUtil util = new ExcelUtil(MyApi.class); + util.exportExcel(response, list, "我的api数据"); + } + + /** + * 获取我的api详细信息 + */ + @RequiresPermissions("api:api:query") + @GetMapping(value = "/{myId}") + public Result> getInfo(@PathVariable("myId") Long myId) + { + return success(myApiService.selectMyApiByMyId(myId)); + } + + /** + * 新增我的api + */ + @RequiresPermissions("api:api:add") + @PostMapping + public Result add( + @Validated @RequestBody MyApi myApi) + { + if (myApiService.checkIdUnique(myApi)) { + return error("新增 我的api '" + myApi + "'失败,我的api已存在"); + } + return toAjax(myApiService.save(myApi)); + } + + /** + * 修改我的api + */ + @RequiresPermissions("api:api:edit") + @PutMapping + public Result edit( + @Validated @RequestBody MyApi myApi) + { + if (!myApiService.checkIdUnique(myApi)) { + return error("修改 我的api '" + myApi + "'失败,我的api不存在"); + } + return toAjax(myApiService.updateById(myApi)); + } + + /** + * 删除我的api + */ + @RequiresPermissions("api:api:remove") + @DeleteMapping("/{myIds}") + public Result remove(@PathVariable("myIds") Long[] myIds) + { + myApiService.removeBatchByIds(Arrays.asList(myIds)); + return success(); + } +} 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 new file mode 100644 index 0000000..24a324a --- /dev/null +++ b/cloud-market-server/src/main/java/com/muyu/market/mapper/MyApiMapper.java @@ -0,0 +1,17 @@ +package com.muyu.market.mapper; + +import java.util.List; +import com.muyu.market.domain.MyApi; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * 我的apiMapper接口 + * + * @author 2112A + * @date 2024-09-06 + */ +@Mapper +public interface MyApiMapper extends BaseMapper{ + +} 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 new file mode 100644 index 0000000..4c6feee --- /dev/null +++ b/cloud-market-server/src/main/java/com/muyu/market/service/IMyApiService.java @@ -0,0 +1,37 @@ +package com.muyu.market.service; + +import java.util.List; +import com.muyu.market.domain.MyApi; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 我的apiService接口 + * + * @author 2112A + * @date 2024-09-06 + */ +public interface IMyApiService extends IService { + /** + * 精确查询我的api + * + * @param myId 我的api主键 + * @return 我的api + */ + public MyApi selectMyApiByMyId(Long myId); + + /** + * 查询我的api列表 + * + * @param myApi 我的api + * @return 我的api集合 + */ + public List selectMyApiList(MyApi myApi); + + /** + * 判断 我的api id是否唯一 + * @param myApi 我的api + * @return 结果 + */ + Boolean checkIdUnique(MyApi myApi); + +} 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 new file mode 100644 index 0000000..1030427 --- /dev/null +++ b/cloud-market-server/src/main/java/com/muyu/market/service/impl/MyApiServiceImpl.java @@ -0,0 +1,77 @@ +package com.muyu.market.service.impl; + +import java.util.List; +import org.springframework.stereotype.Service; +import com.muyu.market.mapper.MyApiMapper; +import com.muyu.market.domain.MyApi; +import com.muyu.market.service.IMyApiService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import org.springframework.util.Assert; + +/** + * 我的apiService业务层处理 + * + * @author 2112A + * @date 2024-09-06 + */ +@Service +public class MyApiServiceImpl + extends ServiceImpl + implements IMyApiService { + + /** + * 精确查询我的api + * + * @param myId 我的api主键 + * @return 我的api + */ + @Override + public MyApi selectMyApiByMyId(Long myId) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(myId, "myId不可为空"); + queryWrapper.eq(MyApi::getMyId, myId); + return this.getOne(queryWrapper); + } + + + /** + * 查询我的api列表 + * + * @param myApi 我的api + * @return 我的api + */ + @Override + public List selectMyApiList(MyApi myApi) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (myApi.getUserId()!=null){ + queryWrapper.eq(MyApi::getUserId, myApi.getUserId()); + } + if (myApi.getApiId()!=null){ + queryWrapper.eq(MyApi::getApiId, myApi.getApiId()); + } + if (myApi.getMyNum()!=null){ + queryWrapper.eq(MyApi::getMyNum, myApi.getMyNum()); + } + if (myApi.getMyStates()!=null){ + queryWrapper.eq(MyApi::getMyStates, myApi.getMyStates()); + } + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param myApi 我的api + * @return 我的api + */ + @Override + public Boolean checkIdUnique(MyApi myApi) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(MyApi::getMyId, myApi.getMyId()); + return this.count(queryWrapper) > 0; + } + +} diff --git a/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml b/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml new file mode 100644 index 0000000..a15b1ca --- /dev/null +++ b/cloud-market-server/src/main/resources/mapper/market/MyApiMapper.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + select my_id, user_id, api_id, my_num, my_time, my_states from my_api + + + + + + + + insert into my_api + + user_id, + api_id, + my_num, + my_time, + my_states, + + + #{userId}, + #{apiId}, + #{myNum}, + #{myTime}, + #{myStates}, + + + + + update my_api + + user_id = #{userId}, + api_id = #{apiId}, + my_num = #{myNum}, + my_time = #{myTime}, + my_states = #{myStates}, + + where my_id = #{myId} + + + + delete from my_api where my_id = #{myId} + + + + delete from my_api where my_id in + + #{myId} + + + \ No newline at end of file