抵扣金管理

This commit is contained in:
2026-05-21 11:09:04 +08:00
parent 6d0cfcdd84
commit b8aff6d0a0
5 changed files with 369 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
package com.rj.controller;
import com.rj.entity.LbDeductionAmount;
import com.rj.service.ILbDeductionAmountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/api/lbDeductionAmount")
@Tag(name = "抵扣金记录", description = "lb_deduction_amount 增删改查与分页")
public class LbDeductionAmountController {
@Autowired
private ILbDeductionAmountService lbDeductionAmountService;
@PostMapping("/add")
@Operation(summary = "新增")
public ResponseEntity<Map<String, Object>> add(
@Parameter(description = "实体id 为空时自动生成 UUID", required = true)
@RequestBody LbDeductionAmount entity) {
Map<String, Object> result = lbDeductionAmountService.add(entity);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
return ResponseEntity.badRequest().body(result);
}
@PutMapping("/update")
@Operation(summary = "编辑")
public ResponseEntity<Map<String, Object>> update(
@Parameter(description = "实体", required = true) @RequestBody LbDeductionAmount entity) {
Map<String, Object> result = lbDeductionAmountService.update(entity);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
return ResponseEntity.badRequest().body(result);
}
@DeleteMapping("/delete/{id}")
@Operation(summary = "删除")
public ResponseEntity<Map<String, Object>> delete(
@Parameter(description = "主键ID(UUID)", required = true) @PathVariable String id) {
Map<String, Object> result = lbDeductionAmountService.deleteById(id);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
return ResponseEntity.badRequest().body(result);
}
@GetMapping("/list")
@Operation(summary = "分页查询")
public ResponseEntity<Map<String, Object>> list(
@RequestParam(defaultValue = "1") Integer current,
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String tenantId,
@RequestParam(required = false) String userName,
@RequestParam(required = false) String userPhone,
@Parameter(description = "创建时间起,格式 yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) String createTimeStart,
@Parameter(description = "创建时间止,格式 yyyy-MM-dd HH:mm:ss")
@RequestParam(required = false) String createTimeEnd) {
Map<String, Object> result = lbDeductionAmountService.pageQuery(
current, size, tenantId, userName, userPhone, createTimeStart, createTimeEnd
);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
return ResponseEntity.internalServerError().body(result);
}
}

View File

@@ -0,0 +1,53 @@
package com.rj.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lb_deduction_amount")
@Schema(description = "抵扣金记录表")
public class LbDeductionAmount implements Serializable {
private static final long serialVersionUID = 1L;
@TableId("id")
@Schema(description = "主键UUID")
private String id;
@TableField("tenant_id")
@Schema(description = "租户ID")
private String tenantId;
@TableField("user_name")
@Schema(description = "用户姓名")
private String userName;
@TableField("user_phone")
@Schema(description = "用户电话")
private String userPhone;
@TableField("dikou_amt")
@Schema(description = "抵扣金额")
private BigDecimal dikouAmt;
@TableField("original_text")
@Schema(description = "原始文本信息")
private String originalText;
@TableField("create_time")
@Schema(description = "创建时间")
private LocalDateTime createTime;
@TableField("update_time")
@Schema(description = "修改时间")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,9 @@
package com.rj.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rj.entity.LbDeductionAmount;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface LbDeductionAmountMapper extends BaseMapper<LbDeductionAmount> {
}

View File

@@ -0,0 +1,23 @@
package com.rj.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.rj.entity.LbDeductionAmount;
import java.util.Map;
public interface ILbDeductionAmountService extends IService<LbDeductionAmount> {
Map<String, Object> add(LbDeductionAmount entity);
Map<String, Object> update(LbDeductionAmount entity);
Map<String, Object> deleteById(String id);
Map<String, Object> pageQuery(Integer current,
Integer size,
String tenantId,
String userName,
String userPhone,
String createTimeStart,
String createTimeEnd);
}

View File

@@ -0,0 +1,204 @@
package com.rj.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rj.entity.LbDeductionAmount;
import com.rj.mapper.LbDeductionAmountMapper;
import com.rj.service.ILbDeductionAmountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@Slf4j
@Service
public class LbDeductionAmountServiceImpl
extends ServiceImpl<LbDeductionAmountMapper, LbDeductionAmount>
implements ILbDeductionAmountService {
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public Map<String, Object> add(LbDeductionAmount entity) {
Map<String, Object> result = new HashMap<>();
try {
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
result.put("success", false);
result.put("message", "tenantId不能为空");
return result;
}
entity.setTenantId(entity.getTenantId().trim());
if (entity.getUserPhone() != null) {
entity.setUserPhone(entity.getUserPhone().trim());
}
if (entity.getUserName() != null) {
entity.setUserName(entity.getUserName().trim());
}
if (entity.getDikouAmt() == null) {
entity.setDikouAmt(BigDecimal.ZERO);
}
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
entity.setId(UUID.randomUUID().toString());
}
LocalDateTime now = LocalDateTime.now();
if (entity.getCreateTime() == null) {
entity.setCreateTime(now);
}
entity.setUpdateTime(now);
boolean ok = this.save(entity);
result.put("success", ok);
result.put("message", ok ? "新增成功" : "新增失败");
if (ok) {
result.put("data", entity);
}
return result;
} catch (Exception e) {
log.error("抵扣金记录新增异常", e);
result.put("success", false);
result.put("message", "新增异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> update(LbDeductionAmount entity) {
Map<String, Object> result = new HashMap<>();
try {
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
result.put("success", false);
result.put("message", "id不能为空");
return result;
}
if (entity.getTenantId() != null) {
entity.setTenantId(entity.getTenantId().trim());
}
if (entity.getUserPhone() != null) {
entity.setUserPhone(entity.getUserPhone().trim());
}
if (entity.getUserName() != null) {
entity.setUserName(entity.getUserName().trim());
}
entity.setUpdateTime(LocalDateTime.now());
boolean ok = this.updateById(entity);
result.put("success", ok);
result.put("message", ok ? "编辑成功" : "编辑失败");
if (ok) {
result.put("data", this.getById(entity.getId()));
}
return result;
} catch (Exception e) {
log.error("抵扣金记录编辑异常", e);
result.put("success", false);
result.put("message", "编辑异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> deleteById(String id) {
Map<String, Object> result = new HashMap<>();
try {
if (id == null || id.trim().isEmpty()) {
result.put("success", false);
result.put("message", "id不能为空");
return result;
}
boolean ok = this.removeById(id.trim());
result.put("success", ok);
result.put("message", ok ? "删除成功" : "删除失败");
return result;
} catch (Exception e) {
log.error("抵扣金记录删除异常", e);
result.put("success", false);
result.put("message", "删除异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> pageQuery(Integer current,
Integer size,
String tenantId,
String userName,
String userPhone,
String createTimeStart,
String createTimeEnd) {
Map<String, Object> result = new HashMap<>();
try {
if (current == null || current < 1) {
current = 1;
}
if (size == null || size < 1) {
size = 10;
}
LambdaQueryWrapper<LbDeductionAmount> queryWrapper = new LambdaQueryWrapper<>();
if (tenantId != null && !tenantId.trim().isEmpty()) {
queryWrapper.eq(LbDeductionAmount::getTenantId, tenantId.trim());
}
if (userName != null && !userName.trim().isEmpty()) {
queryWrapper.like(LbDeductionAmount::getUserName, userName.trim());
}
if (userPhone != null && !userPhone.trim().isEmpty()) {
queryWrapper.like(LbDeductionAmount::getUserPhone, userPhone.trim());
}
LocalDateTime start = parseDateTime(createTimeStart);
if (createTimeStart != null && !createTimeStart.trim().isEmpty() && start == null) {
result.put("success", false);
result.put("message", "createTimeStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
LocalDateTime end = parseDateTime(createTimeEnd);
if (createTimeEnd != null && !createTimeEnd.trim().isEmpty() && end == null) {
result.put("success", false);
result.put("message", "createTimeEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
if (start != null) {
queryWrapper.ge(LbDeductionAmount::getCreateTime, start);
}
if (end != null) {
queryWrapper.le(LbDeductionAmount::getCreateTime, end);
}
queryWrapper.orderByDesc(LbDeductionAmount::getUpdateTime)
.orderByDesc(LbDeductionAmount::getCreateTime);
Page<LbDeductionAmount> page = this.page(new Page<>(current, size), queryWrapper);
result.put("success", true);
result.put("message", "查询成功");
result.put("data", page.getRecords());
result.put("total", page.getTotal());
result.put("current", page.getCurrent());
result.put("size", page.getSize());
result.put("pages", page.getPages());
return result;
} catch (Exception e) {
log.error("抵扣金记录查询异常", e);
result.put("success", false);
result.put("message", "查询异常:" + e.getMessage());
return result;
}
}
private static LocalDateTime parseDateTime(String text) {
if (text == null || text.trim().isEmpty()) {
return null;
}
try {
return LocalDateTime.parse(text.trim(), DATE_TIME_FORMATTER);
} catch (Exception e) {
return null;
}
}
}