This commit is contained in:
weihongyang 2022-09-13 13:04:55 +08:00
父節點 fcf35bd12b
當前提交 f2091d56e2
共有 16 個檔案被更改,包括 669 行新增5 行删除

查看文件

@ -22,6 +22,8 @@ import java.util.stream.Collectors;
@JsonIgnoreProperties(ignoreUnknown = true)
public class LoginUser implements UserDetails{
private static final long serialVersionUID = 1L;
private SysUserEntity sysUserEntity;
private List<String> permissions;

查看文件

@ -28,6 +28,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
* @Author weihongyang
@ -79,7 +80,7 @@ public class LoginServiceImpl implements LoginService {
Map<String,String> map = new HashMap<>();
map.put("token",jwt);
//把完整的用户信息存入redis userid作为key
redisTemplate.opsForValue().set("login:"+userid,loginUser);
redisTemplate.opsForValue().set("login:"+userid,loginUser,1, TimeUnit.DAYS);
//登录成功
log.setStatus(LoginStatusEnum.SUCCESS.value());
log.setCreator(loginUser.getSysUserEntity().getId());

查看文件

@ -0,0 +1,160 @@
package com.cnbm.common.utils;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import static java.math.BigDecimal.ROUND_HALF_UP;
public class CountUtils {
// private static final BigDecimal TWO = BigDecimal.valueOf(2);
//
// public static BigDecimal Mean(List<BigDecimal> data){
// BigDecimal sum = new BigDecimal("0");
// for (BigDecimal datum : data) {
// sum = sum.add(datum);
// }
// BigDecimal divide = sum.divide(BigDecimal.valueOf(data.size()));
// return divide;
// }
//
// // population variance 总体方差
// public static BigDecimal POP_Variance(List<BigDecimal> data) {
// BigDecimal variance = new BigDecimal("0");
// for (BigDecimal datum : data) {
// variance = variance.add(datum.subtract(Mean(data)).pow(2));
// }
// variance = variance.divide(BigDecimal.valueOf(data.size()));
// return variance;
// }
//
// // population standard deviation 总体标准差
// public static BigDecimal POP_STD_dev(List<BigDecimal> data) {
// BigDecimal sqrt = sqrt(POP_Variance(data), 4);
// return sqrt;
// }
//
// //sample variance 样本方差
// public static BigDecimal Sample_Variance(List<BigDecimal> data) {
// BigDecimal variance = new BigDecimal("0");
// for (BigDecimal datum : data) {
// variance = variance.add(datum.subtract(Mean(data)).pow(2));
// }
// variance = variance.divide(BigDecimal.valueOf(data.size() - 1),4);
// return variance;
// }
//
// // sample standard deviation 样本标准差
// public static BigDecimal Sample_STD_dev(List<BigDecimal> data) {
// BigDecimal sqrt = sqrt(Sample_Variance(data), 4);
// return sqrt;
// }
//
// public static BigDecimal sqrt(BigDecimal A, final int SCALE) {
// BigDecimal x0 = new BigDecimal("0");
// BigDecimal x1 = new BigDecimal(Math.sqrt(A.doubleValue()));
// while (!x0.equals(x1)) {
// x0 = x1;
// x1 = A.divide(x0, SCALE, ROUND_HALF_UP);
// x1 = x1.add(x0);
// x1 = x1.divide(TWO, SCALE, ROUND_HALF_UP);
//
// }
// return x1;
// }
double Sum(double[] data) {
double sum = 0;
for (int i = 0; i < data.length; i++)
sum = sum + data[i];
return sum;
}
double Mean(double[] data) {
double mean = 0;
mean = Sum(data) / data.length;
return mean;
}
// population variance 总体方差
double POP_Variance(double[] data) {
double variance = 0;
for (int i = 0; i < data.length; i++) {
variance = variance + (Math.pow((data[i] - Mean(data)), 2));
}
variance = variance / data.length;
return variance;
}
// population standard deviation 总体标准差
double POP_STD_dev(double[] data) {
double std_dev;
std_dev = Math.sqrt(POP_Variance(data));
return std_dev;
}
//sample variance 样本方差
double Sample_Variance(double[] data) {
double variance = 0;
for (int i = 0; i < data.length; i++) {
variance = variance + (Math.pow((data[i] - Mean(data)), 2));
}
variance = variance / (data.length-1);
return variance;
}
// sample standard deviation 样本标准差
double Sample_STD_dev(double[] data) {
double std_dev;
std_dev = Math.sqrt(Sample_Variance(data));
return std_dev;
}
public static void main(String[] args) {
// List<BigDecimal> data = new ArrayList<>();
//
// data.add(new BigDecimal("10.023"));
// data.add(new BigDecimal("11.02"));
// data.add(new BigDecimal("9.99"));
// data.add(new BigDecimal("9.81"));
// data.add(new BigDecimal("10.12"));
// data.add(new BigDecimal("10.9"));
// data.add(new BigDecimal("9.99"));
// data.add(new BigDecimal("10.03"));
// data.add(new BigDecimal("9.99"));
// data.add(new BigDecimal("12.02"));
// CountUtils countUtils = new CountUtils();
//
// BigDecimal mean = countUtils.Mean(data);
// System.out.println(mean.toString());
//
//
// BigDecimal bigDecimal1 = POP_STD_dev(data);
// System.out.println(bigDecimal1.toString());
//
// System.out.println(Sample_STD_dev(data).toString());
//
// BigDecimal bigDecimal = POP_Variance(data);
// System.out.println(bigDecimal.toString());
//
//
// System.out.println(Sample_Variance(data));
double[] data = new double[]{10.023,11.02,9.99,9.81,10.12,10.9,9.99,10.03,9.99,12.02};
CountUtils countUtils = new CountUtils();
System.out.println(countUtils.Mean(data));
System.out.println(countUtils.POP_STD_dev(data));
System.out.println(countUtils.Sample_STD_dev(data));
System.out.println(countUtils.POP_Variance(data));
System.out.println(countUtils.Sample_Variance(data));
}
}

查看文件

@ -0,0 +1,90 @@
package com.cnbm.common.utils;
public class LeastSquares
{
/*
* 杜航 功能返回估计的y值
*/
public static float estimate(float[] x, float[] y, float input)
{
float a = getA(x, y);
float b = getB(x, y);
System.out.println("线性回归系数a值:\t" + a + "\n" + "线性回归系数b值:\t" + b);
return (a * input + b);
}
/*
* 杜航 功能返回x的系数a 公式a = ( n sum( xy ) - sum( x ) sum( y ) ) / ( n sum( x^2 )
* - sum(x) ^ 2 )
*/
public static float getA(float[] x, float[] y)
{
int n = x.length;
return (float) ((n * pSum(x, y) - sum(x) * sum(y)) / (n * sqSum(x) - Math
.pow(sum(x), 2)));
}
/*
* 杜航 功能返回常量系数系数b 公式b = sum( y ) / n - a sum( x ) / n
*/
public static float getB(float[] x, float[] y)
{
int n = x.length;
float a = getA(x, y);
return sum(y) / n - a * sum(x) / n;
}
/*
* 杜航 功能求和
*/
private static float sum(float[] ds)
{
float s = 0;
for (float d : ds)
{
s = s + d;
}
return s;
}
/*
* 杜航 功能求平方和
*/
private static float sqSum(float[] ds)
{
float s = 0;
for (float d : ds)
{
s = (float) (s + Math.pow(d, 2));
}
return s;
}
/*
* 杜航 功能返回对应项相乘后的和
*/
private static float pSum(float[] x, float[] y)
{
float s = 0;
for (int i = 0; i < x.length; i++)
{
s = s + x[i] * y[i];
}
return s;
}
/*
* 杜航 功能main()测试线性回归的最小二乘法java实现函数
*/
public static void main(String[] args)
{
float[] x =
// { 540, 360, 240, 480, 420 };
{ 0.501F, 0.482F, 0.482F, 0.51F, 0.492F, 0.54F, 0.5F, 0.492F, 0.51F, 0.489F};
float[] y =
// { 520, 475, 430, 386, 500 };
{10.023F, 11.02F, 9.99F, 9.81F, 10.12F,10.9F, 9.99F, 10.03F, 9.99F, 12.02F };
System.out.println("经线性回归后的y值:\t" + estimate(x, y,240));
}
}

查看文件

@ -32,7 +32,7 @@ spring:
max-request-size: 100MB
enabled: true
redis:
database: 2
database: 6
host: redis.picaiba.com
port: 6380
password: '@WSXcde3' # 密码(默认为空)

查看文件

@ -19,7 +19,7 @@ public class CodeGenerator {
@Test
public void test(){
mybatisPlusGenerator(new String[]{"sys_user","sys_role"});
mybatisPlusGenerator(new String[]{"sys_user"});
}
public static void mybatisPlusGenerator(String[] include){

查看文件

@ -0,0 +1,116 @@
package com.cnbm.generator.code.controller;
import com.cnbm.admin.annotation.LogOperation;
import com.cnbm.common.constant.Constant;
import com.cnbm.common.page.PageData;
import com.cnbm.common.utils.ExcelUtils;
import com.cnbm.common.utils.Result;
import com.cnbm.common.validator.AssertUtils;
import com.cnbm.common.validator.ValidatorUtils;
import com.cnbm.common.validator.group.AddGroup;
import com.cnbm.common.validator.group.DefaultGroup;
import com.cnbm.common.validator.group.UpdateGroup;
import com.cnbm.generator.code.dto.UserDTO;
import com.cnbm.generator.code.excel.UserExcel;
import com.cnbm.generator.code.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 系统用户 前端控制器
*
* @author why
* @since 2022-08-23
*/
@RestController
@RequestMapping("/code/user")
@Api(tags="系统用户")
public class UserController {
@Autowired
private IUserService userService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class)
})
@PreAuthorize("@ex.hasAuthority('code:user:page')")
public Result<PageData<UserDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<UserDTO> page = userService.page(params);
return new Result<PageData<UserDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@PreAuthorize("@ex.hasAuthority('code:user:info')")
public Result<UserDTO> get(@PathVariable("id") Long id){
UserDTO data = userService.get(id);
return new Result<UserDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@PreAuthorize("@ex.hasAuthority('code:user:save')")
public Result<Long> save(@RequestBody UserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
userService.save(dto);
return new Result<Long>().ok(dto.getId());
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@PreAuthorize("@ex.hasAuthority('code:user:update')")
public Result<Long> update(@RequestBody UserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
userService.update(dto);
return new Result<Long>().ok(dto.getId());
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@PreAuthorize("@ex.hasAuthority('code:user:delete')")
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
userService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@PreAuthorize("@ex.hasAuthority('code:user:export')")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<UserDTO> list = userService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, UserExcel.class);
}
}

查看文件

@ -0,0 +1,74 @@
package com.cnbm.generator.code.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.math.BigDecimal;
/**
* 系统用户
*
* @author why
* @since 2022-08-23
*/
@Data
@ApiModel(value = "系统用户DTO对象")
public class UserDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "用户名")
private String username;
@ApiModelProperty(value = "密码")
private String password;
@ApiModelProperty(value = "姓名")
private String realName;
@ApiModelProperty(value = "头像")
private String headUrl;
@ApiModelProperty(value = "性别 0:男 1:女 2:保密")
private Integer gender;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "部门ID")
private Long deptId;
@ApiModelProperty(value = "超级管理员 0:否 1:是")
private Integer superAdmin;
@ApiModelProperty(value = "状态 0:停用 1:正常")
private Integer status;
@ApiModelProperty(value = "创建者")
private Long creator;
@ApiModelProperty(value = "创建时间")
private LocalDateTime createDate;
@ApiModelProperty(value = "更新者")
private Long updater;
@ApiModelProperty(value = "更新时间")
private LocalDateTime updateDate;
@ApiModelProperty(value = "删除标识,是否有效:1可用 0不可用")
private Integer valid;
}

查看文件

@ -0,0 +1,76 @@
package com.cnbm.generator.code.entity;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
* 系统用户
* </p>
*
* @author why
* @since 2022-08-23
*/
@Data
@TableName("sys_user")
@ApiModel(value = "User对象", description = "系统用户")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("id")
private Long id;
@ApiModelProperty("用户名")
private String username;
@ApiModelProperty("密码")
private String password;
@ApiModelProperty("姓名")
private String realName;
@ApiModelProperty("头像")
private String headUrl;
@ApiModelProperty("性别 0:男 1:女 2:保密")
private Integer gender;
@ApiModelProperty("邮箱")
private String email;
@ApiModelProperty("手机号")
private String mobile;
@ApiModelProperty("部门ID")
private Long deptId;
@ApiModelProperty("超级管理员 0:否 1:是")
private Integer superAdmin;
@ApiModelProperty("状态 0:停用 1:正常")
private Integer status;
@ApiModelProperty("创建者")
private Long creator;
@ApiModelProperty("创建时间")
private LocalDateTime createDate;
@ApiModelProperty("更新者")
private Long updater;
@ApiModelProperty("更新时间")
private LocalDateTime updateDate;
@ApiModelProperty("删除标识,是否有效:1可用 0不可用")
@TableLogic
private Integer valid;
}

