src/main/java/org/springblade/modules/dispatcher/controller/DispatcherUnitController.java
@@ -135,13 +135,14 @@ //数据同步 String s1 = "insert into sys_dispatcher_unit(id,name,dept_id,linkman,phone,jurisdiction,start_time,end_time,serve_type) " + "insert into sys_dispatcher_unit(id,name,dept_id,linkman,phone,jurisdiction,create_time,start_time,end_time,serve_type) " + "values(" + "'" + dispatcherUnit.getId() + "'" + "," + "'" + dispatcherUnit.getName() + "'" + "," + "'" + dispatcherUnit.getDeptId() + "'" + "," + "'" + dispatcherUnit.getLinkman() + "'" + "," + "'" + dispatcherUnit.getPhone() + "'" + "," + "'" + dispatcherUnit.getJurisdiction() + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dispatcherUnit.getCreateTime()) + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcherUnit.getStartTime()) + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(dispatcherUnit.getEndTime()) + "'" + "," + "'" +dispatcherUnit.getServeType() + "'" + ")"; src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -181,49 +181,78 @@ @ApiOperationSupport(order = 4) @ApiOperation(value = "新增或修改", notes = "传入User") //@PreAuth(RoleConstant.HAS_ROLE_ADMIN) public R submit(@Valid @RequestBody User user) throws Exception { CacheUtil.clear(USER_CACHE); //查询角色 // if (null!=user.getRoleId()){ // Role role = new Role(); // role.setId(Long.parseLong(user.getRoleId())); // Role one = roleService.getOne(Condition.getQueryWrapper(role)); // if (one.getRoleAlias().equals("保安")){ // user.setHold("1"); // } // if (one.getRoleAlias().equals("未持证保安")){ // user.setHold("2"); // } // } public R submit(@Valid @RequestBody User user){ if (null==user.getId()) { //新增 //密码加密 if (Func.isNotEmpty(user.getPassword())) { user.setPassword(DigestUtil.encrypt(user.getPassword())); } Integer userCount = userService.selectCountAccount(user.getAccount()); if (userCount > 0) { throw new org.springblade.core.log.exception.ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); } user.setTenantId("000000"); user.setStatus(1); user.setCreateTime(new Date()); user.setUpdateTime(new Date()); //判断是否为民警 code if (null != user.getCode() && !user.getCode().equals("")) { //民警 //根据 deptId 查询dept信息,公安管理员 Dept dept = iDeptService.getById(user.getDeptId()); //获取辖区的数据 Jurisdiction jurisdiction = new Jurisdiction(); jurisdiction.setDeptName(dept.getDeptName()); Jurisdiction one = jurisdictionService.getOne(Condition.getQueryWrapper(jurisdiction)); user.setJurisdiction(one.getId().toString()); } //新增 userService.save(user); //内网同步 String s = "insert into blade_user(" + "id,tenant_id,code,account,password,real_name,phone,sex,role_id,dept_id," + "create_time,update_time,cardid,status,is_deleted,jurisdiction) " + "values(" + "'" + user.getId() + "'" + "," + "'" + user.getTenantId() + "'" + "," + "'" + user.getCode() + "'" + "," + "'" + user.getAccount() + "'" + "," + "'" + user.getPassword() + "'" + "," + "'" + user.getRealName() + "'" + "," + "'" + user.getPhone() + "'" + "," + "'" + user.getSex() + "'" + "," + "'" + user.getRoleId() + "'" + "," + "'" + user.getDeptId() + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" + "," + "'" + user.getCardid() + "'" + "," + "'" + user.getStatus() + "'" + "," + "'" + user.getIsDeleted() + "'" + "," + "'" + user.getJurisdiction() + "'" + ")"; FtpUtil.sqlFileUpload(s); }else { //修改 User user1 = userService.getById(user.getId()); user.setPassword(user1.getPassword()); user.setUpdateTime(new Date()); userService.updateById(user); // //根据 deptId 查询dept信息,公安管理员 // Dept dept = iDeptService.getById(user.getDeptId()); // Long sid = 1123598813738675201L; // if (dept.getParentId().equals(sid)) { // //获取辖区的数据 // Jurisdiction jurisdiction = new Jurisdiction(); // jurisdiction.setDeptName(dept.getDeptName()); // Jurisdiction one = jurisdictionService.getOne(Condition.getQueryWrapper(jurisdiction)); // user.setJurisdiction(one.getId().toString()); // } //user.setRoleId("1412226235153731586"); userService.submit(user); // String birthday = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getBirthday()); // String rtime = null; // if (null != user.getRtime()) { // rtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getRtime()); // } // user.setIsDeleted(0); // String s = "insert into blade_user(id,tenant_id,account,password,name,real_name,avatar,email,phone,sex,role_id,dept_id,cardid,nativePlace,nation,education," + // "politicaloutlook,healstats,height,address,registered,rtime,securitynumber,hold,jurisdiction,is_deleted) " + // "values(" + "'" + user.getId() + "'" + "," + "'" + 000000 + "'" + "," + "'" + user.getAccount() + "'" + "," + // "'" + user.getPassword() + "'" + "," + "'" + user.getName() + "'" + "," + "'" + user.getRealName() + "'" + "," + "'" + user.getAvatar() + "'" + "," + // "'" + user.getEmail() + "'" + "," + "'" + user.getPhone() + "'" + "," + "'" + user.getSex() + "'" + "," + "'" + user.getRoleId() + "'" + // "," + "'" + user.getDeptId() + "'" + "," + "'" + user.getCardid() + "'" + "," + "'" + user.getNativeplace() + "'" + "," + "'" // + user.getNation() + "'" + "," + "'" + user.getEducation() + "'" + "," + "'" + user.getPoliticaloutlook() + "'" + "," + "'" + user.getHealstats() + "'" // + "," + "'" + user.getHeight() + "'" + "," + "'" + user.getAddress() + "'" + "," + "'" + user.getRegistered() + "'" + "," + // "'" + rtime + "'" + "," + "'" + user.getSecuritynumber() + "'" + "," + "'" + user.getHold() + "'" + "," + "'" + user.getJurisdiction() + "'"+"," + "'" +user.getIsDeleted() + "'"+ ")"; // FtpUtil.sqlFileUpload(s); String s1 = "update blade_user set account = " + "'" + user.getAccount() + "'" + ",code = " + "'" + user.getCode() + "'" + ",real_name = " + "'" + user.getRealName() + "'" + ",phone = " + "'" + user.getPhone() + "'" + ",sex = " + "'" + user.getSex() + "'" + ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" + ",role_id = " + "'" + user.getRoleId() + "'" + ",dept_id = " + "'" + user.getDeptId() + "'" + ",cardid = " + "'" + user.getCardid() + "'" + " " + "where id = " + "'" + user.getId() + "'"; FtpUtil.sqlFileUpload(s1); } //返回 return R.success("成功"); } @@ -416,9 +445,9 @@ @PostMapping("import-security") @ApiOperationSupport(order = 12) @ApiOperation(value = "导入用户", notes = "传入excel") public R importSecurity(MultipartFile file, Integer isCovered) { SecurityImporter securityImporter = new SecurityImporter(userService, false); ExcelUtil.save(file, securityImporter, UserExcel.class); public R importSecurity(MultipartFile file, Integer isCovered,String deptId) { SecurityImporter securityImporter = new SecurityImporter(userService, false,deptId); ExcelUtil.save(file, securityImporter, SecurityExcel.class); return R.success("操作成功"); } @@ -457,49 +486,38 @@ @ApiOperationSupport(order = 14) @ApiOperation(value = "导出模板") public void exportSecurity(HttpServletResponse response) throws IOException { List<UserExcel> list = new ArrayList<>(); UserExcel userExcel = new UserExcel(); userExcel.setDeptId("xxx保安公司"); userExcel.setRealName("张三"); userExcel.setEmail("xxx@**.com"); userExcel.setPhone("12345678901"); userExcel.setSex("男"); userExcel.setCardid("360XXX19XXXXXX****"); userExcel.setNativeplace("江西南昌"); userExcel.setNation("汉"); userExcel.setPoliticaloutlook("中共党员"); userExcel.setHeight(180); userExcel.setAddress("江西省南昌市******"); userExcel.setRegistered("江西南昌"); userExcel.setRtime("2021-05-01"); userExcel.setHold("是"); userExcel.setSecuritynumber("赣洪202100001"); list.add(userExcel); UserExcel userExcel1 = new UserExcel(); userExcel1.setDeptId("xxx保安公司"); userExcel1.setRealName("李四"); userExcel1.setEmail("xxx@**.com"); userExcel1.setPhone("12345678901"); userExcel1.setSex("女"); userExcel1.setCardid("360XXX19XXXXXX****"); userExcel1.setNativeplace("江西南昌"); userExcel1.setNation("汉"); userExcel1.setPoliticaloutlook("中共党员"); userExcel1.setHeight(180); userExcel1.setAddress("江西省南昌市******"); userExcel1.setRegistered("江西南昌"); userExcel1.setRtime("2021-05-01"); userExcel1.setHold("否"); userExcel1.setSecuritynumber(""); list.add(userExcel1); List<SecurityExcel> list = new ArrayList<>(); SecurityExcel securityExcel = new SecurityExcel(); securityExcel.setDeptId("xxx保安公司"); securityExcel.setRealName("张三"); securityExcel.setPhone("12345678901"); securityExcel.setSex("男"); securityExcel.setCardid("360XXX19XXXXXX****"); securityExcel.setNation("汉"); securityExcel.setRegistered("江西省南昌市******"); securityExcel.setHold("是"); securityExcel.setSecuritynumber("赣洪202100001"); list.add(securityExcel); SecurityExcel securityExcel1 = new SecurityExcel(); securityExcel1.setDeptId("xxx保安公司"); securityExcel1.setRealName("李四"); securityExcel1.setPhone("12345678901"); securityExcel1.setSex("女"); securityExcel1.setCardid("360XXX19XXXXXX****"); securityExcel1.setNation("汉"); securityExcel1.setRegistered("江西省南昌市******"); securityExcel1.setHold("否"); securityExcel1.setSecuritynumber(""); list.add(securityExcel1); String fileName = null; try { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name()); fileName = URLEncoder.encode("保安员导入数据模板", Charsets.UTF_8.name()); fileName = URLEncoder.encode("保安员导入数据模板"+DateUtil.time(), Charsets.UTF_8.name()); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); //修改单元格格式为文本格式 EasyExcel.write(response.getOutputStream(), UserExcel.class).sheet("保安员数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list); EasyExcel.write(response.getOutputStream(), SecurityExcel.class).sheet("保安员数据表").registerWriteHandler(new RowWriteHandler()).doWrite(list); } catch (Throwable var6) { throw var6; } src/main/java/org/springblade/modules/system/excel/SecurityExcel.java
New file @@ -0,0 +1,75 @@ /* * 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 SecurityExcel implements Serializable { private static final long serialVersionUID = 1L; @ExcelProperty("单位名称*") @ColumnWidth(30) private String deptId; @ColumnWidth(10) @ExcelProperty("姓名*") private String realName; @ColumnWidth(15) @ExcelProperty("联系电话*") private String phone; @ExcelProperty("性别*") @ColumnWidth(10) private String sex; @ExcelProperty("身份证号*") @ColumnWidth(20) private String cardid; @ExcelProperty("民族") @ColumnWidth(10) private String nation; @ExcelProperty("住址*") private String registered; @ExcelProperty("是否持证*") @ColumnWidth(15) private String hold; @ExcelProperty("保安员证编码") @ColumnWidth(20) private String securitynumber; } src/main/java/org/springblade/modules/system/excel/SecurityImporter.java
@@ -28,13 +28,14 @@ * @author Chill */ @RequiredArgsConstructor public class SecurityImporter implements ExcelImporter<UserExcel> { public class SecurityImporter implements ExcelImporter<SecurityExcel> { private final IUserService service; private final Boolean isCovered; private final String deptId; @Override public void save(List<UserExcel> data) { service.importSecurity(data, isCovered); public void save(List<SecurityExcel> data) { service.importSecurity(data, isCovered,deptId); } } src/main/java/org/springblade/modules/system/excel/UserExcel.java
@@ -38,65 +38,26 @@ public class UserExcel implements Serializable { private static final long serialVersionUID = 1L; // @ColumnWidth(15) // @ExcelProperty("账号") // private String account; @ExcelProperty("单位名称*") private String deptId; @ColumnWidth(15) @ExcelProperty("警号*") private String account; @ColumnWidth(10) @ExcelProperty("姓名*") private String realName; @ExcelProperty("邮箱") private String email; @ColumnWidth(15) @ExcelProperty("联系电话*") @ExcelProperty("联系电话") private String phone; @ExcelProperty("性别*") private String sex; // @ExcelProperty("出生日期") // private Date birthday; @ExcelProperty("身份证号*") private String cardid; @ExcelProperty("籍贯") private String nativeplace; @ExcelProperty("民族") private String nation; @ExcelProperty("政治面貌") private String politicaloutlook; @ExcelProperty("身高") private Integer height; @ExcelProperty("联系地址") private String address; @ExcelProperty("户口所在地") private String registered; @ExcelProperty("入职时间") private String rtime; @ExcelProperty("是否持证*") private String hold; @ExcelProperty("保安员证编码") private String securitynumber; // @ExcelProperty("人员状态") // private String status; } src/main/java/org/springblade/modules/system/service/IUserService.java
@@ -25,6 +25,7 @@ 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.SecurityExcel; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.node.TreeNode; import org.springblade.modules.system.vo.UserVO; @@ -289,7 +290,7 @@ * @param data * @param isCovered */ void importSecurity(List<UserExcel> data, Boolean isCovered); void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId); /** * 根据保安员编码查询保安信息 @@ -329,4 +330,10 @@ void importQrCode(List<QrCodeExcel> data, Boolean isCovered, String deptId); /** * 根据用户账户查询用户是否存在 * @param account * @return */ Integer selectCountAccount(String account); } src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -45,6 +45,7 @@ import org.springblade.modules.information.service.IInformationService; import org.springblade.modules.system.entity.*; import org.springblade.modules.system.excel.QrCodeExcel; import org.springblade.modules.system.excel.SecurityExcel; import org.springblade.modules.system.excel.UserExcel; import org.springblade.modules.system.mapper.UserMapper; import org.springblade.modules.system.node.TreeNode; @@ -418,15 +419,6 @@ 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("保安"); @@ -461,22 +453,6 @@ return; }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"); } } if (null!=userExcel.getRegistered()){ user2.setRegistered(userExcel.getRegistered()); }else { user2.setRegistered(""); } //更新用户数据 this.updateById(user2); String s1 = @@ -736,47 +712,147 @@ */ @Override @Transactional(rollbackFor = Exception.class) public void importSecurity(List<UserExcel> data, Boolean isCovered) { public void importSecurity(List<SecurityExcel> data, Boolean isCovered, String deptId) { //将不能导入的保安员账号存起来 List<String> errorList = new ArrayList<>(); //将需要新增的保安员信息存入集合 List<User> insertList = new ArrayList<>(); //将需要更新的保安员信息存入集合 List<User> updateList = new ArrayList<>(); //导入状态,默认为true ,如果有一个出现问题则为 false AtomicBoolean status = new AtomicBoolean(true); data.forEach(userExcel -> { User user = Objects.requireNonNull(BeanUtil.copy(userExcel, User.class)); // 设置租户ID user.setTenantId("000000"); //默认在职 user.setStatus(1); user.setDispatch("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 user.setDeptId(userDeptService.selectIn(user.getDeptId())); //设置账号 user.setAccount(user.getCardid()); //获取默认密码配置 user.setPassword(user.getCardid().substring(user.getCardid().length() - 6)); // user.setPassword(ParamCache.getValue(DEFAULT_PARAM_PASSWORD)); //新增 this.submit(user); String deptIds = userDeptService.selectIn(user.getDeptId()); if (null!=deptIds && !deptIds.equals("")) { if (null != deptId && !deptId.equals("")) { if (!deptId.equals(deptIds)) { throw new ServiceException("导入失败!不能导入不是本公司的保安员数据!"); } } user.setDeptId(deptIds); }else { //如果deptIds 为空,则说明还没有改公司 throw new ServiceException("导入失败!公司名:["+user.getDeptId()+"]不存在!"); } //判断当前用户是否已在本单位,如果是的更新数据 User user1 = new User(); user1.setAccount(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); user.setIsDeleted(0); //判断是否持证 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)); //加密 if (Func.isNotEmpty(user.getPassword())) { user.setPassword(DigestUtil.encrypt(user.getPassword())); } Integer userCount = baseMapper.selectCountAccount(user.getAccount()); if (userCount > 0 && Func.isEmpty(user.getId())) { throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); } //新增 this.save(user); //内网同步 String s = "insert into blade_user(" + "id,tenant_id,account,password,real_name,phone,sex,role_id,dept_id," + "cardid,nation,registered,securitynumber,hold,status,is_deleted) " + "values(" + "'" + user.getId() + "'" + "," + "'" + user.getTenantId() + "'" + "," + "'" + user.getAccount() + "'" + "," + "'" + user.getPassword() + "'" + "," + "'" + user.getRealName() + "'" + "," + "'" + user.getPhone() + "'" + "," + "'" + user.getSex() + "'" + "," + "'" + user.getRoleId() + "'" + "," + "'" + user.getDeptId() + "'" + "," + "'" + user.getCardid() + "'" + "," + "'" + user.getNation() + "'" + "," + "'" + user.getRegistered() + "'" + "," + "'" + user.getSecuritynumber() + "'" + "," + "'" + user.getHold() + "'" + "," + "'" + user.getStatus() + "'" + "," + "'" + user.getIsDeleted() + "'" + ")"; FtpUtil.sqlFileUpload(s); }else { //匹配组织机构是否一致,如果不一致 if(!user2.getDeptId().equals(user.getDeptId())){ Dept dept = deptService.getById(user2.getDeptId()); status.set(false); //加入集合 errorList.add(user.getCardid()); //forEach 只能使用 return 跳出本次循环 return; }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"); } } if (null!=userExcel.getRegistered()){ user2.setRegistered(userExcel.getRegistered()); }else { user2.setRegistered(""); } //更新用户数据 this.updateById(user2); String s1 = "update blade_user set hold = " + "'" + user2.getHold() + "'" + ",securitynumber = " + "'" + user2.getSecuritynumber() + "'" + ",registered = " + "'" + user2.getRegistered() + "'" + " " + "where id = " + "'" + user2.getId() + "'"; FtpUtil.sqlFileUpload(s1); } } }); //如果所有数据导入有一个异常 if (!status.get()){ String errorAccount = StringUtils.join(errorList, "\\\n"); throw new ServiceException("用户:["+errorAccount+"]导入失败!已在其他单位存在!"); } } @@ -929,6 +1005,13 @@ }); } /** * 根据用户账户查询用户是否存在 * @param account * @return */ @Override public Integer selectCountAccount(String account) { return baseMapper.selectCountAccount(account); } }