企业列表出来了

master
法外狂徒张三 2024-09-06 11:06:05 +08:00
parent 48c9956d18
commit bd7540d2e6
6 changed files with 387 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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>{
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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>