first commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.system.mapper.AccountMapper;
|
||||
import com.ichangzuo.system.model.entity.Account;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> {
|
||||
public Account getCurrentAccount(){
|
||||
Long uid = SecurityUtils.getUserId();
|
||||
if(uid==null)
|
||||
return null;
|
||||
|
||||
Account acc = getOne(new LambdaQueryWrapper<Account>()
|
||||
.eq(Account::getUserId, uid));
|
||||
|
||||
Integer vip = acc.getVipTime();
|
||||
if(vip>0 && (vip-System.currentTimeMillis()/1000)<0){
|
||||
acc.setVipTime(-2);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.BankMapper;
|
||||
import com.ichangzuo.system.model.entity.Bank;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class BankServiceImpl extends ServiceImpl<BankMapper, Bank> {
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.constant.RedisConstants;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.system.converter.ConfigConverter;
|
||||
import com.ichangzuo.system.mapper.ConfigMapper;
|
||||
import com.ichangzuo.system.model.entity.Config;
|
||||
import com.ichangzuo.system.model.form.ConfigForm;
|
||||
import com.ichangzuo.system.model.query.ConfigPageQuery;
|
||||
import com.ichangzuo.system.model.vo.ConfigVO;
|
||||
import com.ichangzuo.system.service.ConfigService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统配置Service接口实现
|
||||
*
|
||||
* @author Theo
|
||||
* @since 2024-07-29 11:17:26
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements ConfigService {
|
||||
|
||||
private final ConfigMapper configMapper;
|
||||
|
||||
private final ConfigConverter configConverter;
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* 系统启动完成后,加载系统配置到缓存
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
refreshCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询系统配置
|
||||
*
|
||||
* @param configPageQuery 查询参数
|
||||
* @return 系统配置分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<ConfigVO> page(ConfigPageQuery configPageQuery) {
|
||||
Page<Config> page = new Page<>(configPageQuery.getPageNum(), configPageQuery.getPageSize());
|
||||
String keywords = configPageQuery.getKeywords();
|
||||
LambdaQueryWrapper<Config> query = new LambdaQueryWrapper<Config>()
|
||||
.and(StringUtils.isNotBlank(keywords),
|
||||
q -> q.like(Config::getConfigKey, keywords)
|
||||
.or()
|
||||
.like(Config::getConfigName, keywords)
|
||||
);
|
||||
Page<Config> pageList = this.page(page, query);
|
||||
return configConverter.toPageVo(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存系统配置
|
||||
*
|
||||
* @param configForm 系统配置表单
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
@Override
|
||||
public boolean save(ConfigForm configForm) {
|
||||
Assert.isTrue(
|
||||
super.count(new LambdaQueryWrapper<Config>().eq(Config::getConfigKey, configForm.getConfigKey())) == 0,
|
||||
"配置键已存在");
|
||||
Config config = configConverter.toEntity(configForm);
|
||||
config.setCreateBy(SecurityUtils.getUserId());
|
||||
return this.save(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置表单数据
|
||||
*
|
||||
* @param id 系统配置ID
|
||||
* @return 系统配置表单数据
|
||||
*/
|
||||
@Override
|
||||
public ConfigForm getConfigFormData(Long id) {
|
||||
Config entity = this.getById(id);
|
||||
return configConverter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑系统配置
|
||||
*
|
||||
* @param id 系统配置ID
|
||||
* @param configForm 系统配置表单
|
||||
* @return 是否编辑成功
|
||||
*/
|
||||
@Override
|
||||
public boolean edit(Long id, ConfigForm configForm) {
|
||||
Assert.isTrue(
|
||||
super.count(new LambdaQueryWrapper<Config>().eq(Config::getConfigKey, configForm.getConfigKey()).ne(Config::getId, id)) == 0,
|
||||
"配置键已存在");
|
||||
Config config = configConverter.toEntity(configForm);
|
||||
config.setUpdateBy(SecurityUtils.getUserId());
|
||||
return this.updateById(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除系统配置
|
||||
*
|
||||
* @param id 系统配置ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(Long id) {
|
||||
if (id != null) {
|
||||
return super.remove(new LambdaQueryWrapper<Config>().eq(Config::getId,id));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新系统配置缓存
|
||||
*
|
||||
* @return 是否刷新成功
|
||||
*/
|
||||
@Override
|
||||
public boolean refreshCache() {
|
||||
redisTemplate.delete(RedisConstants.SYSTEM_CONFIG_KEY);
|
||||
List<Config> list = this.list();
|
||||
if (list != null) {
|
||||
Map<String, String> map = list.stream().collect(Collectors.toMap(Config::getConfigKey, Config::getConfigValue));
|
||||
redisTemplate.opsForHash().putAll(RedisConstants.SYSTEM_CONFIG_KEY, map);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置
|
||||
*
|
||||
* @param key 配置键
|
||||
* @return 配置值
|
||||
*/
|
||||
@Override
|
||||
public Object getSystemConfig(String key) {
|
||||
if (StringUtils.isNotBlank(key)) {
|
||||
return redisTemplate.opsForHash().get(RedisConstants.SYSTEM_CONFIG_KEY, key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.constant.SymbolConstant;
|
||||
import com.ichangzuo.common.constant.SystemConstants;
|
||||
import com.ichangzuo.common.enums.StatusEnum;
|
||||
import com.ichangzuo.common.model.Option;
|
||||
import com.ichangzuo.system.converter.DeptConverter;
|
||||
import com.ichangzuo.system.mapper.DeptMapper;
|
||||
import com.ichangzuo.system.model.entity.Dept;
|
||||
import com.ichangzuo.system.model.form.DeptForm;
|
||||
import com.ichangzuo.system.model.query.DeptQuery;
|
||||
import com.ichangzuo.system.model.vo.DeptVO;
|
||||
import com.ichangzuo.system.service.DeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 部门 业务实现类
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2021/08/22
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
|
||||
|
||||
|
||||
private final DeptConverter deptConverter;
|
||||
|
||||
/**
|
||||
* 获取部门列表
|
||||
*/
|
||||
@Override
|
||||
public List<DeptVO> getDeptList(DeptQuery queryParams) {
|
||||
// 查询参数
|
||||
String keywords = queryParams.getKeywords();
|
||||
Integer status = queryParams.getStatus();
|
||||
|
||||
// 查询数据
|
||||
List<Dept> deptList = this.list(
|
||||
new LambdaQueryWrapper<Dept>()
|
||||
.like(StrUtil.isNotBlank(keywords), Dept::getName, keywords)
|
||||
.eq(status != null, Dept::getStatus, status)
|
||||
.orderByAsc(Dept::getSort)
|
||||
);
|
||||
|
||||
if (CollectionUtil.isEmpty(deptList)) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
// 获取所有部门ID
|
||||
Set<Long> deptIds = deptList.stream()
|
||||
.map(Dept::getId)
|
||||
.collect(Collectors.toSet());
|
||||
// 获取父节点ID
|
||||
Set<Long> parentIds = deptList.stream()
|
||||
.map(Dept::getParentId)
|
||||
.collect(Collectors.toSet());
|
||||
// 获取根节点ID(递归的起点),即父节点ID中不包含在部门ID中的节点,注意这里不能拿顶级部门 O 作为根节点,因为部门筛选的时候 O 会被过滤掉
|
||||
List<Long> rootIds = CollectionUtil.subtractToList(parentIds, deptIds);
|
||||
|
||||
// 递归生成部门树形列表
|
||||
return rootIds.stream()
|
||||
.flatMap(rootId -> recurDeptList(rootId, deptList).stream())
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成部门树形列表
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @param deptList 部门列表
|
||||
* @return 部门树形列表
|
||||
*/
|
||||
public List<DeptVO> recurDeptList(Long parentId, List<Dept> deptList) {
|
||||
return deptList.stream()
|
||||
.filter(dept -> dept.getParentId().equals(parentId))
|
||||
.map(dept -> {
|
||||
DeptVO deptVO = deptConverter.toVo(dept);
|
||||
List<DeptVO> children = recurDeptList(dept.getId(), deptList);
|
||||
deptVO.setChildren(children);
|
||||
return deptVO;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门下拉选项
|
||||
*
|
||||
* @return 部门下拉List集合
|
||||
*/
|
||||
@Override
|
||||
public List<Option<Long>> listDeptOptions() {
|
||||
|
||||
List<Dept> deptList = this.list(new LambdaQueryWrapper<Dept>()
|
||||
.eq(Dept::getStatus, StatusEnum.ENABLE.getValue())
|
||||
.select(Dept::getId, Dept::getParentId, Dept::getName)
|
||||
.orderByAsc(Dept::getSort)
|
||||
);
|
||||
if (CollectionUtil.isEmpty(deptList)) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
Set<Long> deptIds = deptList.stream()
|
||||
.map(Dept::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
Set<Long> parentIds = deptList.stream()
|
||||
.map(Dept::getParentId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<Long> rootIds = CollectionUtil.subtractToList(parentIds, deptIds);
|
||||
|
||||
// 递归生成部门树形列表
|
||||
return rootIds.stream()
|
||||
.flatMap(rootId -> recurDeptTreeOptions(rootId, deptList).stream())
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
*
|
||||
* @param formData 部门表单
|
||||
* @return 部门ID
|
||||
*/
|
||||
@Override
|
||||
public Long saveDept(DeptForm formData) {
|
||||
// 校验部门名称是否存在
|
||||
String code = formData.getCode();
|
||||
long count = this.count(new LambdaQueryWrapper<Dept>()
|
||||
.eq(Dept::getCode, code)
|
||||
);
|
||||
Assert.isTrue(count == 0, "部门编号已存在");
|
||||
|
||||
// form->entity
|
||||
Dept entity = deptConverter.toEntity(formData);
|
||||
|
||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||
String treePath = generateDeptTreePath(formData.getParentId());
|
||||
entity.setTreePath(treePath);
|
||||
|
||||
// 保存部门并返回部门ID
|
||||
boolean result = this.save(entity);
|
||||
Assert.isTrue(result, "部门保存失败");
|
||||
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门表单
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门表单对象
|
||||
*/
|
||||
@Override
|
||||
public DeptForm getDeptForm(Long deptId) {
|
||||
Dept entity = this.getById(deptId);
|
||||
return deptConverter.toForm(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @param formData 部门表单
|
||||
* @return 部门ID
|
||||
*/
|
||||
@Override
|
||||
public Long updateDept(Long deptId, DeptForm formData) {
|
||||
// 校验部门名称/部门编号是否存在
|
||||
String code = formData.getCode();
|
||||
long count = this.count(new LambdaQueryWrapper<Dept>()
|
||||
.ne(Dept::getId, deptId)
|
||||
.eq(Dept::getCode, code)
|
||||
);
|
||||
Assert.isTrue(count == 0, "部门编号已存在");
|
||||
|
||||
|
||||
// form->entity
|
||||
Dept entity = deptConverter.toEntity(formData);
|
||||
entity.setId(deptId);
|
||||
|
||||
// 生成部门路径(tree_path),格式:父节点tree_path + , + 父节点ID,用于删除部门时级联删除子部门
|
||||
String treePath = generateDeptTreePath(formData.getParentId());
|
||||
entity.setTreePath(treePath);
|
||||
|
||||
// 保存部门并返回部门ID
|
||||
boolean result = this.updateById(entity);
|
||||
Assert.isTrue(result, "部门更新失败");
|
||||
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成部门表格层级列表
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @param deptList 部门列表
|
||||
* @return 部门表格层级列表
|
||||
*/
|
||||
public static List<Option<Long>> recurDeptTreeOptions(long parentId, List<Dept> deptList) {
|
||||
return CollectionUtil.emptyIfNull(deptList).stream()
|
||||
.filter(dept -> dept.getParentId().equals(parentId))
|
||||
.map(dept -> {
|
||||
Option<Long> option = new Option<>(dept.getId(), dept.getName());
|
||||
List<Option<Long>> children = recurDeptTreeOptions(dept.getId(), deptList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
option.setChildren(children);
|
||||
}
|
||||
return option;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param ids 部门ID,多个以英文逗号,拼接字符串
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteByIds(String ids) {
|
||||
// 删除部门及子部门
|
||||
if (StrUtil.isNotBlank(ids)) {
|
||||
String[] menuIds = ids.split(SymbolConstant.COMMA);
|
||||
for (String deptId : menuIds) {
|
||||
this.remove(new LambdaQueryWrapper<Dept>()
|
||||
.eq(Dept::getId, deptId)
|
||||
.or()
|
||||
.apply("CONCAT (',',tree_path,',') LIKE CONCAT('%,',{0},',%')", deptId));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 部门路径生成
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @return 父节点路径以英文逗号(, )分割,eg: 1,2,3
|
||||
*/
|
||||
private String generateDeptTreePath(Long parentId) {
|
||||
String treePath = null;
|
||||
if (SystemConstants.ROOT_NODE_ID.equals(parentId)) {
|
||||
treePath = String.valueOf(parentId);
|
||||
} else {
|
||||
Dept parent = this.getById(parentId);
|
||||
if (parent != null) {
|
||||
treePath = parent.getTreePath() + SymbolConstant.COMMA + parent.getId();
|
||||
}
|
||||
}
|
||||
return treePath;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.DictItemMapper;
|
||||
import com.ichangzuo.system.model.entity.DictItem;
|
||||
import com.ichangzuo.system.service.DictItemService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 数据字典 服务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/10/12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DictItemServiceImpl extends ServiceImpl<DictItemMapper, DictItem> implements DictItemService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.model.Option;
|
||||
import com.ichangzuo.system.converter.DictConverter;
|
||||
import com.ichangzuo.system.converter.DictItemConverter;
|
||||
import com.ichangzuo.system.mapper.DictMapper;
|
||||
import com.ichangzuo.system.model.entity.Dict;
|
||||
import com.ichangzuo.system.model.entity.DictItem;
|
||||
import com.ichangzuo.system.model.form.DictForm;
|
||||
import com.ichangzuo.system.model.query.DictPageQuery;
|
||||
import com.ichangzuo.system.model.vo.DictPageVO;
|
||||
import com.ichangzuo.system.service.DictItemService;
|
||||
import com.ichangzuo.system.service.DictService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据字典业务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/10/12
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {
|
||||
|
||||
private final DictItemService dictItemService;
|
||||
private final DictConverter dictConverter;
|
||||
private final DictItemConverter dictItemConverter;
|
||||
|
||||
/**
|
||||
* 字典分页列表
|
||||
*
|
||||
* @param queryParams 分页查询对象
|
||||
*/
|
||||
@Override
|
||||
public Page<DictPageVO> getDictPage(DictPageQuery queryParams) {
|
||||
// 查询参数
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
|
||||
// 查询数据
|
||||
return this.baseMapper.getDictPage(new Page<>(pageNum, pageSize), queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典
|
||||
*
|
||||
* @param dictForm 字典表单数据
|
||||
*/
|
||||
@Override
|
||||
public boolean saveDict(DictForm dictForm) {
|
||||
// 保存字典
|
||||
Dict entity = dictConverter.toEntity(dictForm);
|
||||
|
||||
// 校验 code 是否唯一
|
||||
long count = this.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getCode, entity.getCode())
|
||||
);
|
||||
Assert.isTrue(count == 0, "字典编码已存在");
|
||||
|
||||
boolean result = this.save(entity);
|
||||
// 保存字典项
|
||||
if (result) {
|
||||
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
||||
List<DictItem> dictItems = dictItemConverter.toEntity(dictFormDictItems);
|
||||
dictItems.forEach(dictItem -> dictItem.setDictId(entity.getId()));
|
||||
dictItemService.saveBatch(dictItems);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典表单详情
|
||||
*
|
||||
* @param id 字典ID
|
||||
*/
|
||||
@Override
|
||||
public DictForm getDictForm(Long id) {
|
||||
// 获取字典
|
||||
Dict entity = this.getById(id);
|
||||
Assert.isTrue(entity != null, "字典不存在");
|
||||
DictForm dictForm = dictConverter.toForm(entity);
|
||||
|
||||
// 获取字典项集合
|
||||
List<DictItem> dictItems = dictItemService.list(new LambdaQueryWrapper<DictItem>()
|
||||
.eq(DictItem::getDictId, id)
|
||||
);
|
||||
// 转换数据项
|
||||
List<DictForm.DictItem> dictItemList = dictItemConverter.toDictItem(dictItems);
|
||||
dictForm.setDictItems(dictItemList);
|
||||
return dictForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典
|
||||
*
|
||||
* @param id 字典ID
|
||||
* @param dictForm 字典表单
|
||||
*/
|
||||
@Override
|
||||
public boolean updateDict(Long id, DictForm dictForm) {
|
||||
// 更新字典
|
||||
Dict entity = dictConverter.toEntity(dictForm);
|
||||
|
||||
// 校验 code 是否唯一
|
||||
long count = this.count(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getCode, entity.getCode())
|
||||
.ne(Dict::getId, id)
|
||||
);
|
||||
Assert.isTrue(count == 0, "字典编码已存在");
|
||||
|
||||
boolean result = this.updateById(entity);
|
||||
|
||||
if (result) {
|
||||
// 更新字典项
|
||||
List<DictForm.DictItem> dictFormDictItems = dictForm.getDictItems();
|
||||
List<DictItem> dictItems = dictItemConverter.toEntity(dictFormDictItems);
|
||||
|
||||
// 获取当前数据库中的字典项
|
||||
List<DictItem> currentDictItemEntities = dictItemService.list(new LambdaQueryWrapper<DictItem>()
|
||||
.eq(DictItem::getDictId, id)
|
||||
);
|
||||
|
||||
// 获取当前数据库中存在的字典项ID集合
|
||||
Set<Long> currentDictItemIds = currentDictItemEntities.stream()
|
||||
.map(DictItem::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 获取新提交的字典项ID集合
|
||||
Set<Long> newAttrIds = dictItems.stream()
|
||||
.map(DictItem::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 需要删除的字典项ID集合(存在于数据库但不在新提交的字典项中)
|
||||
Set<Long> idsToDelete = new HashSet<>(currentDictItemIds);
|
||||
idsToDelete.removeAll(newAttrIds);
|
||||
|
||||
// 删除不在新提交字典项中的旧字典项
|
||||
if (!idsToDelete.isEmpty()) {
|
||||
dictItemService.removeByIds(idsToDelete);
|
||||
}
|
||||
|
||||
// 更新或新增字典项
|
||||
for (DictItem dictItem : dictItems) {
|
||||
if (dictItem.getId() != null && currentDictItemIds.contains(dictItem.getId())) {
|
||||
// 更新现有字典项
|
||||
dictItemService.updateById(dictItem);
|
||||
} else {
|
||||
// 新增字典项
|
||||
dictItem.setDictId(id);
|
||||
dictItemService.save(dictItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典
|
||||
*
|
||||
* @param ids 字典ID,多个以英文逗号(,)分割
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteDictByIds(String ids) {
|
||||
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "请选择需要删除的字典");
|
||||
|
||||
List<String> idList = Arrays.stream(ids.split(","))
|
||||
.toList();
|
||||
|
||||
for (String id : idList) {
|
||||
boolean result = this.removeById(id);
|
||||
if (result) {
|
||||
// 删除字典下的字典项
|
||||
dictItemService.remove(
|
||||
new LambdaQueryWrapper<DictItem>()
|
||||
.eq(DictItem::getDictId, id)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典的数据项
|
||||
*
|
||||
* @param code 字典编码
|
||||
*/
|
||||
@Override
|
||||
public List<Option<Long>> listDictItemsByCode(String code) {
|
||||
// 根据字典编码获取字典ID
|
||||
Dict dict = this.getOne(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getCode, code)
|
||||
.select(Dict::getId)
|
||||
.last("limit 1")
|
||||
);
|
||||
// 如果字典不存在,则返回空集合
|
||||
if (dict == null) {
|
||||
return CollectionUtil.newArrayList();
|
||||
}
|
||||
|
||||
// 获取字典项
|
||||
List<DictItem> dictItems = dictItemService.list(
|
||||
new LambdaQueryWrapper<DictItem>()
|
||||
.eq(DictItem::getDictId, dict.getId())
|
||||
);
|
||||
|
||||
// 转换为 Option
|
||||
return dictItemConverter.toOption(dictItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典列表
|
||||
*/
|
||||
@Override
|
||||
public List<Option<String>> getDictList() {
|
||||
return this.list(new LambdaQueryWrapper<Dict>()
|
||||
.eq(Dict::getStatus, 1)
|
||||
.select(Dict::getName, Dict::getCode)
|
||||
).stream()
|
||||
.map(dict -> new Option<>(dict.getCode(), dict.getName()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.FontMapper;
|
||||
import com.ichangzuo.system.model.entity.Font;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class FontServiceImpl extends ServiceImpl<FontMapper, Font> {
|
||||
@Override
|
||||
public List<Font> list(){
|
||||
return list(new LambdaQueryWrapper<Font>().eq(Font::getState, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.IntegralMapper;
|
||||
import com.ichangzuo.system.model.entity.Integral;
|
||||
import com.ichangzuo.system.model.query.IntegralPageQuery;
|
||||
import com.ichangzuo.system.model.vo.IntegralAdminPageVO;
|
||||
import com.ichangzuo.system.model.vo.IntegralUserPageVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class IntegralServiceImpl extends ServiceImpl<IntegralMapper, Integral> {
|
||||
public IPage<IntegralAdminPageVO> listPagedAdmin(IntegralPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
return baseMapper.listPagedAdmin(new Page<>(pageNum, pageSize), queryParams);
|
||||
}
|
||||
|
||||
public IPage<IntegralUserPageVO> listPagedUser(IntegralPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
|
||||
return baseMapper.listPagedUser(new Page<>(pageNum, pageSize), queryParams);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.LogMapper;
|
||||
import com.ichangzuo.system.model.bo.VisitCount;
|
||||
import com.ichangzuo.system.model.entity.Log;
|
||||
import com.ichangzuo.system.model.query.LogPageQuery;
|
||||
import com.ichangzuo.system.model.vo.LogPageVO;
|
||||
import com.ichangzuo.system.model.vo.VisitStatsVO;
|
||||
import com.ichangzuo.system.model.vo.VisitTrendVO;
|
||||
import com.ichangzuo.system.service.LogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统日志 服务实现类
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2.10.0
|
||||
*/
|
||||
@Service
|
||||
public class LogServiceImpl extends ServiceImpl<LogMapper, Log>
|
||||
implements LogService {
|
||||
|
||||
/**
|
||||
* 获取日志分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<LogPageVO> listPagedLogs(LogPageQuery queryParams) {
|
||||
return this.baseMapper.listPagedLogs(new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
|
||||
queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问趋势
|
||||
*
|
||||
* @param startDate 开始时间
|
||||
* @param endDate 结束时间
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public VisitTrendVO getVisitTrend(LocalDate startDate, LocalDate endDate) {
|
||||
VisitTrendVO visitTrend = new VisitTrendVO();
|
||||
List<String> dates = new ArrayList<>();
|
||||
|
||||
// 获取日期范围内的日期
|
||||
while (!startDate.isAfter(endDate)) {
|
||||
dates.add(startDate.toString());
|
||||
startDate = startDate.plusDays(1);
|
||||
}
|
||||
visitTrend.setDates(dates);
|
||||
|
||||
// 获取访问量和访问 IP 数的统计数据
|
||||
List<VisitCount> pvCounts = this.baseMapper.getPvCounts(dates.get(0) + " 00:00:00", dates.get(dates.size() - 1) + " 23:59:59");
|
||||
List<VisitCount> ipCounts = this.baseMapper.getIpCounts(dates.get(0) + " 00:00:00", dates.get(dates.size() - 1) + " 23:59:59");
|
||||
|
||||
// 将统计数据转换为 Map
|
||||
Map<String, Integer> pvMap = pvCounts.stream().collect(Collectors.toMap(VisitCount::getDate, VisitCount::getCount));
|
||||
Map<String, Integer> ipMap = ipCounts.stream().collect(Collectors.toMap(VisitCount::getDate, VisitCount::getCount));
|
||||
|
||||
// 匹配日期和访问量/访问 IP 数
|
||||
List<Integer> pvList = new ArrayList<>();
|
||||
List<Integer> ipList = new ArrayList<>();
|
||||
|
||||
for (String date : dates) {
|
||||
pvList.add(pvMap.getOrDefault(date, 0));
|
||||
ipList.add(ipMap.getOrDefault(date, 0));
|
||||
}
|
||||
|
||||
visitTrend.setPvList(pvList);
|
||||
visitTrend.setIpList(ipList);
|
||||
|
||||
return visitTrend;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取访问统计
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<VisitStatsVO> getVisitStats() {
|
||||
List<VisitStatsVO> list = new ArrayList<>();
|
||||
|
||||
// 访问量
|
||||
VisitStatsVO pvStats = this.baseMapper.getPvStats();
|
||||
pvStats.setTitle("浏览量");
|
||||
pvStats.setType("pv");
|
||||
pvStats.setGranularityLabel("日");
|
||||
list.add(pvStats);
|
||||
|
||||
// 访客数
|
||||
VisitStatsVO uvStats = new VisitStatsVO();
|
||||
uvStats.setTitle("访客数");
|
||||
uvStats.setType("uv");
|
||||
uvStats.setTodayCount(100);
|
||||
uvStats.setTotalCount(2000);
|
||||
uvStats.setGrowthRate(BigDecimal.ZERO);
|
||||
uvStats.setGranularityLabel("日");
|
||||
list.add(uvStats);
|
||||
|
||||
// IP数
|
||||
VisitStatsVO ipStats = this.baseMapper.getIpStats();
|
||||
ipStats.setTitle("IP数");
|
||||
ipStats.setType("ip");
|
||||
ipStats.setGranularityLabel("日");
|
||||
list.add(ipStats);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.ichangzuo.common.constant.SystemConstants;
|
||||
import com.ichangzuo.common.enums.MenuTypeEnum;
|
||||
import com.ichangzuo.common.enums.StatusEnum;
|
||||
import com.ichangzuo.common.model.KeyValue;
|
||||
import com.ichangzuo.common.model.Option;
|
||||
import com.ichangzuo.module.codegen.model.entity.GenConfig;
|
||||
import com.ichangzuo.system.converter.MenuConverter;
|
||||
import com.ichangzuo.system.mapper.MenuMapper;
|
||||
import com.ichangzuo.system.model.bo.RouteBO;
|
||||
import com.ichangzuo.system.model.entity.Menu;
|
||||
import com.ichangzuo.system.model.form.MenuForm;
|
||||
import com.ichangzuo.system.model.query.MenuQuery;
|
||||
import com.ichangzuo.system.model.vo.MenuVO;
|
||||
import com.ichangzuo.system.model.vo.RouteVO;
|
||||
import com.ichangzuo.system.service.MenuService;
|
||||
import com.ichangzuo.system.service.RoleMenuService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 菜单业务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2020/11/06
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
|
||||
|
||||
private final MenuConverter menuConverter;
|
||||
|
||||
private final RoleMenuService roleMenuService;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @param queryParams {@link MenuQuery}
|
||||
*/
|
||||
@Override
|
||||
public List<MenuVO> listMenus(MenuQuery queryParams) {
|
||||
List<Menu> menus = this.list(new LambdaQueryWrapper<Menu>()
|
||||
.like(StrUtil.isNotBlank(queryParams.getKeywords()), Menu::getName, queryParams.getKeywords())
|
||||
.orderByAsc(Menu::getSort)
|
||||
);
|
||||
// 获取所有菜单ID
|
||||
Set<Long> menuIds = menus.stream()
|
||||
.map(Menu::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 获取所有父级ID
|
||||
Set<Long> parentIds = menus.stream()
|
||||
.map(Menu::getParentId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 获取根节点ID(递归的起点),即父节点ID中不包含在部门ID中的节点,注意这里不能拿顶级菜单 O 作为根节点,因为菜单筛选的时候 O 会被过滤掉
|
||||
List<Long> rootIds = parentIds.stream()
|
||||
.filter(id -> !menuIds.contains(id))
|
||||
.toList();
|
||||
|
||||
// 使用递归函数来构建菜单树
|
||||
return rootIds.stream()
|
||||
.flatMap(rootId -> buildMenuTree(rootId, menus).stream())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成菜单列表
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
* @param menuList 菜单列表
|
||||
* @return 菜单列表
|
||||
*/
|
||||
private List<MenuVO> buildMenuTree(Long parentId, List<Menu> menuList) {
|
||||
return CollectionUtil.emptyIfNull(menuList)
|
||||
.stream()
|
||||
.filter(menu -> menu.getParentId().equals(parentId))
|
||||
.map(entity -> {
|
||||
MenuVO menuVO = menuConverter.toVo(entity);
|
||||
List<MenuVO> children = buildMenuTree(entity.getId(), menuList);
|
||||
menuVO.setChildren(children);
|
||||
return menuVO;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单下拉数据
|
||||
*
|
||||
* @param onlyParent 是否只查询父级菜单 如果为true,排除按钮
|
||||
*/
|
||||
@Override
|
||||
public List<Option> listMenuOptions(boolean onlyParent) {
|
||||
List<Menu> menuList = this.list(new LambdaQueryWrapper<Menu>()
|
||||
.in(onlyParent, Menu::getType, MenuTypeEnum.CATALOG.getValue(), MenuTypeEnum.MENU.getValue())
|
||||
.orderByAsc(Menu::getSort)
|
||||
);
|
||||
return buildMenuOptions(SystemConstants.ROOT_NODE_ID, menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成菜单下拉层级列表
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
* @param menuList 菜单列表
|
||||
* @return 菜单下拉列表
|
||||
*/
|
||||
private List<Option> buildMenuOptions(Long parentId, List<Menu> menuList) {
|
||||
List<Option> menuOptions = new ArrayList<>();
|
||||
|
||||
for (Menu menu : menuList) {
|
||||
if (menu.getParentId().equals(parentId)) {
|
||||
Option option = new Option(menu.getId(), menu.getName());
|
||||
List<Option> subMenuOptions = buildMenuOptions(menu.getId(), menuList);
|
||||
if (!subMenuOptions.isEmpty()) {
|
||||
option.setChildren(subMenuOptions);
|
||||
}
|
||||
menuOptions.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
return menuOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单路由列表
|
||||
*/
|
||||
@Override
|
||||
public List<RouteVO> listRoutes(Set<String> roles) {
|
||||
|
||||
if (CollectionUtil.isEmpty(roles)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<RouteBO> menuList = this.baseMapper.listRoutes(roles);
|
||||
return buildRoutes(SystemConstants.ROOT_NODE_ID, menuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归生成菜单路由层级列表
|
||||
*
|
||||
* @param parentId 父级ID
|
||||
* @param menuList 菜单列表
|
||||
* @return 路由层级列表
|
||||
*/
|
||||
private List<RouteVO> buildRoutes(Long parentId, List<RouteBO> menuList) {
|
||||
List<RouteVO> routeList = new ArrayList<>();
|
||||
|
||||
for (RouteBO menu : menuList) {
|
||||
if (menu.getParentId().equals(parentId)) {
|
||||
RouteVO routeVO = toRouteVo(menu);
|
||||
List<RouteVO> children = buildRoutes(menu.getId(), menuList);
|
||||
if (!children.isEmpty()) {
|
||||
routeVO.setChildren(children);
|
||||
}
|
||||
routeList.add(routeVO);
|
||||
}
|
||||
}
|
||||
|
||||
return routeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据RouteBO创建RouteVO
|
||||
*/
|
||||
private RouteVO toRouteVo(RouteBO routeBO) {
|
||||
RouteVO routeVO = new RouteVO();
|
||||
// 获取路由名称
|
||||
String routeName = routeBO.getRouteName();
|
||||
if (StrUtil.isBlank(routeName)) {
|
||||
// 路由 name 需要驼峰,首字母大写
|
||||
routeName = StringUtils.capitalize(StrUtil.toCamelCase(routeBO.getRoutePath(), '-'));
|
||||
}
|
||||
// 根据name路由跳转 this.$router.push({name:xxx})
|
||||
routeVO.setName(routeName);
|
||||
|
||||
// 根据path路由跳转 this.$router.push({path:xxx})
|
||||
routeVO.setPath(routeBO.getRoutePath());
|
||||
routeVO.setRedirect(routeBO.getRedirect());
|
||||
routeVO.setComponent(routeBO.getComponent());
|
||||
|
||||
RouteVO.Meta meta = new RouteVO.Meta();
|
||||
meta.setTitle(routeBO.getName());
|
||||
meta.setIcon(routeBO.getIcon());
|
||||
meta.setHidden(StatusEnum.DISABLE.getValue().equals(routeBO.getVisible()));
|
||||
// 【菜单】是否开启页面缓存
|
||||
if (MenuTypeEnum.MENU.equals(routeBO.getType())
|
||||
&& ObjectUtil.equals(routeBO.getKeepAlive(), 1)) {
|
||||
meta.setKeepAlive(true);
|
||||
}
|
||||
meta.setAlwaysShow(ObjectUtil.equals(routeBO.getAlwaysShow(), 1));
|
||||
|
||||
String paramsJson = routeBO.getParams();
|
||||
// 将 JSON 字符串转换为 Map<String, String>
|
||||
if (StrUtil.isNotBlank(paramsJson)) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
Map<String, String> paramMap = objectMapper.readValue(paramsJson, new TypeReference<>() {
|
||||
});
|
||||
meta.setParams(paramMap);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("解析参数失败", e);
|
||||
}
|
||||
}
|
||||
routeVO.setMeta(meta);
|
||||
return routeVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增/修改菜单
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||
public boolean saveMenu(MenuForm menuForm) {
|
||||
|
||||
MenuTypeEnum menuType = menuForm.getType();
|
||||
|
||||
if (menuType == MenuTypeEnum.CATALOG) { // 如果是目录
|
||||
String path = menuForm.getRoutePath();
|
||||
if (menuForm.getParentId() == 0 && !path.startsWith("/")) {
|
||||
menuForm.setRoutePath("/" + path); // 一级目录需以 / 开头
|
||||
}
|
||||
menuForm.setComponent("Layout");
|
||||
} else if (menuType == MenuTypeEnum.EXTLINK) { // 如果是外链
|
||||
|
||||
menuForm.setComponent(null);
|
||||
}
|
||||
|
||||
Menu entity = menuConverter.toEntity(menuForm);
|
||||
String treePath = generateMenuTreePath(menuForm.getParentId());
|
||||
entity.setTreePath(treePath);
|
||||
|
||||
List<KeyValue> params = menuForm.getParams();
|
||||
// 路由参数 [{key:"id",value:"1"},{key:"name",value:"张三"}] 转换为 [{"id":"1"},{"name":"张三"}]
|
||||
if (CollectionUtil.isNotEmpty(params)) {
|
||||
entity.setParams(JSONUtil.toJsonStr(params.stream()
|
||||
.collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue))));
|
||||
} else {
|
||||
entity.setParams(null);
|
||||
}
|
||||
if (menuType != MenuTypeEnum.BUTTON && menuType != MenuTypeEnum.CATALOG) {
|
||||
Assert.isFalse(this.exists(new LambdaQueryWrapper<Menu>()
|
||||
.eq(Menu::getRouteName, entity.getRouteName())
|
||||
.ne(menuForm.getId() != null, Menu::getId, menuForm.getId())
|
||||
), "路由名称已存在");
|
||||
}
|
||||
|
||||
boolean result = this.saveOrUpdate(entity);
|
||||
if (result) {
|
||||
// 编辑刷新角色权限缓存
|
||||
if (menuForm.getId() != null) {
|
||||
roleMenuService.refreshRolePermsCache();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 部门路径生成
|
||||
*
|
||||
* @param parentId 父ID
|
||||
* @return 父节点路径以英文逗号(, )分割,eg: 1,2,3
|
||||
*/
|
||||
private String generateMenuTreePath(Long parentId) {
|
||||
if (SystemConstants.ROOT_NODE_ID.equals(parentId)) {
|
||||
return String.valueOf(parentId);
|
||||
} else {
|
||||
Menu parent = this.getById(parentId);
|
||||
return parent != null ? parent.getTreePath() + "," + parent.getId() : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改菜单显示状态
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @param visible 是否显示(1->显示;2->隐藏)
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||
public boolean updateMenuVisible(Long menuId, Integer visible) {
|
||||
return this.update(new LambdaUpdateWrapper<Menu>()
|
||||
.eq(Menu::getId, menuId)
|
||||
.set(Menu::getVisible, visible)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单表单数据
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @return 菜单表单数据
|
||||
*/
|
||||
@Override
|
||||
public MenuForm getMenuForm(Long id) {
|
||||
Menu entity = this.getById(id);
|
||||
Assert.isTrue(entity != null, "菜单不存在");
|
||||
MenuForm formData = menuConverter.toForm(entity);
|
||||
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
||||
String params = entity.getParams();
|
||||
if (StrUtil.isNotBlank(params)) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
// 解析 JSON 字符串为 Map<String, String>
|
||||
Map<String, String> paramMap = objectMapper.readValue(params, new TypeReference<>() {
|
||||
});
|
||||
|
||||
// 转换为 List<KeyValue> 格式 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
||||
List<KeyValue> transformedList = paramMap.entrySet().stream()
|
||||
.map(entry -> new KeyValue(entry.getKey(), entry.getValue()))
|
||||
.toList();
|
||||
|
||||
// 将转换后的列表存入 MenuForm
|
||||
formData.setParams(transformedList);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("解析参数失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
return formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||
public boolean deleteMenu(Long id) {
|
||||
boolean result = this.remove(new LambdaQueryWrapper<Menu>()
|
||||
.eq(Menu::getId, id)
|
||||
.or()
|
||||
.apply("CONCAT (',',tree_path,',') LIKE CONCAT('%,',{0},',%')", id));
|
||||
|
||||
|
||||
// 刷新角色权限缓存
|
||||
if (result) {
|
||||
roleMenuService.refreshRolePermsCache();
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成时添加菜单
|
||||
*
|
||||
* @param parentMenuId 父菜单ID
|
||||
* @param genConfig 实体名称
|
||||
*/
|
||||
@Override
|
||||
public void addMenuForCodegen(Long parentMenuId, GenConfig genConfig) {
|
||||
Menu parentMenu = this.getById(parentMenuId);
|
||||
Assert.notNull(parentMenu, "上级菜单不存在");
|
||||
|
||||
String entityName = genConfig.getEntityName();
|
||||
|
||||
long count = this.count(new LambdaQueryWrapper<Menu>().eq(Menu::getRouteName, entityName));
|
||||
if (count > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取父级菜单子菜单最带的排序
|
||||
Menu maxSortMenu = this.getOne(new LambdaQueryWrapper<Menu>().eq(Menu::getParentId, parentMenuId)
|
||||
.orderByDesc(Menu::getSort)
|
||||
.last("limit 1")
|
||||
);
|
||||
int sort = 1;
|
||||
if (maxSortMenu != null) {
|
||||
sort = maxSortMenu.getSort() + 1;
|
||||
}
|
||||
|
||||
Menu menu = new Menu();
|
||||
menu.setParentId(parentMenuId);
|
||||
menu.setName(genConfig.getBusinessName());
|
||||
|
||||
menu.setRouteName(entityName);
|
||||
menu.setRoutePath(StrUtil.toSymbolCase(entityName, '-'));
|
||||
menu.setComponent(genConfig.getModuleName() + "/" + StrUtil.toSymbolCase(entityName, '-') + "/index");
|
||||
menu.setType(MenuTypeEnum.MENU);
|
||||
menu.setSort(sort);
|
||||
menu.setVisible(1);
|
||||
boolean result = this.save(menu);
|
||||
|
||||
if (result) {
|
||||
// 生成treePath
|
||||
String treePath = generateMenuTreePath(parentMenuId);
|
||||
menu.setTreePath(treePath);
|
||||
this.updateById(menu);
|
||||
|
||||
// 生成CURD按钮权限
|
||||
String permPrefix = genConfig.getModuleName() + ":" + StrUtil.lowerFirst(entityName) + ":";
|
||||
String[] actions = {"查询", "新增", "编辑", "删除"};
|
||||
String[] perms = {"query", "add", "edit", "delete"};
|
||||
|
||||
for (int i = 0; i < actions.length; i++) {
|
||||
Menu button = new Menu();
|
||||
button.setParentId(menu.getId());
|
||||
button.setType(MenuTypeEnum.BUTTON);
|
||||
button.setName(actions[i]);
|
||||
button.setPerm(permPrefix + perms[i]);
|
||||
button.setSort(i + 1);
|
||||
this.save(button);
|
||||
|
||||
// 生成 treepath
|
||||
button.setTreePath(treePath + "," + button.getId());
|
||||
this.updateById(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.MessageMapper;
|
||||
import com.ichangzuo.system.model.entity.Message;
|
||||
import com.ichangzuo.system.model.query.MessagePageQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IService<Message> {
|
||||
public IPage<Message> listPage(MessagePageQuery queryParams) {
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<Message> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
LambdaQueryWrapper<Message> lqw = new LambdaQueryWrapper<Message>();
|
||||
Integer type = queryParams.getType();
|
||||
Long uid = queryParams.getUserId();
|
||||
if(type==0) {
|
||||
lqw.eq(Message::getType, 0);
|
||||
if(uid!=null && uid>0){
|
||||
lqw.lt(Message::getState, 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (uid == null || uid == 0) { //全部
|
||||
lqw.eq(Message::getType, 1);
|
||||
} else {
|
||||
lqw.eq(Message::getType, 1)
|
||||
.eq(Message::getUserId, uid)
|
||||
.lt(Message::getState, 2)
|
||||
.orderByAsc(Message::getState);
|
||||
}
|
||||
}
|
||||
|
||||
lqw.orderByDesc(Message::getMsgId);
|
||||
|
||||
return baseMapper.selectPage(page, lqw);
|
||||
}
|
||||
|
||||
public List<Message> getLatest(Long userId){
|
||||
//公告
|
||||
LambdaQueryWrapper<Message> lqw = new LambdaQueryWrapper<Message>()
|
||||
.eq(Message::getType, 0)
|
||||
.lt(Message::getState, 2)
|
||||
.orderByDesc(Message::getMsgId)
|
||||
.last("limit 5");
|
||||
List<Message> list = baseMapper.selectList(lqw);
|
||||
//未读消息
|
||||
lqw = new LambdaQueryWrapper<Message>()
|
||||
.eq(Message::getUserId, userId)
|
||||
.eq(Message::getType, 1)
|
||||
.eq(Message::getState, 0)
|
||||
.orderByDesc(Message::getMsgId)
|
||||
.last("limit 5");
|
||||
|
||||
list.addAll(baseMapper.selectList(lqw));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean setByIds(String idsStr, Integer set){
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "消息号列表为空");
|
||||
List<Integer> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.toList();
|
||||
Integer now = (int) (System.currentTimeMillis()/1000);
|
||||
boolean result = true;
|
||||
|
||||
for(Integer id: ids){
|
||||
result = update(new LambdaUpdateWrapper<Message>()
|
||||
.eq(Message::getMsgId, id)
|
||||
.set(Message::getState, set)
|
||||
.set(set==2 ? Message::getDeleteTime : Message::getReadTime, now));
|
||||
|
||||
if(!result) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void sendUserMessage(Long toId, String title, String content){
|
||||
Message msg = new Message();
|
||||
msg.setUserId(toId);
|
||||
msg.setTitle(title);
|
||||
msg.setContent(content);
|
||||
msg.setType(1);
|
||||
msg.setSendTime((int) (System.currentTimeMillis()/1000));
|
||||
|
||||
save(msg);
|
||||
}
|
||||
|
||||
public boolean saveMessage(Message message){
|
||||
Integer msgId = message.getMsgId();
|
||||
if(msgId==null){
|
||||
message.setSendTime((int) (System.currentTimeMillis()/1000));
|
||||
message.setState(0);
|
||||
}
|
||||
|
||||
return saveOrUpdate(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.NewUserMapper;
|
||||
import com.ichangzuo.system.model.entity.NewUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class NewUserServiceImpl extends ServiceImpl<NewUserMapper, NewUser> {
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.NoticeMapper;
|
||||
import com.ichangzuo.system.model.entity.Notice;
|
||||
import com.ichangzuo.system.model.query.NoticePageQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> {
|
||||
public IPage<Notice> listPage(NoticePageQuery queryParams) {
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<Notice> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
LambdaQueryWrapper<Notice> lqw = new LambdaQueryWrapper<>();
|
||||
Integer state = queryParams.getState();
|
||||
if(state!=null) {
|
||||
lqw.eq(Notice::getState, state);
|
||||
}
|
||||
|
||||
lqw.orderByDesc(Notice::getNoticeId);
|
||||
|
||||
return baseMapper.selectPage(page, lqw);
|
||||
}
|
||||
|
||||
public boolean saveNotice(Notice notice){
|
||||
Integer id = notice.getNoticeId();
|
||||
if(id==null){
|
||||
notice.setReleaseTime((int) (System.currentTimeMillis()/1000));
|
||||
}
|
||||
|
||||
return saveOrUpdate(notice);
|
||||
}
|
||||
|
||||
public boolean setByIds(String idsStr, Integer set){
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "消息号列表为空");
|
||||
List<Integer> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.toList();
|
||||
Integer now = (int) (System.currentTimeMillis()/1000);
|
||||
boolean result = true;
|
||||
|
||||
for(Integer id: ids){
|
||||
result = update(new LambdaUpdateWrapper<Notice>()
|
||||
.eq(Notice::getNoticeId, id)
|
||||
.set(Notice::getState, set)
|
||||
.set(set==0 ? Notice::getReleaseTime : Notice::getShieldTime, now));
|
||||
|
||||
if(!result) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.OrderMapper;
|
||||
import com.ichangzuo.system.model.entity.Order;
|
||||
import com.ichangzuo.system.model.query.OrderPageQuery;
|
||||
import com.ichangzuo.system.model.vo.OrderPageVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> {
|
||||
public IPage<OrderPageVO> listPage(OrderPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
return baseMapper.listPaged(new Page<>(pageNum, pageSize), queryParams);
|
||||
}
|
||||
|
||||
public Order createNewOrder(Long userId, String payType, String money){
|
||||
Date now = new Date();
|
||||
SimpleDateFormat formatYmd = new SimpleDateFormat("yyyyMMdd");
|
||||
String ymd = formatYmd.format(now);
|
||||
SimpleDateFormat formatHms = new SimpleDateFormat("HHmmss");
|
||||
String hms = formatHms.format(now);
|
||||
|
||||
Order order = new Order();
|
||||
order.setUserId(userId);
|
||||
order.setOrderNumber(ymd + "-" + payType + "-" + userId + "-" + hms);
|
||||
order.setMoney(Double.parseDouble(money));
|
||||
order.setPayway(payType);
|
||||
order.setPaytime((int)(now.getTime()/1000));
|
||||
order.setState(0);
|
||||
|
||||
if( save(order) )
|
||||
return order;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean createNewOrder(String orderNo, String money){
|
||||
String[] arr = orderNo.split("-");
|
||||
|
||||
Order order = new Order();
|
||||
order.setUserId(Long.parseLong(arr[2]));
|
||||
order.setOrderNumber(orderNo);
|
||||
order.setMoney(Double.parseDouble(money));
|
||||
order.setPayway(arr[1]);
|
||||
order.setPaytime((int)(System.currentTimeMillis()/1000));
|
||||
order.setState(0);
|
||||
|
||||
return save(order);
|
||||
}
|
||||
|
||||
public String generatorOrderNo(Long userId, String payType){
|
||||
Date now = new Date();
|
||||
SimpleDateFormat formatYmd = new SimpleDateFormat("yyyyMMdd");
|
||||
String ymd = formatYmd.format(now);
|
||||
SimpleDateFormat formatHms = new SimpleDateFormat("HHmmss");
|
||||
String hms = formatHms.format(now);
|
||||
|
||||
return ymd + "-" + payType + "-" + userId + "-" + hms;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.QnAMapper;
|
||||
import com.ichangzuo.system.model.bo.QnABO;
|
||||
import com.ichangzuo.system.model.bo.QnAFullBO;
|
||||
import com.ichangzuo.system.model.bo.QnAUpdateBO;
|
||||
import com.ichangzuo.system.model.entity.QnA;
|
||||
import com.ichangzuo.system.model.query.QnAPageQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class QnAServiceImpl extends ServiceImpl<QnAMapper, QnA> {
|
||||
public List<QnABO> listByType(Integer typeId){
|
||||
return baseMapper.listByType(typeId);
|
||||
}
|
||||
|
||||
public IPage<QnAFullBO> listPage(QnAPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
return baseMapper.listPage(new Page<>(pageNum, pageSize),queryParams);
|
||||
}
|
||||
|
||||
public boolean updateOrSave(QnAUpdateBO bo){
|
||||
QnA qna = null;
|
||||
|
||||
if(bo.getHelpId()==null || bo.getHelpId()==0)
|
||||
qna = new QnA();
|
||||
else
|
||||
qna = getById(bo.getHelpId());
|
||||
|
||||
if(qna==null)
|
||||
return false;
|
||||
|
||||
qna.setQuestion(bo.getQuestion());
|
||||
qna.setAnswer(bo.getAnswer());
|
||||
qna.setState(bo.getState());
|
||||
qna.setHelpTypeId(bo.getHelpTypeId());
|
||||
qna.setAnswerTime((int)(System.currentTimeMillis()/1000));
|
||||
|
||||
return saveOrUpdate(qna);
|
||||
}
|
||||
|
||||
public boolean setByIds(String idsStr, Integer set){
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "QnA号列表为空");
|
||||
List<Integer> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.toList();
|
||||
Integer now = (int) (System.currentTimeMillis()/1000);
|
||||
boolean result = true;
|
||||
|
||||
for(Integer id: ids){
|
||||
result = update(new LambdaUpdateWrapper<QnA>()
|
||||
.eq(QnA::getHelpId, id)
|
||||
.set(QnA::getState, set)
|
||||
.set(QnA::getAnswerTime, now));
|
||||
|
||||
if(!result) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.base.BasePageQuery;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.system.mapper.RealNameMapper;
|
||||
import com.ichangzuo.system.model.entity.Message;
|
||||
import com.ichangzuo.system.model.entity.RealNameInfo;
|
||||
import com.ichangzuo.system.model.query.MessagePageQuery;
|
||||
import com.ichangzuo.system.model.query.RealNameInfoPageQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RealNameServiceImpl extends ServiceImpl<RealNameMapper, RealNameInfo> {
|
||||
@Autowired
|
||||
private RealNameMapper realNameMapper;
|
||||
|
||||
public RealNameInfo getCurrentRealName() {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
return getOne(new LambdaQueryWrapper<RealNameInfo>()
|
||||
.eq(RealNameInfo::getUserId, userId)
|
||||
);
|
||||
}
|
||||
|
||||
public boolean setVerifyRealName(Long uid, int state){
|
||||
return update(new LambdaUpdateWrapper<RealNameInfo>()
|
||||
.eq(RealNameInfo::getUserId, uid)
|
||||
.set(RealNameInfo::getIsName, state));
|
||||
}
|
||||
|
||||
public IPage<RealNameInfo> listPage(RealNameInfoPageQuery queryParams) {
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<RealNameInfo> page = new Page<>(pageNum, pageSize);
|
||||
Integer isName = queryParams.getIsName();
|
||||
|
||||
LambdaQueryWrapper<RealNameInfo> lqw = new LambdaQueryWrapper<RealNameInfo>()
|
||||
.isNotNull(RealNameInfo::getIdentityCard)
|
||||
.orderByAsc(RealNameInfo::getUserId);
|
||||
if(isName>=1 && isName<=3){
|
||||
lqw.eq(RealNameInfo::getIsName, isName);
|
||||
}
|
||||
else{
|
||||
lqw.orderByDesc(RealNameInfo::getIsName);
|
||||
}
|
||||
|
||||
return realNameMapper.selectPage(page, lqw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.constant.SecurityConstants;
|
||||
import com.ichangzuo.system.mapper.RoleMenuMapper;
|
||||
import com.ichangzuo.system.model.bo.RolePermsBO;
|
||||
import com.ichangzuo.system.model.entity.RoleMenu;
|
||||
import com.ichangzuo.system.service.RoleMenuService;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* 角色菜单业务实现
|
||||
*
|
||||
* @author Ray
|
||||
* @since 2.5.0
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements RoleMenuService {
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/**
|
||||
* 初始化权限缓存
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initRolePermsCache() {
|
||||
log.info("初始化权限缓存... ");
|
||||
refreshRolePermsCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新权限缓存
|
||||
*/
|
||||
@Override
|
||||
public void refreshRolePermsCache() {
|
||||
// 清理权限缓存
|
||||
redisTemplate.opsForHash().delete(SecurityConstants.ROLE_PERMS_PREFIX, "*");
|
||||
|
||||
List<RolePermsBO> list = this.baseMapper.getRolePermsList(null);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
list.forEach(item -> {
|
||||
String roleCode = item.getRoleCode();
|
||||
Set<String> perms = item.getPerms();
|
||||
if (CollectionUtil.isNotEmpty(perms)) {
|
||||
redisTemplate.opsForHash().put(SecurityConstants.ROLE_PERMS_PREFIX, roleCode, perms);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新权限缓存
|
||||
*/
|
||||
@Override
|
||||
public void refreshRolePermsCache(String roleCode) {
|
||||
// 清理权限缓存
|
||||
redisTemplate.opsForHash().delete(SecurityConstants.ROLE_PERMS_PREFIX, roleCode);
|
||||
|
||||
List<RolePermsBO> list = this.baseMapper.getRolePermsList(roleCode);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
RolePermsBO rolePerms = list.get(0);
|
||||
if (rolePerms == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> perms = rolePerms.getPerms();
|
||||
if (CollectionUtil.isNotEmpty(perms)) {
|
||||
redisTemplate.opsForHash().put(SecurityConstants.ROLE_PERMS_PREFIX, roleCode, perms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新权限缓存 (角色编码变更时调用)
|
||||
*/
|
||||
@Override
|
||||
public void refreshRolePermsCache(String oldRoleCode, String newRoleCode) {
|
||||
// 清理旧角色权限缓存
|
||||
redisTemplate.opsForHash().delete(SecurityConstants.ROLE_PERMS_PREFIX, oldRoleCode);
|
||||
|
||||
// 添加新角色权限缓存
|
||||
List<RolePermsBO> list = this.baseMapper.getRolePermsList(newRoleCode);
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
RolePermsBO rolePerms = list.get(0);
|
||||
if (rolePerms == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> perms = rolePerms.getPerms();
|
||||
redisTemplate.opsForHash().put(SecurityConstants.ROLE_PERMS_PREFIX, newRoleCode, perms);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色权限集合
|
||||
*
|
||||
* @param roles 角色编码集合
|
||||
* @return 权限集合
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getRolePermsByRoleCodes(Set<String> roles) {
|
||||
return this.baseMapper.listRolePerms(roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色拥有的菜单ID集合
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 菜单ID集合
|
||||
*/
|
||||
@Override
|
||||
public List<Long> listMenuIdsByRoleId(Long roleId) {
|
||||
return this.baseMapper.listMenuIdsByRoleId(roleId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.constant.SystemConstants;
|
||||
import com.ichangzuo.common.model.Option;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.system.converter.RoleConverter;
|
||||
import com.ichangzuo.system.service.RoleService;
|
||||
import com.ichangzuo.system.mapper.RoleMapper;
|
||||
import com.ichangzuo.system.model.entity.Role;
|
||||
import com.ichangzuo.system.model.entity.RoleMenu;
|
||||
import com.ichangzuo.system.model.form.RoleForm;
|
||||
import com.ichangzuo.system.model.query.RolePageQuery;
|
||||
import com.ichangzuo.system.model.vo.RolePageVO;
|
||||
import com.ichangzuo.system.service.RoleMenuService;
|
||||
import com.ichangzuo.system.service.UserRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色业务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/6/3
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||
|
||||
private final RoleMenuService roleMenuService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final RoleConverter roleConverter;
|
||||
|
||||
/**
|
||||
* 角色分页列表
|
||||
*
|
||||
* @param queryParams 角色查询参数
|
||||
* @return {@link Page< RolePageVO >} – 角色分页列表
|
||||
*/
|
||||
@Override
|
||||
public Page<RolePageVO> getRolePage(RolePageQuery queryParams) {
|
||||
// 查询参数
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
String keywords = queryParams.getKeywords();
|
||||
|
||||
// 查询数据
|
||||
Page<Role> rolePage = this.page(new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<Role>()
|
||||
.and(StrUtil.isNotBlank(keywords),
|
||||
wrapper ->
|
||||
wrapper.like(StrUtil.isNotBlank(keywords), Role::getName, keywords)
|
||||
.or()
|
||||
.like(StrUtil.isNotBlank(keywords), Role::getCode, keywords)
|
||||
)
|
||||
.ne(!SecurityUtils.isRoot(), Role::getCode, SystemConstants.ROOT_ROLE_CODE) // 非超级管理员不显示超级管理员角色
|
||||
);
|
||||
|
||||
// 实体转换
|
||||
return roleConverter.toPageVo(rolePage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色下拉列表
|
||||
*
|
||||
* @return {@link List< Option >} – 角色下拉列表
|
||||
*/
|
||||
@Override
|
||||
public List<Option<Long>> listRoleOptions() {
|
||||
// 查询数据
|
||||
List<Role> roleList = this.list(new LambdaQueryWrapper<Role>()
|
||||
.ne(!SecurityUtils.isRoot(), Role::getCode, SystemConstants.ROOT_ROLE_CODE)
|
||||
.select(Role::getId, Role::getName)
|
||||
.orderByAsc(Role::getSort)
|
||||
);
|
||||
|
||||
// 实体转换
|
||||
return roleConverter.entities2Options(roleList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存角色
|
||||
*
|
||||
* @param roleForm 角色表单数据
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public boolean saveRole(RoleForm roleForm) {
|
||||
|
||||
Long roleId = roleForm.getId();
|
||||
|
||||
// 编辑角色时,判断角色是否存在
|
||||
Role oldRole = null;
|
||||
if (roleId != null) {
|
||||
oldRole = this.getById(roleId);
|
||||
Assert.isTrue(oldRole != null, "角色不存在");
|
||||
}
|
||||
|
||||
String roleCode = roleForm.getCode();
|
||||
long count = this.count(new LambdaQueryWrapper<Role>()
|
||||
.ne(roleId != null, Role::getId, roleId)
|
||||
.and(wrapper ->
|
||||
wrapper.eq(Role::getCode, roleCode).or().eq(Role::getName, roleForm.getName())
|
||||
));
|
||||
Assert.isTrue(count == 0, "角色名称或角色编码已存在,请修改后重试!");
|
||||
|
||||
// 实体转换
|
||||
Role role = roleConverter.toEntity(roleForm);
|
||||
|
||||
boolean result = this.saveOrUpdate(role);
|
||||
if (result) {
|
||||
// 判断角色编码或状态是否修改,修改了则刷新权限缓存
|
||||
if (oldRole != null
|
||||
&& (
|
||||
!StrUtil.equals(oldRole.getCode(), roleCode) ||
|
||||
!ObjectUtil.equals(oldRole.getStatus(), roleForm.getStatus())
|
||||
)) {
|
||||
roleMenuService.refreshRolePermsCache(oldRole.getCode(), roleCode);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色表单数据
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return {@link RoleForm} – 角色表单数据
|
||||
*/
|
||||
@Override
|
||||
public RoleForm getRoleForm(Long roleId) {
|
||||
Role entity = this.getById(roleId);
|
||||
return roleConverter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param status 角色状态(1:启用;0:禁用)
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public boolean updateRoleStatus(Long roleId, Integer status) {
|
||||
|
||||
Role role = this.getById(roleId);
|
||||
Assert.isTrue(role != null, "角色不存在");
|
||||
|
||||
role.setStatus(status);
|
||||
boolean result = this.updateById(role);
|
||||
if (result) {
|
||||
// 刷新角色的权限缓存
|
||||
roleMenuService.refreshRolePermsCache(role.getCode());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色
|
||||
*
|
||||
* @param ids 角色ID,多个使用英文逗号(,)分割
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteRoles(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的角色ID不能为空");
|
||||
List<Long> roleIds = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
|
||||
for (Long roleId : roleIds) {
|
||||
Role role = this.getById(roleId);
|
||||
Assert.isTrue(role != null, "角色不存在");
|
||||
|
||||
// 判断角色是否被用户关联
|
||||
boolean isRoleAssigned = userRoleService.hasAssignedUsers(roleId);
|
||||
Assert.isTrue(!isRoleAssigned, "角色【{}】已分配用户,请先解除关联后删除", role.getName());
|
||||
|
||||
boolean deleteResult = this.removeById(roleId);
|
||||
if (deleteResult) {
|
||||
// 删除成功,刷新权限缓存
|
||||
roleMenuService.refreshRolePermsCache(role.getCode());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色的菜单ID集合
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 菜单ID集合(包括按钮权限ID)
|
||||
*/
|
||||
@Override
|
||||
public List<Long> getRoleMenuIds(Long roleId) {
|
||||
return roleMenuService.listMenuIdsByRoleId(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色的资源权限
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param menuIds 菜单ID集合
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||
public boolean assignMenusToRole(Long roleId, List<Long> menuIds) {
|
||||
Role role = this.getById(roleId);
|
||||
Assert.isTrue(role != null, "角色不存在");
|
||||
|
||||
// 删除角色菜单
|
||||
roleMenuService.remove(
|
||||
new LambdaQueryWrapper<RoleMenu>()
|
||||
.eq(RoleMenu::getRoleId, roleId)
|
||||
);
|
||||
// 新增角色菜单
|
||||
if (CollectionUtil.isNotEmpty(menuIds)) {
|
||||
List<RoleMenu> roleMenus = menuIds
|
||||
.stream()
|
||||
.map(menuId -> new RoleMenu(roleId, menuId))
|
||||
.toList();
|
||||
roleMenuService.saveBatch(roleMenus);
|
||||
}
|
||||
|
||||
// 刷新角色的权限缓存
|
||||
roleMenuService.refreshRolePermsCache(role.getCode());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最大范围的数据权限
|
||||
*
|
||||
* @param roles 角色编码集合
|
||||
* @return {@link Integer} – 数据权限范围
|
||||
*/
|
||||
@Override
|
||||
public Integer getMaximumDataScope(Set<String> roles) {
|
||||
Integer dataScope = this.baseMapper.getMaximumDataScope(roles);
|
||||
return dataScope;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.SoftwareMapper;
|
||||
import com.ichangzuo.system.model.entity.Software;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SoftwareServiceImpl extends ServiceImpl<SoftwareMapper, Software> {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.StatisticsMapper;
|
||||
import com.ichangzuo.system.model.entity.Statistics;
|
||||
import com.ichangzuo.system.model.query.StatisticsPageQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StatisticsServiceImpl extends ServiceImpl<StatisticsMapper, Statistics> {
|
||||
public void statistics(int iClient, String sOp, int num){
|
||||
baseMapper.callStatistics(iClient, sOp, num);
|
||||
}
|
||||
|
||||
public IPage<Statistics> page(StatisticsPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
|
||||
LambdaQueryWrapper<Statistics> lqw = null;
|
||||
List<Integer> range = queryParams.getRange();
|
||||
if(range!=null && range.size()==2){
|
||||
lqw = new LambdaQueryWrapper<>();
|
||||
lqw.ge(Statistics::getStatisticsDate, range.get(0))
|
||||
.le(Statistics::getStatisticsDate, range.get(1));
|
||||
}
|
||||
|
||||
return baseMapper.selectPage(new Page<Statistics>(pageNum, pageSize), lqw);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.StyleRecommendMapper;
|
||||
import com.ichangzuo.system.model.entity.StyleRecommend;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class StyleRecommendServiceImpl extends ServiceImpl<StyleRecommendMapper, StyleRecommend> {
|
||||
public StyleRecommend selectByStyleId(Integer sid){
|
||||
return getOne(new LambdaQueryWrapper<StyleRecommend>().eq(StyleRecommend::getStyleID, sid));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.StyleMapper;
|
||||
import com.ichangzuo.system.model.bo.StyleRecomStatBO;
|
||||
import com.ichangzuo.system.model.bo.StyleUpdateBO;
|
||||
import com.ichangzuo.system.model.entity.Style;
|
||||
import com.ichangzuo.system.model.entity.StyleRecommend;
|
||||
import com.ichangzuo.system.model.query.StylePageQuery;
|
||||
import com.ichangzuo.system.model.vo.StyleStatisticVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class StyleServiceImpl extends ServiceImpl<StyleMapper, Style> {
|
||||
private final StyleRecommendServiceImpl recommendService;
|
||||
|
||||
public StyleStatisticVO statistic(){
|
||||
StyleStatisticVO vo = new StyleStatisticVO();
|
||||
|
||||
List<StyleRecomStatBO> recStat = baseMapper.statRecommand();
|
||||
recStat.forEach(item->{
|
||||
switch (item.getTimesignature()) {
|
||||
case 0:
|
||||
vo.setTs0(item.getCount());
|
||||
break;
|
||||
case 1:
|
||||
vo.setTs1(item.getCount());
|
||||
break;
|
||||
case 2:
|
||||
vo.setTs2(item.getCount());
|
||||
break;
|
||||
case 3:
|
||||
vo.setTs3(item.getCount());
|
||||
break;
|
||||
}
|
||||
});
|
||||
vo.setTemp(baseMapper.countTemp());
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
public IPage<Style> pageStyle(StylePageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
|
||||
Page<Style> page = new Page<>(pageNum, pageSize);
|
||||
if(queryParams.getState()!=null && queryParams.getState()==0)
|
||||
page.setCountId("pageStyle_COUNT");
|
||||
|
||||
return baseMapper.pageStyle(page,queryParams);
|
||||
}
|
||||
|
||||
public boolean updateStyle(StyleUpdateBO bo){
|
||||
Integer styleId = bo.getAccompanyId();
|
||||
Integer state = bo.getState();
|
||||
Integer cost = bo.getCost();
|
||||
|
||||
if(state!=null){
|
||||
StyleRecommend styleRecommend = recommendService.selectByStyleId(styleId);
|
||||
if(state==0) { //设为推荐
|
||||
if (styleRecommend != null)
|
||||
return true;
|
||||
|
||||
styleRecommend = new StyleRecommend();
|
||||
styleRecommend.setStyleID(styleId);
|
||||
styleRecommend.setValid(1);
|
||||
return recommendService.save(styleRecommend);
|
||||
}
|
||||
else{
|
||||
Style style = getById(styleId);
|
||||
if(style==null)
|
||||
return false;
|
||||
|
||||
if(styleRecommend!=null){
|
||||
recommendService.removeById(styleRecommend.getId());
|
||||
}
|
||||
|
||||
if(!style.getState().equals(state)){
|
||||
style.setState(state);
|
||||
return updateById(style);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(cost!=null){
|
||||
Style style = getById(styleId);
|
||||
if( cost.equals(style.getCost()))
|
||||
return true;
|
||||
|
||||
style.setCost(cost);
|
||||
return updateById(style);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.SwDescribeMapper;
|
||||
import com.ichangzuo.system.mapper.SwVersionMapper;
|
||||
import com.ichangzuo.system.model.entity.SwDescribe;
|
||||
import com.ichangzuo.system.model.entity.SwVersion;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SwDecribeServiceImpl extends ServiceImpl<SwDescribeMapper, SwDescribe> {
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.SwVersionMapper;
|
||||
import com.ichangzuo.system.model.entity.Message;
|
||||
import com.ichangzuo.system.model.entity.SwVersion;
|
||||
import com.ichangzuo.system.model.query.SwVersionPageQuery;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SwVersionServiceImpl extends ServiceImpl<SwVersionMapper, SwVersion> {
|
||||
public IPage<SwVersion> page(SwVersionPageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
|
||||
Integer softwareId = queryParams.getSoftwareId();
|
||||
Integer innerId = queryParams.getInnerId();
|
||||
Integer incompatible = queryParams.getIncompatible();
|
||||
|
||||
Page<SwVersion> page = new Page<>(pageNum, pageSize);
|
||||
LambdaQueryWrapper<SwVersion> lqw = new LambdaQueryWrapper<SwVersion>();
|
||||
|
||||
if(softwareId!=null)
|
||||
lqw.eq(SwVersion::getSoftwareId, softwareId);
|
||||
if(innerId!=null)
|
||||
lqw.eq(SwVersion::getInnerId, innerId);
|
||||
if(incompatible!=null)
|
||||
lqw.eq(SwVersion::getIncompatible, incompatible);
|
||||
|
||||
return baseMapper.selectPage(page, lqw.orderByDesc(SwVersion::getVersionId));
|
||||
}
|
||||
|
||||
public SwVersion lastVersion(Integer swId, Integer innerId){
|
||||
return getOne(new LambdaQueryWrapper<SwVersion>()
|
||||
.eq(SwVersion::getSoftwareId, swId)
|
||||
.eq(SwVersion::getInnerId, innerId)
|
||||
.eq(SwVersion::getIsDeleted, 0)
|
||||
.orderByDesc(SwVersion::getVersionId)
|
||||
.last("limit 1")
|
||||
);
|
||||
}
|
||||
|
||||
public int update(SwVersion version){
|
||||
Integer verId = version.getVersionId();
|
||||
if(verId==null){ //新增软件版本
|
||||
SwVersion lastVer = lastVersion(version.getSoftwareId(), version.getInnerId());
|
||||
|
||||
if(lastVer!=null) {
|
||||
int lastV1 = lastVer.getVersionMajor();
|
||||
int lastV2 = lastVer.getVersionMinor();
|
||||
int lastV3 = lastVer.getVersionModify();
|
||||
int lastV4 = lastVer.getVersionBuild();
|
||||
int newV1 = version.getVersionMajor();
|
||||
int newV2 = version.getVersionMinor();
|
||||
int newV3 = version.getVersionModify();
|
||||
int newV4 = version.getVersionBuild();
|
||||
|
||||
if(lastV1>newV1 || lastV1==newV1 && ( lastV2>newV2 || lastV2==newV2
|
||||
&& ( lastV3>newV3 || lastV3==newV3 && lastV4>=newV4 )))
|
||||
return -1;
|
||||
}
|
||||
|
||||
version.setReleaseTime((int) (System.currentTimeMillis()/1000));
|
||||
}
|
||||
|
||||
if( !saveOrUpdate(version) )
|
||||
return -2;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean setByIds(String idsStr, Integer set){
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "版本列表为空");
|
||||
List<Integer> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.toList();
|
||||
boolean result = true;
|
||||
|
||||
for(Integer id: ids){
|
||||
result = update(new LambdaUpdateWrapper<SwVersion>()
|
||||
.eq(SwVersion::getVersionId, id)
|
||||
.set(SwVersion::getIsDeleted, set));
|
||||
|
||||
if(!result) break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.base.BasePageQuery;
|
||||
import com.ichangzuo.system.mapper.TakeOrderMapper;
|
||||
import com.ichangzuo.system.model.entity.RealNameInfo;
|
||||
import com.ichangzuo.system.model.entity.TakeOrder;
|
||||
import com.ichangzuo.system.model.vo.TakeOrderPageVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TakeOrderServiceImpl extends ServiceImpl<TakeOrderMapper, TakeOrder> {
|
||||
public IPage<TakeOrderPageVO> listPagedDraw(BasePageQuery queryParams){
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<TakeOrderPageVO> page = new Page<>(pageNum, pageSize);
|
||||
// 查询数据
|
||||
|
||||
return baseMapper.listPagedDraw(page, queryParams);
|
||||
}
|
||||
|
||||
public TakeOrder setDrawState(Integer orderId, int state){
|
||||
TakeOrder order = getById(orderId);
|
||||
if(order!=null){
|
||||
order.setState(state);
|
||||
order.setMakeTime((int)(System.currentTimeMillis()/1000));
|
||||
if( !updateById(order) )
|
||||
return null;
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.system.mapper.UserBankMapper;
|
||||
import com.ichangzuo.system.model.entity.Account;
|
||||
import com.ichangzuo.system.model.entity.UserBank;
|
||||
import org.mapstruct.control.MappingControl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserBankServiceImpl extends ServiceImpl<UserBankMapper, UserBank> {
|
||||
public UserBank getCurrentBankInfo(){
|
||||
Long uid = SecurityUtils.getUserId();
|
||||
if(uid==null)
|
||||
return null;
|
||||
|
||||
return getOne(new LambdaQueryWrapper<UserBank>()
|
||||
.eq(UserBank::getUserId, uid));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.system.mapper.UserRoleMapper;
|
||||
import com.ichangzuo.system.model.entity.UserRole;
|
||||
import com.ichangzuo.system.service.UserRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
|
||||
|
||||
/**
|
||||
* 保存用户角色
|
||||
*
|
||||
* @param userId
|
||||
* @param roleIds
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean saveUserRoles(Long userId, List<Long> roleIds) {
|
||||
|
||||
if (userId == null || CollectionUtil.isEmpty(roleIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 用户原角色ID集合
|
||||
List<Long> userRoleIds = this.list(new LambdaQueryWrapper<UserRole>()
|
||||
.eq(UserRole::getUserId, userId))
|
||||
.stream()
|
||||
.map(UserRole::getRoleId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 新增用户角色
|
||||
List<Long> saveRoleIds;
|
||||
if (CollectionUtil.isEmpty(userRoleIds)) {
|
||||
saveRoleIds = roleIds;
|
||||
} else {
|
||||
saveRoleIds = roleIds.stream()
|
||||
.filter(roleId -> !userRoleIds.contains(roleId))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<UserRole> saveUserRoles = saveRoleIds
|
||||
.stream()
|
||||
.map(roleId -> new UserRole(userId, roleId))
|
||||
.collect(Collectors.toList());
|
||||
this.saveBatch(saveUserRoles);
|
||||
|
||||
// 删除用户角色
|
||||
if (CollectionUtil.isNotEmpty(userRoleIds)) {
|
||||
List<Long> removeRoleIds = userRoleIds.stream()
|
||||
.filter(roleId -> !roleIds.contains(roleId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollectionUtil.isNotEmpty(removeRoleIds)) {
|
||||
this.remove(new LambdaQueryWrapper<UserRole>()
|
||||
.eq(UserRole::getUserId, userId)
|
||||
.in(UserRole::getRoleId, removeRoleIds)
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断角色是否存在绑定的用户
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return true:已分配 false:未分配
|
||||
*/
|
||||
@Override
|
||||
public boolean hasAssignedUsers(Long roleId) {
|
||||
int count = this.baseMapper.countUsersForRole(roleId);
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,998 @@
|
||||
package com.ichangzuo.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ichangzuo.common.constant.RedisConstants;
|
||||
import com.ichangzuo.common.constant.SystemConstants;
|
||||
import com.ichangzuo.common.enums.ContactType;
|
||||
import com.ichangzuo.common.exception.BusinessException;
|
||||
import com.ichangzuo.common.result.Result;
|
||||
import com.ichangzuo.config.property.AliyunSmsProperties;
|
||||
import com.ichangzuo.core.security.service.PermissionService;
|
||||
import com.ichangzuo.core.security.util.SecurityUtils;
|
||||
import com.ichangzuo.module.mail.service.MailService;
|
||||
import com.ichangzuo.module.sms.service.SmsService;
|
||||
import com.ichangzuo.system.converter.UserConverter;
|
||||
import com.ichangzuo.system.model.entity.*;
|
||||
import com.ichangzuo.system.model.form.*;
|
||||
import com.ichangzuo.common.base.BasePageQuery;
|
||||
import com.ichangzuo.system.model.vo.TakeOrderPageVO;
|
||||
import com.ichangzuo.system.model.vo.UserProfileVO;
|
||||
import com.ichangzuo.system.mapper.UserMapper;
|
||||
import com.ichangzuo.system.model.dto.UserAuthInfo;
|
||||
import com.ichangzuo.system.model.bo.UserBO;
|
||||
import com.ichangzuo.system.model.query.UserPageQuery;
|
||||
import com.ichangzuo.system.model.query.DrawQuery;
|
||||
import com.ichangzuo.system.model.dto.UserExportDTO;
|
||||
import com.ichangzuo.system.model.vo.UserInfoVO;
|
||||
import com.ichangzuo.system.model.vo.UserPageVO;
|
||||
import com.ichangzuo.system.service.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ichangzuo.common.constant.SystemConstants.*;
|
||||
import static com.ichangzuo.common.result.ResultCode.*;
|
||||
|
||||
/**
|
||||
* 用户业务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/1/14
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
|
||||
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final UserRoleService userRoleService;
|
||||
private final UserConverter userConverter;
|
||||
private final RoleMenuService roleMenuService;
|
||||
private final RoleService roleService;
|
||||
private final PermissionService permissionService;
|
||||
private final SmsService smsService;
|
||||
private final MailService mailService;
|
||||
private final AliyunSmsProperties aliyunSmsProperties;
|
||||
private final StringRedisTemplate redisTemplate;
|
||||
private final RealNameServiceImpl realNameService;
|
||||
private final AccountServiceImpl accountService;
|
||||
private final MessageServiceImpl messageService;
|
||||
private final IntegralServiceImpl integralService;
|
||||
private final OrderServiceImpl orderService;
|
||||
private final TakeOrderServiceImpl takeOrderService;
|
||||
private final UserBankServiceImpl userBankService;
|
||||
private final NewUserServiceImpl newUserService;
|
||||
private final StatisticsServiceImpl statisticsService;
|
||||
|
||||
/**
|
||||
* 获取用户分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<UserPageVO>} 用户分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<UserPageVO> listPagedUsers(UserPageQuery queryParams) {
|
||||
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<UserBO> page = new Page<>(pageNum, pageSize);
|
||||
// 查询数据
|
||||
Page<UserBO> userPage = this.baseMapper.listPagedUsers(page, queryParams);
|
||||
|
||||
// 实体转换
|
||||
return userConverter.toPageVo(userPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户表单数据
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserForm getUserFormData(Long userId) {
|
||||
return this.baseMapper.getUserFormData(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*
|
||||
* @param userForm 用户表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean saveUser(UserForm userForm) {
|
||||
|
||||
String username = userForm.getUsername();
|
||||
|
||||
long count = this.count(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
|
||||
Assert.isTrue(count == 0, "用户名已存在");
|
||||
|
||||
// 实体转换 form->entity
|
||||
User entity = userConverter.toEntity(userForm);
|
||||
|
||||
// 设置默认加密密码
|
||||
String defaultEncryptPwd = passwordEncoder.encode(SystemConstants.DEFAULT_PASSWORD);
|
||||
entity.setPassword(defaultEncryptPwd);
|
||||
|
||||
// 新增用户
|
||||
boolean result = this.save(entity);
|
||||
|
||||
if (result) {
|
||||
// 保存用户角色
|
||||
userRoleService.saveUserRoles(entity.getId(), userForm.getRoleIds());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param userForm 用户表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateUser(Long userId, UserForm userForm) {
|
||||
|
||||
String username = userForm.getUsername();
|
||||
|
||||
long count = this.count(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getUsername, username)
|
||||
.ne(User::getId, userId)
|
||||
);
|
||||
Assert.isTrue(count == 0, "用户名已存在");
|
||||
|
||||
// form -> entity
|
||||
User entity = userConverter.toEntity(userForm);
|
||||
|
||||
// 修改用户
|
||||
boolean result = this.updateById(entity);
|
||||
|
||||
if (result) {
|
||||
// 保存用户角色
|
||||
userRoleService.saveUserRoles(entity.getId(), userForm.getRoleIds());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param idsStr 用户ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUsers(String idsStr) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的用户数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
return this.removeByIds(ids);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 锁定/恢复用户
|
||||
*
|
||||
* @param idsStr 用户ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean setUsersState(String idsStr, int state) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(idsStr), "删除的用户数据为空");
|
||||
List<Long> ids = Arrays.stream(idsStr.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
|
||||
for(Long id: ids){
|
||||
User user = getById(id);
|
||||
user.setStatus(state);
|
||||
updateById(user);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户认证信息 {@link UserAuthInfo}
|
||||
*/
|
||||
@Override
|
||||
public UserAuthInfo getUserAuthInfo(String username) {
|
||||
UserAuthInfo userAuthInfo = this.baseMapper.getUserAuthInfo(username);
|
||||
if (userAuthInfo != null) {
|
||||
Set<String> roles = userAuthInfo.getRoles();
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
Set<String> perms = roleMenuService.getRolePermsByRoleCodes(roles);
|
||||
userAuthInfo.setPerms(perms);
|
||||
}
|
||||
|
||||
// 获取最大范围的数据权限
|
||||
Integer dataScope = roleService.getMaximumDataScope(roles);
|
||||
userAuthInfo.setDataScope(dataScope);
|
||||
}
|
||||
return userAuthInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取导出用户列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link List< UserExportDTO >} 导出用户列表
|
||||
*/
|
||||
@Override
|
||||
public List<UserExportDTO> listExportUsers(UserPageQuery queryParams) {
|
||||
return this.baseMapper.listExportUsers(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户信息
|
||||
*
|
||||
* @return {@link UserInfoVO} 用户信息
|
||||
*/
|
||||
@Override
|
||||
public UserInfoVO getCurrentUserInfo() {
|
||||
|
||||
String username = SecurityUtils.getUsername();
|
||||
|
||||
// 获取登录用户基础信息
|
||||
User user = this.getOne(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getUsername, username)
|
||||
.select(
|
||||
User::getId,
|
||||
User::getUsername,
|
||||
User::getNickname,
|
||||
User::getAvatar
|
||||
)
|
||||
);
|
||||
// entity->VO
|
||||
UserInfoVO userInfoVO = userConverter.toUserInfoVo(user);
|
||||
|
||||
// 用户角色集合
|
||||
Set<String> roles = SecurityUtils.getRoles();
|
||||
userInfoVO.setRoles(roles);
|
||||
|
||||
// 用户权限集合
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
Set<String> perms = permissionService.getRolePermsFormCache(roles);
|
||||
userInfoVO.setPerms(perms);
|
||||
}
|
||||
return userInfoVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人中心用户信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public UserProfileVO getUserProfile(Long userId) {
|
||||
UserBO entity = this.baseMapper.getUserProfile(userId);
|
||||
return userConverter.toProfileVO(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改个人中心用户信息
|
||||
*
|
||||
* @param formData 表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateUserProfile(UserProfileForm formData) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User entity = userConverter.toEntity(formData);
|
||||
entity.setId(userId);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param data 密码修改表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean changePassword(Long userId, PasswordChangeForm data) {
|
||||
|
||||
User user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
String oldPassword = data.getOldPassword();
|
||||
|
||||
// 校验原密码
|
||||
if (!passwordEncoder.matches(oldPassword, user.getPassword())) {
|
||||
throw new BusinessException("原密码错误");
|
||||
}
|
||||
// 新旧密码不能相同
|
||||
if (passwordEncoder.matches(data.getNewPassword(), user.getPassword())) {
|
||||
throw new BusinessException("新密码不能与原密码相同");
|
||||
}
|
||||
|
||||
// String newPassword = data.getNewPassword();
|
||||
return resetPassword(userId, data.getNewPassword());
|
||||
// this.update(new LambdaUpdateWrapper<User>()
|
||||
// .eq(User::getId, userId)
|
||||
// .set(User::getPassword, passwordEncoder.encode(newPassword))
|
||||
// );
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param password 密码重置表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean resetPassword(Long userId, String password) {
|
||||
return this.update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, userId)
|
||||
.set(User::getPassword, passwordEncoder.encode(password))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<?> sendResetPasswordCode(String username, String contact) {
|
||||
User user = getOne(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getUsername, username)
|
||||
.select(
|
||||
User::getId,
|
||||
User::getStatus,
|
||||
User::getEmail
|
||||
)
|
||||
);
|
||||
|
||||
if(user==null){
|
||||
return Result.failed(USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
Integer state = user.getStatus();
|
||||
if(state==0){
|
||||
return Result.failed(USER_ACCOUNT_INVALID);
|
||||
}
|
||||
else if(state==1) {
|
||||
return Result.failed(USER_ACCOUNT_LOCKED);
|
||||
}
|
||||
|
||||
ContactType type;
|
||||
if( contact.matches(REGREX_PHONE) ) {
|
||||
type = ContactType.MOBILE;
|
||||
}
|
||||
else if(contact.matches(REGREX_EMAIL)) {
|
||||
type = ContactType.EMAIL;
|
||||
}
|
||||
else
|
||||
return Result.failed(PARAM_ERROR);
|
||||
|
||||
if(type==ContactType.EMAIL){
|
||||
if(state!=2){
|
||||
return Result.failed(USER_EMAIL_UNBIND);
|
||||
}
|
||||
|
||||
if(!contact.equals(user.getEmail())){
|
||||
return Result.failed(USER_EMAIL_INVALID);
|
||||
}
|
||||
}
|
||||
else{
|
||||
Account account = getAccountById(user.getId());
|
||||
|
||||
if(account.getIsPhone()!=1){
|
||||
return Result.failed(USER_PHONE_UNBIND);
|
||||
}
|
||||
|
||||
if(!contact.equals(account.getPhone())){
|
||||
return Result.failed(USER_PHONE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
if( sendVerificationCode(contact, "重置密码", type) ){
|
||||
return Result.success(user.getId());
|
||||
}
|
||||
else {
|
||||
return Result.failed(MESSAGE_SERVICE_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendVerificationCode(String contact, String subject){
|
||||
ContactType type;
|
||||
if( contact.matches(REGREX_PHONE) ) {
|
||||
type = ContactType.MOBILE;
|
||||
}
|
||||
else if(contact.matches(REGREX_EMAIL)) {
|
||||
type = ContactType.EMAIL;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return sendVerificationCode(contact, subject, type);
|
||||
}
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param contact 联系方式 手机号/邮箱
|
||||
* @param subject 发送标题
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean sendVerificationCode(String contact, String subject, ContactType contactType) {
|
||||
String verificationKey = ( contactType==ContactType.MOBILE
|
||||
? RedisConstants.MOBILE_VERIFICATION_CODE_PREFIX
|
||||
: RedisConstants.EMAIL_VERIFICATION_CODE_PREFIX )
|
||||
+ contact + subject;
|
||||
String existCode = redisTemplate.opsForValue().get(verificationKey);
|
||||
|
||||
if(existCode!=null){
|
||||
return true;
|
||||
}
|
||||
|
||||
// 随机生成6位验证码
|
||||
String code = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
|
||||
try {
|
||||
// 发送验证码
|
||||
switch (contactType) {
|
||||
case MOBILE:
|
||||
// 获取修改密码的模板code
|
||||
String templateCode = null;
|
||||
if(subject.equals("绑定手机"))
|
||||
templateCode = aliyunSmsProperties.getTemplateCodes().get("bindMobile");
|
||||
else if(subject.equals("注册新用户"))
|
||||
templateCode = aliyunSmsProperties.getTemplateCodes().get("register");
|
||||
else if(subject.equals("重置密码"))
|
||||
templateCode = aliyunSmsProperties.getTemplateCodes().get("resetPassword");
|
||||
else
|
||||
throw new BusinessException("不支持的短信模板");
|
||||
|
||||
if(!smsService.sendSms(contact, templateCode, "{\"code\":\"" + code + "\"}"))
|
||||
return false;
|
||||
|
||||
break;
|
||||
case EMAIL:
|
||||
String content = TEMPLATE_MAIL_SENDCODE.replace("${sub}", subject)
|
||||
.replace("${code}", code);
|
||||
if(!mailService.sendHtmlMail(contact, subject+"验证码", content)){
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("不支持的联系方式类型");
|
||||
}
|
||||
|
||||
// 存入 redis 用于校验, 5分钟有效
|
||||
redisTemplate.opsForValue().set(verificationKey, code, 15, TimeUnit.MINUTES);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前用户手机号码
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean bindMobile(MobileBindingForm data) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
// 校验验证码
|
||||
String verificationCode = data.getCode();
|
||||
String contact = data.getMobile();
|
||||
String verificationCodeKey = RedisConstants.MOBILE_VERIFICATION_CODE_PREFIX + contact + "绑定手机";
|
||||
String code = redisTemplate.opsForValue().get(verificationCodeKey);
|
||||
if (!verificationCode.equals(code)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 更新手机号码
|
||||
return accountService.update(new LambdaUpdateWrapper<Account>()
|
||||
.eq(Account::getUserId, userId)
|
||||
.set(Account::getPhone, contact)
|
||||
.set(Account::getIsPhone, 1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改当前用户邮箱
|
||||
*
|
||||
* @param data 表单数据
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean bindEmail(EmailChangeForm data) {
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
User user = this.getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
// 校验验证码
|
||||
String verificationCode = data.getCode();
|
||||
String contact = data.getEmail();
|
||||
String verificationCodeKey = RedisConstants.EMAIL_VERIFICATION_CODE_PREFIX + contact + "绑定邮箱";
|
||||
String code = redisTemplate.opsForValue().get(verificationCodeKey);
|
||||
if (!verificationCode.equals(code)) {
|
||||
throw new BusinessException("验证码错误");
|
||||
}
|
||||
// 更新邮箱
|
||||
return update(new LambdaUpdateWrapper<User>()
|
||||
.eq(User::getId, userId)
|
||||
.set(User::getEmail, contact)
|
||||
.set(User::getStatus, 2)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置密码验证码检验
|
||||
*
|
||||
* @param contact
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int checkVerificationCode(String contact, String code, String title) {
|
||||
String verificationKey;
|
||||
if( contact.matches(REGREX_PHONE) ) {
|
||||
verificationKey = RedisConstants.MOBILE_VERIFICATION_CODE_PREFIX;
|
||||
}
|
||||
else if(contact.matches(REGREX_EMAIL)) {
|
||||
verificationKey = RedisConstants.EMAIL_VERIFICATION_CODE_PREFIX;
|
||||
}
|
||||
else
|
||||
return -3; //参数错误
|
||||
|
||||
verificationKey += contact + title;
|
||||
|
||||
String existCode = redisTemplate.opsForValue().get(verificationKey);
|
||||
if (existCode == null) {
|
||||
return -2; //验证码已过期
|
||||
}
|
||||
|
||||
return code.equals(existCode) ? 0 : -1; //验证码错误
|
||||
}
|
||||
|
||||
@Override
|
||||
public RealNameInfo getCurrentRealNameInfo(){
|
||||
return realNameService.getCurrentRealName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean submitRealName(RealNameInfo info){
|
||||
boolean result = realNameService.updateById(info);
|
||||
if(result){
|
||||
result = realNameService.setVerifyRealName(info.getUserId(), 3);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean verifyRealName(Long userId, String rejectReason){
|
||||
boolean result;
|
||||
String title, content;
|
||||
if(rejectReason==null || rejectReason.isEmpty()){
|
||||
result = realNameService.setVerifyRealName(userId, 1);
|
||||
title = "实名认证已通过";
|
||||
content = "恭喜您,您申请的 <span style=\"font-size:16px;\">实名认证</span> "
|
||||
+ "<b><span style=\"color:#e13c39;font-size:16px;\">已通过</span></b>";
|
||||
}
|
||||
else {
|
||||
result = realNameService.setVerifyRealName(userId, 2);
|
||||
title = "实名认证未通过";
|
||||
content = "很抱歉,您申请的 <span style=\"font-size:16px;\">实名认证</span> "
|
||||
+ "<b><span style=\"color:#e13c39;font-size:16px;\">未通过</span></b>!"
|
||||
+ "原因为:<br/>" + rejectReason;
|
||||
}
|
||||
|
||||
if(result) {
|
||||
messageService.sendUserMessage(userId, title, content);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int beingVIP(Integer vipType) {
|
||||
Account account = accountService.getCurrentAccount();
|
||||
if(account==null)
|
||||
return -1; //账户异常
|
||||
|
||||
if(account.getState()<2)
|
||||
return -2;
|
||||
|
||||
Integer vipTime = account.getVipTime();
|
||||
if(vipTime==-1)
|
||||
return 0; //终身VIP
|
||||
|
||||
int pay = 0; //支付音符数
|
||||
int nowTime = (int) (System.currentTimeMillis()/1000);
|
||||
if(vipTime<nowTime)
|
||||
vipTime = nowTime;
|
||||
|
||||
//统一按365.25天/年计算
|
||||
switch (vipType){
|
||||
case 0:
|
||||
pay = 1000;
|
||||
vipTime += 2629800;
|
||||
break;
|
||||
case 1:
|
||||
pay = 5500;
|
||||
vipTime += 15778800;
|
||||
break;
|
||||
case 2:
|
||||
pay = 10000;
|
||||
vipTime += 31557600;
|
||||
break;
|
||||
case 3:
|
||||
pay = 20000;
|
||||
vipTime += 63115200;
|
||||
break;
|
||||
default:
|
||||
return -3; //参数异常
|
||||
}
|
||||
|
||||
Integer integral = account.getIntegral();
|
||||
if(integral<pay)
|
||||
return -4; //余额不足
|
||||
|
||||
//先扣除积分
|
||||
account.setIntegral(integral - pay);
|
||||
account.setVipTime(vipTime);
|
||||
|
||||
if(!accountService.updateById(account) )
|
||||
return -5; //数据库异常
|
||||
|
||||
//再写积分明细
|
||||
Integral detail = new Integral();
|
||||
detail.setUserId(account.getUserId());
|
||||
detail.setScore(pay);
|
||||
detail.setBalance(account.getIntegral());
|
||||
detail.setAddtime(nowTime);
|
||||
detail.setTitle("兑换唱作网VIP会员");
|
||||
detail.setRuleid(-7);
|
||||
detail.setRuletype(2);
|
||||
|
||||
if(!integralService.save(detail))
|
||||
return -5; //数据库异常
|
||||
|
||||
//音符消费
|
||||
statisticsService.statistics(5,"consume", pay);
|
||||
|
||||
return vipTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<?> buyNotes(String payType, String amount) {
|
||||
Account account = accountService.getCurrentAccount();
|
||||
if(account==null)
|
||||
return Result.failed(USER_LOGIN_ERROR); //账户异常
|
||||
if(account.getState()==0)
|
||||
return Result.failed(USER_ACCOUNT_DELETED);
|
||||
if(account.getState()==1)
|
||||
return Result.failed(USER_ACCOUNT_LOCKED);
|
||||
|
||||
String order = orderService.generatorOrderNo(account.getUserId(), payType);
|
||||
if( order==null )
|
||||
return Result.failed(DATABASE_ERROR);
|
||||
|
||||
return Result.success(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<?> drawNotes(DrawQuery draw){
|
||||
Account account = accountService.getCurrentAccount();
|
||||
if(account==null)
|
||||
return Result.failed(USER_LOGIN_ERROR); //账户异常
|
||||
if(account.getState()==0)
|
||||
return Result.failed(USER_ACCOUNT_DELETED);
|
||||
if(account.getState()==1)
|
||||
return Result.failed(USER_ACCOUNT_LOCKED);
|
||||
|
||||
if(account.getIsName()!=1)
|
||||
return Result.failed(USER_ACCOUNT_NOREALNAME);
|
||||
|
||||
int amount = draw.getAmount();
|
||||
String bankName = draw.getBankName();
|
||||
String cardNum = draw.getCardNum();
|
||||
if(amount/10000 == 0 || amount % 10000 != 0 || bankName.isEmpty() || cardNum.isEmpty())
|
||||
return Result.failed(PARAM_ERROR);
|
||||
|
||||
int integral = account.getIntegral();
|
||||
if(integral<amount)
|
||||
return Result.failed(USER_ACCOUNT_SHORT);
|
||||
|
||||
String cardName = null;
|
||||
if(!bankName.equals("支付宝") && !bankName.equals("微信")){
|
||||
cardName = draw.getCardName();
|
||||
if(cardName.isEmpty())
|
||||
return Result.failed(PARAM_ERROR);
|
||||
}
|
||||
|
||||
String money = String.valueOf((amount*94/10000));
|
||||
|
||||
int nowTime = (int)(System.currentTimeMillis()/1000);
|
||||
|
||||
TakeOrder order = new TakeOrder();
|
||||
order.setUserId(account.getUserId());
|
||||
order.setMoney(money);
|
||||
order.setCardNum(cardNum);
|
||||
order.setBankName(bankName);
|
||||
order.setTakeTime(nowTime);
|
||||
|
||||
if(cardName!=null){
|
||||
order.setCardName(cardName);
|
||||
}
|
||||
|
||||
if( !takeOrderService.save(order) )
|
||||
return Result.failed(DATABASE_ERROR);
|
||||
|
||||
account.setIntegral(integral - amount);
|
||||
|
||||
if(!accountService.updateById(account) )
|
||||
return Result.failed(DATABASE_ERROR);
|
||||
|
||||
//积分明细
|
||||
Integral detail = new Integral();
|
||||
detail.setUserId(account.getUserId());
|
||||
detail.setScore(amount);
|
||||
detail.setBalance(account.getIntegral());
|
||||
detail.setAddtime(nowTime);
|
||||
detail.setTitle("银行卡提现:¥" + money);
|
||||
detail.setRuleid(-8);
|
||||
detail.setRuletype(2);
|
||||
|
||||
if(!integralService.save(detail))
|
||||
return Result.failed(DATABASE_ERROR);
|
||||
|
||||
UserBank userBank = userBankService.getById(account.getUserId());
|
||||
userBank.setBankName(draw.getBankName());
|
||||
userBank.setBankCardNum(draw.getCardNum());
|
||||
userBank.setBankCardName(draw.getCardName());
|
||||
|
||||
userBankService.updateById(userBank);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<TakeOrderPageVO> listPageDraw(BasePageQuery queryParams){
|
||||
return takeOrderService.listPagedDraw(queryParams);
|
||||
}
|
||||
@Override
|
||||
public int verifyDraw(Integer orderId, String rejectReason){
|
||||
TakeOrder order = null;
|
||||
String title="", content="";
|
||||
if(rejectReason==null || rejectReason.isEmpty()){
|
||||
order = takeOrderService.setDrawState(orderId, 1);
|
||||
if(order!=null) {
|
||||
title = "提现申请已转账";
|
||||
content = "您申请的 <span style=\"font-size: 16px;\">¥"
|
||||
+ order.getMoney() + "</span> 提现 "
|
||||
+ "<strong style=\"color: rgb(225, 60, 57); font-size: 16px;\"> 已转入 </strong>"
|
||||
+ "您指定的账户<br/>请注意查收!";
|
||||
}
|
||||
}
|
||||
else {
|
||||
order = takeOrderService.setDrawState(orderId, 3);
|
||||
if(order!=null) {
|
||||
title = "提现申请未通过";
|
||||
content = "很抱歉,您申请的 <span style=\"font-size: 16px;\">¥"
|
||||
+ order.getMoney() + "</span> 提现 "
|
||||
+ "<strong style=\"color: rgb(225, 60, 57); font-size: 16px;\">未能通过</strong> ,原因是:<br/>" + rejectReason;
|
||||
|
||||
Account account = accountService.getById(order.getUserId());
|
||||
Integer integral = account.getIntegral();
|
||||
int money = Integer.parseInt(order.getMoney());
|
||||
int amount = money / 94 * 10000;
|
||||
account.setIntegral(integral + amount);
|
||||
accountService.updateById(account);
|
||||
|
||||
//写入积分明细
|
||||
Integral detail = new Integral();
|
||||
detail.setUserId(account.getUserId());
|
||||
detail.setScore(amount);
|
||||
detail.setBalance(account.getIntegral());
|
||||
detail.setAddtime((int)(System.currentTimeMillis()/1000));
|
||||
detail.setTitle("提现¥" + money + "未通过退回");
|
||||
detail.setRuleid(-8);
|
||||
detail.setRuletype(1);
|
||||
integralService.save(detail);
|
||||
}
|
||||
}
|
||||
|
||||
if(order!=null) {
|
||||
messageService.sendUserMessage(order.getUserId(), title, content);
|
||||
return order.getState();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getCurrentAccount(){
|
||||
return accountService.getCurrentAccount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account getAccountById(Long userId){
|
||||
return accountService.getById(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterUserLogon(){
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Account account = getAccountById(userId);
|
||||
Long loginTime = account.getLoginTime();
|
||||
long nowTime = System.currentTimeMillis();
|
||||
|
||||
account.setLoginTime(nowTime/1000);
|
||||
account.setLoginNum(account.getLoginNum()+1);
|
||||
accountService.updateById(account);
|
||||
|
||||
//登录次数
|
||||
statisticsService.statistics(5,"login", 1);
|
||||
|
||||
//与上次不是同一天则统计到当天登录人数
|
||||
boolean bSameDay = false;
|
||||
if(loginTime!=null) {
|
||||
Calendar lastCal = Calendar.getInstance(Locale.CHINA);
|
||||
Calendar nowCal = Calendar.getInstance(Locale.CHINA);
|
||||
lastCal.setTimeInMillis(loginTime * 1000);
|
||||
nowCal.setTimeInMillis(nowTime);
|
||||
if (lastCal.get(Calendar.YEAR) == nowCal.get(Calendar.YEAR)
|
||||
&& lastCal.get(Calendar.MONTH) == nowCal.get(Calendar.MONTH)
|
||||
&& lastCal.get(Calendar.DAY_OF_MONTH) == nowCal.get(Calendar.DAY_OF_MONTH)) {
|
||||
bSameDay = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSameDay) {
|
||||
statisticsService.statistics(5, "login_usersum", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existUsername(String username){
|
||||
return getOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username))!=null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(String username, String password){
|
||||
NewUser user = new NewUser();
|
||||
user.setUserName(username);
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setRegTime((int)(System.currentTimeMillis()/1000));
|
||||
|
||||
if(username.matches(REGREX_EMAIL)){
|
||||
String nickname = username.split("@")[0];
|
||||
if(nickname.length()>20)
|
||||
nickname = nickname.substring(0, 20);
|
||||
user.setNickname(nickname);
|
||||
user.setEmail(username);
|
||||
user.setState(2);
|
||||
}
|
||||
else if(username.matches(REGREX_PHONE)){
|
||||
user.setNickname(username);
|
||||
user.setPhone(username);
|
||||
user.setIsPhone(1);
|
||||
}
|
||||
|
||||
boolean ret = newUserService.save(user);
|
||||
if(ret){
|
||||
statisticsService.statistics(5,"register", 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteUser(String username, String password) {
|
||||
User user = verifyUser(username, password);
|
||||
if(user!=null) {
|
||||
Long uid = user.getId();
|
||||
user.setStatus(0);
|
||||
// user.setUsername("DEL_" + username + "_" + uid);
|
||||
if (updateById(user)) {
|
||||
Account account = accountService.getById(uid);
|
||||
account.setDeleteTime((int)(System.currentTimeMillis()/1000));
|
||||
accountService.updateById(account);
|
||||
|
||||
return Math.toIntExact(uid);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User verifyUser(String username, String password) {
|
||||
return getOne(new LambdaQueryWrapper<User>()
|
||||
.eq(User::getUsername, username)
|
||||
.eq(User::getPassword, passwordEncoder.encode(password)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addNotes(Long userId, Integer amount, Integer time){
|
||||
Account account = accountService.getById(userId);
|
||||
if(account==null)
|
||||
return false;
|
||||
|
||||
account.setIntegral( account.getIntegral() + amount );
|
||||
if(!accountService.updateById(account))
|
||||
return false;
|
||||
|
||||
Integral integral = new Integral();
|
||||
integral.setUserId(account.getUserId());
|
||||
integral.setScore(amount);
|
||||
integral.setBalance(account.getIntegral());
|
||||
integral.setTitle("音符充值");
|
||||
integral.setRuleid(1);
|
||||
integral.setRuletype(5);
|
||||
integral.setAddtime(time);
|
||||
|
||||
return integralService.save(integral);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer checkOrder(String orderNo){
|
||||
Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
|
||||
.eq(Order::getOrderNumber, orderNo));
|
||||
if(order==null)
|
||||
return -1;
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if(!order.getUserId().equals(userId))
|
||||
return -1;
|
||||
|
||||
if( order.getState()==0 )
|
||||
return 0;
|
||||
|
||||
Account account = accountService.getById(userId);
|
||||
if(account==null)
|
||||
return -1;
|
||||
|
||||
return account.getIntegral();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNewAccount() {
|
||||
Account account = accountService.getCurrentAccount();
|
||||
if(account!=null){
|
||||
account.setIntegral(12);
|
||||
accountService.updateById(account);
|
||||
|
||||
String title = "成功注册唱作网";
|
||||
String content = "新用户,您好!<br>感谢加入唱作网,您已获赠12个唱作音符。<br>欢迎使用唱作魔方软件。";
|
||||
messageService.sendUserMessage(account.getUserId(), title, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user