Browse Source

编写实体类和工具类

feature/0725lihuilin
willy 1 month ago
parent
commit
3599d738f7
  1. 124
      lottery-system/.idea/uiDesigner.xml
  2. 28
      lottery-system/lottery-common/src/main/java/com/lottery/context/RequestContext.java
  3. 2
      lottery-system/lottery-common/src/main/java/com/lottery/result/Result.java
  4. 63
      lottery-system/lottery-common/src/main/java/com/lottery/utils/ConvertBeanUtil.java
  5. 1
      lottery-system/lottery-pojo/src/main/java/com/lottery/dto/Prize.java
  6. 52
      lottery-system/lottery-pojo/src/main/java/com/lottery/entity/LotteryRound.java
  7. 55
      lottery-system/lottery-pojo/src/main/java/com/lottery/entity/Prize.java
  8. 45
      lottery-system/lottery-pojo/src/main/java/com/lottery/entity/User.java
  9. 40
      lottery-system/lottery-pojo/src/main/java/com/lottery/entity/WinnerRecord.java
  10. 2
      lottery-system/lottery-service/src/main/java/com/lottery/service/Impl/PrizeServiceImpl.java
  11. 2
      lottery-system/lottery-service/src/main/resources/application.yml
  12. 6
      lottery-system/pom.xml

124
lottery-system/.idea/uiDesigner.xml

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

28
lottery-system/lottery-common/src/main/java/com/lottery/context/RequestContext.java

@ -0,0 +1,28 @@
package com.lottery.context;
/**
* @program: lottery-system
* @ClassName RequestContext
* @description: 获取上下文
* @author: wwl
* @create: 2025-07-11 10:39
* @Version 1.0
**/
public class RequestContext {
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
public static void setCurrentId(Long id) {
threadLocal.set(id);
}
public static Long getCurrentId() {
return threadLocal.get();
}
public static void removeCurrentId() {
threadLocal.remove();
}
}

2
lottery-system/lottery-common/src/main/java/com/lottery/utils/Result.java → lottery-system/lottery-common/src/main/java/com/lottery/result/Result.java

@ -1,4 +1,4 @@
package com.lottery.utils;
package com.lottery.result;
/** /**
* @program: lottery-system * @program: lottery-system

63
lottery-system/lottery-common/src/main/java/com/lottery/utils/ConvertBeanUtil.java

@ -0,0 +1,63 @@
package com.lottery.utils;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @program: lottery-system
* @ClassName ConvertBeanUtil
* @description: Bean转换工具
* @author: wwl
* @create: 2025-07-11 10:01
* @Version 1.0
**/
public class ConvertBeanUtil {
/**
* 将一个对象转成目标对象
*
* @param source
* @param targetClass
* @param <T>
* @return
*/
public static <T> T convert(Object source, Class<T> targetClass) {
if (source == null) {
return null;
}
T t = newInstance(targetClass);
BeanUtils.copyProperties(source, t);
return t;
}
/**
* 将List对象转换成目标对象注意实现是ArrayList
*
* @param targetClass
* @param <K>
* @param <T>
* @return
*/
public static <K, T> List<T> convertList(List<K> sourceList, Class<T> targetClass) {
if (sourceList == null) {
return null;
}
List targetList = new ArrayList((int) (sourceList.size() / 0.75) + 1);
for (K source : sourceList) {
targetList.add(convert(source, targetClass));
}
return targetList;
}
private static <T> T newInstance(Class<T> targetClass) {
try {
return targetClass.newInstance();
} catch (Exception e) {
throw new BeanInstantiationException(targetClass, "instantiation error", e);
}
}
}

1
lottery-system/lottery-pojo/src/main/java/com/lottery/dto/Prize.java

@ -8,6 +8,7 @@ package com.lottery.dto;
* @create: 202507-10 15:20 * @create: 202507-10 15:20
* @Version 1.0 * @Version 1.0
**/ **/
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

