| @@ -22,7 +22,13 @@ | |||
| <groupId>com.ruoyi</groupId> | |||
| <artifactId>ruoyi-common-core</artifactId> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.alibaba</groupId> | |||
| <artifactId>easyexcel-core</artifactId> | |||
| <version>3.3.2</version> | |||
| <scope>compile</scope> | |||
| </dependency> | |||
| </dependencies> | |||
| </project> | |||
| @@ -1,7 +1,11 @@ | |||
| package com.ruoyi.system.api.domain; | |||
| import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |||
| import com.alibaba.excel.annotation.ExcelProperty; | |||
| import com.alibaba.excel.annotation.write.style.ContentStyle; | |||
| import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; | |||
| import com.alibaba.excel.enums.poi.VerticalAlignmentEnum; | |||
| import com.ruoyi.common.core.annotation.Excel; | |||
| import com.ruoyi.common.core.annotation.Excel.ColumnType; | |||
| import com.ruoyi.common.core.annotation.Excel.Type; | |||
| import com.ruoyi.common.core.annotation.Excels; | |||
| import com.ruoyi.common.core.web.domain.BaseEntity; | |||
| @@ -20,49 +24,52 @@ import java.util.List; | |||
| * | |||
| * @author ruoyi | |||
| */ | |||
| @ExcelIgnoreUnannotated | |||
| @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, | |||
| verticalAlignment = VerticalAlignmentEnum.CENTER) | |||
| public class SysUser extends BaseEntity { | |||
| private static final long serialVersionUID = 1L; | |||
| /** | |||
| * 用户ID | |||
| */ | |||
| @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") | |||
| @ExcelProperty(value = "用户序号", order = 1) | |||
| private Long userId; | |||
| /** | |||
| * 部门ID | |||
| */ | |||
| @Excel(name = "部门编号", type = Type.IMPORT) | |||
| @ExcelProperty(value = "部门编号", order = 2) | |||
| private Long deptId; | |||
| /** | |||
| * 用户账号 | |||
| */ | |||
| @Excel(name = "登录名称") | |||
| @ExcelProperty(value = "登录名称", order = 3) | |||
| private String userName; | |||
| /** | |||
| * 用户昵称 | |||
| */ | |||
| @Excel(name = "用户名称") | |||
| @ExcelProperty(value = "用户名称", order = 4) | |||
| private String nickName; | |||
| /** | |||
| * 用户邮箱 | |||
| */ | |||
| @Excel(name = "用户邮箱") | |||
| @ExcelProperty(value = "用户邮箱", order = 4) | |||
| private String email; | |||
| /** | |||
| * 手机号码 | |||
| */ | |||
| @Excel(name = "手机号码") | |||
| @ExcelProperty(value = "手机号码", order = 5) | |||
| private String phonenumber; | |||
| /** | |||
| * 用户性别 | |||
| */ | |||
| @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知") | |||
| @ExcelProperty(value = "用户性别", order = 6) | |||
| private String sex; | |||
| /** | |||
| @@ -80,7 +87,7 @@ public class SysUser extends BaseEntity { | |||
| /** | |||
| * 帐号状态(0正常 1停用) | |||
| */ | |||
| @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") | |||
| @ExcelProperty(value = "帐号状态", order = 7) | |||
| private String status; | |||
| /** | |||
| @@ -91,22 +98,24 @@ public class SysUser extends BaseEntity { | |||
| /** | |||
| * 最后登录IP | |||
| */ | |||
| @Excel(name = "最后登录IP", type = Type.EXPORT) | |||
| @ExcelProperty(value = "最后登录IP", order = 8) | |||
| private String loginIp; | |||
| /** | |||
| * 最后登录时间 | |||
| */ | |||
| @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) | |||
| // @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT) | |||
| @ExcelProperty(value = "最后登录时间", order = 9) | |||
| private Date loginDate; | |||
| /** | |||
| * 部门对象 | |||
| */ | |||
| @Excels({ | |||
| @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), | |||
| @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) | |||
| }) | |||
| // @Excels({ | |||
| // @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), | |||
| // @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) | |||
| // }) | |||
| // @ExcelProperty(value = "部门", order = 4) | |||
| private SysDept dept; | |||
| /** | |||
| @@ -257,7 +257,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 对excel表单默认第一个索引名转换成list | |||
| * | |||
| * | |||
| * @param is 输入流 | |||
| * @return 转换后集合 | |||
| */ | |||
| @@ -282,7 +282,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 对excel表单默认第一个索引名转换成list | |||
| * | |||
| * | |||
| * @param is 输入流 | |||
| * @param titleNum 标题占用行数 | |||
| * @return 转换后集合 | |||
| @@ -294,7 +294,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 对excel表单指定表格索引名转换成list | |||
| * | |||
| * | |||
| * @param sheetName 表格索引名 | |||
| * @param titleNum 标题占用行数 | |||
| * @param is 输入流 | |||
| @@ -503,7 +503,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 对list数据源将其里面的数据导入到excel表单 | |||
| * | |||
| * | |||
| * @return 结果 | |||
| */ | |||
| public void exportExcel(HttpServletResponse response) | |||
| @@ -565,7 +565,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 填充excel数据 | |||
| * | |||
| * | |||
| * @param index 序号 | |||
| * @param row 单元格行 | |||
| */ | |||
| @@ -636,7 +636,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 创建表格样式 | |||
| * | |||
| * | |||
| * @param wb 工作薄对象 | |||
| * @return 样式列表 | |||
| */ | |||
| @@ -689,7 +689,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 根据Excel注解创建表格头样式 | |||
| * | |||
| * | |||
| * @param wb 工作薄对象 | |||
| * @return 自定义样式列表 | |||
| */ | |||
| @@ -722,7 +722,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 根据Excel注解创建表格列样式 | |||
| * | |||
| * | |||
| * @param wb 工作薄对象 | |||
| * @return 自定义样式列表 | |||
| */ | |||
| @@ -784,7 +784,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 设置单元格信息 | |||
| * | |||
| * | |||
| * @param value 单元格值 | |||
| * @param attr 注解相关 | |||
| * @param cell 单元格信息 | |||
| @@ -943,7 +943,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 设置 POI XSSFSheet 单元格提示或选择框 | |||
| * | |||
| * | |||
| * @param sheet 表单 | |||
| * @param textlist 下拉框显示的内容 | |||
| * @param promptContent 提示内容 | |||
| @@ -953,7 +953,7 @@ public class ExcelUtil<T> | |||
| * @param endCol 结束列 | |||
| */ | |||
| public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, | |||
| int firstCol, int endCol) | |||
| int firstCol, int endCol) | |||
| { | |||
| DataValidationHelper helper = sheet.getDataValidationHelper(); | |||
| DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); | |||
| @@ -980,7 +980,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框). | |||
| * | |||
| * | |||
| * @param sheet 要设置的sheet. | |||
| * @param textlist 下拉框显示的内容 | |||
| * @param promptContent 提示内容 | |||
| @@ -1069,7 +1069,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 反向解析值 男=0,女=1,未知=2 | |||
| * | |||
| * | |||
| * @param propertyValue 参数值 | |||
| * @param converterExp 翻译注解 | |||
| * @param separator 分隔符 | |||
| @@ -1311,7 +1311,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 创建工作表 | |||
| * | |||
| * | |||
| * @param sheetNo sheet数量 | |||
| * @param index 序号 | |||
| */ | |||
| @@ -1328,7 +1328,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 获取单元格值 | |||
| * | |||
| * | |||
| * @param row 获取的行 | |||
| * @param column 获取单元格列号 | |||
| * @return 单元格值 | |||
| @@ -1388,7 +1388,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 判断是否是空行 | |||
| * | |||
| * | |||
| * @param row 判断的行 | |||
| * @return | |||
| */ | |||
| @@ -1411,7 +1411,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 格式化不同类型的日期对象 | |||
| * | |||
| * | |||
| * @param dateFormat 日期格式 | |||
| * @param val 被格式化的日期对象 | |||
| * @return 格式化后的日期字符 | |||
| @@ -1477,7 +1477,7 @@ public class ExcelUtil<T> | |||
| /** | |||
| * 获取对象的子列表方法 | |||
| * | |||
| * | |||
| * @param name 名称 | |||
| * @param pojoClass 类对象 | |||
| * @return 子列表方法 | |||
| @@ -197,7 +197,7 @@ public class GitServiceImpl implements GitService { | |||
| @Override | |||
| public void resetPwd(SysUser sysUser) throws Exception { | |||
| String token = checkoutToken(); | |||
| String token = login(sysUser.getUserName(), sysUser.getOriginPassword()); | |||
| Map<String, Object> resMap = new HashMap<>(); | |||
| resMap.put("login", sysUser.getUserName()); | |||
| resMap.put("password", sysUser.getPassword()); | |||
| @@ -78,6 +78,14 @@ | |||
| <artifactId>ruoyi-common-swagger</artifactId> | |||
| </dependency> | |||
| <!-- easyexcel --> | |||
| <dependency> | |||
| <groupId>com.alibaba</groupId> | |||
| <artifactId>easyexcel</artifactId> | |||
| <version>3.3.2</version> | |||
| <exclusions> | |||
| </exclusions> | |||
| </dependency> | |||
| </dependencies> | |||
| <build> | |||
| @@ -1,5 +1,7 @@ | |||
| package com.ruoyi.system.controller; | |||
| import cn.hutool.core.date.DateUtil; | |||
| import com.alibaba.excel.EasyExcel; | |||
| import com.ruoyi.common.core.domain.R; | |||
| import com.ruoyi.common.core.utils.StringUtils; | |||
| import com.ruoyi.common.core.utils.poi.ExcelUtil; | |||
| @@ -25,12 +27,12 @@ import org.springframework.web.multipart.MultipartFile; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.net.URLEncoder; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import java.util.stream.Collectors; | |||
| import static com.ruoyi.common.security.utils.SecurityUtils.encrypt; | |||
| /** | |||
| * 用户信息 | |||
| * | |||
| @@ -74,10 +76,17 @@ public class SysUserController extends BaseController { | |||
| @Log(title = "用户管理", businessType = BusinessType.EXPORT) | |||
| @RequiresPermissions("system:user:export") | |||
| @PostMapping("/export") | |||
| public void export(HttpServletResponse response, @RequestBody SysUser user) { | |||
| public void export(HttpServletResponse response, @RequestBody SysUser user) throws IOException { | |||
| List<SysUser> list = userService.selectUserList(user); | |||
| ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | |||
| util.exportExcel(response, list, "用户数据"); | |||
| // ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); | |||
| // util.exportExcel(response, list, "用户数据"); | |||
| String fileName = URLEncoder.encode("用户表-" + DateUtil.format(new Date(), "yyyyMMddHHmmss"), "UTF-8"); | |||
| response.setContentType("application/x-download;charset=utf-8"); | |||
| response.addHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx"); | |||
| EasyExcel.write(response.getOutputStream(), SysUser.class).sheet("sheet1").doWrite(list); | |||
| } | |||
| @Log(title = "用户管理", businessType = BusinessType.IMPORT) | |||
| @@ -317,7 +317,7 @@ public class SysUserServiceImpl implements ISysUserService { | |||
| } | |||
| } | |||
| if (StringUtils.isNotEmpty(user.getPassword()) && !decrypt(oldUser.getOriginPassword()).equals(user.getPassword())) { | |||
| if (StringUtils.isNotEmpty(user.getPassword())) { | |||
| GenericsAjaxResult<String> result = remoteMmpService.resetPwd(user); | |||
| if (result.getCode() != 200) { | |||
| throw new Exception(result.getMsg()); | |||
| @@ -24,7 +24,6 @@ | |||
| <result property="updateBy" column="update_by"/> | |||
| <result property="updateTime" column="update_time"/> | |||
| <result property="remark" column="remark"/> | |||
| <result property="gitLinkPassword" column="git_link_password"/> | |||
| <result property="credit" column="credit"/> | |||
| <association property="dept" javaType="SysDept" resultMap="deptResult"/> | |||
| <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/> | |||
| @@ -89,7 +88,7 @@ | |||
| <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult"> | |||
| select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, | |||
| ROUND(u.credit, 1) as credit, | |||
| u.origin_password , ROUND(u.credit, 1) as credit, | |||
| u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader | |||
| from sys_user u | |||
| left join sys_dept d on u.dept_id = d.dept_id | |||
| @@ -209,7 +208,6 @@ | |||
| <if test="status != null and status != ''">status,</if> | |||
| <if test="createBy != null and createBy != ''">create_by,</if> | |||
| <if test="remark != null and remark != ''">remark,</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password,</if> | |||
| <if test="credit != null">credit,</if> | |||
| create_time | |||
| )values( | |||
| @@ -226,8 +224,6 @@ | |||
| <if test="status != null and status != ''">#{status},</if> | |||
| <if test="createBy != null and createBy != ''">#{createBy},</if> | |||
| <if test="remark != null and remark != ''">#{remark},</if> | |||
| <if test="gitLinkUsername != null and gitLinkUsername != ''">#{gitLinkUsername},</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">#{gitLinkPassword},</if> | |||
| <if test="credit != null">#{credit},</if> | |||
| sysdate() | |||
| ) | |||
| @@ -250,7 +246,6 @@ | |||
| <if test="loginDate != null">login_date = #{loginDate},</if> | |||
| <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | |||
| <if test="remark != null">remark = #{remark},</if> | |||
| <if test="gitLinkPassword != null and gitLinkPassword != ''">git_link_password = #{gitLinkPassword},</if> | |||
| <if test="credit != null">credit = #{credit},</if> | |||
| update_time = sysdate() | |||
| </set> | |||