查看文件

@ -0,0 +1,52 @@
package com.cnbm.generator.code.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.Date;
/**
* 系统用户
*
* @author why
* @since 2022-08-23
*/
@Data
public class UserExcel {
@Excel(name = "id")
private Long id;
@Excel(name = "用户名")
private String username;
@Excel(name = "密码")
private String password;
@Excel(name = "姓名")
private String realName;
@Excel(name = "头像")
private String headUrl;
@Excel(name = "性别 0:男 1:女 2:保密")
private Integer gender;
@Excel(name = "邮箱")
private String email;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "部门ID")
private Long deptId;
@Excel(name = "超级管理员 0:否 1:是")
private Integer superAdmin;
@Excel(name = "状态 0:停用 1:正常")
private Integer status;
@Excel(name = "创建者")
private Long creator;
@Excel(name = "创建时间")
private LocalDateTime createDate;
@Excel(name = "更新者")
private Long updater;
@Excel(name = "更新时间")
private LocalDateTime updateDate;
@Excel(name = "删除标识,是否有效:1可用 0不可用")
private Integer valid;
}

查看文件

@ -0,0 +1,16 @@
package com.cnbm.generator.code.mapper;
import com.cnbm.common.dao.BaseDao;
import com.cnbm.generator.code.entity.User;
import org.apache.ibatis.annotations.Mapper;
/**
* 系统用户
*
* @author why
* @since 2022-08-23
*/
@Mapper
public interface UserMapper extends BaseDao<User> {
}

