Browse Source

后端整合模块

detached
huangqizhen 5 months ago
parent
commit
ba68304285
  1. 5
      src/main/java/com/example/demo/controller/ConsumeController.java
  2. 5
      src/main/java/com/example/demo/controller/KafkaConsumer.java
  3. 2
      src/main/java/com/example/demo/domain/entity/DetailY.java
  4. 2
      src/main/java/com/example/demo/domain/vo/DetailYVo.java
  5. 3
      src/main/java/com/example/demo/mapper/ActivityMapper.java
  6. 13
      src/main/java/com/example/demo/mapper/ConsumeMapper.java
  7. 20
      src/main/java/com/example/demo/serviceImpl/ConsumeServiceImpl.java
  8. 3
      src/main/java/com/example/demo/sevice/ConsumeService.java

5
src/main/java/com/example/demo/controller/ConsumeController.java

@ -1,6 +1,7 @@
package com.example.demo.controller; package com.example.demo.controller;
import com.example.demo.domain.entity.Detail; import com.example.demo.domain.entity.Detail;
import com.example.demo.domain.entity.DetailY;
import com.example.demo.domain.vo.*; import com.example.demo.domain.vo.*;
import com.example.demo.controller.KafkaProducer; import com.example.demo.controller.KafkaProducer;
import com.example.demo.serviceImpl.ConsumeServiceImpl; import com.example.demo.serviceImpl.ConsumeServiceImpl;
@ -31,11 +32,11 @@ public class ConsumeController {
private KafkaProducer kafkaProducer; private KafkaProducer kafkaProducer;
@PostMapping("/add") @PostMapping("/add")
public Result add(@RequestBody Detail detail) throws Exception {
public Result add(@RequestBody DetailY detailY) throws Exception {
try { try {
// Detail 对象转换为 JSON 字符串 // Detail 对象转换为 JSON 字符串
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
String detailJson = objectMapper.writeValueAsString(detail);
String detailJson = objectMapper.writeValueAsString(detailY);
// 发送消息到 Kafka 队列 // 发送消息到 Kafka 队列
kafkaProducer.sendMessage("consume-topic", detailJson); kafkaProducer.sendMessage("consume-topic", detailJson);

5
src/main/java/com/example/demo/controller/KafkaConsumer.java

@ -1,6 +1,7 @@
package com.example.demo.controller; package com.example.demo.controller;
import com.example.demo.domain.entity.Detail; import com.example.demo.domain.entity.Detail;
import com.example.demo.domain.entity.DetailY;
import com.example.demo.domain.entity.Recharge; import com.example.demo.domain.entity.Recharge;
import com.example.demo.serviceImpl.ConsumeServiceImpl; import com.example.demo.serviceImpl.ConsumeServiceImpl;
import com.example.demo.sevice.RechargeService; import com.example.demo.sevice.RechargeService;
@ -25,10 +26,10 @@ public class KafkaConsumer {
@KafkaListener(topics = "consume-topic", groupId = "my-group") @KafkaListener(topics = "consume-topic", groupId = "my-group")
public void listenConsume(String message) { public void listenConsume(String message) {
try { try {
Detail detail = objectMapper.readValue(message, Detail.class);
DetailY detailY = objectMapper.readValue(message, DetailY.class);
// 处理消费请求 // 处理消费请求
Integer result = consumeService.insert(detail);
Integer result = consumeService.insert(detailY);
log.info("Processed consume request with result: {}", result); log.info("Processed consume request with result: {}", result);
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing consume message: {}", message, e); log.error("Error processing consume message: {}", message, e);

2
src/main/java/com/example/demo/domain/entity/DetailY.java

@ -1,6 +1,7 @@
package com.example.demo.domain.entity; package com.example.demo.domain.entity;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@ -11,6 +12,7 @@ import java.util.Date;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class DetailY implements Serializable { public class DetailY implements Serializable {
private Integer detailyId; private Integer detailyId;
private String name; private String name;

2
src/main/java/com/example/demo/domain/vo/DetailYVo.java

@ -10,7 +10,7 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
public class DetailYVo { public class DetailYVo {
private Integer detailId;
private Integer detailYId;
private String name; private String name;
private String jwcode; private String jwcode;
private String area; private String area;

3
src/main/java/com/example/demo/mapper/ActivityMapper.java

@ -63,7 +63,8 @@ public interface ActivityMapper {
"AND activity.activity_id = #{activityId}", "AND activity.activity_id = #{activityId}",
"</if>", "</if>",
"</where>", "</where>",
"ORDER BY activity.status,activity.create_time DESC,activity.start_time DESC",
// "ORDER BY activity.status,activity.create_time DESC,activity.start_time DESC",
"ORDER BY CASE WHEN activity.activity_name = '无赠送活动' THEN 0 ELSE 1 END, activity.status, activity.create_time DESC, activity.start_time DESC",
"</script>" "</script>"
}) })
List<Activity> select(Activity activity); List<Activity> select(Activity activity);

13
src/main/java/com/example/demo/mapper/ConsumeMapper.java

@ -1,10 +1,7 @@
package com.example.demo.mapper; package com.example.demo.mapper;
import com.example.demo.domain.entity.Admin;
import com.example.demo.domain.entity.Detail;
import com.example.demo.domain.entity.Product;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.entity.*;
import com.example.demo.domain.vo.ConsumeDetail; import com.example.demo.domain.vo.ConsumeDetail;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
@ -32,15 +29,15 @@ public interface ConsumeMapper {
// "(#{jwcode},#{activityId},#{rechargeWay},#{productId},'金币系统','购买商品',#{refundType},#{refundGoods},#{contactId},#{remark},#{rechargeCoin},#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now(),1,#{orderCode})" // "(#{jwcode},#{activityId},#{rechargeWay},#{productId},'金币系统','购买商品',#{refundType},#{refundGoods},#{contactId},#{remark},#{rechargeCoin},#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now(),1,#{orderCode})"
"insert into detail_y", "insert into detail_y",
"(jwcode,order_code,activity_id,recharge_way,product_id,consume_platform,consume_type,refund_type,refund_goods," + "(jwcode,order_code,activity_id,recharge_way,product_id,consume_platform,consume_type,refund_type,refund_goods," +
"contact_id,remark,recharge_coin,free_coin,task_coin,admin_id,update_type,detail_flag,create_time,first_recharge)",
"contact_id,remark,recharge_coin,free_coin,task_coin,admin_id,update_type,detail_flag,create_time,first_recharge,`name`,username,area)",
"values ", "values ",
"(#{jwcode},#{orderCode},#{activityId},#{rechargeWay},#{productId},'金币系统','购买商品',#{refundType}" + "(#{jwcode},#{orderCode},#{activityId},#{rechargeWay},#{productId},'金币系统','购买商品',#{refundType}" +
",#{refundGoods},#{contactId},#{remark},#{rechargeCoin}" + ",#{refundGoods},#{contactId},#{remark},#{rechargeCoin}" +
",#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now(),#{firstRecharge})"
",#{freeCoin},#{taskCoin},#{adminId},#{updateType},1,now(),#{firstRecharge},#{name},#{username},#{area})"
}) })
// 获取自增主键 // 获取自增主键
@Options(useGeneratedKeys = true,keyColumn = "detail_id",keyProperty = "detailId")
int insert(Detail detail);
@Options(useGeneratedKeys = true,keyColumn = "detaily_id",keyProperty = "detailyId")
int insert(DetailY detailY);

20
src/main/java/com/example/demo/serviceImpl/ConsumeServiceImpl.java

@ -38,16 +38,19 @@ public class ConsumeServiceImpl implements ConsumeService {
@CacheEvict(value = "consume,detailY", allEntries = true) @CacheEvict(value = "consume,detailY", allEntries = true)
@Override @Override
//新增消费记录 //新增消费记录
public int insert(Detail detail) throws Exception {
int result =consumeMapper.insert(detail);
System.out.println(detail+"----------------------------------------");
public int insert(DetailY detailY) throws Exception {
int result =consumeMapper.insert(detailY);
System.out.println(detailY+"----------------------------------------");
if (result != 1) { if (result != 1) {
throw new Exception("Failed to insert another entity"); throw new Exception("Failed to insert another entity");
} }
BigDecimal paidGold1 =detail.getRechargeCoin();
BigDecimal freeGold1 =detail.getFreeCoin();
BigDecimal taskGold1 =detail.getTaskCoin();
String jwcode = detail.getJwcode();
BigDecimal paidGold1 =detailY.getRechargeCoin();
BigDecimal freeGold1 =detailY.getFreeCoin();
BigDecimal taskGold1 =detailY.getTaskCoin();
String name = detailY.getName();
String username =detailY.getUsername();
String area = detailY.getArea();
String jwcode = detailY.getJwcode();
UserGold userGold = userMapper.selectGold(jwcode); UserGold userGold = userMapper.selectGold(jwcode);
BigDecimal buyJb =userGold.getBuyJb(); BigDecimal buyJb =userGold.getBuyJb();
BigDecimal coreJb=userGold.getCoreJb(); BigDecimal coreJb=userGold.getCoreJb();
@ -83,7 +86,8 @@ public class ConsumeServiceImpl implements ConsumeService {
} }
// 生成UUID作为订单编号 // 生成UUID作为订单编号
String uuid = UUID.randomUUID().toString().replace("-", ""); // 去掉UUID中的'-' String uuid = UUID.randomUUID().toString().replace("-", ""); // 去掉UUID中的'-'
detail.setOrderCode(uuid);
detailY.setOrderCode(uuid);
//添加表单数据 //添加表单数据
// 更新用户对象以反映新的余额 // 更新用户对象以反映新的余额

3
src/main/java/com/example/demo/sevice/ConsumeService.java

@ -3,6 +3,7 @@ package com.example.demo.sevice;
import com.example.demo.domain.entity.Admin; import com.example.demo.domain.entity.Admin;
import com.example.demo.domain.entity.Detail; import com.example.demo.domain.entity.Detail;
import com.example.demo.domain.entity.DetailY;
import com.example.demo.domain.entity.User; import com.example.demo.domain.entity.User;
import com.example.demo.domain.vo.ConsumeDetail; import com.example.demo.domain.vo.ConsumeDetail;
import com.example.demo.domain.vo.DetailVo; import com.example.demo.domain.vo.DetailVo;
@ -13,7 +14,7 @@ import java.util.List;
public interface ConsumeService { public interface ConsumeService {
//新增消费记录 //新增消费记录
int insert(Detail detail) throws Exception;
int insert(DetailY detailY) throws Exception;
User getByUserId(Integer userId); User getByUserId(Integer userId);

Loading…
Cancel
Save