数据管理开发
This commit is contained in:
parent
cd33672694
commit
201c5d378e
|
@ -0,0 +1,161 @@
|
|||
package org.jeecg.modules.contoller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.modules.entity.CeesUser;
|
||||
import org.jeecg.modules.enums.IdentityEnum;
|
||||
import org.jeecg.modules.enums.MajorEnum;
|
||||
import org.jeecg.modules.service.ICeesUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Description: CEES用户表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-03-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Api(tags = "CEES用户表")
|
||||
@RestController
|
||||
@RequestMapping("/org.jeecg.modules/ceesUser")
|
||||
@Slf4j
|
||||
public class CeesUserController extends JeecgController<CeesUser, ICeesUserService> {
|
||||
@Autowired
|
||||
private ICeesUserService ceesUserService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param ceesUser
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "CEES用户表-分页列表查询")
|
||||
@ApiOperation(value = "CEES用户表-分页列表查询", notes = "CEES用户表-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<CeesUser>> queryPageList(CeesUser ceesUser, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
QueryWrapper<CeesUser> queryWrapper = QueryGenerator.initQueryWrapper(ceesUser, req.getParameterMap());
|
||||
Page<CeesUser> page = new Page<>(pageNo, pageSize);
|
||||
IPage<CeesUser> pageList = ceesUserService.page(page, queryWrapper);
|
||||
pageList.convert(e -> {
|
||||
e.setMajorIdDescription(MajorEnum.describe(e.getMajorId()));
|
||||
e.setIdentityDescription(IdentityEnum.describe(e.getIdentity()));
|
||||
return e;
|
||||
});
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param ceesUser
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "CEES用户表-添加")
|
||||
@ApiOperation(value = "CEES用户表-添加", notes = "CEES用户表-添加")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody CeesUser ceesUser) {
|
||||
ceesUser.setUserHeadingCode(ceesUserService.createIdentityID(ceesUser));
|
||||
ceesUser.setGroupId(1);
|
||||
ceesUserService.save(ceesUser);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param ceesUser
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "CEES用户表-编辑")
|
||||
@ApiOperation(value = "CEES用户表-编辑", notes = "CEES用户表-编辑")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody CeesUser ceesUser) {
|
||||
ceesUserService.updateById(ceesUser);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "CEES用户表-通过id删除")
|
||||
@ApiOperation(value = "CEES用户表-通过id删除", notes = "CEES用户表-通过id删除")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
ceesUserService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "CEES用户表-批量删除")
|
||||
@ApiOperation(value = "CEES用户表-批量删除", notes = "CEES用户表-批量删除")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.ceesUserService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "CEES用户表-通过id查询")
|
||||
@ApiOperation(value = "CEES用户表-通过id查询", notes = "CEES用户表-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<CeesUser> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
CeesUser ceesUser = ceesUserService.getById(id);
|
||||
if (ceesUser == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(ceesUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param ceesUser
|
||||
*/
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, CeesUser ceesUser) {
|
||||
return super.exportXls(request, ceesUser, CeesUser.class, "CEES用户表");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, CeesUser.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package org.jeecg.modules.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: CEES用户表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-03-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("cees_user")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="cees_user对象", description="CEES用户表")
|
||||
public class CeesUser implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**主键*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private Date createTime;
|
||||
/**更新人*/
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新日期")
|
||||
private Date updateTime;
|
||||
/**所属部门*/
|
||||
@ApiModelProperty(value = "所属部门")
|
||||
private String sysOrgCode;
|
||||
/**用户姓名*/
|
||||
@Excel(name = "用户姓名", width = 15)
|
||||
@ApiModelProperty(value = "用户姓名")
|
||||
private String userName;
|
||||
/**用户身份码*/
|
||||
@Excel(name = "用户身份码", width = 15)
|
||||
@ApiModelProperty(value = "用户身份码")
|
||||
private String userId;
|
||||
/**用户识别码*/
|
||||
@Excel(name = "用户识别码", width = 15)
|
||||
@ApiModelProperty(value = "用户识别码")
|
||||
private String userHeadingCode;
|
||||
/**工作量*/
|
||||
@Excel(name = "工作量", width = 15)
|
||||
@ApiModelProperty(value = "工作量")
|
||||
private Integer workload;
|
||||
/**组id*/
|
||||
@Excel(name = "组id", width = 15)
|
||||
@ApiModelProperty(value = "组id")
|
||||
private Integer groupId;
|
||||
/**身份:管理员1 学生2,老师 3 ,外校老师4*/
|
||||
@Excel(name = "身份:管理员1 学生2,老师 3 ,外校老师4", width = 15)
|
||||
@ApiModelProperty(value = "身份:管理员1 学生2,老师 3 ,外校老师4")
|
||||
private Integer identity;
|
||||
/**
|
||||
* 身份描述
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String identityDescription;
|
||||
/**未知属性*/
|
||||
@Excel(name = "未知属性", width = 15)
|
||||
@ApiModelProperty(value = "未知属性")
|
||||
private Integer numberuse;
|
||||
/**学科*/
|
||||
@Excel(name = "学科", width = 15)
|
||||
@ApiModelProperty(value = "学科")
|
||||
private Integer majorId;
|
||||
/**专业id*/
|
||||
@ApiModelProperty(value = "专业id")
|
||||
@TableField(exist = false)
|
||||
private String majorIdDescription;
|
||||
/**状态:0正常 1禁用*/
|
||||
@Excel(name = "状态:0正常 1禁用", width = 15)
|
||||
@ApiModelProperty(value = "状态:0正常 1禁用")
|
||||
private Integer status;
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.jeecg.modules.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jeecg.modules.utils.EnumUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@Getter
|
||||
public enum IdentityEnum {
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN(1, "管理员"),
|
||||
/**
|
||||
* 学生
|
||||
*/
|
||||
STUDENT(2, "学生"),
|
||||
/**
|
||||
* 老师
|
||||
*/
|
||||
TEACHER(3, "老师"),
|
||||
/**
|
||||
* 外校老师
|
||||
*/
|
||||
OUT_TEACHER(4, "外校老师");
|
||||
|
||||
|
||||
private Integer value;
|
||||
private String label;
|
||||
|
||||
IdentityEnum(Integer value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static Optional<IdentityEnum> valueOf(Integer typeId) {
|
||||
return EnumUtil.getEnumObject(IdentityEnum.class, e -> Objects.equals(e.getValue(), typeId));
|
||||
}
|
||||
|
||||
public static String describe(Integer typeId) {
|
||||
return IdentityEnum.valueOf(typeId).map(IdentityEnum::getLabel).orElse("");
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> getOptionList() {
|
||||
return EnumUtil.getEnumOptionList(IdentityEnum.class,
|
||||
IdentityEnum::getLabel,
|
||||
IdentityEnum::getValue);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.jeecg.modules.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jeecg.modules.utils.EnumUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,7 +8,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Getter
|
||||
public enum MajorEnum {
|
||||
/**
|
||||
* 语文
|
||||
|
@ -49,11 +50,4 @@ public enum MajorEnum {
|
|||
MajorEnum::getValue);
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.jeecg.modules.enums.identity;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jeecg.modules.utils.EnumUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
public enum MajorLetterEnum {
|
||||
|
||||
/**
|
||||
* 语文
|
||||
*/
|
||||
CHINESE(1, 'C'),
|
||||
/**
|
||||
* 地理
|
||||
*/
|
||||
GEOGRAPHY(4, 'G'),
|
||||
/**
|
||||
* 历史
|
||||
*/
|
||||
HISTORY(7, 'H'),
|
||||
/**
|
||||
* 政治
|
||||
*/
|
||||
POLITICS(8, 'P');
|
||||
|
||||
private Integer value;
|
||||
private char label;
|
||||
|
||||
MajorLetterEnum(Integer value, char label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
public static Optional<MajorLetterEnum> valueOf(Integer typeId) {
|
||||
return EnumUtil.getEnumObject(MajorLetterEnum.class, e -> Objects.equals(e.getValue(), typeId));
|
||||
}
|
||||
|
||||
public static char describe(Integer typeId) {
|
||||
return MajorLetterEnum.valueOf(typeId).map(MajorLetterEnum::getLabel).orElse('E');//Error
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.jeecg.modules.enums.identity;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jeecg.modules.utils.EnumUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@Getter
|
||||
public enum StudentLetterEnum {
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
ADMIN(1,'A'),
|
||||
/**
|
||||
* 学生
|
||||
*/
|
||||
STUDENT(2, 'S'),
|
||||
/**
|
||||
* 本校老师
|
||||
*/
|
||||
LOCAL_TEACHER(3, 'L'),
|
||||
/**
|
||||
* 外校老师
|
||||
*/
|
||||
OUT_TEACHER(4, 'O');
|
||||
|
||||
|
||||
|
||||
private Integer value;
|
||||
private char label;
|
||||
|
||||
StudentLetterEnum(Integer value, char label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
public static Optional<StudentLetterEnum> valueOf(Integer typeId) {
|
||||
return EnumUtil.getEnumObject(StudentLetterEnum.class, e -> Objects.equals(e.getValue(), typeId));
|
||||
}
|
||||
|
||||
public static char describe(Integer typeId) {
|
||||
return StudentLetterEnum.valueOf(typeId).map(StudentLetterEnum::getLabel).orElse('E');//Error
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.jeecg.modules.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.jeecg.modules.entity.CeesUser;
|
||||
|
||||
/**
|
||||
* @Description: CEES用户表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-03-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface CeesUserMapper extends BaseMapper<CeesUser> {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?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="org.jeecg.modules.demo.org.jeecg.modules.mapper.CeesUserMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,15 @@
|
|||
package org.jeecg.modules.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.entity.CeesUser;
|
||||
|
||||
/**
|
||||
* @Description: CEES用户表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-03-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ICeesUserService extends IService<CeesUser> {
|
||||
String createIdentityID(CeesUser ceesUser);
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.jeecg.modules.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jeecg.modules.entity.CeesUser;
|
||||
import org.jeecg.modules.enums.identity.MajorLetterEnum;
|
||||
import org.jeecg.modules.enums.identity.StudentLetterEnum;
|
||||
import org.jeecg.modules.mapper.CeesUserMapper;
|
||||
import org.jeecg.modules.service.ICeesUserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: CEES用户表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-03-06
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> implements ICeesUserService {
|
||||
|
||||
|
||||
@Override
|
||||
public String createIdentityID(CeesUser ceesUser) {
|
||||
String res = null;
|
||||
int count = 0;
|
||||
//生成10次,若一直重复则抛出异常
|
||||
while (count++ < 10) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(MajorLetterEnum.describe(ceesUser.getMajorId()));
|
||||
sb.append(StudentLetterEnum.describe(ceesUser.getIdentity()));
|
||||
//生成5位随机数
|
||||
for (int i = 0; i < 5; i++) {
|
||||
sb.append((int) (Math.random() * 10));
|
||||
}
|
||||
String temp = sb.toString();
|
||||
LambdaQueryWrapper<CeesUser> wrapper = Wrappers.lambdaQuery(CeesUser.class).eq(CeesUser::getIdentity, temp);
|
||||
CeesUser user = getOne(wrapper);
|
||||
if (user == null) {
|
||||
res = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (res == null) {
|
||||
throw new RuntimeException("生成身份码失败");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue