This commit is contained in:
lu7213 committed 2025-12-02 23:07:47 +08:00
1 parent 81eca8933a
commit 345f906c35
540 files changed
+494222 -90

No files matched your search

@@ -0,0 +1,64 @@
package com.luqj.common.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 邮件系统属性信息
*/
@Component
@ConfigurationProperties(prefix = "lu.admin.mail")
public class EmailProperties {
/**
* 是否smtp授权
*/
private Boolean smtpAuth = true;
/**
* 邮件系统smtp
*/
private String smtpHost = "smtp.163.com";
/**
* 默认用户
*/
private String user;
/**
* 用户密码
*/
private String password;
public Boolean getSmtpAuth() {
return smtpAuth;
}
public void setSmtpAuth(Boolean smtpAuth) {
this.smtpAuth = smtpAuth;
}
public String getSmtpHost() {
return smtpHost;
}
public void setSmtpHost(String smtpHost) {
this.smtpHost = smtpHost;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
@@ -0,0 +1,109 @@
package com.luqj.common.controller;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.luqj.common.domain.ComCategory;
import com.luqj.common.service.IComCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 类别Controller
*
* @author luqj
* @date 2021-07-24
*/
@RestController
@RequestMapping("/common/category")
public class ComCategoryController extends BaseController
{
@Autowired
private IComCategoryService comCategoryService;
@GetMapping("/treeselect")
public AjaxResult treeselect(ComCategory comCategory)
{
List<ComCategory> depts = comCategoryService.selectComCategoryList(comCategory);
return AjaxResult.success(comCategoryService.buildCategoryTreeSelect(depts));
}
/**
* 查询类别列表
*/
@PreAuthorize("@ss.hasPermi('common:category:list')")
@GetMapping("/list")
public TableDataInfo list(ComCategory comCategory)
{
startPage();
List<ComCategory> list = comCategoryService.selectComCategoryList(comCategory);
return getDataTable(list);
}
/**
* 导出类别列表
*/
@PreAuthorize("@ss.hasPermi('common:category:export')")
@Log(title = "类别", businessType = BusinessType.EXPORT)
@GetMapping("/export")
public AjaxResult export(ComCategory comCategory)
{
List<ComCategory> list = comCategoryService.selectComCategoryList(comCategory);
ExcelUtil<ComCategory> util = new ExcelUtil<ComCategory>(ComCategory.class);
return util.exportExcel(list, "category");
}
/**
* 获取类别详细信息
*/
@PreAuthorize("@ss.hasPermi('common:category:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(comCategoryService.selectComCategoryById(id));
}
/**
* 新增类别
*/
@PreAuthorize("@ss.hasPermi('common:category:add')")
@Log(title = "类别", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ComCategory comCategory)
{
return toAjax(comCategoryService.insertComCategory(comCategory));
}
/**
* 修改类别
*/
@PreAuthorize("@ss.hasPermi('common:category:edit')")
@Log(title = "类别", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ComCategory comCategory)
{
return toAjax(comCategoryService.updateComCategory(comCategory));
}
/**
* 删除类别
*/
@PreAuthorize("@ss.hasPermi('common:category:remove')")
@Log(title = "类别", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(comCategoryService.deleteComCategoryByIds(ids));
}
}
@@ -0,0 +1,28 @@
package com.luqj.common.controller;
import com.luqj.common.domain.SelectItem;
import com.luqj.common.service.ICommonService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/common")
public class SelectCommonController extends BaseController {
@Autowired
private ICommonService comCategory;
@GetMapping("/select/search")
public AjaxResult selectSearch(String tableName, String keyword, String fieldId, String fieldName) {
if(tableName.contains(" ") || fieldId.contains(" ") || fieldName.contains(" ")){
return AjaxResult.error("注入嫌疑");
}
List<SelectItem> searchs = comCategory.search(tableName, fieldId, fieldName, keyword);
return AjaxResult.success(searchs);
}
}
@@ -0,0 +1,14 @@
package com.luqj.common.domain;
import com.ruoyi.common.core.domain.TreeSelect;
import java.util.stream.Collectors;
public class CategoryTreeSelect extends TreeSelect {
public CategoryTreeSelect(ComCategory comCategory)
{
this.id = comCategory.getId();
this.label = comCategory.getName();
this.children = comCategory.getChildren().stream().map(CategoryTreeSelect::new).collect(Collectors.toList());
}
}
@@ -0,0 +1,233 @@
package com.luqj.common.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 类别对象 com_category
*
* @author luqj
* @date 2021-07-24
*/
public class ComCategory extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** id */
private Long id;
/** 名称 */
@Excel(name = "名称")
private String name;
/** 父id */
@Excel(name = "父id")
private Long parentId;
/** 所有父级id组合,以逗号隔开 */
@Excel(name = "所有父级id组合,以逗号隔开")
private String parentIds;
/** 系统层级类目 */
@Excel(name = "系统层级类目")
private Long projectType;
/** 排序 */
@Excel(name = "排序")
private Long sortNum;
/** 图标地址 */
@Excel(name = "图标地址")
private String iconUrl;
/** 图片地址 */
@Excel(name = "图片地址")
private String picUrl;
/** 是否叶子节点(0否,1是) */
@Excel(name = "是否叶子节点(0否,1是)")
private Integer hasLeaf;
/** 是否前台首页展示(0否,1是) */
@Excel(name = "是否前台首页展示(0否,1是)")
private Integer homeShow;
/** 类目级别,1:一级类目;2:二级类目;3:三级类目,目前只支持三级类目 */
@Excel(name = "类目级别,1:一级类目;2:二级类目;3:三级类目,目前只支持三级类目")
private Integer level;
/** 标示位:例如热门分类等 */
@Excel(name = "标示位:例如热门分类等")
private Long flag;
/** 描述 */
@Excel(name = "描述")
private String description;
/** 状态 0-禁用,1-启用,2-删除 */
@Excel(name = "状态 0-禁用,1-启用,2-删除")
private Integer status;
private List<ComCategory> children = new ArrayList<>();
public void setId(Long id)
{
this.id = id;
}
public List<ComCategory> getChildren() {
return children;
}
public void setChildren(List<ComCategory> children) {
this.children = children;
}
public Long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setParentIds(String parentIds)
{
this.parentIds = parentIds;
}
public String getParentIds()
{
return parentIds;
}
public void setProjectType(Long projectType)
{
this.projectType = projectType;
}
public Long getProjectType()
{
return projectType;
}
public void setSortNum(Long sortNum)
{
this.sortNum = sortNum;
}
public Long getSortNum()
{
return sortNum;
}
public void setIconUrl(String iconUrl)
{
this.iconUrl = iconUrl;
}
public String getIconUrl()
{
return iconUrl;
}
public void setPicUrl(String picUrl)
{
this.picUrl = picUrl;
}
public String getPicUrl()
{
return picUrl;
}
public void setHasLeaf(Integer hasLeaf)
{
this.hasLeaf = hasLeaf;
}
public Integer getHasLeaf()
{
return hasLeaf;
}
public void setHomeShow(Integer homeShow)
{
this.homeShow = homeShow;
}
public Integer getHomeShow()
{
return homeShow;
}
public void setLevel(Integer level)
{
this.level = level;
}
public Integer getLevel()
{
return level;
}
public void setFlag(Long flag)
{
this.flag = flag;
}
public Long getFlag()
{
return flag;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setStatus(Integer status)
{
this.status = status;
}
public Integer getStatus()
{
return status;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("parentId", getParentId())
.append("parentIds", getParentIds())
.append("projectType", getProjectType())
.append("sortNum", getSortNum())
.append("iconUrl", getIconUrl())
.append("picUrl", getPicUrl())
.append("hasLeaf", getHasLeaf())
.append("homeShow", getHomeShow())
.append("level", getLevel())
.append("flag", getFlag())
.append("description", getDescription())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.append("status", getStatus())
.toString();
}
}
@@ -0,0 +1,232 @@
package com.luqj.common.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.io.Serializable;
import java.util.Date;
/**
* 类别对象 com_category
*
* @author luqj
* @date 2021-07-24
*/
@TableName(value = "com_category")
public class ComCategoryPlus implements Serializable
{
private static final long serialVersionUID = 1L;
/** id */
private Long id;
/** 名称 */
@Excel(name = "名称")
private String name;
/** 父id */
@Excel(name = "父id")
private Long parentId;
/** 所有父级id组合,以逗号隔开 */
@Excel(name = "所有父级id组合,以逗号隔开")
private String parentIds;
/** 系统层级类目 */
@Excel(name = "系统层级类目")
private Long projectType;
/** 排序 */
@Excel(name = "排序")
private Long sortNum;
/** 图标地址 */
@Excel(name = "图标地址")
private String iconUrl;
/** 图片地址 */
@Excel(name = "图片地址")
private String picUrl;
/** 是否叶子节点(0否,1是) */
@Excel(name = "是否叶子节点(0否,1是)")
private Integer hasLeaf;
/** 是否前台首页展示(0否,1是) */
@Excel(name = "是否前台首页展示(0否,1是)")
private Integer homeShow;
/** 类目级别,1:一级类目;2:二级类目;3:三级类目,目前只支持三级类目 */
@Excel(name = "类目级别,1:一级类目;2:二级类目;3:三级类目,目前只支持三级类目")
private Integer level;
/** 标示位:例如热门分类等 */
@Excel(name = "标示位:例如热门分类等")
private Long flag;
/** 描述 */
@Excel(name = "描述")
private String description;
/** 创建时间 */
private Date createTime;
/** 修改时间 */
private Date updateTime;
/** 状态 0-禁用,1-启用,2-删除 */
@Excel(name = "状态 0-禁用,1-启用,2-删除")
private Integer status;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setParentIds(String parentIds)
{
this.parentIds = parentIds;
}
public String getParentIds()
{
return parentIds;
}
public void setProjectType(Long projectType)
{
this.projectType = projectType;
}
public Long getProjectType()
{
return projectType;
}
public void setSortNum(Long sortNum)
{
this.sortNum = sortNum;
}
public Long getSortNum()
{
return sortNum;
}
public void setIconUrl(String iconUrl)
{
this.iconUrl = iconUrl;
}
public String getIconUrl()
{
return iconUrl;
}
public void setPicUrl(String picUrl)
{
this.picUrl = picUrl;
}
public String getPicUrl()
{
return picUrl;
}
public void setHasLeaf(Integer hasLeaf)
{
this.hasLeaf = hasLeaf;
}
public Integer getHasLeaf()
{
return hasLeaf;
}
public void setHomeShow(Integer homeShow)
{
this.homeShow = homeShow;
}
public Integer getHomeShow()
{
return homeShow;
}
public void setLevel(Integer level)
{
this.level = level;
}
public Integer getLevel()
{
return level;
}
public void setFlag(Long flag)
{
this.flag = flag;
}
public Long getFlag()
{
return flag;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setCreateTime(Date createTime)
{
this.createTime = createTime;
}
public Date getCreateTime()
{
return createTime;
}
public void setUpdateTime(Date updateTime)
{
this.updateTime = updateTime;
}
public Date getUpdateTime()
{
return updateTime;
}
public void setStatus(Integer status)
{
this.status = status;
}
public Integer getStatus()
{
return status;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("parentId", getParentId())
.append("parentIds", getParentIds())
.append("projectType", getProjectType())
.append("sortNum", getSortNum())
.append("iconUrl", getIconUrl())
.append("picUrl", getPicUrl())
.append("hasLeaf", getHasLeaf())
.append("homeShow", getHomeShow())
.append("level", getLevel())
.append("flag", getFlag())
.append("description", getDescription())
.append("createTime", getCreateTime())
.append("updateTime", getUpdateTime())
.append("status", getStatus())
.toString();
}
}
@@ -0,0 +1,17 @@
package com.luqj.common.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class ContactItem<T> implements Serializable,Comparable<ContactItem> {
private String letter;
private List<T> data;
@Override
public int compareTo(ContactItem o) {
return this.getLetter().compareTo(o.getLetter());
}
}
@@ -0,0 +1,75 @@
package com.luqj.common.domain;
import com.ruoyi.common.utils.StringUtils;
import java.math.BigDecimal;
import java.util.Date;
public class RedisKey {
private StringBuffer stringBuffer = new StringBuffer("");
public RedisKey() {
}
public RedisKey(String key) {
stringBuffer = new StringBuffer(key);
}
public RedisKey add(String key) {
if (StringUtils.isNotBlank(key)) {
stringBuffer.append(key).append("_");
} else {
stringBuffer.append("NULL_");
}
return this;
}
public RedisKey add(BigDecimal key) {
if (key != null) {
stringBuffer.append(key).append("_");
} else {
stringBuffer.append("NULL_");
}
return this;
}
public RedisKey add(Boolean key) {
if (key != null) {
stringBuffer.append(key).append("_");
} else {
stringBuffer.append("NULL_");
}
return this;
}
public RedisKey add(Long key) {
if (key != null) {
stringBuffer.append(key).append("_");
} else {
stringBuffer.append("NULL_");
}
return this;
}
public RedisKey add(Date key) {
if (key != null) {
stringBuffer.append(key.getTime()).append("_");
} else {
stringBuffer.append("_NULL");
}
return this;
}
public RedisKey add(Integer key) {
if (key != null) {
stringBuffer.append(key).append("_");
} else {
stringBuffer.append("_NULL");
}
return this;
}
public String key() {
return this.stringBuffer.toString();
}
}
@@ -0,0 +1,11 @@
package com.luqj.common.domain;
import lombok.Data;
import java.io.Serializable;
@Data
public class SelectItem implements Serializable {
private String id;
private String name;
}
@@ -0,0 +1,65 @@
package com.luqj.common.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import com.luqj.common.domain.ComCategory;
import com.luqj.common.domain.ComCategoryPlus;
/**
* 类别Mapper接口
*
* @author luqj
* @date 2021-07-24
*/
public interface ComCategoryMapper extends BaseMapper<ComCategoryPlus>
{
/**
* 查询类别
*
* @param id 类别ID
* @return 类别
*/
public ComCategory selectComCategoryById(Long id);
/**
* 查询类别列表
*
* @param comCategory 类别
* @return 类别集合
*/
public List<ComCategory> selectComCategoryList(ComCategory comCategory);
/**
* 新增类别
*
* @param comCategory 类别
* @return 结果
*/
public int insertComCategory(ComCategory comCategory);
/**
* 修改类别
*
* @param comCategory 类别
* @return 结果
*/
public int updateComCategory(ComCategory comCategory);
/**
* 删除类别
*
* @param id 类别ID
* @return 结果
*/
public int deleteComCategoryById(Long id);
/**
* 批量删除类别
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteComCategoryByIds(Long[] ids);
}
@@ -0,0 +1,90 @@
package com.luqj.common.service;
import java.util.Map;
import java.util.List;
import com.luqj.common.domain.CategoryTreeSelect;
import com.luqj.common.domain.ComCategory;
import com.luqj.common.domain.ComCategoryPlus;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
/**
* 类别Service接口
*
* @author luqj
* @date 2021-07-24
*/
public interface IComCategoryService extends IService<ComCategoryPlus>
{
/**
* 查询类别
*
* @param id 类别ID
* @return 类别
*/
public ComCategory selectComCategoryById(Long id);
/**
* 查询类别列表
*
* @param comCategory 类别
* @return 类别集合
*/
public List<ComCategory> selectComCategoryList(ComCategory comCategory);
/**
* 新增类别
*
* @param comCategory 类别
* @return 结果
*/
public int insertComCategory(ComCategory comCategory);
/**
* 修改类别
*
* @param comCategory 类别
* @return 结果
*/
public int updateComCategory(ComCategory comCategory);
/**
* 批量删除类别
*
* @param ids 需要删除的类别ID
* @return 结果
*/
public int deleteComCategoryByIds(Long[] ids);
/**
* 删除类别信息
*
* @param id 类别ID
* @return 结果
*/
public int deleteComCategoryById(Long id);
List<ComCategoryPlus> getByIds(List<Long> ids, SFunction<ComCategoryPlus, ?>... columns);
ComCategoryPlus getById(Long id, SFunction<ComCategoryPlus, ?>... columns);
Map<Long, ComCategoryPlus> getMapByIds(List<Long> ids, SFunction<ComCategoryPlus, ?>... columns);
List<CategoryTreeSelect> buildCategoryTreeSelect(List<ComCategory> comCategory);
List<ComCategoryPlus> getByIds(List<Long> ids);
Map<Long, ComCategoryPlus> getMapByIds(List<Long> ids);
/**
* @param field sum 字段
* @param where 条件
* @param tClass 返回类型
* @param <T>
* @return
*/
<T> T sum(String field, String where, Class<T> tClass);
Long count(String where);
<T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass);
}
@@ -0,0 +1,9 @@
package com.luqj.common.service;
import com.luqj.common.domain.SelectItem;
import java.util.List;
public interface ICommonService {
List<SelectItem> search(String tableName, String fieldId, String fieldName, String keyword);
}
@@ -0,0 +1,8 @@
package com.luqj.common.service;
import javax.mail.MessagingException;
import java.security.GeneralSecurityException;
public interface ISendEmailService {
boolean send(String email, String subject, String content) throws MessagingException, GeneralSecurityException;
}
@@ -0,0 +1,275 @@
package com.luqj.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import java.util.*;
import com.luqj.common.domain.CategoryTreeSelect;
import com.ruoyi.common.utils.StringUtils;
import com.alibaba.fastjson.JSONArray;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.luqj.common.mapper.ComCategoryMapper;
import com.luqj.common.domain.ComCategory;
import com.luqj.common.domain.ComCategoryPlus;
import com.luqj.common.service.IComCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* 类别Service业务层处理
*
* @author luqj
* @date 2021-07-24
*/
@Service
public class ComCategoryServiceImpl extends ServiceImpl<ComCategoryMapper, ComCategoryPlus> implements IComCategoryService
{
@Autowired
private ComCategoryMapper comCategoryMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<ComCategoryPlus> getByIds(List<Long> ids, SFunction<ComCategoryPlus, ?>... columns) {
LambdaQueryWrapper<ComCategoryPlus> lambdaQueryWrapper = new LambdaQueryWrapper<ComCategoryPlus>()
.select(columns).in(ComCategoryPlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
@Override
public ComCategoryPlus getById(Long id, SFunction<ComCategoryPlus, ?>... columns) {
LambdaQueryWrapper<ComCategoryPlus> lambdaQueryWrapper = new LambdaQueryWrapper<ComCategoryPlus>()
.select(columns).eq(ComCategoryPlus::getId, id);
return baseMapper.selectOne(lambdaQueryWrapper);
}
@Override
public Map<Long, ComCategoryPlus> getMapByIds(List<Long> ids, SFunction<ComCategoryPlus, ?>... columns) {
List<ComCategoryPlus> list = this.getByIds(ids, columns);
Map<Long, ComCategoryPlus> map = new HashMap<>();
for (ComCategoryPlus item : list) {
map.put(item.getId(), item);
}
return map;
}
public List<CategoryTreeSelect> buildCategoryTreeSelect(List<ComCategory> comCategory)
{
List<ComCategory> deptTrees = buildCategoryTree(comCategory);
ComCategory com =new ComCategory();
com.setId(0L);
com.setName("根目录");
com.setChildren(deptTrees);
List<ComCategory> pc = new ArrayList<>();
for(ComCategory c:deptTrees){
if(c.getParentId() == 0L){
pc.add(c);
}
}
com.setChildren(pc);
return Arrays.asList(com).stream().map(CategoryTreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<ComCategory> list, ComCategory t)
{
// 得到子节点列表
List<ComCategory> childList = getChildList(list, t);
t.setChildren(childList);
for (ComCategory tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<ComCategory> getChildList(List<ComCategory> list, ComCategory t)
{
List<ComCategory> tlist = new ArrayList<ComCategory>();
Iterator<ComCategory> it = list.iterator();
while (it.hasNext())
{
ComCategory n = (ComCategory) it.next();
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<ComCategory> list, ComCategory t)
{
return getChildList(list, t).size() > 0 ? true : false;
}
public List<ComCategory> buildCategoryTree(List<ComCategory> depts)
{
List<ComCategory> returnList = new ArrayList<ComCategory>();
List<Long> tempList = new ArrayList<Long>();
for (ComCategory dept : depts)
{
tempList.add(dept.getId());
}
for (Iterator<ComCategory> iterator = depts.iterator(); iterator.hasNext();)
{
ComCategory dept = (ComCategory) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId()))
{
recursionFn(depts, dept);
returnList.add(dept);
}
}
if (returnList.isEmpty())
{
returnList = depts;
}
return returnList;
}
@Override
public Map<Long, ComCategoryPlus> getMapByIds(List<Long> ids) {
List<ComCategoryPlus> list = this.getByIds(ids);
Map<Long, ComCategoryPlus> map = new HashMap<>();
for (ComCategoryPlus item : list) {
map.put(item.getId(), item);
}
return map;
}
@Override
public List<ComCategoryPlus> getByIds(List<Long> ids) {
LambdaQueryWrapper<ComCategoryPlus> lambdaQueryWrapper = new LambdaQueryWrapper<ComCategoryPlus>().in(ComCategoryPlus::getId, ids);
return this.list(lambdaQueryWrapper);
}
public <T> T sum(String field, String where, Class<T> tClass) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(" sum(" + field + ") as total ");
stringBuffer.append(" from com_category ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
T result = jdbcTemplate.queryForObject(stringBuffer.toString(), tClass);
return result;
}
public Long count(String where) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(" count(1)");
stringBuffer.append(" from ");
stringBuffer.append(" com_category ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
Long result = jdbcTemplate.queryForObject(stringBuffer.toString(), Long.class);
return result;
}
public <T> List<T> countByGroupBy(String select, String where, String groupby, Class<T> tClass) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(select);
stringBuffer.append(" from ");
stringBuffer.append(" com_category ");
if (StringUtils.isNotBlank(where)) {
stringBuffer.append(" where ");
stringBuffer.append(where);
}
stringBuffer.append(" group by ");
stringBuffer.append(groupby);
List result = jdbcTemplate.queryForList(stringBuffer.toString());
List<T> tList = JSONArray.parseArray(JSONArray.toJSONString(result), tClass);
return tList;
}
/**
* 查询类别
*
* @param id 类别ID
* @return 类别
*/
@Override
public ComCategory selectComCategoryById(Long id)
{
return comCategoryMapper.selectComCategoryById(id);
}
/**
* 查询类别列表
*
* @param comCategory 类别
* @return 类别
*/
@Override
public List<ComCategory> selectComCategoryList(ComCategory comCategory)
{
return comCategoryMapper.selectComCategoryList(comCategory);
}
/**
* 新增类别
*
* @param comCategory 类别
* @return 结果
*/
@Override
public int insertComCategory(ComCategory comCategory)
{
comCategory.setCreateTime(DateUtils.getNowDate());
return comCategoryMapper.insertComCategory(comCategory);
}
/**
* 修改类别
*
* @param comCategory 类别
* @return 结果
*/
@Override
public int updateComCategory(ComCategory comCategory)
{
comCategory.setUpdateTime(DateUtils.getNowDate());
return comCategoryMapper.updateComCategory(comCategory);
}
/**
* 批量删除类别
*
* @param ids 需要删除的类别ID
* @return 结果
*/
@Override
public int deleteComCategoryByIds(Long[] ids)
{
return comCategoryMapper.deleteComCategoryByIds(ids);
}
/**
* 删除类别信息
*
* @param id 类别ID
* @return 结果
*/
@Override
public int deleteComCategoryById(Long id)
{
return comCategoryMapper.deleteComCategoryById(id);
}
}
@@ -0,0 +1,39 @@
package com.luqj.common.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.luqj.common.domain.SelectItem;
import com.luqj.common.service.ICommonService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class CommonServiceImpl implements ICommonService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public List<SelectItem> search(String tableName, String fieldId, String fieldName, String keyword) {
if (StringUtils.isEmpty(tableName)) {
return new ArrayList<>();
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("select ");
stringBuffer.append(fieldId + " as id,");
stringBuffer.append(fieldName + " as name");
stringBuffer.append(" from ");
stringBuffer.append(" " + tableName + " ");
if (StringUtils.isNotBlank(keyword)) {
stringBuffer.append(" where ");
stringBuffer.append(fieldName + " like '%" + keyword + "%'");
}
stringBuffer.append(" limit 0,100 ");
List result = jdbcTemplate.queryForList(stringBuffer.toString());
List<SelectItem> tList = JSONArray.parseArray(JSONArray.toJSONString(result), SelectItem.class);
return tList;
}
}
@@ -0,0 +1,65 @@
package com.luqj.common.service.impl;
import com.luqj.common.config.EmailProperties;
import com.luqj.common.service.ISendEmailService;
import com.sun.mail.util.MailSSLSocketFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.security.GeneralSecurityException;
import java.util.Properties;
@Service
public class SendEmailServiceImpl implements ISendEmailService {
@Autowired
private EmailProperties emailProperties;
private final Properties props = new Properties();
@Override
public boolean send(String email, String subject, String content) throws MessagingException, GeneralSecurityException {
// qq邮件
// 设置邮件服务器主机名
props.setProperty("mail.host", emailProperties.getSmtpHost());
// 发送服务器需要身份验证
props.setProperty("mail.smtp.auth", emailProperties.getSmtpAuth() + "");
// 发送邮件协议名称
props.setProperty("mail.transport.protocol", "smtp");
// 开启SSL加密,否则会失败
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.socketFactory", sf);
// 创建session
Session session = Session.getInstance(props);
// 通过session得到transport对象
Transport ts = session.getTransport();
ts.connect(emailProperties.getSmtpHost(), emailProperties.getUser(), emailProperties.getPassword());// 后面的字符是授权码
// 创建邮件对象
Message message = new MimeMessage(session);
// 指明邮件的发件人
message.setFrom(new InternetAddress(emailProperties.getUser()));
// 指明邮件的收件人,现在发件人和收件人是一样的,那就是自己给自己发
message.setRecipient(Message.RecipientType.TO, new InternetAddress(email));
// 邮件的标题
message.setSubject(subject);
// 邮件的文本内容
message.setContent(content, "text/html;charset=UTF-8");
// 发送邮件
ts.sendMessage(message, message.getAllRecipients());
ts.close();
return true;
}
public static void main(String[] args) {
}
}