├── src
├── main
│ ├── java
│ │ └── com
│ │ │ └── im
│ │ │ └── lottery
│ │ │ ├── entity
│ │ │ ├── InventoryCount.java
│ │ │ ├── Record.java
│ │ │ └── Prize.java
│ │ │ ├── utils
│ │ │ ├── SignCheckUtil.java
│ │ │ ├── LotteryUtil.java
│ │ │ ├── MD5Util.java
│ │ │ └── ResponseUtil.java
│ │ │ ├── LotteryApplication.java
│ │ │ ├── req
│ │ │ ├── DeletePrizeReq.java
│ │ │ ├── FindPrizeByIdReq.java
│ │ │ ├── FindAllReq.java
│ │ │ ├── LotteryReq.java
│ │ │ ├── FindPageReq.java
│ │ │ ├── CreatePrizeReq.java
│ │ │ ├── FillInfomationReq.java
│ │ │ └── UpdatePrizeReq.java
│ │ │ ├── resp
│ │ │ ├── FindOnePrizeResp.java
│ │ │ ├── FindAllPrizeResp.java
│ │ │ ├── LotteryResp.java
│ │ │ ├── Response.java
│ │ │ └── FindAllRecordResp.java
│ │ │ ├── persistence
│ │ │ ├── RecordMapper.java
│ │ │ └── PrizeMapper.java
│ │ │ ├── service
│ │ │ ├── LotteryService.java
│ │ │ ├── PrizeService.java
│ │ │ └── impl
│ │ │ │ ├── PrizeServiceImpl.java
│ │ │ │ └── LotteryServiceImpl.java
│ │ │ ├── config
│ │ │ ├── DruidConfiguation.java
│ │ │ ├── MybatisConfiguation.java
│ │ │ └── LocalRedisConfig.java
│ │ │ └── controller
│ │ │ └── PrizeController.java
│ └── resources
│ │ ├── mybatis-config.xml
│ │ ├── com
│ │ └── im
│ │ │ └── lottery
│ │ │ └── persistence
│ │ │ ├── RecordMapper.xml
│ │ │ └── PrizeMapper.xml
│ │ └── application.properties
└── test
│ └── java
│ └── com
│ └── im
│ └── lottery
│ └── LotteryApplicationTests.java
├── .gitattributes
├── .gitignore
├── sql
└── lottery_schema.sql
└── pom.xml
/src/main/java/com/im/lottery/entity/InventoryCount.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.entity;
2 |
3 | import lombok.Data;
4 | import lombok.ToString;
5 |
6 | @Data
7 | @ToString
8 | public class InventoryCount {
9 | private Integer inventory;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/utils/SignCheckUtil.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.utils;
2 |
3 | public class SignCheckUtil {
4 | public static boolean check(String sign,String attach,String value){
5 | if(MD5Util.MD5Encode(value+attach, "utf-8").equals(sign)){
6 | return true;
7 | }else {
8 | return false;
9 | }
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/resources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/LotteryApplication.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class LotteryApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(LotteryApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/DeletePrizeReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 | @Data
8 | @ToString
9 | public class DeletePrizeReq implements Serializable{
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 | private String sign;
15 | private Integer prizeId;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/FindPrizeByIdReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 |
8 | @Data
9 | @ToString
10 | public class FindPrizeByIdReq implements Serializable{
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1L;
15 | private String sign;
16 | private Integer prizeId;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/FindAllReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 | import java.time.LocalDate;
5 |
6 | import lombok.Data;
7 | import lombok.ToString;
8 | @Data
9 | @ToString
10 | public class FindAllReq implements Serializable{
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1L;
15 | private String sign;
16 | private String queryTime;
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/LotteryReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 |
8 | @Data
9 | @ToString
10 | public class LotteryReq implements Serializable{
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1L;
15 | private String lotteryTime;
16 | private String sign;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/resp/FindOnePrizeResp.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.resp;
2 |
3 | import com.im.lottery.entity.Prize;
4 | public class FindOnePrizeResp extends Response{
5 | /**
6 | *
7 | */
8 | private static final long serialVersionUID = 1L;
9 | private Prize prize;
10 | public Prize getPrize() {
11 | return prize;
12 | }
13 | public void setPrize(Prize prize) {
14 | this.prize = prize;
15 | }
16 |
17 |
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/persistence/RecordMapper.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.persistence;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.im.lottery.entity.Record;
8 |
9 | public interface RecordMapper {
10 | public Integer insert(Record record);
11 | public Record findById(@Param("recordId") Long recordId);
12 | public List findAll();
13 | public Integer update(Record record);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/FindPageReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 | @Data
8 | @ToString
9 | public class FindPageReq implements Serializable{
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 | private Integer index;
15 | private Integer pageSize;
16 | private String queryTime;
17 | private String sign;
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/resp/FindAllPrizeResp.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.resp;
2 |
3 | import java.util.List;
4 |
5 | import com.im.lottery.entity.Prize;
6 | public class FindAllPrizeResp extends Response{
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 1L;
11 | private List prizes;
12 | public List getPrizes() {
13 | return prizes;
14 | }
15 | public void setPrizes(List prizes) {
16 | this.prizes = prizes;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/service/LotteryService.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.service;
2 |
3 | import com.im.lottery.req.FillInfomationReq;
4 | import com.im.lottery.req.FindPageReq;
5 | import com.im.lottery.req.LotteryReq;
6 | import com.im.lottery.resp.Response;
7 |
8 | public interface LotteryService {
9 | public Response lottery(LotteryReq lotteryReq);
10 | public Response fillInfomation(FillInfomationReq fillInfomationReq);
11 | public Response findAll(FindPageReq findPageReq);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/CreatePrizeReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 | @ToString
8 | @Data
9 | public class CreatePrizeReq implements Serializable{
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 | private String sign;
15 | private String name; //奖项
16 | private String detail; //奖品类容
17 | private String text; //二维码
18 | private Integer inventory;
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/FillInfomationReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 |
8 | @Data
9 | @ToString
10 | public class FillInfomationReq implements Serializable{
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1L;
15 | private Long recordId;
16 | private String name; //姓名
17 | private Long phone; //手机号
18 | private String address; //地址
19 | private String sign;
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/req/UpdatePrizeReq.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.req;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 | @Data
8 | @ToString
9 | public class UpdatePrizeReq implements Serializable{
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 | private String sign;
15 | private Integer prizeId;
16 | private String name; //奖项
17 | private String detail; //奖品类容
18 | private String text; //二维码
19 | private Integer inventory;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/resp/LotteryResp.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.resp;
2 |
3 | import com.im.lottery.entity.Prize;
4 | import com.im.lottery.entity.Record;
5 |
6 | public class LotteryResp extends Response{
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 1L;
11 | private Record record;
12 | private Prize prize;
13 | public Record getRecord() {
14 | return record;
15 | }
16 | public void setRecord(Record record) {
17 | this.record = record;
18 | }
19 | public Prize getPrize() {
20 | return prize;
21 | }
22 | public void setPrize(Prize prize) {
23 | this.prize = prize;
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/persistence/PrizeMapper.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.persistence;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.ibatis.annotations.Param;
6 |
7 | import com.im.lottery.entity.InventoryCount;
8 | import com.im.lottery.entity.Prize;
9 |
10 | public interface PrizeMapper {
11 | Integer insert(Prize prize);
12 | Integer delete(@Param("prizeId") Integer prizeId);
13 | Integer update(Prize prize);
14 | List findAll();
15 | Prize findById(@Param("prizeId")Integer prizeId);
16 | InventoryCount getInventory(@Param("prizeId")Integer prizeId);
17 | Integer minusInventort(@Param("prizeId")Integer prizeId);
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/resp/Response.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.resp;
2 |
3 | import java.io.Serializable;
4 |
5 | import lombok.Data;
6 | import lombok.ToString;
7 |
8 | @Data
9 | @ToString
10 | public class Response implements Serializable{
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1L;
15 | private String resultCode;
16 | private String resultMessage;
17 | public Response(String resultCode, String resultMessage) {
18 | super();
19 | this.resultCode = resultCode;
20 | this.resultMessage = resultMessage;
21 | }
22 | public Response() {
23 | super();
24 | // TODO Auto-generated constructor stub
25 | }
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/service/PrizeService.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.service;
2 |
3 | import com.im.lottery.req.CreatePrizeReq;
4 | import com.im.lottery.req.DeletePrizeReq;
5 | import com.im.lottery.req.FindAllReq;
6 | import com.im.lottery.req.FindPrizeByIdReq;
7 | import com.im.lottery.req.UpdatePrizeReq;
8 | import com.im.lottery.resp.Response;
9 |
10 | public interface PrizeService {
11 | public Response InsertPrize(CreatePrizeReq createPrizeReq);
12 | public Response delete(DeletePrizeReq deletePrizeReq);
13 | public Response update(UpdatePrizeReq updatePrizeReq);
14 | public Response findAll(FindAllReq findAllReq);
15 | public Response findById(FindPrizeByIdReq findPrizeByIdReq);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/resp/FindAllRecordResp.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.resp;
2 |
3 | import com.github.pagehelper.Page;
4 | import com.im.lottery.entity.Record;
5 |
6 | public class FindAllRecordResp extends Response{
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 1L;
11 | private Page records;
12 | private Integer pageNum;
13 | public Page getRecords() {
14 | return records;
15 | }
16 | public void setRecords(Page records) {
17 | this.records = records;
18 | }
19 | public Integer getPageNum() {
20 | return pageNum;
21 | }
22 | public void setPageNum(Integer pageNum) {
23 | this.pageNum = pageNum;
24 | }
25 |
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/entity/Record.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.entity;
2 |
3 | import java.io.Serializable;
4 | import java.sql.Timestamp;
5 |
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 |
8 | import lombok.Data;
9 | import lombok.ToString;
10 |
11 | /**
12 | *
13 | * @author wangpeng
14 | * 获奖记录实体
15 | */
16 | @ToString
17 | @Data
18 | public class Record implements Serializable{
19 | /**
20 | *
21 | */
22 | private static final long serialVersionUID = 1L;
23 | private Long recordId;
24 | private String name; //姓名
25 | private Long phone; //手机号
26 | private String address; //地址
27 | private Integer prizeId; //关联奖品名称
28 | private Integer status; //状态
29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
30 | private Timestamp addTime; //添加时间
31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
32 | private Timestamp updateTime; //更新时间
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/entity/Prize.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.entity;
2 |
3 | import java.io.Serializable;
4 | import java.sql.Timestamp;
5 |
6 | import com.fasterxml.jackson.annotation.JsonFormat;
7 |
8 | import lombok.Data;
9 | import lombok.ToString;
10 |
11 | /**
12 | *
13 | * @author wangpeng
14 | * 奖品实体
15 | */
16 | @Data
17 | @ToString
18 | public class Prize implements Serializable{
19 | /**
20 | *
21 | */
22 | private static final long serialVersionUID = 1L;
23 | private Integer prizeId;
24 | private String name; //奖项
25 | private String detail; //奖品类容
26 | private String text; //二维码
27 | private Integer inventory; //库存
28 | private Integer status; //状态
29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
30 | private Timestamp addTime; //添加时间
31 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
32 | private Timestamp updateTime; //更新时间
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/com/im/lottery/LotteryApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery;
2 |
3 | import java.sql.Timestamp;
4 | import java.time.LocalDateTime;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.SpringApplicationConfiguration;
10 | import org.springframework.data.redis.core.RedisTemplate;
11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 | import org.springframework.test.context.web.WebAppConfiguration;
13 |
14 | import com.im.lottery.entity.Prize;
15 | import com.im.lottery.entity.Record;
16 | import com.im.lottery.persistence.PrizeMapper;
17 | import com.im.lottery.service.PrizeService;
18 |
19 | @RunWith(SpringJUnit4ClassRunner.class)
20 | @SpringApplicationConfiguration(classes = LotteryApplication.class)
21 | @WebAppConfiguration
22 | public class LotteryApplicationTests {
23 |
24 | @Test
25 | public void contextLoads() {
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
14 | # =========================
15 | # Operating System Files
16 | # =========================
17 |
18 | # OSX
19 | # =========================
20 |
21 | .DS_Store
22 | .AppleDouble
23 | .LSOverride
24 |
25 | # Thumbnails
26 | ._*
27 |
28 | # Files that might appear on external disk
29 | .Spotlight-V100
30 | .Trashes
31 |
32 | # Directories potentially created on remote AFP share
33 | .AppleDB
34 | .AppleDesktop
35 | Network Trash Folder
36 | Temporary Items
37 | .apdisk
38 |
39 | # Windows
40 | # =========================
41 |
42 | # Windows image file caches
43 | Thumbs.db
44 | ehthumbs.db
45 |
46 | # Folder config file
47 | Desktop.ini
48 |
49 | # Recycle Bin used on file shares
50 | $RECYCLE.BIN/
51 |
52 | # Windows Installer files
53 | *.cab
54 | *.msi
55 | *.msm
56 | *.msp
57 |
58 | # Windows shortcuts
59 | *.lnk
60 |
--------------------------------------------------------------------------------
/src/main/resources/com/im/lottery/persistence/RecordMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 | INSERT INTO t_record(
7 | `name`,
8 | `phone`,
9 | `address`,
10 | `prizeId`,
11 | `status`,
12 | `addTime`
13 | )VALUES(
14 | #{name},
15 | #{phone},
16 | #{address},
17 | #{prizeId},
18 | #{status},
19 | #{addTime}
20 | )
21 |
22 |
28 |
31 |
32 | UPDATE t_record SET
33 |
34 | `name`=#{name},
35 |
36 |
37 | `address`=#{address},
38 |
39 |
40 | `phone`=#{phone},
41 |
42 |
43 | `name`=#{name},
44 |
45 | `updateTime`=#{updateTime},
46 | `status`=#{status}
47 |
48 | recordId=#{recordId}
49 |
50 |
51 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/utils/LotteryUtil.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.utils;
2 |
3 | import java.util.Arrays;
4 | import java.util.concurrent.atomic.LongAdder;
5 |
6 | import com.im.lottery.entity.Record;
7 |
8 | public class LotteryUtil {
9 | public static LongAdder addr=new LongAdder();
10 | private static Integer[] sixPrize={4,5,6,10,11,12,17,18,23,24,29,30,34,35,39,40,42,43,48,49,54,55,59};
11 | private static Integer[] fivePrize={1,2,7,8,13,14,19,20,26,27,31,32,36,37,44,45,51,52,56,57};
12 | private static Integer[] fourPrize={3,9,16,21,22,28,33,41,46,47,53,58};
13 | private static Integer[] threePrize={15,38};
14 | private static Integer[] twoPrize={25,50};
15 | private static Integer[] onePrize={60};
16 |
17 | public static Record lotteryDistribution(Record record){
18 | addr.increment();
19 | System.out.println("----"+addr.intValue()+"--------------");
20 | if(Arrays.asList(sixPrize).contains(addr.intValue())){
21 | record.setPrizeId(6);
22 | }else if(Arrays.asList(fivePrize).contains(addr.intValue())){
23 | record.setPrizeId(5);
24 | }else if(Arrays.asList(fourPrize).contains(addr.intValue())){
25 | record.setPrizeId(4);
26 | }else if(Arrays.asList(threePrize).contains(addr.intValue())){
27 | record.setPrizeId(3);
28 | }else if(Arrays.asList(twoPrize).contains(addr.intValue())){
29 | record.setPrizeId(2);
30 | }else if(Arrays.asList(onePrize).contains(addr.intValue())){
31 | record.setPrizeId(1);
32 | }
33 | if(addr.intValue()==60){
34 | addr=new LongAdder();
35 | }
36 | return record;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/sql/lottery_schema.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : localhost
5 | Source Server Version : 50528
6 | Source Host : localhost:3306
7 | Source Database : lottery
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50528
11 | File Encoding : 65001
12 |
13 | Date: 2016-12-15 16:04:59
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 |
18 | -- ----------------------------
19 | -- Table structure for t_prize
20 | -- ----------------------------
21 | DROP TABLE IF EXISTS `t_prize`;
22 | CREATE TABLE `t_prize` (
23 | `prizeId` int(11) NOT NULL AUTO_INCREMENT,
24 | `name` varchar(255) DEFAULT NULL,
25 | `detail` varchar(255) DEFAULT NULL,
26 | `text` varchar(255) DEFAULT NULL,
27 | `inventory` int(11) DEFAULT NULL,
28 | `status` int(11) DEFAULT NULL,
29 | `addTime` datetime DEFAULT NULL,
30 | `updateTime` datetime DEFAULT NULL,
31 | PRIMARY KEY (`prizeId`)
32 | ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
33 |
34 | -- ----------------------------
35 | -- Table structure for t_record
36 | -- ----------------------------
37 | DROP TABLE IF EXISTS `t_record`;
38 | CREATE TABLE `t_record` (
39 | `recordId` bigint(20) NOT NULL AUTO_INCREMENT,
40 | `name` varchar(255) DEFAULT NULL,
41 | `phone` bigint(20) DEFAULT NULL,
42 | `address` varchar(255) DEFAULT NULL,
43 | `prizeId` int(11) DEFAULT NULL,
44 | `status` int(11) DEFAULT NULL,
45 | `addTime` datetime DEFAULT NULL,
46 | `updateTime` datetime DEFAULT NULL,
47 | PRIMARY KEY (`recordId`)
48 | ) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8;
49 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/config/DruidConfiguation.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.config;
2 |
3 | import java.sql.SQLException;
4 |
5 | import javax.sql.DataSource;
6 |
7 | import org.springframework.boot.context.embedded.ServletRegistrationBean;
8 | import org.springframework.boot.context.properties.ConfigurationProperties;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.jdbc.datasource.DataSourceTransactionManager;
12 |
13 | import com.alibaba.druid.pool.DruidDataSource;
14 | import com.alibaba.druid.support.http.StatViewServlet;
15 |
16 | @Configuration
17 | public class DruidConfiguation {
18 | @Bean(initMethod="init",destroyMethod="close")
19 | @ConfigurationProperties(prefix="datasource.druid")
20 | public DataSource dataSource() {
21 | DruidDataSource druidDataSource=new DruidDataSource();
22 | try {
23 | druidDataSource.setFilters("stat, wall");
24 | } catch (SQLException e) {
25 | e.printStackTrace();
26 | }
27 | return druidDataSource;
28 | }
29 | @Bean
30 | public ServletRegistrationBean druidServlet() {
31 | ServletRegistrationBean srb=new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
32 | srb.addInitParameter("loginUsername","user");// 用户名
33 | srb.addInitParameter("loginPassword", "1234");// 密码
34 | srb.addInitParameter("resetEnable", "false");// 禁用HTML页面上的"Reset All"功能
35 | return srb;
36 | }
37 | @Bean
38 | public DataSourceTransactionManager transactionManager(){
39 | DataSourceTransactionManager transactionManager=new DataSourceTransactionManager();
40 | transactionManager.setDataSource(dataSource());
41 | return transactionManager;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/resources/com/im/lottery/persistence/PrizeMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 | INSERT INTO
7 | t_prize(
8 | `name`,
9 | `detail`,
10 | `text`,
11 | `inventory`,
12 | `status`,
13 | `addTime`,
14 | `updateTime`
15 | )VALUES(
16 | #{name},
17 | #{detail},
18 | #{text},
19 | #{inventory},
20 | #{status},
21 | #{addTime},
22 | #{updateTime}
23 | )
24 |
25 |
26 | DELETE FROM t_prize
27 |
28 | prizeId=#{prizeId}
29 |
30 |
31 |
32 |
33 | UPDATE t_prize SET
34 |
35 | `name`=#{name},
36 |
37 |
38 | `detail`=#{detail},
39 |
40 |
41 | `text`=#{text},
42 |
43 |
44 | `inventory`=#{inventory},
45 |
46 | `updateTime`=#{updateTime}
47 |
48 | prizeId=#{prizeId}
49 |
50 |
51 |
54 |
60 |
66 |
67 | UPDATE t_prize SET `inventory`=`inventory`-1
68 |
69 | prizeId=#{prizeId}
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/config/MybatisConfiguation.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.config;
2 |
3 | import java.util.Properties;
4 |
5 | import javax.sql.DataSource;
6 |
7 | import org.apache.ibatis.plugin.Interceptor;
8 | import org.mybatis.spring.SqlSessionFactoryBean;
9 | import org.mybatis.spring.annotation.MapperScan;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 | import org.springframework.core.io.ClassPathResource;
14 |
15 | import com.github.pagehelper.PageHelper;
16 | @Configuration
17 | @MapperScan(basePackages="com.im.lottery.persistence")
18 | public class MybatisConfiguation {
19 |
20 | @Autowired
21 | private DataSource dataSource;
22 | //分页插件
23 | @Bean
24 | public Interceptor pageHelper(){
25 | //分页插件
26 | PageHelper pageHelper = new PageHelper();
27 | Properties properties = new Properties();
28 | properties.setProperty("reasonable", "false");
29 | properties.setProperty("supportMethodsArguments", "true");
30 | properties.setProperty("returnPageInfo", "check");
31 | properties.setProperty("params", "count=countSql");
32 | pageHelper.setProperties(properties);
33 | return pageHelper;
34 | }
35 | @Bean
36 | public SqlSessionFactoryBean sqlSessionFactory(){
37 | SqlSessionFactoryBean sqlSessionFactory=new SqlSessionFactoryBean();
38 | sqlSessionFactory.setDataSource(dataSource);
39 | sqlSessionFactory.setTypeAliasesPackage("com.im.lottery.entity");
40 |
41 | sqlSessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
42 |
43 | Interceptor[] interceptors=new Interceptor[1];
44 | interceptors[0]=pageHelper();
45 | sqlSessionFactory.setPlugins(interceptors);
46 | return sqlSessionFactory;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/utils/MD5Util.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.utils;
2 |
3 | import java.security.MessageDigest;
4 | import java.util.Iterator;
5 | import java.util.Map;
6 | import java.util.Set;
7 | import java.util.SortedMap;
8 |
9 | public class MD5Util {
10 |
11 | private static String byteArrayToHexString(byte b[]) {
12 | StringBuffer resultSb = new StringBuffer();
13 | for (int i = 0; i < b.length; i++)
14 | resultSb.append(byteToHexString(b[i]));
15 |
16 | return resultSb.toString();
17 | }
18 |
19 | private static String byteToHexString(byte b) {
20 | int n = b;
21 | if (n < 0)
22 | n += 256;
23 | int d1 = n / 16;
24 | int d2 = n % 16;
25 | return hexDigits[d1] + hexDigits[d2];
26 | }
27 |
28 | public static String MD5Encode(String origin, String charsetname) {
29 | String resultString = null;
30 | try {
31 | resultString = new String(origin);
32 | MessageDigest md = MessageDigest.getInstance("MD5");
33 | if (charsetname == null || "".equals(charsetname))
34 | resultString = byteArrayToHexString(md.digest(resultString
35 | .getBytes()));
36 | else
37 | resultString = byteArrayToHexString(md.digest(resultString
38 | .getBytes(charsetname)));
39 | } catch (Exception exception) {
40 | }
41 | return resultString;
42 | }
43 |
44 | private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
45 | "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
46 |
47 | /**
48 | * 拼接数据并进行MD5签名
49 | * @param obj
50 | * @return String 转换成字符串,若对象为null,则返回空字符串.
51 | */
52 | public static String createSign(SortedMap packageParams,String key) {
53 | StringBuffer sb = new StringBuffer();
54 | Set es = packageParams.entrySet();
55 | Iterator it = es.iterator();
56 | while (it.hasNext()) {
57 | Map.Entry entry = (Map.Entry) it.next();
58 | String k = (String) entry.getKey();
59 | String v = (String) entry.getValue();
60 | if (null != v && !"".equals(v) && !"sign".equals(k)
61 | && !"key".equals(k)) {
62 | sb.append(k + "=" + v + "&");
63 | }
64 | }
65 | System.out.println(sb.toString());
66 | sb.append("key=" + key);
67 | String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
68 | //System.out.println("packge签名:" + sign);
69 | return sign;
70 |
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | # SERVER
2 | server.port=8086
3 |
4 | # LOG
5 | logging.file=lottery.log
6 | logging.level.com.vrimmer.utils=error
7 | logging.level.com.vrimmer.mapper=error
8 |
9 | # ACTUATOR
10 | management.context-path=/actuator
11 | security.basic.path=/sys,/
12 | security.user.name=immer
13 | security.user.password=vrimmer123456
14 |
15 | # SECURITY
16 | MD5.ATTACH=ImmAimee
17 |
18 | # Mybatis
19 | mybatis.config-location=classpath:mybatis-config.xml
20 | mybatis.check-config-location=true
21 |
22 | # JDBC
23 | datasource.druid.type=com.alibaba.druid.pool.DruidDataSource
24 | datasource.druid.driverClassName=com.mysql.jdbc.Driver
25 | datasource.druid.url=jdbc:mysql://172.16.1.81:3306/lottery?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&useSSL=true
26 | datasource.druid.username=root
27 | datasource.druid.password=ym-123456
28 | # 下面为连接池的补充设置,应用到上面所有数据源中
29 | # 初始化大小,最小,最大
30 | datasource.druid.initialSize=5
31 | datasource.druid.minIdle=5
32 | datasource.druid.maxActive=20
33 | # 配置获取连接等待超时的时间
34 | datasource.druid.maxWait=60000
35 | # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
36 | datasource.druid.timeBetweenEvictionRunsMillis=60000
37 | # 配置一个连接在池中最小生存的时间,单位是毫秒
38 | datasource.druid.minEvictableIdleTimeMillis=300000
39 | datasource.druid.validationQuery=SELECT 1 FROM DUAL
40 | datasource.druid.testWhileIdle=true
41 | datasource.druid.testOnBorrow=false
42 | datasource.druid.testOnReturn=false
43 | # 打开PSCache,并且指定每个连接上PSCache的大小
44 | datasource.druid.poolPreparedStatements=true
45 | datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
46 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
47 | datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
48 | # 合并多个DruidDataSource的监控数据
49 | #datasource.druid.useGlobalDataSourceStat=true
50 | #IP白名单 (没有配置或者为空,则允许所有访问)
51 | datasource.druid.state.allow=
52 | #IP黑名单 (存在共同时,deny优先于allow)
53 | datasource.druid.state.deny=
54 |
55 |
56 | # VERSION
57 | verId = v1
58 |
59 | # REDIS
60 | spring.redis.database=0
61 | spring.redis.host=localhost
62 | spring.redis.password=
63 | # Login password of the redis server. K^bFLy%^68M%
64 | spring.redis.pool.max-active=8
65 | spring.redis.pool.max-idle=8
66 | spring.redis.pool.max-wait=-1
67 | spring.redis.pool.min-idle=0
68 | spring.redis.port=6379
69 | spring.redis.sentinel.master=
70 | # Name of Redis server.
71 | spring.redis.sentinel.nodes=
72 | # Comma-separated list of host:port pairs.
73 | spring.redis.timeout=0
74 |
75 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/controller/PrizeController.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.controller;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.RequestBody;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import com.im.lottery.req.CreatePrizeReq;
10 | import com.im.lottery.req.DeletePrizeReq;
11 | import com.im.lottery.req.FillInfomationReq;
12 | import com.im.lottery.req.FindAllReq;
13 | import com.im.lottery.req.FindPageReq;
14 | import com.im.lottery.req.FindPrizeByIdReq;
15 | import com.im.lottery.req.LotteryReq;
16 | import com.im.lottery.req.UpdatePrizeReq;
17 | import com.im.lottery.resp.Response;
18 | import com.im.lottery.service.LotteryService;
19 | import com.im.lottery.service.PrizeService;
20 |
21 | @RestController
22 | public class PrizeController {
23 | @Autowired
24 | private PrizeService prizeService;
25 | @Autowired
26 | private LotteryService lotteryService;
27 |
28 | @RequestMapping(value="/createPrize",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
29 | public Response createPrize(@RequestBody CreatePrizeReq createPrizeReq){
30 | return prizeService.InsertPrize(createPrizeReq);
31 | }
32 | @RequestMapping(value="/deletePrize",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
33 | public Response deletePrize(@RequestBody DeletePrizeReq deletePrizeReq){
34 | return prizeService.delete(deletePrizeReq);
35 | }
36 | @RequestMapping(value="/updatePrize",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
37 | public Response updatePrize(@RequestBody UpdatePrizeReq updatePrizeReq){
38 | return prizeService.update(updatePrizeReq);
39 | }
40 | @RequestMapping(value="/findAllPrize",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
41 | public Response findAllPrize(@RequestBody FindAllReq findAllReq){
42 | return prizeService.findAll(findAllReq);
43 | }
44 | @RequestMapping(value="/FindPrizeById",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
45 | public Response FindPrizeById(@RequestBody FindPrizeByIdReq FindPrizeByIdReq){
46 | return prizeService.findById(FindPrizeByIdReq);
47 | }
48 | @RequestMapping(value="/lottery",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
49 | public Response lottery(@RequestBody LotteryReq lotteryReq){
50 | return lotteryService.lottery(lotteryReq);
51 | }
52 | @RequestMapping(value="/fillInfomation",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
53 | public Response fillInfomation(@RequestBody FillInfomationReq fillInfomationReq){
54 | return lotteryService.fillInfomation(fillInfomationReq);
55 | }
56 | @RequestMapping(value="/findAllRecord",method=RequestMethod.POST,produces = "application/json; charset=UTF-8")
57 | public Response findAllRecord(@RequestBody FindPageReq findPageReq){
58 | return lotteryService.findAll(findPageReq);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.im
7 | Lottery
8 | v1.0.0
9 | jar
10 |
11 | Lottery
12 | Lottery Platform
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.3.8.RELEASE
18 |
19 |
20 |
21 |
22 |
23 | UTF-8
24 | UTF-8
25 | 1.8
26 |
27 | 4.1.6
28 | 1.0.21
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-actuator
35 |
36 |
37 | org.mybatis.spring.boot
38 | mybatis-spring-boot-starter
39 | 1.1.1
40 |
41 |
42 | com.github.pagehelper
43 | pagehelper
44 | ${pagehelper.version}
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-starter-web
49 |
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-devtools
54 | runtime
55 |
56 |
57 | mysql
58 | mysql-connector-java
59 | runtime
60 |
61 |
62 | org.springframework.boot
63 | spring-boot-starter-test
64 | test
65 |
66 |
67 |
68 | com.alibaba
69 | druid
70 | ${druid.version}
71 |
72 |
73 | org.projectlombok
74 | lombok
75 | 1.16.8
76 |
77 |
78 | org.springframework.data
79 | spring-data-redis
80 |
81 |
82 | org.slf4j
83 | slf4j-log4j12
84 |
85 |
86 | log4j
87 | log4j
88 |
89 |
90 |
91 |
92 | redis.clients
93 | jedis
94 | jar
95 | compile
96 |
97 |
98 | org.springframework.boot
99 | spring-boot-configuration-processor
100 | true
101 |
102 |
103 |
104 |
105 |
106 |
107 | org.springframework.boot
108 | spring-boot-maven-plugin
109 |
110 |
111 |
112 |
113 |
114 |
115 |
--------------------------------------------------------------------------------
/src/main/java/com/im/lottery/config/LocalRedisConfig.java:
--------------------------------------------------------------------------------
1 | package com.im.lottery.config;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.data.redis.connection.RedisConnectionFactory;
7 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
8 | import org.springframework.data.redis.core.RedisTemplate;
9 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
10 |
11 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
12 | import com.fasterxml.jackson.annotation.PropertyAccessor;
13 | import com.fasterxml.jackson.databind.ObjectMapper;
14 |
15 | import redis.clients.jedis.JedisPoolConfig;
16 |
17 | @Configuration
18 | public class LocalRedisConfig {
19 | @Value("${spring.redis.host}")
20 | private String hostName;
21 | @Value("${spring.redis.port}")
22 | private int port;
23 | @Value("${spring.redis.password}")
24 | private String passWord;
25 | @Value("${spring.redis.pool.max-idle}")
26 | private int maxIdl;
27 | @Value("${spring.redis.pool.min-idle}")
28 | private int minIdl;
29 |
30 | // @Value("${activity.appIds}")
31 | // private String appIds;
32 | // @Value("${activity.startTime}")
33 | // private String startTime;
34 | // @Value("${activity.during}")
35 | // private int during;
36 |
37 | @Bean
38 | public RedisConnectionFactory jedisConnectionFactory(){
39 | JedisPoolConfig poolConfig=new JedisPoolConfig();
40 | poolConfig.setMaxIdle(maxIdl);
41 | poolConfig.setMinIdle(minIdl);
42 | poolConfig.setTestOnBorrow(true);
43 | poolConfig.setTestOnReturn(true);
44 | poolConfig.setTestWhileIdle(true);
45 | poolConfig.setNumTestsPerEvictionRun(10);
46 | poolConfig.setTimeBetweenEvictionRunsMillis(60000);
47 |
48 | JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(poolConfig);
49 | jedisConnectionFactory.setHostName(hostName);
50 | if(!passWord.isEmpty()){
51 | jedisConnectionFactory.setPassword(passWord);
52 | }
53 | jedisConnectionFactory.setPort(port);
54 | return jedisConnectionFactory;
55 | }
56 |
57 | // @Bean
58 | // public StringRedisTemplate redisTemplate() throws Exception {
59 | // StringRedisTemplate redisTemplate = new StringRedisTemplate(jedisConnectionFactory());
60 | // Date start = new SimpleDateFormat("yyyy-MM-dd").parse(startTime);
61 | // Date now = new Date();
62 | // long duration = during*60*60*1000;
63 | // if(now.getTime()-start.getTime() < duration){
64 | // String redisKey = "activity_key";
65 | // long expire = duration+start.getTime()-now.getTime();
66 | // redisTemplate.opsForValue().set(redisKey, appIds, expire, TimeUnit.MILLISECONDS);
67 | // }
68 | // return redisTemplate;
69 | // }
70 |
71 | @Bean
72 | public RedisTemplate redisTemplateObject() throws Exception {
73 | RedisTemplate redisTemplateObject = new RedisTemplate();
74 | redisTemplateObject.setConnectionFactory(jedisConnectionFactory());
75 | setSerializer(redisTemplateObject);
76 | redisTemplateObject.afterPropertiesSet();
77 | return redisTemplateObject;
78 | }
79 |
80 | /**
81 | * 设置序列化方法
82 | */
83 | private void setSerializer(RedisTemplate template) {
84 | Jackson2JsonRedisSerializer