Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
xunj
/
festival-activites
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a249f4c4
authored
Jan 29, 2021
by
xunj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
概率随机、用户牛牌数量查询
1 parent
b9ffaba9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
169 additions
and
2 deletions
activity-admin/src/main/java/com/polysoft/activity/controller/CattleController.java
activity-admin/src/main/java/com/polysoft/activity/mapper/CattleBrandMapper.java
activity-admin/src/main/java/com/polysoft/activity/model/vo/CattleBrandFroUserVO.java
activity-admin/src/main/java/com/polysoft/activity/service/CattleBrandService.java
activity-admin/src/main/java/com/polysoft/activity/service/impl/CattleBrandServiceImpl.java
activity-admin/src/main/java/com/polysoft/activity/utils/MathRandom.java
activity-admin/src/main/resources/mapper/CattleBrandMapper.xml
activity-admin/src/main/java/com/polysoft/activity/controller/CattleController.java
0 → 100644
View file @
a249f4c
package
com
.
polysoft
.
activity
.
controller
;
import
com.polysoft.activity.model.param.UserInfoParam
;
import
com.polysoft.activity.service.CattleBrandService
;
import
com.polysoft.activity.utils.ApiResult
;
import
io.swagger.annotations.Api
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
/**
* @author lvyp
* @date 2021/1/29
*/
@RestController
@RequestMapping
(
"/cattle"
)
@Api
(
value
=
"牛牌"
,
description
=
"牛牌接口"
)
public
class
CattleController
{
@Resource
private
CattleBrandService
cattleBrandService
;
@GetMapping
(
"/queryCattleBrandByUserId"
)
@ResponseBody
public
ApiResult
queryCattleBrandByUserId
(
@RequestParam
(
value
=
"userId"
)
Long
userId
)
{
if
(
userId
==
null
){
return
ApiResult
.
error
(
"用户不能为空"
);
}
return
cattleBrandService
.
queryCattleBrandByUserId
(
userId
);
}
}
activity-admin/src/main/java/com/polysoft/activity/mapper/CattleBrandMapper.java
View file @
a249f4c
...
@@ -2,7 +2,9 @@ package com.polysoft.activity.mapper;
...
@@ -2,7 +2,9 @@ package com.polysoft.activity.mapper;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.polysoft.activity.model.dto.CattleBrandDto
;
import
com.polysoft.activity.model.dto.CattleBrandDto
;
import
com.polysoft.activity.model.vo.CattleBrandFroUserVO
;
import
com.polysoft.activity.model.vo.CattleBrandVO
;
import
com.polysoft.activity.model.vo.CattleBrandVO
;
import
org.apache.ibatis.annotations.Param
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapper
;
import
java.util.List
;
import
java.util.List
;
...
@@ -10,4 +12,5 @@ import java.util.List;
...
@@ -10,4 +12,5 @@ import java.util.List;
@Mapper
@Mapper
public
interface
CattleBrandMapper
extends
BaseMapper
<
CattleBrandDto
>
{
public
interface
CattleBrandMapper
extends
BaseMapper
<
CattleBrandDto
>
{
List
<
CattleBrandVO
>
queryCattleBrandList
();
List
<
CattleBrandVO
>
queryCattleBrandList
();
CattleBrandFroUserVO
queryCattleBrandByUserId
(
@Param
(
"userId"
)
Long
userId
);
}
}
activity-admin/src/main/java/com/polysoft/activity/model/vo/CattleBrandFroUserVO.java
0 → 100644
View file @
a249f4c
package
com
.
polysoft
.
activity
.
model
.
vo
;
import
lombok.Data
;
/**
* @author lvyp
* @date 2021/1/29
*/
@Data
public
class
CattleBrandFroUserVO
{
private
String
jiangKang
;
private
String
fuYun
;
private
String
zhaoCai
;
private
String
pingAn
;
private
String
ruYi
;
}
activity-admin/src/main/java/com/polysoft/activity/service/CattleBrandService.java
View file @
a249f4c
package
com
.
polysoft
.
activity
.
service
;
package
com
.
polysoft
.
activity
.
service
;
import
com.polysoft.activity.model.vo.CattleBrandVO
;
import
com.polysoft.activity.utils.ApiResult
;
import
com.polysoft.activity.utils.ApiResult
;
import
java.util.List
;
public
interface
CattleBrandService
{
public
interface
CattleBrandService
{
ApiResult
queryCattleBrandList
();
ApiResult
queryCattleBrandList
();
ApiResult
queryCattleBrandByUserId
(
Long
userId
);
}
}
activity-admin/src/main/java/com/polysoft/activity/service/impl/CattleBrandServiceImpl.java
View file @
a249f4c
...
@@ -16,4 +16,9 @@ public class CattleBrandServiceImpl implements CattleBrandService {
...
@@ -16,4 +16,9 @@ public class CattleBrandServiceImpl implements CattleBrandService {
public
ApiResult
queryCattleBrandList
()
{
public
ApiResult
queryCattleBrandList
()
{
return
ApiResult
.
ok
(
cattleBrandMapper
.
queryCattleBrandList
());
return
ApiResult
.
ok
(
cattleBrandMapper
.
queryCattleBrandList
());
}
}
@Override
public
ApiResult
queryCattleBrandByUserId
(
Long
userId
)
{
return
ApiResult
.
ok
(
cattleBrandMapper
.
queryCattleBrandByUserId
(
userId
));
}
}
}
activity-admin/src/main/java/com/polysoft/activity/utils/MathRandom.java
0 → 100644
View file @
a249f4c
package
com
.
polysoft
.
activity
.
utils
;
/**
* @author lvyp
* @date 2021/1/29
*/
public
class
MathRandom
{
public
MathRandom
(
double
rate0
,
double
rate1
,
double
rate2
,
double
rate3
,
double
rate4
)
{
this
.
rate0
=
rate0
;
this
.
rate1
=
rate1
;
this
.
rate2
=
rate2
;
this
.
rate3
=
rate3
;
this
.
rate4
=
rate4
;
}
/**
* 0出现的概率为%50
*/
public
double
rate0
;
/**
* 1出现的概率为%20
*/
public
double
rate1
;
/**
* 2出现的概率为%15
*/
public
double
rate2
;
/**
* 3出现的概率为%10
*/
public
double
rate3
;
/**
* 4出现的概率为%4
*/
public
double
rate4
;
/**
* Math.random()产生一个double型的随机数,判断一下
* 例如0出现的概率为%50,则介于0到0.50中间的返回0
* @return int
*
*/
private
int
PercentageRandom
()
{
double
randomNumber
;
randomNumber
=
Math
.
random
();
if
(
randomNumber
>=
0
&&
randomNumber
<=
rate0
)
{
return
0
;
}
else
if
(
randomNumber
>=
rate0
/
100
&&
randomNumber
<=
rate0
+
rate1
)
{
return
1
;
}
else
if
(
randomNumber
>=
rate0
+
rate1
&&
randomNumber
<=
rate0
+
rate1
+
rate2
)
{
return
2
;
}
else
if
(
randomNumber
>=
rate0
+
rate1
+
rate2
&&
randomNumber
<=
rate0
+
rate1
+
rate2
+
rate3
)
{
return
3
;
}
else
if
(
randomNumber
>=
rate0
+
rate1
+
rate2
+
rate3
&&
randomNumber
<=
rate0
+
rate1
+
rate2
+
rate3
+
rate4
)
{
return
4
;
}
else
if
(
randomNumber
>=
rate0
+
rate1
+
rate2
+
rate3
+
rate4
&&
randomNumber
<=
rate0
+
rate1
+
rate2
+
rate3
+
rate4
)
{
return
5
;
}
return
-
1
;
}
/**
* 测试主程序
* @param agrs
*/
public
static
void
main
(
String
[]
agrs
)
{
int
i
=
0
;
MathRandom
a
=
new
MathRandom
(
0.50
,
0.30
,
0.15
,
0.04
,
0.01
);
for
(
i
=
0
;
i
<=
100
;
i
++)
//打印100个测试概率的准确性
{
System
.
out
.
println
(
a
.
PercentageRandom
()+
1
);
}
}
}
activity-admin/src/main/resources/mapper/CattleBrandMapper.xml
View file @
a249f4c
...
@@ -8,6 +8,18 @@
...
@@ -8,6 +8,18 @@
brand_type,
brand_type,
brand_name
brand_name
from t_cattle_brand
from t_cattle_brand
</select>
<select
id=
"queryCattleBrandByUserId"
resultType=
"com.polysoft.activity.model.vo.CattleBrandFroUserVO"
>
SELECT
count( t.cattle_brand_id = 1 OR NULL ) as jiangKang,
count( t.cattle_brand_id = 2 OR NULL ) as fuYun,
count( t.cattle_brand_id = 3 OR NULL ) as zhaoCai,
count( t.cattle_brand_id = 4 OR NULL ) as pingAn,
count( t.cattle_brand_id = 5 OR NULL ) as ruYi
FROM
t_user_cattle t
WHERE
t.user_id =#{userId} GROUP BY t.user_id
</select>
</select>
</mapper>
</mapper>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment