乐观锁、逻辑删除功能

This commit is contained in:
dataprince 2024-01-08 16:01:31 +08:00
parent b0d0aefde8
commit f3e2afcaa3
62 changed files with 391 additions and 348 deletions

View File

@ -149,13 +149,15 @@ public class SysLoginService {
* 记录登录信息
*
* @param userId 用户ID
* @param version 乐观锁
*/
public void recordLoginInfo(Long userId) {
public void recordLoginInfo(Long userId,Integer version) {
SysUserBo sysUser = new SysUserBo();
sysUser.setUserId(userId);
sysUser.setLoginIp(ServletUtils.getClientIP());
sysUser.setLoginDate(DateUtils.getNowDate());
sysUser.setUpdateBy(userId);
sysUser.setVersion(version);
userService.updateUserProfile(sysUser);
}

View File

@ -81,7 +81,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
LoginHelper.login(loginUser, model);
loginService.recordLogininfor(loginUser.getTenantId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
loginService.recordLoginInfo(user.getUserId());
loginService.recordLoginInfo(user.getUserId(),user.getVersion());
LoginVo loginVo = new LoginVo();
loginVo.setAccessToken(StpUtil.getTokenValue());

View File

@ -98,7 +98,7 @@ public class GenConstants {
/**
* Entity基类字段
*/
public static final String[] BASE_ENTITY = {"tenantId", "createBy", "createTime", "updateBy", "updateTime"};
public static final String[] BASE_ENTITY = {"tenantId", "version", "createBy", "createTime", "updateBy", "updateTime"};
/**
* Tree基类字段

View File

@ -27,8 +27,13 @@ public class BaseEntity implements Serializable {
/**
* 租户编号
*/
@Column(tenantId = true)
private Long tenantId;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 搜索值
*/

View File

@ -1,6 +1,7 @@
package com.ruoyi.common.orm.core.domain;
import com.mybatisflex.annotation.Column;
import lombok.Data;
import java.io.Serial;
import java.util.ArrayList;
@ -10,7 +11,9 @@ import java.util.List;
* Tree基类
*
* @author ruoyi
* @author 数据小王子
*/
@Data
public class TreeEntity extends BaseEntity
{
@Serial
@ -33,54 +36,4 @@ public class TreeEntity extends BaseEntity
/** 子部门 */
@Column(ignore = true)
private List<Object> children = new ArrayList<>();
public String getParentName()
{
return parentName;
}
public void setParentName(String parentName)
{
this.parentName = parentName;
}
public Long getParentId()
{
return parentId;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Integer getOrderNum()
{
return orderNum;
}
public void setOrderNum(Integer orderNum)
{
this.orderNum = orderNum;
}
public String getAncestors()
{
return ancestors;
}
public void setAncestors(String ancestors)
{
this.ancestors = ancestors;
}
public List<Object> getChildren()
{
return children;
}
public void setChildren(List<Object> children)
{
this.children = children;
}
}

View File

@ -1,9 +1,9 @@
package com.ruoyi.mf.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
@ -23,7 +23,7 @@ import com.ruoyi.mf.service.IMfProductService;
* 产品树Controller
*
* @author 数据小王子
* 2023-11-23
* 2024-01-06
*/
@Validated
@RequiredArgsConstructor
@ -94,7 +94,7 @@ public class MfProductController extends BaseController
{
Boolean updated = mfProductService.update(mfProductBo);
if (!updated) {
R.fail("修改产品树记录失败!");
return R.fail("修改产品树记录失败!");
}
return R.ok();
}
@ -109,7 +109,7 @@ public class MfProductController extends BaseController
{
boolean deleted = mfProductService.deleteByIds(productIds);
if (!deleted) {
R.fail("删除产品树记录失败!");
return R.fail("删除产品树记录失败!");
}
return R.ok();
}

View File

@ -1,9 +1,9 @@
package com.ruoyi.mf.controller;
import java.util.List;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
@ -24,7 +24,7 @@ import com.ruoyi.common.orm.core.page.TableDataInfo;
* 学生信息表Controller
*
* @author 数据小王子
* 2023-11-22
* 2024-01-05
*/
@Validated
@RequiredArgsConstructor
@ -94,7 +94,7 @@ public class MfStudentController extends BaseController
{
Boolean updated = mfStudentService.update(mfStudentBo);
if (!updated) {
R.fail("修改学生信息表记录失败!");
return R.fail("修改学生信息表记录失败!");
}
return R.ok();
}
@ -109,7 +109,7 @@ public class MfStudentController extends BaseController
{
boolean deleted = mfStudentService.deleteByIds(studentIds);
if (!deleted) {
R.fail("删除学生信息表记录失败!");
return R.fail("删除学生信息表记录失败!");
}
return R.ok();
}

View File

@ -4,23 +4,28 @@ import java.util.List;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.mf.domain.Goods;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 客户主表对象 mf_customer
*
* @author 数据小王子
* 2023-12-06
* 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_customer")
public class Customer extends BaseEntity
{
@Serial
private static final long serialVersionUID = 1L;
/** 客户id */
@Id
private Long customerId;
@ -40,7 +45,11 @@ public class Customer extends BaseEntity
/** 客户描述 */
private String remark;
/** 商品子表信息 */
/** 逻辑删除标志0代表存在 1代表删除 */
@Column(isLogicDelete = true)
private Integer delFlag;
/** 商品子信息 */
private List<Goods> goodsList;
}

View File

@ -12,10 +12,10 @@ import java.io.Serializable;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 商品子对象 mf_goods
* 商品子对象 mf_goods
*
* @author 数据小王子
* 2023-12-06
* 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ -36,7 +36,7 @@ public class Goods extends BaseEntity
private String name;
/** 商品重量 */
private Long weight;
private Integer weight;
/** 商品价格 */
private BigDecimal price;

View File

@ -1,22 +1,28 @@
package com.ruoyi.mf.domain;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import com.ruoyi.common.orm.core.domain.TreeEntity;
/**
* 产品树对象 mf_product
*
* @author 数据小王子
* 2023-11-23
* 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_product")
public class MfProduct extends TreeEntity
{
@Serial
private static final long serialVersionUID = 1L;
/** 产品id */
@Id
private Long productId;
@ -27,4 +33,9 @@ public class MfProduct extends TreeEntity
/** 产品状态0正常 1停用 */
private String status;
/** 逻辑删除标志0代表存在 1代表删除 */
@Column(isLogicDelete = true)
private Integer delFlag;
}

View File

@ -2,23 +2,29 @@ package com.ruoyi.mf.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 学生信息表对象 mf_student
*
* @author 数据小王子
* 2023-11-22
* 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Table(value = "mf_student")
public class MfStudent extends BaseEntity
{
@Serial
private static final long serialVersionUID = 1L;
/** 编号 */
@Id
private Long studentId;
@ -27,7 +33,7 @@ public class MfStudent extends BaseEntity
private String studentName;
/** 年龄 */
private Long studentAge;
private Integer studentAge;
/** 爱好0代码 1音乐 2电影 */
private String studentHobby;
@ -41,4 +47,9 @@ public class MfStudent extends BaseEntity
/** 生日 */
private Date studentBirthday;
/** 逻辑删除标志0代表存在 1代表删除 */
@Column(isLogicDelete = true)
private Integer delFlag;
}

View File

@ -15,7 +15,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
* 客户主表业务对象 mf_customer
*
* @author 数据小王子
* @date 2023-12-06
* @date 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ -31,30 +31,34 @@ public class CustomerBo extends BaseEntity
/**
* 客户姓名
*/
@NotBlank(message = "客户姓名不能为空")
private String customerName;
/**
* 手机号码
*/
@NotBlank(message = "手机号码不能为空")
private String phonenumber;
/**
* 客户性别
*/
@NotBlank(message = "客户性别不能为空")
private String gender;
/**
* 客户生日
*/
@NotNull(message = "客户生日不能为空")
@JsonFormat(pattern = "yyyy-MM-dd")
private Date birthday;
/**
* 客户描述
*/
@NotBlank(message = "客户描述不能为空")
private String remark;
/** 商品子表信息 */
/** 商品子信息 */
private List<Goods> goodsList;
}

View File

@ -11,7 +11,7 @@ import com.ruoyi.common.orm.core.domain.TreeEntity;
* 产品树业务对象 mf_product
*
* @author 数据小王子
* @date 2023-11-23
* @date 2024-01-06
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ -36,5 +36,4 @@ public class MfProductBo extends TreeEntity
@NotBlank(message = "产品状态0正常 1停用不能为空")
private String status;
}

View File

@ -1,24 +1,25 @@
package com.ruoyi.mf.domain.bo;
import com.ruoyi.mf.domain.MfStudent;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.orm.core.domain.BaseEntity;
/**
* 学生信息表业务对象 mf_student
*
* @author 数据小王子
* @date 2023-11-22
* @date 2024-01-05
*/
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = MfStudent.class, reverseConvertGenerate = false)
public class MfStudentBo extends BaseEntity {
public class MfStudentBo extends BaseEntity
{
/**
* 编号
@ -35,7 +36,7 @@ public class MfStudentBo extends BaseEntity {
* 年龄
*/
@NotNull(message = "年龄不能为空")
private Long studentAge;
private Integer studentAge;
/**
* 爱好0代码 1音乐 2电影
@ -62,5 +63,4 @@ public class MfStudentBo extends BaseEntity {
@JsonFormat(pattern = "yyyy-MM-dd")
private Date studentBirthday;
}

View File

@ -22,7 +22,7 @@ import com.ruoyi.common.orm.core.domain.BaseEntity;
* 客户主表视图对象 mf_customer
*
* @author 数据小王子
* @date 2023-12-06
* @date 2024-01-06
*/
@Data
@ExcelIgnoreUnannotated
@ -59,8 +59,12 @@ public class CustomerVo extends BaseEntity implements Serializable
@ExcelProperty(value = "客户描述")
private String remark;
/** 逻辑删除标志0代表存在 1代表删除 */
@ExcelProperty(value = "逻辑删除标志0代表存在 1代表删除")
private Integer delFlag;
/** 商品子表信息 */
/** 商品子信息 */
@RelationOneToMany(selfField = "customerId", targetField = "customerId")
private List<Goods> goodsList;

View File

@ -8,7 +8,6 @@ import com.ruoyi.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
@ -18,7 +17,7 @@ import com.ruoyi.common.orm.core.domain.TreeEntity;
* 产品树视图对象 mf_product
*
* @author 数据小王子
* @date 2023-11-23
* @date 2024-01-06
*/
@Data
@ExcelIgnoreUnannotated
@ -43,4 +42,8 @@ public class MfProductVo extends TreeEntity implements Serializable
@ExcelDictFormat(dictType = "sys_student_status")
private String status;
/** 逻辑删除标志0代表存在 1代表删除 */
@ExcelProperty(value = "逻辑删除标志0代表存在 1代表删除")
private Integer delFlag;
}

View File

@ -9,19 +9,17 @@ import com.ruoyi.common.excel.annotation.ExcelDictFormat;
import com.ruoyi.common.excel.convert.ExcelDictConvert;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import lombok.EqualsAndHashCode;
/**
* 学生信息表视图对象 mf_student
*
* @author 数据小王子
* @date 2023-11-22
* @date 2024-01-05
*/
@Data
@ExcelIgnoreUnannotated
@ -43,7 +41,7 @@ public class MfStudentVo extends BaseEntity implements Serializable
/** 年龄 */
@ExcelProperty(value = "年龄")
private Long studentAge;
private Integer studentAge;
/** 爱好0代码 1音乐 2电影 */
@ExcelProperty(value = "爱好", converter = ExcelDictConvert.class)
@ -64,4 +62,8 @@ public class MfStudentVo extends BaseEntity implements Serializable
@ExcelProperty(value = "生日")
private Date studentBirthday;
/** 逻辑删除标志0代表存在 1代表删除 */
@ExcelProperty(value = "逻辑删除标志0代表存在 1代表删除")
private Integer delFlag;
}

View File

@ -8,7 +8,7 @@ import com.ruoyi.mf.domain.MfProduct;
* 产品树Mapper接口
*
* @author 数据小王子
* 2023-11-23
* 2024-01-06
*/
@Mapper
public interface MfProductMapper extends BaseMapper<MfProduct>

View File

@ -10,7 +10,7 @@ import com.ruoyi.common.orm.core.service.IBaseService;
* 产品树Service接口
*
* @author 数据小王子
* 2023-11-23
* 2024-01-06
*/
public interface IMfProductService extends IBaseService<MfProduct>
{

View File

@ -11,7 +11,7 @@ import com.ruoyi.common.orm.core.page.TableDataInfo;
* 学生信息表Service接口
*
* @author 数据小王子
* 2023-11-22
* 2024-01-05
*/
public interface IMfStudentService extends IBaseService<MfStudent>
{

View File

@ -3,42 +3,40 @@ package com.ruoyi.mf.service.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.relation.RelationManager;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.PageQuery;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import com.ruoyi.mf.domain.Goods;
import com.ruoyi.mf.mapper.GoodsMapper;
import static com.ruoyi.mf.domain.table.GoodsTableDef.GOODS;
import com.ruoyi.mf.mapper.CustomerMapper;
import com.ruoyi.mf.domain.Customer;
import com.ruoyi.mf.domain.bo.CustomerBo;
import com.ruoyi.mf.domain.vo.CustomerVo;
import com.ruoyi.mf.service.ICustomerService;
import static com.ruoyi.mf.domain.table.CustomerTableDef.CUSTOMER;
/**
* 客户主表Service业务层处理
*
* @author 数据小王子
* 2023-12-06
* 2024-01-06
*/
@Service
public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Customer> implements ICustomerService {
public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Customer> implements ICustomerService
{
@Resource
private CustomerMapper customerMapper;
@Resource
@ -54,6 +52,7 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
queryWrapper.and(CUSTOMER.CUSTOMER_NAME.like(customerBo.getCustomerName()));
queryWrapper.and(CUSTOMER.PHONENUMBER.eq(customerBo.getPhonenumber()));
queryWrapper.and(CUSTOMER.GENDER.eq(customerBo.getGender()));
return queryWrapper;
}
@ -64,7 +63,8 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
* @return 客户主表
*/
@Override
public CustomerVo selectById(Long customerId) {
public CustomerVo selectById(Long customerId)
{
return customerMapper.selectOneWithRelationsByQueryAs(query().where(CUSTOMER.CUSTOMER_ID.eq(customerId)), CustomerVo.class);
}
@ -76,7 +76,8 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
* @return 客户主表集合
*/
@Override
public List<CustomerVo> selectList(CustomerBo customerBo) {
public List<CustomerVo> selectList(CustomerBo customerBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(customerBo);
return customerMapper.selectListWithRelationsByQueryAs(queryWrapper, CustomerVo.class);
}
@ -88,8 +89,11 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
* @return 分页客户主表集合
*/
@Override
public TableDataInfo<CustomerVo> selectPage(CustomerBo customerBo) {
public TableDataInfo<CustomerVo> selectPage(CustomerBo customerBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(customerBo);
//忽略注解本次不查询子表数据
RelationManager.addIgnoreRelations("goodsList");
Page<CustomerVo> page = customerMapper.paginateWithRelationsAs(PageQuery.build(), queryWrapper, CustomerVo.class);
return TableDataInfo.build(page);
}
@ -102,7 +106,8 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
*/
@Transactional
@Override
public boolean insert(CustomerBo customerBo) {
public boolean insert(CustomerBo customerBo)
{
Customer customer = MapstructUtils.convert(customerBo, Customer.class);
boolean inserted = this.save(customer);//使用全局配置的雪花算法主键生成器生成ID值
@ -120,9 +125,10 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
*/
@Transactional
@Override
public boolean update(CustomerBo customerBo) {
public boolean update(CustomerBo customerBo)
{
Customer customer = MapstructUtils.convert(customerBo, Customer.class);
if (ObjectUtil.isNotNull(customer) && ObjectUtil.isNotNull(customer.getCustomerId())) {
if(ObjectUtil.isNotNull(customer) && ObjectUtil.isNotNull(customer.getCustomerId())) {
boolean updated = this.updateById(customer);
if (updated) {
QueryWrapper queryWrapper = QueryWrapper.create().from(GOODS).where(GOODS.CUSTOMER_ID.eq(customer.getCustomerId()));
@ -141,28 +147,33 @@ public class CustomerServiceImpl extends BaseServiceImpl<CustomerMapper, Custome
*/
@Transactional
@Override
public boolean deleteByIds(Long[] customerIds) {
public boolean deleteByIds(Long[] customerIds)
{
QueryWrapper queryWrapper = QueryWrapper.create().from(GOODS).where(GOODS.CUSTOMER_ID.in(Arrays.asList(customerIds)));
goodsMapper.deleteByQuery(queryWrapper);
return this.removeByIds(Arrays.asList(customerIds));
}
/**
* 新增商品子信息
* 新增商品子信息
*
* @param customer 客户主表对象
*/
private boolean insertGoods(Customer customer) {
private boolean insertGoods(Customer customer)
{
List<Goods> goodsList = customer.getGoodsList();
Long customerId = customer.getCustomerId();
if (StringUtils.isNotNull(goodsList)) {
if (StringUtils.isNotNull(goodsList))
{
List<Goods> list = new ArrayList<>();
for (Goods goods : goodsList) {
for (Goods goods : goodsList)
{
goods.setCustomerId(customerId);
list.add(goods);
}
if (list.size() > 0) {
return goodsMapper.insertBatch(list) > 0;
if (list.size() > 0)
{
return goodsMapper.insertBatch(list)>0;
}
}
return true;

View File

@ -3,10 +3,15 @@ package com.ruoyi.mf.service.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.PageQuery;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -15,17 +20,17 @@ import com.ruoyi.mf.domain.MfProduct;
import com.ruoyi.mf.domain.bo.MfProductBo;
import com.ruoyi.mf.domain.vo.MfProductVo;
import com.ruoyi.mf.service.IMfProductService;
import static com.ruoyi.mf.domain.table.MfProductTableDef.MF_PRODUCT;
/**
* 产品树Service业务层处理
*
* @author 数据小王子
* 2023-11-23
* 2024-01-06
*/
@Service
public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfProduct> implements IMfProductService {
public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfProduct> implements IMfProductService
{
@Resource
private MfProductMapper mfProductMapper;
@ -37,8 +42,9 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
private QueryWrapper buildQueryWrapper(MfProductBo mfProductBo) {
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
queryWrapper.and(MF_PRODUCT.PRODUCT_NAME.like(mfProductBo.getProductName()));
queryWrapper.and(MF_PRODUCT.ORDER_NUM.eq(mfProductBo.getOrderNum()));
queryWrapper.and(MF_PRODUCT.STATUS.eq(mfProductBo.getStatus()));
queryWrapper.orderBy(MF_PRODUCT.ORDER_NUM.asc());
return queryWrapper;
}
@ -49,8 +55,10 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
* @return 产品树
*/
@Override
public MfProductVo selectById(Long productId) {
public MfProductVo selectById(Long productId)
{
return this.getOneAs(query().where(MF_PRODUCT.PRODUCT_ID.eq(productId)), MfProductVo.class);
}
/**
@ -60,7 +68,8 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
* @return 产品树集合
*/
@Override
public List<MfProductVo> selectList(MfProductBo mfProductBo) {
public List<MfProductVo> selectList(MfProductBo mfProductBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(mfProductBo);
return this.listAs(queryWrapper, MfProductVo.class);
}
@ -73,7 +82,8 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
* @return 结果:true 操作成功false 操作失败
*/
@Override
public boolean insert(MfProductBo mfProductBo) {
public boolean insert(MfProductBo mfProductBo)
{
MfProduct mfProduct = MapstructUtils.convert(mfProductBo, MfProduct.class);
return this.save(mfProduct);//使用全局配置的雪花算法主键生成器生成ID值
@ -86,11 +96,14 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
* @return 结果:true 更新成功false 更新失败
*/
@Override
public boolean update(MfProductBo mfProductBo) {
public boolean update(MfProductBo mfProductBo)
{
MfProduct mfProduct = MapstructUtils.convert(mfProductBo, MfProduct.class);
boolean updated = this.updateById(mfProduct);
return updated;
if(ObjectUtil.isNotNull(mfProduct) && ObjectUtil.isNotNull(mfProduct.getProductId())) {
boolean updated = this.updateById(mfProduct);
return updated;
}
return false;
}
/**
@ -101,7 +114,8 @@ public class MfProductServiceImpl extends BaseServiceImpl<MfProductMapper, MfPro
*/
@Transactional
@Override
public boolean deleteByIds(Long[] productIds) {
public boolean deleteByIds(Long[] productIds)
{
return this.removeByIds(Arrays.asList(productIds));
}

View File

@ -2,14 +2,16 @@ package com.ruoyi.mf.service.impl;
import java.util.Arrays;
import java.util.List;
import com.mybatisflex.annotation.UseDataSource;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.orm.core.page.PageQuery;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -18,17 +20,17 @@ import com.ruoyi.mf.domain.MfStudent;
import com.ruoyi.mf.domain.bo.MfStudentBo;
import com.ruoyi.mf.domain.vo.MfStudentVo;
import com.ruoyi.mf.service.IMfStudentService;
import static com.ruoyi.mf.domain.table.MfStudentTableDef.MF_STUDENT;
/**
* 学生信息表Service业务层处理
*
* @author 数据小王子
* 2023-11-22
* 2024-01-05
*/
@Service
public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStudent> implements IMfStudentService {
public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStudent> implements IMfStudentService
{
@Resource
private MfStudentMapper mfStudentMapper;
@ -41,6 +43,7 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
QueryWrapper queryWrapper = super.buildBaseQueryWrapper();
queryWrapper.and(MF_STUDENT.STUDENT_NAME.like(mfStudentBo.getStudentName()));
queryWrapper.and(MF_STUDENT.STUDENT_STATUS.eq(mfStudentBo.getStudentStatus()));
return queryWrapper;
}
@ -51,8 +54,10 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
* @return 学生信息表
*/
@Override
public MfStudentVo selectById(Long studentId) {
public MfStudentVo selectById(Long studentId)
{
return this.getOneAs(query().where(MF_STUDENT.STUDENT_ID.eq(studentId)), MfStudentVo.class);
}
/**
@ -62,7 +67,8 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
* @return 学生信息表集合
*/
@Override
public List<MfStudentVo> selectList(MfStudentBo mfStudentBo) {
public List<MfStudentVo> selectList(MfStudentBo mfStudentBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(mfStudentBo);
return this.listAs(queryWrapper, MfStudentVo.class);
}
@ -74,8 +80,8 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
* @return 分页学生信息表集合
*/
@Override
//@UseDataSource("ds2")
public TableDataInfo<MfStudentVo> selectPage(MfStudentBo mfStudentBo) {
public TableDataInfo<MfStudentVo> selectPage(MfStudentBo mfStudentBo)
{
QueryWrapper queryWrapper = buildQueryWrapper(mfStudentBo);
Page<MfStudentVo> page = this.pageAs(PageQuery.build(), queryWrapper, MfStudentVo.class);
return TableDataInfo.build(page);
@ -88,7 +94,8 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
* @return 结果:true 操作成功false 操作失败
*/
@Override
public boolean insert(MfStudentBo mfStudentBo) {
public boolean insert(MfStudentBo mfStudentBo)
{
MfStudent mfStudent = MapstructUtils.convert(mfStudentBo, MfStudent.class);
return this.save(mfStudent);//使用全局配置的雪花算法主键生成器生成ID值
@ -101,11 +108,14 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
* @return 结果:true 更新成功false 更新失败
*/
@Override
public boolean update(MfStudentBo mfStudentBo) {
public boolean update(MfStudentBo mfStudentBo)
{
MfStudent mfStudent = MapstructUtils.convert(mfStudentBo, MfStudent.class);
boolean updated = this.updateById(mfStudent);
return updated;
if(ObjectUtil.isNotNull(mfStudent) && ObjectUtil.isNotNull(mfStudent.getStudentId())) {
boolean updated = this.updateById(mfStudent);
return updated;
}
return false;
}
/**
@ -116,7 +126,8 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
*/
@Transactional
@Override
public boolean deleteByIds(Long[] studentIds) {
public boolean deleteByIds(Long[] studentIds)
{
return this.removeByIds(Arrays.asList(studentIds));
}

View File

@ -122,6 +122,10 @@ public class GenTable implements Serializable
@Column(ignore = true)
private String parentMenuName;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 创建者
*/

View File

@ -1,6 +1,7 @@
package com.ruoyi.generator.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import jakarta.validation.constraints.NotBlank;
@ -80,6 +81,10 @@ public class GenTableColumn implements Serializable
/** 排序 */
private Integer sort;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 创建者
*/

View File

@ -16,13 +16,11 @@ import com.ruoyi.generator.domain.GenTableColumn;
* @author ruoyi
* @author 数据小王子
*/
public class GenUtils
{
public class GenUtils {
/**
* 初始化表信息
*/
public static void initTable(GenTable genTable)
{
public static void initTable(GenTable genTable) {
genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@ -35,8 +33,7 @@ public class GenUtils
/**
* 初始化列属性字段
*/
public static void initColumnField(GenTableColumn column, GenTable table)
{
public static void initColumnField(GenTableColumn column, GenTable table) {
String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName();
column.setTableId(table.getTableId());
@ -47,37 +44,34 @@ public class GenUtils
column.setJavaType(GenConstants.TYPE_STRING);
column.setQueryType(GenConstants.QUERY_EQ);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
{
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
// 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType);
}
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME);
}
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
{
} else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
{
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
{
if (arraysContains(GenConstants.COLUMNTYPE_INTEGER, dataType)) {
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else
{
column.setJavaType(GenConstants.TYPE_LONG);
} else if ("numeric".equals(dataType)) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);//为PostgreSQL数据库设置numeric类型
} else {
// 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
}
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
column.setJavaType(GenConstants.TYPE_INTEGER);
}
// 长整形
else {
column.setJavaType(GenConstants.TYPE_LONG);
}
}
}
@ -105,34 +99,28 @@ public class GenUtils
}
// 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
column.setQueryType(GenConstants.QUERY_LIKE);
}
// 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status"))
{
if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
column.setHtmlType(GenConstants.HTML_RADIO);
}
// 类型&性别字段设置下拉框
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "gender"))
{
|| StringUtils.endsWithIgnoreCase(columnName, "gender")) {
column.setHtmlType(GenConstants.HTML_SELECT);
}
// 图片字段设置图片上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
}
// 文件字段设置文件上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
}
// 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
{
else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
column.setHtmlType(GenConstants.HTML_EDITOR);
}
}
@ -140,12 +128,11 @@ public class GenUtils
/**
* 校验数组是否包含指定值
*
* @param arr 数组
* @param arr 数组
* @param targetValue
* @return 是否包含
*/
public static boolean arraysContains(String[] arr, String targetValue)
{
public static boolean arraysContains(String[] arr, String targetValue) {
return Arrays.asList(arr).contains(targetValue);
}
@ -155,8 +142,7 @@ public class GenUtils
* @param packageName 包名
* @return 模块名
*/
public static String getModuleName(String packageName)
{
public static String getModuleName(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length();
return StringUtils.substring(packageName, lastIndex + 1, nameLength);
@ -168,8 +154,7 @@ public class GenUtils
* @param tableName 表名
* @return 业务名
*/
public static String getBusinessName(String tableName)
{
public static String getBusinessName(String tableName) {
int firstIndex = tableName.indexOf("_");
int nameLength = tableName.length();
String businessName = StringUtils.substring(tableName, firstIndex + 1, nameLength);
@ -183,12 +168,10 @@ public class GenUtils
* @param tableName 表名称
* @return 类名
*/
public static String convertClassName(String tableName)
{
public static String convertClassName(String tableName) {
boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix();
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
{
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
String[] searchList = StringUtils.split(tablePrefix, ",");
tableName = replaceFirst(tableName, searchList);
}
@ -199,15 +182,12 @@ public class GenUtils
* 批量替换前缀
*
* @param replacementm 替换值
* @param searchList 替换列表
* @param searchList 替换列表
*/
public static String replaceFirst(String replacementm, String[] searchList)
{
public static String replaceFirst(String replacementm, String[] searchList) {
String text = replacementm;
for (String searchString : searchList)
{
if (replacementm.startsWith(searchString))
{
for (String searchString : searchList) {
if (replacementm.startsWith(searchString)) {
text = replacementm.replaceFirst(searchString, "");
break;
}
@ -221,8 +201,7 @@ public class GenUtils
* @param text 需要被替换的名字
* @return 替换后的名字
*/
public static String replaceText(String text)
{
public static String replaceText(String text) {
return RegExUtils.replaceAll(text, "(?:表|若依)", "");
}
@ -232,14 +211,10 @@ public class GenUtils
* @param columnType 列类型
* @return 截取后的列类型
*/
public static String getDbType(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static String getDbType(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
return StringUtils.substringBefore(columnType, "(");
}
else
{
} else {
return columnType;
}
}
@ -250,15 +225,11 @@ public class GenUtils
* @param columnType 列类型
* @return 截取后的列类型
*/
public static Integer getColumnLength(String columnType)
{
if (StringUtils.indexOf(columnType, "(") > 0)
{
public static Integer getColumnLength(String columnType) {
if (StringUtils.indexOf(columnType, "(") > 0) {
String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length);
}
else
{
} else {
return 0;
}
}

View File

@ -105,7 +105,7 @@ public class ${ClassName}Controller extends BaseController
{
Boolean updated = ${className}Service.update(${className}Bo);
if (!updated) {
R.fail("修改${functionName}记录失败!");
return R.fail("修改${functionName}记录失败!");
}
return R.ok();
}
@ -120,7 +120,7 @@ public class ${ClassName}Controller extends BaseController
{
boolean deleted = ${className}Service.deleteByIds(${pkColumn.javaField}s);
if (!deleted) {
R.fail("删除${functionName}记录失败!");
return R.fail("删除${functionName}记录失败!");
}
return R.ok();
}

View File

@ -6,6 +6,20 @@ import ${import};
#if($table.sub)
import ${packageName}.domain.${subClassName};
#end
#set($exitsDelFlagVersionFlag=false)
#foreach ($column in $columns)
#if(!$table.isSuperColumn($column.javaField))
#if($column.javaField=='delFlag')
#set($exitsDelFlagVersionFlag=true)
#end
#if($column.javaField=='version')
#set($exitsDelFlagVersionFlag=true)
#end
#end
#end
#if($exitsDelFlagVersionFlag)
import com.mybatisflex.annotation.Column;
#end
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;

View File

@ -73,6 +73,9 @@ public class ${ClassName}ServiceImpl extends BaseServiceImpl<${ClassName}Mapper,
#end
#end
#end
#if($table.tree)
queryWrapper.orderBy(${CapitalUnderScoreClassName}.ORDER_NUM.asc());
#end
return queryWrapper;
}
@ -178,6 +181,8 @@ public class ${ClassName}ServiceImpl extends BaseServiceImpl<${ClassName}Mapper,
${subclassName}Mapper.deleteByQuery(queryWrapper);
return insert${subClassName}(${className});
}
#else
return updated;
#end
}
return false;

View File

@ -279,7 +279,7 @@
</div>
</template>
<script setup name="${BusinessName}">
<script setup>
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
const { proxy } = getCurrentInstance();

View File

@ -342,7 +342,7 @@
</div>
</template>
<script setup name="${BusinessName}">
<script setup>
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
const { proxy } = getCurrentInstance();

View File

@ -110,7 +110,7 @@ public class SysClientController {
@Log(title = "客户端管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
public R<Void> changeStatus(@RequestBody SysClientBo sysClientBo) {
Boolean updated = sysClientService.updateStatus(sysClientBo.getId(),sysClientBo.getStatus());
Boolean updated = sysClientService.updateStatus(sysClientBo);
if (!updated) {
R.fail("修改客户端管理状态失败!");
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.system.controller.system;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.encrypt.annotation.ApiEncrypt;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.LoginHelper;
@ -85,9 +86,9 @@ public class SysProfileController extends BaseController
return R.fail("修改用户'" + username + "'失败,邮箱账号已存在");
}
user.setUserId(sysUser.getUserId());
// user.setPassword(null);
// user.setAvatar(null);
// user.setDeptId(null);
user.setVersion(sysUser.getVersion());
user.setPassword(null);
user.setDeptId(null);
if (userService.updateUserProfile(user))
{
return R.ok();
@ -98,12 +99,12 @@ public class SysProfileController extends BaseController
/**
* 重置密码
*/
@ApiEncrypt
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public R<Void> updatePwd(String oldPassword, String newPassword)
{
SysUserVo sysUser = userService.selectUserById(LoginHelper.getUserId());
String userName = sysUser.getUserName();
String password = sysUser.getPassword();
if (!BCrypt.checkpw(oldPassword, password)) {
return R.fail("修改密码失败,旧密码错误");
@ -111,7 +112,12 @@ public class SysProfileController extends BaseController
if (BCrypt.checkpw(newPassword, password)) {
return R.fail("新密码不能与旧密码相同");
}
if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)))
SysUserBo sysUserBo=new SysUserBo();
sysUserBo.setUserId(sysUser.getUserId());
sysUserBo.setPassword(BCrypt.hashpw(newPassword));
sysUserBo.setVersion(sysUser.getVersion());
if (userService.resetPwd(sysUserBo))
{
return R.ok();
}

View File

@ -11,6 +11,7 @@ import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.core.core.domain.model.LoginUser;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.core.utils.StreamUtils;
import com.ruoyi.common.encrypt.annotation.ApiEncrypt;
import com.ruoyi.common.excel.core.ExcelResult;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
@ -237,7 +238,9 @@ public class SysUserController extends BaseController {
/**
* 重置密码
*/
@ApiEncrypt
@SaCheckPermission("system:user:resetPwd")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd")
public R<Void> resetPwd(@RequestBody SysUserBo user) {
userService.checkUserAllowed(user.getUserId());

View File

@ -1,12 +1,11 @@
package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
@ -18,7 +17,7 @@ import java.util.Date;
*/
@Data
@Table(value = "sys_client")
public class SysClient implements Serializable {
public class SysClient implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@ -69,6 +68,10 @@ public class SysClient implements Serializable {
*/
private String status;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 删除标志0就代表存在 1就代表删除
*/
@ -95,4 +98,5 @@ public class SysClient implements Serializable {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@ -77,6 +77,10 @@ public class SysMenu implements Serializable
/** 菜单图标 */
private String icon;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 创建者
*/

View File

@ -1,6 +1,7 @@
package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
@ -87,6 +88,10 @@ public class SysTenant implements Serializable {
*/
private String status;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 删除标志0代表存在 1代表删除
*/

View File

@ -1,6 +1,7 @@
package com.ruoyi.system.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import lombok.Data;
@ -46,6 +47,11 @@ public class SysTenantPackage implements Serializable {
* 状态0正常 1停用
*/
private String status;
/** 乐观锁 */
@Column(version = true)
private Integer version;
/**
* 删除标志0代表存在 1代表删除
*/
@ -72,4 +78,5 @@ public class SysTenantPackage implements Serializable {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.system.domain;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -11,6 +12,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
*
* @author ruoyi
*/
@Data
@Table(value = "sys_user_post")
public class SysUserPost
{
@ -21,32 +23,4 @@ public class SysUserPost
/** 岗位ID */
@Id
private Long postId;
public Long getUserId()
{
return userId;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getPostId()
{
return postId;
}
public void setPostId(Long postId)
{
this.postId = postId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("postId", getPostId())
.toString();
}
}

View File

@ -1,12 +1,11 @@
package com.ruoyi.system.domain.bo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.system.domain.SysClient;
import com.ruoyi.common.orm.core.domain.BaseEntity;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.*;
import java.io.Serializable;
@ -19,7 +18,7 @@ import java.util.List;
*/
@Data
@AutoMapper(target = SysClient.class, reverseConvertGenerate = false)
public class SysClientBo implements Serializable {
public class SysClientBo implements Serializable {
/**
* id
@ -74,5 +73,7 @@ public class SysClientBo implements Serializable {
*/
private String status;
/** 乐观锁 */
private Integer version;
}

View File

@ -105,5 +105,6 @@ public class SysMenuBo implements Serializable {
*/
private String remark;
/** 乐观锁 */
private Integer version;
}

View File

@ -95,4 +95,7 @@ public class SysTenantBo implements Serializable {
* 租户状态0正常 1停用
*/
private String status;
/** 乐观锁 */
private Integer version;
}

View File

@ -48,4 +48,7 @@ public class SysTenantPackageBo implements Serializable {
* 状态0正常 1停用
*/
private String status;
/** 乐观锁 */
private Integer version;
}

View File

@ -50,6 +50,6 @@ public class SysUserProfileBo extends BaseEntity {
/**
* 用户性别0男 1女 2未知
*/
private String sex;
private String gender;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.domain.vo;
import com.mybatisflex.annotation.Column;
import com.ruoyi.system.domain.SysClient;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -22,7 +23,7 @@ import java.util.List;
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = SysClient.class)
public class SysClientVo implements Serializable {
public class SysClientVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@ -86,5 +87,9 @@ public class SysClientVo implements Serializable {
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
private String status;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
}

View File

@ -60,6 +60,10 @@ public class SysConfigVo implements Serializable {
@ExcelProperty(value = "备注")
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -84,6 +84,10 @@ public class SysDeptVo implements Serializable {
@ExcelDictFormat(dictType = "sys_normal_disable")
private String status;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -78,6 +78,10 @@ public class SysDictDataVo implements Serializable {
@ExcelProperty(value = "备注")
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -45,6 +45,10 @@ public class SysDictTypeVo implements Serializable {
@ExcelProperty(value = "备注")
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.system.domain.SysMenu;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
@ -103,6 +104,10 @@ public class SysMenuVo implements Serializable {
*/
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.mybatisflex.annotation.RelationOneToOne;
import lombok.Data;
@ -50,6 +51,10 @@ public class SysNoticeVo implements Serializable {
*/
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建者
*/

View File

@ -1,6 +1,7 @@
package com.ruoyi.system.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ruoyi.system.domain.SysOssConfig;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
@ -94,4 +95,8 @@ public class SysOssConfigVo implements Serializable {
*/
private String accessPolicy;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
}

View File

@ -1,5 +1,6 @@
package com.ruoyi.system.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.mybatisflex.annotation.RelationOneToOne;
import com.ruoyi.system.domain.SysOss;
import io.github.linpeilie.annotations.AutoMapper;
@ -46,6 +47,10 @@ public class SysOssVo implements Serializable {
*/
private String url;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -61,6 +61,10 @@ public class SysPostVo implements Serializable {
@ExcelProperty(value = "备注")
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -83,6 +83,10 @@ public class SysRoleVo implements Serializable {
@ExcelProperty(value = "备注")
private String remark;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
/**
* 创建时间
*/

View File

@ -61,4 +61,8 @@ public class SysTenantPackageVo implements Serializable {
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
private String status;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
}

View File

@ -105,4 +105,8 @@ public class SysTenantVo implements Serializable {
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
private String status;
/** 乐观锁 */
@ExcelProperty(value = "乐观锁版本号")
private Integer version;
}

View File

@ -51,7 +51,7 @@ public interface ISysClientService extends IService<SysClient> {
/**
* 修改状态
*/
boolean updateStatus(Long id, String status);
boolean updateStatus(SysClientBo sysClientBo);
/**
* 校验并批量删除客户端管理信息

View File

@ -3,9 +3,7 @@ package com.ruoyi.system.service;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import com.ruoyi.common.orm.core.service.IBaseService;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.bo.SysPostBo;
import com.ruoyi.system.domain.bo.SysUserBo;
import com.ruoyi.system.domain.vo.SysPostVo;
import com.ruoyi.system.domain.vo.SysUserVo;
import java.util.List;
@ -218,23 +216,6 @@ public interface ISysUserService extends IBaseService<SysUser>
*/
boolean resetPwd(SysUserBo user);
/**
* 重置用户密码
*
* @param userName 用户名
* @param password 密码
* @return 结果:true 更新成功false 更新失败
*/
boolean resetUserPwd(String userName, String password);
/**
* 通过用户ID删除用户
*
* @param userId 用户ID
* @return 结果:true 更新成功false 更新失败
*/
boolean deleteUserById(Long userId);
/**
* 批量删除用户信息
*

View File

@ -118,17 +118,15 @@ public class SysClientServiceImpl extends ServiceImpl<SysClientMapper, SysClient
* 修改状态
*/
@Override
public boolean updateStatus(Long id, String status) {
SysClient sysClient = UpdateEntity.of(SysClient.class, id);
public boolean updateStatus(SysClientBo sysClientBo) {
SysClient sysClient = MapstructUtils.convert(sysClientBo, SysClient.class);
Long loginUserId = LoginHelper.getUserId();
Date createTime = new Date();
sysClient.setUpdateBy(loginUserId);
sysClient.setUpdateTime(createTime);
sysClient.setStatus(status);
return clientMapper.update(sysClient) > 0;
return this.updateById(sysClient);
}
/**

View File

@ -377,16 +377,16 @@ public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole>
*/
@Override
public boolean updateRoleStatus(SysRoleBo roleBo) {
Long roleId = roleBo.getRoleId();
String status = roleBo.getStatus();
SysRole role = MapstructUtils.convert(roleBo, SysRole.class);
Long roleId = role.getRoleId();
String status = role.getStatus();
if (UserConstants.ROLE_DISABLE.equals(status) && userRoleService.countUserRoleByRoleId(roleId) > 0) {
throw new ServiceException("角色已分配,不能禁用!");
}
return UpdateChain.of(SysRole.class)
.set(SysRole::getStatus, status)
.where(SysRole::getRoleId).eq(roleId)
.update();
// 修改角色信息
return this.updateById(role);
}
/**

View File

@ -92,7 +92,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
left join sys_dept d on u.dept_id = d.dept_id
where u.del_flag = '0'*/
QueryWrapper queryWrapper = QueryWrapper.create()
.select(SYS_USER.USER_ID, SYS_USER.TENANT_ID, SYS_USER.DEPT_ID, SYS_USER.NICK_NAME, SYS_USER.USER_NAME, SYS_USER.USER_TYPE, SYS_USER.EMAIL, SYS_USER.AVATAR, SYS_USER.PHONENUMBER, SYS_USER.GENDER, SYS_USER.STATUS, SYS_USER.DEL_FLAG, SYS_USER.LOGIN_IP, SYS_USER.LOGIN_DATE, SYS_USER.CREATE_BY, SYS_USER.CREATE_TIME, SYS_USER.REMARK, SYS_DEPT.DEPT_NAME, SYS_DEPT.LEADER)
.select(SYS_USER.USER_ID, SYS_USER.TENANT_ID, SYS_USER.DEPT_ID, SYS_USER.NICK_NAME, SYS_USER.USER_NAME, SYS_USER.USER_TYPE, SYS_USER.EMAIL, SYS_USER.AVATAR, SYS_USER.PHONENUMBER, SYS_USER.GENDER, SYS_USER.STATUS, SYS_USER.VERSION, SYS_USER.DEL_FLAG, SYS_USER.LOGIN_IP, SYS_USER.LOGIN_DATE, SYS_USER.CREATE_BY, SYS_USER.CREATE_TIME, SYS_USER.REMARK, SYS_DEPT.DEPT_NAME, SYS_DEPT.LEADER)
.from(SYS_USER.as("u"))
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
.where(SYS_USER.DEL_FLAG.eq(0));
@ -136,7 +136,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.USER_ID.eq(SYS_USER.USER_ID))
.leftJoin(SYS_ROLE).as("r").on(SYS_ROLE.ROLE_ID.eq(SYS_USER_ROLE.ROLE_ID));*/
return QueryWrapper.create()
.select(QueryMethods.distinct(SYS_USER.USER_ID, SYS_USER.TENANT_ID, SYS_USER.DEPT_ID, SYS_USER.NICK_NAME, SYS_USER.USER_NAME, SYS_USER.USER_TYPE, SYS_USER.EMAIL, SYS_USER.AVATAR, SYS_USER.PHONENUMBER, SYS_USER.PASSWORD, SYS_USER.GENDER, SYS_USER.STATUS, SYS_USER.DEL_FLAG, SYS_USER.LOGIN_IP, SYS_USER.LOGIN_DATE, SYS_USER.CREATE_BY, SYS_USER.CREATE_TIME, SYS_USER.REMARK,
.select(QueryMethods.distinct(SYS_USER.USER_ID, SYS_USER.TENANT_ID, SYS_USER.DEPT_ID, SYS_USER.NICK_NAME, SYS_USER.USER_NAME, SYS_USER.USER_TYPE, SYS_USER.EMAIL, SYS_USER.AVATAR, SYS_USER.PHONENUMBER, SYS_USER.PASSWORD, SYS_USER.GENDER, SYS_USER.STATUS, SYS_USER.VERSION, SYS_USER.DEL_FLAG, SYS_USER.LOGIN_IP, SYS_USER.LOGIN_DATE, SYS_USER.CREATE_BY, SYS_USER.CREATE_TIME, SYS_USER.REMARK,
SYS_DEPT.DEPT_ID, SYS_DEPT.PARENT_ID, SYS_DEPT.ANCESTORS, SYS_DEPT.DEPT_NAME, SYS_DEPT.ORDER_NUM, SYS_DEPT.LEADER, SYS_DEPT.STATUS.as("dept_status")
))
.from(SYS_USER.as("u"))
@ -414,7 +414,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
* 校验email是否唯一
*
* @param user 用户信息
* @return
* @return true或者false
*/
@Override
public boolean checkEmailUnique(SysUserBo user) {
@ -511,7 +511,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
@Override
public boolean registerUser(SysUserBo user, Long tenantId) {
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
sysUser.setTenantId(Long.valueOf(tenantId));
sysUser.setTenantId(tenantId);
return this.save(sysUser);
}
@ -557,7 +557,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
/**
* 修改用户状态
* update sys_user set status = #{status} where user_id = #{userId}
* update sys_user set status = #{status},version=version+1 where user_id = #{userId} and version=#{version}
*
* @param user 用户信息
* @return 结果true 操作成功false 操作失败
@ -567,6 +567,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
return UpdateChain.of(SysUser.class)
.set(SysUser::getStatus, user.getStatus())
.where(SysUser::getUserId).eq(user.getUserId())
.and(SysUser::getVersion).eq(user.getVersion()) //手动添加乐观锁条件
.update();
}
@ -584,7 +585,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
/**
* 修改用户头像
* update sys_user set avatar = #{avatar} where user_id = #{userId}
*
* @param userId 用户ID
* @param avatar 头像地址
@ -610,25 +610,10 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
return UpdateChain.of(SysUser.class)
.set(SysUser::getPassword, user.getPassword())
.where(SysUser::getUserId).eq(user.getUserId())
.and(SysUser::getVersion).eq(user.getVersion()) //手动添加乐观锁条件
.update();
}
/**
* 重置用户密码
* update sys_user set password = #{password} where user_name = #{userName}
*
* @param userName 用户名
* @param password 密码
* @return 结果:true 更新成功false 更新失败
*/
@Override
public boolean resetUserPwd(String userName, String password) {
QueryWrapper queryWrapper = query().where(SYS_USER.USER_NAME.eq(userName));
SysUser sysUser = new SysUser();
sysUser.setPassword(password);
return this.update(sysUser, queryWrapper);
}
/**
* 新增用户角色信息
*
@ -657,34 +642,13 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
up.setPostId(postId);
list.add(up);
}
if (list.size() > 0) {
if (!list.isEmpty()) {
return userPostService.saveBatchWithPk(list, 100);//批量保存
}
}
return inserted;
}
/**
* 通过用户ID删除用户
*
* @param userId 用户ID
* @return 结果:true 更新成功false 更新失败
*/
@Override
@Transactional
public boolean deleteUserById(Long userId) {
// 删除用户与角色关联
userRoleService.deleteUserRoleByUserId(userId);
// 删除用户与岗位表
userPostService.deleteUserPostByUserId(userId);
//逻辑删除用户update sys_user set del_flag = '1' where user_id = #{userId}
SysUser sysUser = new SysUser();
sysUser.setUserId(userId);
sysUser.setDelFlag(1);
return this.updateById(sysUser);
}
/**
* 批量删除用户信息
*
@ -703,15 +667,8 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
// 删除用户与岗位关联
userPostService.deleteUserPost(userIds);
//逻辑删除update sys_user set del_flag = '1' where user_id in
QueryWrapper queryWrapper = query().where(SYS_USER.USER_ID.in(Arrays.asList(userIds)));
SysUser sysUser = new SysUser();
sysUser.setDelFlag(1);
return this.update(sysUser, queryWrapper);
//return UpdateChain.of(SysUser.class)
// .set(SysUser::getDelFlag, "1")
// .where(SysUser::getUserId).in(Arrays.asList(userIds))
// .update();
//逻辑删除UPDATE `sys_user` SET `del_flag` = 1 WHERE (`user_id` = 101810794781507584 ) AND `del_flag` = 0 AND `tenant_id` = 0
return this.removeByIds(Arrays.asList(userIds));
}
/**
@ -724,7 +681,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
*/
@Override
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, Long operId) {
if (StringUtils.isNull(userList) || userList.size() == 0) {
if (StringUtils.isNull(userList) || userList.isEmpty()) {
throw new ServiceException("导入用户数据不能为空!");
}
int successNum = 0;
@ -747,6 +704,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
BeanValidators.validateWithException(validator, user);
checkUserAllowed(u.getUserId());
checkUserDataScope(u.getUserId());
user.setVersion(u.getVersion());
user.setUserId(u.getUserId());
user.setUpdateBy(operId);
this.updateById(user);
@ -782,7 +740,7 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
/**
* 通过部门id查询当前部门所有用户
*
* @param deptId
* @param deptId 部门主键
* @return 用户vo列表
*/
@Override