企业列表出来了
parent
48c9956d18
commit
bd7540d2e6
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<TableDataInfo<MyApi>> list(MyApi myApi)
|
||||
{
|
||||
startPage();
|
||||
List<MyApi> list = myApiService.selectMyApiList(myApi);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出我的api列表
|
||||
*/
|
||||
@RequiresPermissions("api:api:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, MyApi myApi)
|
||||
{
|
||||
List<MyApi> list = myApiService.selectMyApiList(myApi);
|
||||
ExcelUtil<MyApi> util = new ExcelUtil<MyApi>(MyApi.class);
|
||||
util.exportExcel(response, list, "我的api数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取我的api详细信息
|
||||
*/
|
||||
@RequiresPermissions("api:api:query")
|
||||
@GetMapping(value = "/{myId}")
|
||||
public Result<List<MyApi>> getInfo(@PathVariable("myId") Long myId)
|
||||
{
|
||||
return success(myApiService.selectMyApiByMyId(myId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增我的api
|
||||
*/
|
||||
@RequiresPermissions("api:api:add")
|
||||
@PostMapping
|
||||
public Result<Integer> 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<Integer> 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<Integer> remove(@PathVariable("myIds") Long[] myIds)
|
||||
{
|
||||
myApiService.removeBatchByIds(Arrays.asList(myIds));
|
||||
return success();
|
||||
}
|
||||
}
|
|
@ -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<MyApi>{
|
||||
|
||||
}
|
|
@ -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<MyApi> {
|
||||
/**
|
||||
* 精确查询我的api
|
||||
*
|
||||
* @param myId 我的api主键
|
||||
* @return 我的api
|
||||
*/
|
||||
public MyApi selectMyApiByMyId(Long myId);
|
||||
|
||||
/**
|
||||
* 查询我的api列表
|
||||
*
|
||||
* @param myApi 我的api
|
||||
* @return 我的api集合
|
||||
*/
|
||||
public List<MyApi> selectMyApiList(MyApi myApi);
|
||||
|
||||
/**
|
||||
* 判断 我的api id是否唯一
|
||||
* @param myApi 我的api
|
||||
* @return 结果
|
||||
*/
|
||||
Boolean checkIdUnique(MyApi myApi);
|
||||
|
||||
}
|
|
@ -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<MyApiMapper, MyApi>
|
||||
implements IMyApiService {
|
||||
|
||||
/**
|
||||
* 精确查询我的api
|
||||
*
|
||||
* @param myId 我的api主键
|
||||
* @return 我的api
|
||||
*/
|
||||
@Override
|
||||
public MyApi selectMyApiByMyId(Long myId)
|
||||
{
|
||||
LambdaQueryWrapper<MyApi> 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<MyApi> selectMyApiList(MyApi myApi)
|
||||
{
|
||||
LambdaQueryWrapper<MyApi> 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<MyApi> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MyApi::getMyId, myApi.getMyId());
|
||||
return this.count(queryWrapper) > 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.market.mapper.MyApiMapper">
|
||||
|
||||
<resultMap type="MyApi" id="MyApiResult">
|
||||
<result property="myId" column="my_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="apiId" column="api_id" />
|
||||
<result property="myNum" column="my_num" />
|
||||
<result property="myTime" column="my_time" />
|
||||
<result property="myStates" column="my_states" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectMyApiVo">
|
||||
select my_id, user_id, api_id, my_num, my_time, my_states from my_api
|
||||
</sql>
|
||||
|
||||
<select id="selectMyApiList" parameterType="MyApi" resultMap="MyApiResult">
|
||||
<include refid="selectMyApiVo"/>
|
||||
<where>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="apiId != null "> and api_id = #{apiId}</if>
|
||||
<if test="myNum != null "> and my_num = #{myNum}</if>
|
||||
<if test="myTime != null "> and my_time = #{myTime}</if>
|
||||
<if test="myStates != null "> and my_states = #{myStates}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectMyApiByMyId" parameterType="Long" resultMap="MyApiResult">
|
||||
<include refid="selectMyApiVo"/>
|
||||
where my_id = #{myId}
|
||||
</select>
|
||||
|
||||
<insert id="insertMyApi" parameterType="MyApi" useGeneratedKeys="true" keyProperty="myId">
|
||||
insert into my_api
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="apiId != null">api_id,</if>
|
||||
<if test="myNum != null">my_num,</if>
|
||||
<if test="myTime != null">my_time,</if>
|
||||
<if test="myStates != null">my_states,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="apiId != null">#{apiId},</if>
|
||||
<if test="myNum != null">#{myNum},</if>
|
||||
<if test="myTime != null">#{myTime},</if>
|
||||
<if test="myStates != null">#{myStates},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateMyApi" parameterType="MyApi">
|
||||
update my_api
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="apiId != null">api_id = #{apiId},</if>
|
||||
<if test="myNum != null">my_num = #{myNum},</if>
|
||||
<if test="myTime != null">my_time = #{myTime},</if>
|
||||
<if test="myStates != null">my_states = #{myStates},</if>
|
||||
</trim>
|
||||
where my_id = #{myId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteMyApiByMyId" parameterType="Long">
|
||||
delete from my_api where my_id = #{myId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteMyApiByMyIds" parameterType="String">
|
||||
delete from my_api where my_id in
|
||||
<foreach item="myId" collection="array" open="(" separator="," close=")">
|
||||
#{myId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue