feat_crud
This commit is contained in:
+58
-4
@@ -1,18 +1,24 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.PackagePlan;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.service.IPackagePlanService;
|
||||
import com.central.order.service.IQrCodeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Tag(name = "套餐管理")
|
||||
@@ -21,6 +27,28 @@ public class PackagePlanController {
|
||||
|
||||
@Autowired
|
||||
private IPackagePlanService packagePlanService;
|
||||
@Autowired
|
||||
private IQrCodeService qrCodeService;
|
||||
|
||||
@Operation(summary = "分页查询套餐列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping
|
||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||
return packagePlanService.findList(params);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID查询套餐")
|
||||
@GetMapping("/{id}")
|
||||
public Result<PackagePlan> getById(@PathVariable("id") Long id) {
|
||||
PackagePlan plan = packagePlanService.getById(id);
|
||||
if (plan == null) {
|
||||
return Result.failed("暂无数据");
|
||||
}
|
||||
return Result.succeed(plan, "获取成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "根据二维码编码获取套餐内容")
|
||||
@GetMapping("/byCode/{codeId}")
|
||||
@@ -31,4 +59,30 @@ public class PackagePlanController {
|
||||
}
|
||||
return Result.succeed(list, "获取成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "新增或更新套餐")
|
||||
@PostMapping
|
||||
public Result<PackagePlan> saveOrUpdate(@RequestBody PackagePlan plan) {
|
||||
if (plan.getId() == null) {
|
||||
// 新增时补齐租户ID:优先取二维码的租户,否则用当前上下文租户
|
||||
if (plan.getCodeId() != null) {
|
||||
QrCode qr = qrCodeService.getByCodeId(plan.getCodeId());
|
||||
if (qr != null) {
|
||||
plan.setTenantId(qr.getTenantId());
|
||||
}
|
||||
}
|
||||
if (plan.getTenantId() == null) {
|
||||
plan.setTenantId(TenantContextHolder.getTenant());
|
||||
}
|
||||
}
|
||||
boolean ok = packagePlanService.saveOrUpdate(plan);
|
||||
return ok ? Result.succeed(plan, "操作成功") : Result.failed("操作失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID删除套餐")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<String> delete(@PathVariable("id") Long id) {
|
||||
boolean ok = packagePlanService.removeById(id);
|
||||
return ok ? Result.succeed("删除成功") : Result.failed("删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -6,6 +6,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@Mapper
|
||||
public interface PackagePlanMapper extends SuperMapper<PackagePlan> {
|
||||
@@ -14,5 +16,9 @@ public interface PackagePlanMapper extends SuperMapper<PackagePlan> {
|
||||
* 根据二维码编码查询套餐列表
|
||||
*/
|
||||
List<PackagePlan> findByCodeId(@Param("codeId") String codeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
List<PackagePlan> findList(Page<PackagePlan> page, @Param("p") Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,52 @@
|
||||
package com.central.order.model;
|
||||
|
||||
public class PackagePlan {
|
||||
}
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 套餐配置
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("packages")
|
||||
@Schema(description = "套餐配置")
|
||||
public class PackagePlan extends SuperEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "二维码编码(codeId)")
|
||||
private String codeId;
|
||||
|
||||
@Schema(description = "Vlog数量")
|
||||
private Integer vlogCount;
|
||||
|
||||
@Schema(description = "视频数量")
|
||||
private Integer videoCount;
|
||||
|
||||
@Schema(description = "照片数量")
|
||||
private Integer photoCount;
|
||||
|
||||
@Schema(description = "租户ID")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "所属公司")
|
||||
private String company;
|
||||
|
||||
@Schema(description = "是否删除 0-否 1-是")
|
||||
private Integer isDel;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateTime;
|
||||
}
|
||||
+5
-1
@@ -13,5 +13,9 @@ public interface IPackagePlanService extends ISuperService<PackagePlan> {
|
||||
* 根据二维码编码查询套餐列表
|
||||
*/
|
||||
List<PackagePlan> getByCodeId(String codeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页条件查询
|
||||
*/
|
||||
com.central.common.model.PageResult<PackagePlan> findList(java.util.Map<String, Object> params);
|
||||
}
|
||||
|
||||
+11
-1
@@ -7,6 +7,10 @@ import com.central.order.service.IPackagePlanService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.PageResult;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
@Service
|
||||
public class PackagePlanServiceImpl extends SuperServiceImpl<PackagePlanMapper, PackagePlan> implements IPackagePlanService {
|
||||
@@ -15,5 +19,11 @@ public class PackagePlanServiceImpl extends SuperServiceImpl<PackagePlanMapper,
|
||||
public List<PackagePlan> getByCodeId(String codeId) {
|
||||
return baseMapper.findByCodeId(codeId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<PackagePlan> findList(Map<String, Object> params) {
|
||||
Page<PackagePlan> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||
List<PackagePlan> list = baseMapper.findList(page, params);
|
||||
return PageResult.<PackagePlan>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,20 @@
|
||||
<resultMap id="PackagePlanResultMap" type="com.central.order.model.PackagePlan">
|
||||
</resultMap>
|
||||
|
||||
<select id="findList" resultMap="PackagePlanResultMap">
|
||||
SELECT *
|
||||
FROM packages t
|
||||
<where>
|
||||
<if test="p.codeId != null and p.codeId != ''">
|
||||
AND t.code_id = #{p.codeId}
|
||||
</if>
|
||||
<if test="p.isDel != null">
|
||||
AND t.is_del = #{p.isDel}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="findByCodeId" resultMap="PackagePlanResultMap">
|
||||
SELECT *
|
||||
FROM packages
|
||||
@@ -15,4 +29,3 @@
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user