52
lottery-system/lottery-pojo/src/main/java/com/lottery/entity/LotteryRound.java

@ -0,0 +1,52 @@
package com.lottery.entity;
/**
* @program: lottery-system
* @ClassName
* @description:
* @author: wwl
* @create: 2025-07-11 10:01
* @Version 1.0
**/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("lottery_round")
public class LotteryRound {
@TableId(type = IdType.AUTO)
private Long id; // 主键ID表中未显示但通常需要
private String name; // 活动名称
private Date startTime; // 开始时间
private Date endTime; // 结束时间
private String description; // 描述
private Integer status; // 状态
private Date createTime; // 创建时间
private Date updateTime; // 更新时间
}

55
lottery-system/lottery-pojo/src/main/java/com/lottery/entity/Prize.java

@ -0,0 +1,55 @@
package com.lottery.entity;
/**
* @program: lottery-system
* @ClassName Gift
* @description:
* @author:jihaipeng
* @create: 202507-10 15:20
* @Version 1.0
**/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("prize")
public class Prize {
// 主键ID
@TableId(type = IdType.AUTO)
private Long id;
// 名称
private String name;
// 描述
private String description;
// 图片URL
private String imageUrl;
// 库存数量
private Integer stock;
// 中奖概率
private BigDecimal probability;
// 奖品类型
private Integer prizeType;
// 状态
private Integer status;
// 创建时间
private Date createTime;
// 更新时间
private Date updateTime;
}

45
lottery-system/lottery-pojo/src/main/java/com/lottery/entity/User.java

@ -0,0 +1,45 @@
package com.lottery.entity;
/**
* @program: lottery-system
* @ClassName
* @description:
* @author: wwl
* @create: 2025-07-11 10:01
* @Version 1.0
**/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
public class User {
@TableId(type = IdType.AUTO)
private Long id; // 主键ID表中未显示但建议添加
private String username; // 用户名
private String phone; // 手机号
private Integer status; // 状态tinyint对应Integer
private Date createTime; // 创建时间
private Date updateTime; // 更新时间
}

40
lottery-system/lottery-pojo/src/main/java/com/lottery/entity/WinnerRecord.java

@ -0,0 +1,40 @@
package com.lottery.entity;
/**
* @program: lottery-system
* @ClassName
* @description:
* @author: wwl
* @create: 2025-07-11 10:01
* @Version 1.0
**/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("winner_record")
public class WinnerRecord {
@TableId(type = IdType.AUTO)
private Long id; // 主键ID
private Long userId; // 用户ID
private Long prizeId; // 奖品ID
private Long roundId; // 轮次ID
private Date winTime; // 中奖时间
private Boolean isClaimed; // 是否已领取tinyint映射为Boolean
private Date claimTime; // 领取时间
}

2
lottery-system/lottery-service/src/main/java/com/lottery/service/Impl/PrizeServiceImpl.java

@ -32,6 +32,8 @@ public class PrizeServiceImpl implements IPrizeService {
prize.setProbability(new BigDecimal(0.1)); prize.setProbability(new BigDecimal(0.1));
prize.setPrizeType(1); prize.setPrizeType(1);
prize.setStatus(1); prize.setStatus(1);
prize.setCreateTime(new Date());
prize.setUpdateTime(new Date());
return prizeMapper.add(prize); return prizeMapper.add(prize);

2
lottery-system/lottery-service/src/main/resources/application.yml

@ -6,7 +6,7 @@ spring:
datasource: datasource:
url: jdbc:mysql://localhost:3306/lottery_system?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai url: jdbc:mysql://localhost:3306/lottery_system?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root username: root
password: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
hikari: hikari:
pool-name: LotteryHikariCP pool-name: LotteryHikariCP

6
lottery-system/pom.xml

@ -73,6 +73,12 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
<!-- 其他工具类(可选) --> <!-- 其他工具类(可选) -->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>

Loading…
Cancel
Save