查看文件

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cnbm.generator.code.mapper.UserMapper">
<resultMap type="com.cnbm.generator.code.entity.User" id="UserMap">
<id column="id" property="id" />
<id column="username" property="username" />
<id column="password" property="password" />
<id column="real_name" property="realName" />
<id column="head_url" property="headUrl" />
<id column="gender" property="gender" />
<id column="email" property="email" />
<id column="mobile" property="mobile" />
<id column="dept_id" property="deptId" />
<id column="super_admin" property="superAdmin" />
<id column="status" property="status" />
<id column="creator" property="creator" />
<id column="create_date" property="createDate" />
<id column="updater" property="updater" />
<id column="update_date" property="updateDate" />
<id column="valid" property="valid" />
</resultMap>
</mapper>

查看文件

@ -0,0 +1,7 @@
-- 菜单初始SQL
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date)VALUES (1561967314641956865, 1067246875800000035, '系统用户', 'code/user', NULL, 0, 'icon-desktop', 0, 1067246875800000001, now(), 1067246875800000001, now());
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date) VALUES (1561967315476623361, 1561967314641956865, '查看', NULL, 'code:user:page,code:user:info', 1, NULL, 0, 1067246875800000001, now(), 1067246875800000001, now());
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date) VALUES (1561967315476623362, 1561967314641956865, '新增', NULL, 'code:user:save', 1, NULL, 1, 1067246875800000001, now(), 1067246875800000001, now());
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date) VALUES (1561967315476623363, 1561967314641956865, '修改', NULL, 'code:user:update', 1, NULL, 2, 1067246875800000001, now(), 1067246875800000001, now());
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date) VALUES (1561967315476623364, 1561967314641956865, '删除', NULL, 'code:user:delete', 1, NULL, 3, 1067246875800000001, now(), 1067246875800000001, now());
INSERT INTO sys_menu(id, pid, name, url, permissions, type, icon, sort, creator, create_date, updater, update_date) VALUES (1561967315476623365, 1561967314641956865, '导出', NULL, 'code:user:export', 1, NULL, 4, 1067246875800000001, now(), 1067246875800000001, now());

查看文件

@ -0,0 +1,15 @@
package com.cnbm.generator.code.service;
import com.cnbm.common.service.CrudService;
import com.cnbm.generator.code.dto.UserDTO;
import com.cnbm.generator.code.entity.User;
/**
* 系统用户
*
* @author why
* @since 2022-08-23
*/
public interface IUserService extends CrudService<User, UserDTO> {
}

查看文件

@ -0,0 +1,34 @@
package com.cnbm.generator.code.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnbm.common.service.impl.CrudServiceImpl;
import com.cnbm.generator.code.dto.UserDTO;
import com.cnbm.generator.code.mapper.UserMapper;
import com.cnbm.generator.code.entity.User;
import com.cnbm.generator.code.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 系统用户
*
* @author why
* @since 2022-08-23
*/
@Service
public class UserServiceImpl extends CrudServiceImpl<UserMapper, User, UserDTO> implements IUserService {
@Override
public QueryWrapper<User> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}

查看文件

@ -9,8 +9,6 @@ import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Author weihongyang
* @Date 2022/6/29 2:01 PM