| src/main/java/org/springblade/modules/qrcode/QrCodeController.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/system/controller/UserController.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/system/excel/QrCodeExcel.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/system/excel/QrCodeImporter.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/system/service/IUserService.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/application-test.yml | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/application.yml | ●●●●● patch | view | raw | blame | history | |
| src/main/resources/log/logback-test.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/org/springblade/modules/qrcode/QrCodeController.java
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController; import sun.misc.BASE64Encoder; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -40,11 +41,13 @@ * @return */ @GetMapping("/getQrCode") public ResponseEntity<byte[]> getQrCode(String securityNumber){ public ResponseEntity<byte[]> getQrCode(String securityNumber) throws UnsupportedEncodingException { // String url = "http://s16s652780.51mypc.cn/securityInfo/securityInfo.html"; String url = "http://223.82.109.183:2080/securityInfo.html"; if (null!=securityNumber) { String content = url + "?securityNumber=" + securityNumber; String encoded = URLEncoder.encode(securityNumber,"UTF-8"); System.out.println("encoded = " + encoded); String content = url + "?securityNumber=" + encoded; // "&realName=" + one.getRealName() + // "&age=" + one.getAge() + // "&sex=" + one.getSex() + @@ -56,6 +59,7 @@ try { URLEncoder.encode(content,"utf-8"); byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); // Set headers final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); @@ -89,6 +93,29 @@ return null; } /** * 二维码生成base64 * @param securityNumber 保安证编号 * @return */ @GetMapping("/getQrCodeDown") public String getQrCodeDown(String securityNumber) throws Exception{ // String url = "http://s16s652780.51mypc.cn/securityInfo/securityInfo.html"; String url = "http://223.82.109.183:2080/securityInfo.html"; if (null!=securityNumber) { String content = url + "?securityNumber=" + securityNumber; byte[] qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); String path = "D:\\QrCode\\"; FileOutputStream fileOutputStream = new FileOutputStream(path+securityNumber+".png"); fileOutputStream.write(qrCodeImage,0,qrCodeImage.length); fileOutputStream.flush(); fileOutputStream.close(); return securityNumber; } return null; } /** * 根据保安员编码查询保安员信息 * @param securityNumber src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -57,9 +57,7 @@ import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.Role; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.excel.SecurityImporter; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.excel.UserImporter; import org.springblade.modules.system.excel.*; import org.springblade.modules.system.node.TreeNode; import org.springblade.modules.system.service.IDeptService; import org.springblade.modules.system.service.IRoleService; @@ -374,6 +372,19 @@ /** * 保安员证二维码批量生成 */ @PostMapping("import-qrCode") @ApiOperationSupport(order = 12) @ApiOperation(value = "导入用户", notes = "传入excel") public R importQrCode(@RequestParam("file") MultipartFile file, Integer isCovered,String deptId) { QrCodeImporter qrCodeImporter = new QrCodeImporter(userService, false,deptId); ExcelUtil.save(file, qrCodeImporter, QrCodeExcel.class); return R.success("操作成功"); } /** * 导入保安员 */ @PostMapping("import-security") src/main/java/org/springblade/modules/system/excel/QrCodeExcel.java
New file @@ -0,0 +1,47 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.system.excel; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight; import lombok.Data; import java.io.Serializable; /** * UserExcel * * @author Chill */ @Data @ColumnWidth(25) @HeadRowHeight(20) @ContentRowHeight(18) public class QrCodeExcel implements Serializable { private static final long serialVersionUID = 1L; @ColumnWidth(10) @ExcelProperty("姓名*") private String realName; @ExcelProperty("保安员证编码") private String securitynumber; } src/main/java/org/springblade/modules/system/excel/QrCodeImporter.java
New file @@ -0,0 +1,41 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.system.excel; import lombok.RequiredArgsConstructor; import org.springblade.core.excel.support.ExcelImporter; import org.springblade.modules.system.service.IUserService; import java.util.List; /** * 用户数据导入类 * * @author Chill */ @RequiredArgsConstructor public class QrCodeImporter implements ExcelImporter<QrCodeExcel> { private final IUserService service; private final Boolean isCovered; private final String deptId; @Override public void save(List<QrCodeExcel> data) { service.importQrCode(data, isCovered,deptId); } } src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -26,6 +26,7 @@ import org.springblade.modules.system.entity.User; import org.springblade.modules.system.entity.UserInfo; import org.springblade.modules.system.entity.UserOauth; import org.springblade.modules.system.excel.QrCodeExcel; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.node.TreeNode; import org.springblade.modules.system.vo.UserVO; @@ -314,4 +315,12 @@ * @return */ User getUserInfo(String username); /** * 生成二维码 * @param data * @param isCovered * @param deptId */ void importQrCode(List<QrCodeExcel> data, Boolean isCovered, String deptId); } src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.zxing.WriterException; import lombok.AllArgsConstructor; import org.springblade.common.cache.DictCache; import org.springblade.common.cache.ParamCache; @@ -30,6 +31,7 @@ import org.springblade.common.constant.CommonConstant; import org.springblade.common.constant.TenantConstant; import org.springblade.common.enums.DictEnum; import org.springblade.common.utils.QRCodeUtil; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.support.Condition; @@ -49,18 +51,21 @@ import org.springblade.modules.information.service.IInformationService; import org.springblade.modules.jurisdiction.entity.Jurisdiction; import org.springblade.modules.system.entity.*; import org.springblade.modules.system.excel.QrCodeExcel; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.mapper.UserMapper; import org.springblade.modules.system.node.TreeNode; import org.springblade.modules.system.service.IRoleService; import org.springblade.modules.system.service.IUserDeptService; import org.springblade.modules.system.service.IUserOauthService; import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.*; import org.springblade.modules.system.vo.UserVO; import org.springblade.modules.system.wrapper.UserWrapper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.*; @@ -81,6 +86,7 @@ private final IRoleService roleService; private final BladeTenantProperties tenantProperties; private final IInformationService iInformationService; private final IDeptService deptService; @Override @Transactional(rollbackFor = Exception.class) @@ -386,33 +392,6 @@ public void importUser(List<UserExcel> data, Boolean isCovered,String deptId) { data.forEach(userExcel -> { User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class)); // 设置租户ID user.setTenantId("000000"); //默认在职 user.setStatus(1); //判断是否持证 if (null != userExcel.getHold() && userExcel.getHold() != "") { if (userExcel.getHold().equals("是")) { user.setHold("1"); } if (userExcel.getHold().equals("否")) { user.setHold("2"); } } //分配保安角色 Role role = new Role(); role.setRoleAlias("保安"); Role oneRole = roleService.getOne(Condition.getQueryWrapper(role)); user.setRoleId(oneRole.getId().toString()); //性别 if (null != userExcel.getSex()) { if (userExcel.getSex().equals("男")) { user.setSex(1); } if (userExcel.getSex().equals("女")) { user.setSex(2); } } //设置部门id String deptIds = userDeptService.selectIn(user.getDeptId()); if (null!=deptIds && !deptIds.equals("")) { @@ -422,14 +401,81 @@ } } user.setDeptId(deptIds); }else { //如果deptIds 为空,则说明还没有改公司 throw new ServiceException("公司名:"+user.getDeptId()+"不存在!"); } //设置账号 user.setAccount(user.getCardid()); //获取默认密码配置 user.setPassword(user.getCardid().substring(user.getCardid().length() - 6)); //判断当前用户是否已在本单位,如果是的更新数据 User user1 = new User(); user1.setAccount(user.getCardid()); System.out.println("user.getCardid() = " + user.getCardid()); user1.setIsDeleted(0); user1.setStatus(1); User user2 = this.getOne(Condition.getQueryWrapper(user1)); if (null==user2){ //用户不存在,去新增 // 设置租户ID user.setTenantId("000000"); //默认在职 user.setStatus(1); //判断是否持证 if (null != userExcel.getHold() && userExcel.getHold() != "") { if (userExcel.getHold().equals("是")) { user.setHold("1"); } if (userExcel.getHold().equals("否")) { user.setHold("2"); } } //分配保安角色 Role role = new Role(); role.setRoleAlias("保安"); Role oneRole = roleService.getOne(Condition.getQueryWrapper(role)); user.setRoleId(oneRole.getId().toString()); //性别 if (null != userExcel.getSex()) { if (userExcel.getSex().equals("男")) { user.setSex(1); } if (userExcel.getSex().equals("女")) { user.setSex(2); } } //设置账号 user.setAccount(user.getCardid()); //获取默认密码配置 user.setPassword(user.getCardid().substring(user.getCardid().length() - 6)); // user.setPassword(ParamCache.getValue(DEFAULT_PARAM_PASSWORD)); //新增 this.submit(user); //新增 this.submit(user); }else { //匹配组织机构是否一致,如果不一致 if(!user2.getDeptId().equals(user.getDeptId())){ Dept dept = deptService.getById(user2.getDeptId()); throw new ServiceException("用户:"+"["+user.getCardid()+"]"+"已在["+dept.getDeptName()+"]存在!"); }else { //如果是一致,则更新用户数据 //判断是否持证 if (null != userExcel.getHold() && userExcel.getHold() != "") { if (userExcel.getHold().equals("是") && userExcel.getSecuritynumber()!=null && !userExcel.getSecuritynumber().equals("")) { user2.setHold("1"); //更新保安证编号 user2.setSecuritynumber(user.getSecuritynumber()); } if (userExcel.getHold().equals("否")) { user2.setHold("2"); } } //更新用户数据 this.updateById(user2); String s1 = "update blade_user set hold = " + "'" + user2.getHold() + "'" + ",securitynumber = " + "'" + user2.getSecuritynumber() + "'" + " " + "where id = " + "'" + user2.getId() + "'"; FtpUtil.sqlFileUpload(s1); } } }); } @@ -776,4 +822,52 @@ public User getUserInfo(String username) { return baseMapper.getUserInfo(username); } /** * 生成二维码 * @param data * @param isCovered * @param deptId */ @Override public void importQrCode(List<QrCodeExcel> data, Boolean isCovered, String deptId) { String url = "http://223.82.109.183:2080/securityInfo.html"; data.forEach(qrCodeExcel -> { if (null!=qrCodeExcel.getSecuritynumber()) { String encoded = null; try { //中文字符串编码 encoded = URLEncoder.encode(qrCodeExcel.getSecuritynumber(),"UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //url 拼接 String content = url + "?securityNumber=" + encoded; byte[] qrCodeImage = new byte[0]; try { //生成二维码字节流 qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); } catch (WriterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String path = "D:\\QrCode\\"; FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(path+qrCodeExcel.getSecuritynumber()+".png"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { //图片下载到本地 fileOutputStream.write(qrCodeImage,0,qrCodeImage.length); fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }); } } src/main/resources/application-test.yml
@@ -39,7 +39,7 @@ #ftp 设置 ftp: sqlConnect: jdbc:mysql://223.82.109.183:2083/zhbaw?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true sqlConnect: jdbc:mysql://223.82.109.183:2083/zhbaw-test?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true ftpHost: 192.168.0.199 ftpPort: 21 ftpUserName: arsn src/main/resources/application.yml
@@ -213,6 +213,9 @@ - /blade-resource/** - /liveLocation/** - /qrCode/** - /blade-resource/attach/detail #授权认证配置 auth: - method: ALL src/main/resources/log/logback-test.xml
@@ -32,7 +32,7 @@ </encoder> <!-- 打印日志级别 --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <level>WARN</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter>