Commit 039f5e9f6f41056f092d5012d3dbdceaebf3adc9
1 parent
bd498804
考生账号批量导入 批量初始化当天排班
Showing
7 changed files
with
296 additions
and
13 deletions
src/main/java/com/bsth/controller/ddexam/DdexamController.java
| ... | ... | @@ -2,11 +2,15 @@ package com.bsth.controller.ddexam; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.sys.SysUser; |
| 4 | 4 | import com.bsth.service.ddexam.DdexamService; |
| 5 | +import com.google.common.io.Files; | |
| 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | +import org.springframework.web.bind.annotation.RequestMethod; | |
| 7 | 9 | import org.springframework.web.bind.annotation.RequestParam; |
| 8 | 10 | import org.springframework.web.bind.annotation.RestController; |
| 11 | +import org.springframework.web.multipart.MultipartFile; | |
| 9 | 12 | |
| 13 | +import java.io.File; | |
| 10 | 14 | import java.util.Date; |
| 11 | 15 | import java.util.List; |
| 12 | 16 | import java.util.Map; |
| ... | ... | @@ -51,7 +55,19 @@ public class DdexamController { |
| 51 | 55 | return new Date(); |
| 52 | 56 | } |
| 53 | 57 | |
| 54 | - | |
| 55 | - | |
| 56 | - | |
| 58 | + | |
| 59 | + | |
| 60 | + @RequestMapping(value = "/uploadFile",method = RequestMethod.POST) | |
| 61 | + public String uploadFile(@RequestParam Map map , MultipartFile file) throws Exception{ | |
| 62 | + System.out.println(file.getSize()); | |
| 63 | + File newFile = new File( | |
| 64 | + getDataImportClasspath() + File.separator + | |
| 65 | + file.getOriginalFilename()); | |
| 66 | + Files.write(file.getBytes(), newFile); | |
| 67 | + String result = ddexamService.importExcel(newFile,map); | |
| 68 | + return "{\"result\":" + "\""+result+"\"}"; | |
| 69 | + } | |
| 70 | + public String getDataImportClasspath(){ | |
| 71 | + return this.getClass().getResource("/").getPath() + "/static/pages/ddexam"; | |
| 72 | + } | |
| 57 | 73 | } | ... | ... |
src/main/java/com/bsth/entity/sys/SysUser.java
| ... | ... | @@ -41,6 +41,9 @@ public class SysUser implements Serializable { |
| 41 | 41 | private String status; |
| 42 | 42 | |
| 43 | 43 | private String ksstatus; |
| 44 | + | |
| 45 | + @Column(name = "parent_id") | |
| 46 | + private String parentID; | |
| 44 | 47 | |
| 45 | 48 | @ManyToMany(fetch = FetchType.EAGER) |
| 46 | 49 | private Set<Role> roles = new LinkedHashSet<>(); |
| ... | ... | @@ -133,4 +136,12 @@ public class SysUser implements Serializable { |
| 133 | 136 | public void setKsstatus(String ksstatus) { |
| 134 | 137 | this.ksstatus = ksstatus; |
| 135 | 138 | } |
| 139 | + | |
| 140 | + public String getParentID() { | |
| 141 | + return parentID; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public void setParentID(String parentID) { | |
| 145 | + this.parentID = parentID; | |
| 146 | + } | |
| 136 | 147 | } | ... | ... |
src/main/java/com/bsth/repository/sys/SysUserRepository.java
| ... | ... | @@ -49,4 +49,7 @@ public interface SysUserRepository extends BaseRepository<SysUser, Integer>{ |
| 49 | 49 | @Query("SELECT u FROM SysUser u where u.status is null") |
| 50 | 50 | List<SysUser> findBySusUserAll(); |
| 51 | 51 | |
| 52 | + | |
| 53 | + @Query("SELECT u FROM SysUser u where u.parentID = ?1") | |
| 54 | + List<SysUser> findByParentID(String parentID ); | |
| 52 | 55 | } | ... | ... |
src/main/java/com/bsth/service/ddexam/DdexamService.java
| ... | ... | @@ -2,7 +2,7 @@ package com.bsth.service.ddexam; |
| 2 | 2 | |
| 3 | 3 | import com.bsth.entity.sys.SysUser; |
| 4 | 4 | |
| 5 | -import java.io.IOException; | |
| 5 | +import java.io.File; | |
| 6 | 6 | import java.util.List; |
| 7 | 7 | import java.util.Map; |
| 8 | 8 | |
| ... | ... | @@ -18,5 +18,7 @@ public interface DdexamService { |
| 18 | 18 | public int initDate(String date); |
| 19 | 19 | |
| 20 | 20 | public List<SysUser> userAll(); |
| 21 | + | |
| 22 | + String importExcel(File file, Map map); | |
| 21 | 23 | |
| 22 | 24 | } | ... | ... |
src/main/java/com/bsth/service/ddexam/impl/DdexamServiceImpl.java
| 1 | 1 | package com.bsth.service.ddexam.impl; |
| 2 | 2 | |
| 3 | -import com.alibaba.dubbo.common.URL; | |
| 4 | 3 | import com.bsth.data.BasicData; |
| 5 | 4 | import com.bsth.data.LineConfigData; |
| 6 | 5 | import com.bsth.data.schedule.DayOfSchedule; |
| ... | ... | @@ -21,9 +20,13 @@ import com.bsth.repository.realcontrol.ScheduleRealInfoStRepository; |
| 21 | 20 | import com.bsth.repository.sys.BsthCSysUserRolesRepository; |
| 22 | 21 | import com.bsth.repository.sys.RealControAuthorityRepository; |
| 23 | 22 | import com.bsth.repository.sys.SysUserRepository; |
| 23 | +import com.bsth.security.util.SecurityUtils; | |
| 24 | 24 | import com.bsth.service.ddexam.DdexamService; |
| 25 | 25 | import com.bsth.util.ConfigUtil; |
| 26 | -import org.junit.Test; | |
| 26 | +import org.apache.poi.xssf.usermodel.XSSFCell; | |
| 27 | +import org.apache.poi.xssf.usermodel.XSSFRow; | |
| 28 | +import org.apache.poi.xssf.usermodel.XSSFSheet; | |
| 29 | +import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |
| 27 | 30 | import org.slf4j.Logger; |
| 28 | 31 | import org.slf4j.LoggerFactory; |
| 29 | 32 | import org.springframework.beans.BeanUtils; |
| ... | ... | @@ -32,7 +35,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| 32 | 35 | import org.springframework.stereotype.Service; |
| 33 | 36 | import org.springframework.transaction.annotation.Transactional; |
| 34 | 37 | |
| 38 | +import java.io.File; | |
| 39 | +import java.io.FileInputStream; | |
| 35 | 40 | import java.io.IOException; |
| 41 | +import java.io.InputStream; | |
| 36 | 42 | import java.net.URLConnection; |
| 37 | 43 | import java.text.SimpleDateFormat; |
| 38 | 44 | import java.util.*; |
| ... | ... | @@ -226,15 +232,22 @@ public class DdexamServiceImpl implements DdexamService { |
| 226 | 232 | public Map initializationAll2(Long userName){ |
| 227 | 233 | Long start = System.currentTimeMillis(); |
| 228 | 234 | Map m = new HashMap<>(); |
| 229 | - String t = String.valueOf(userName).substring(0,7); | |
| 235 | + | |
| 230 | 236 | |
| 231 | 237 | try { //用户当天分配完直接改状态 无二次分配的可能 |
| 232 | - List<SysUser> userList = sysUserRepository.findBySusUser(t); //已有的用户 不考虑用户角色表 正常情况下创建必分配 | |
| 238 | + List<SysUser> userList=new ArrayList<>(); | |
| 239 | + if(userName!=null){ | |
| 240 | + userList= sysUserRepository.findBySusUser(String.valueOf(userName)); | |
| 241 | + }else { | |
| 242 | + SysUser loginUser = SecurityUtils.getCurrentUser(); | |
| 243 | + userList= sysUserRepository.findByParentID(String.valueOf(loginUser.getId())); | |
| 244 | + } | |
| 233 | 245 | if (userList.size() > 0) { |
| 234 | 246 | //已有的人检查分配线路 |
| 247 | + List<SysUser> finalUserList = userList; | |
| 235 | 248 | new Thread() { |
| 236 | 249 | public synchronized void run() { |
| 237 | - if (snt(userList)) { | |
| 250 | + if (snt(finalUserList)) { | |
| 238 | 251 | kk(); |
| 239 | 252 | } |
| 240 | 253 | } |
| ... | ... | @@ -444,7 +457,153 @@ public class DdexamServiceImpl implements DdexamService { |
| 444 | 457 | ScheduleRealInfoRepository.saveAll(sriList); |
| 445 | 458 | } |
| 446 | 459 | |
| 460 | + public String importExcel(File file, Map map) { | |
| 461 | + List<String> textList = new ArrayList<>(); | |
| 462 | + List<SysUser> userList = new ArrayList<>(); | |
| 463 | + | |
| 464 | + try{ | |
| 465 | + InputStream fs = new FileInputStream(file); | |
| 466 | + XSSFWorkbook wb = new XSSFWorkbook(fs); | |
| 467 | + XSSFSheet sheet = wb.getSheetAt(0); | |
| 468 | + // 取得总行数 | |
| 469 | + int rowNum = sheet.getLastRowNum() + 1; | |
| 470 | + // 取得总列数 | |
| 471 | + int cellNum = sheet.getRow(0).getLastCellNum(); | |
| 472 | + XSSFRow row = null; | |
| 473 | + XSSFCell cell = null; | |
| 474 | + for(int i = 1; i < rowNum; i++){ | |
| 475 | + row = sheet.getRow(i); | |
| 476 | + if (row == null){ | |
| 477 | + continue; | |
| 478 | + } | |
| 479 | + String text = ""; | |
| 480 | + for(int j = 0; j < cellNum; j++){ | |
| 481 | + row.getCell(j).setCellType(1); | |
| 482 | + cell = row.getCell(j); | |
| 483 | + if(cell == null){ | |
| 484 | + text += ","; | |
| 485 | + continue; | |
| 486 | + } | |
| 487 | + text += String.valueOf(cell) + ","; | |
| 488 | + } | |
| 489 | + String[] split = (text+";").split(","); | |
| 490 | + String str = ""; | |
| 491 | + for(int j = 0; j < split.length && j < 5; j++){ | |
| 492 | + str += split[j]; | |
| 493 | + } | |
| 494 | + if(str.trim().length() == 0) | |
| 495 | + continue; | |
| 496 | + textList.add(text + ";"); | |
| 497 | + } | |
| 498 | + SysUser loginUser = SecurityUtils.getCurrentUser(); | |
| 499 | + for(int i = 0; i < textList.size(); i++) { | |
| 500 | + String text = textList.get(i); | |
| 501 | + String[] split = text.split(","); | |
| 502 | + SysUser user = new SysUser(); | |
| 503 | + user.setCreateDate(new Date()); | |
| 504 | + user.setEnabled(true); | |
| 505 | + user.setName(split[1].trim()); | |
| 506 | + user.setPassword(new BCryptPasswordEncoder(4).encode("123456")); | |
| 507 | + user.setUserName(split[0].trim()); | |
| 508 | + user.setKsstatus("1"); //状态 表示今日账户已用 | |
| 509 | + user.setLastLoginDate(new Date()); | |
| 510 | + user.setParentID(String.valueOf(loginUser.getId())); | |
| 511 | + userList.add(user); | |
| 512 | + } | |
| 513 | + List<SysUser> users = sysUserRepository.findBySusUserAll(); | |
| 514 | + Iterator<SysUser> it=userList.iterator(); | |
| 515 | + while (it.hasNext()){ | |
| 516 | + SysUser u=it.next(); | |
| 517 | + for (SysUser user : users) { | |
| 518 | + if(u.getUserName().equals(user.getUserName())){ | |
| 519 | + it.remove(); | |
| 520 | + continue; | |
| 521 | + } | |
| 522 | + } | |
| 523 | + } | |
| 524 | + boolean flag = true; | |
| 525 | + for (SysUser user : userList) { | |
| 526 | + if(!createUser(user)){ | |
| 527 | + flag=false; | |
| 528 | + } | |
| 529 | + } | |
| 530 | + if(!flag){ | |
| 531 | + return "文件导入失败"; | |
| 532 | + } | |
| 533 | + }catch (Exception e) { | |
| 534 | + // TODO Auto-generated catch block | |
| 535 | + e.printStackTrace(); | |
| 536 | + return "文件导入失败"; | |
| 537 | + } finally { | |
| 538 | + file.delete(); | |
| 539 | + } | |
| 540 | + | |
| 541 | + return "导入文件成功"; | |
| 542 | + | |
| 543 | + } | |
| 544 | + | |
| 447 | 545 | |
| 448 | - | |
| 546 | + public synchronized Boolean createUser(SysUser user){ | |
| 547 | + sysUserRepository.save(user); //用户存库 | |
| 548 | + BsthCSysUserRoles userRoles = new BsthCSysUserRoles(); | |
| 549 | + userRoles.setUsers(user.getId()); | |
| 550 | + userRoles.setRoles(73); //统一用73考生 | |
| 551 | + bsthCSysUserRolesRepository.save(userRoles); //权限存库 | |
| 552 | + List<LineConfigSt> lineConfigList = lineConfigStRepository.findAll(); //线调 线路相关配置信息 | |
| 553 | + Integer linebumber = lineRepository.findAll().size(); //线路数量 线路code | |
| 554 | + String [] mtline = {"A线","B线","C线","D线","E线","F线"}; //对应模板6条线 换成线路name | |
| 555 | + List<LineInformationSt> litst = (List<LineInformationSt>) LineInformationStRepository.findAll(); //所有模板线路标准和线路 | |
| 556 | + if(litst.size() != 6){ | |
| 557 | + return false; | |
| 558 | + } | |
| 559 | + String lineCodeStr = ""; | |
| 560 | + for(int j = 0 ; j < litst.size() ; j++){ //6个 <6 | |
| 561 | + LineSt linest = litst.get(j).getLine(); //旧line | |
| 562 | + LineInformationSt Limst = litst.get(j); | |
| 563 | + Line line = new Line(); | |
| 564 | + BeanUtils.copyProperties(linest,line); //copy | |
| 565 | + Integer linecodeId = linebumber++ ; | |
| 566 | + line.setId(linecodeId); | |
| 567 | + line.setLineCode(linecodeId.toString()); | |
| 568 | + line.setName(mtline[j]+"-"+user.getUserName()); | |
| 569 | + line.setCoLineCode(linest.getLineCode()); | |
| 570 | + lineRepository.save(line); //线路添加 | |
| 571 | + //----------------线路--------------------------// | |
| 572 | + LineInformation lifat = new LineInformation(); //线路标准 | |
| 573 | + BeanUtils.copyProperties(Limst,lifat); | |
| 574 | + lifat.setLine(line); | |
| 575 | + lineInformationRepository.save(lifat); //线路标准信息条件 | |
| 576 | + //-------------------线路标准-----------------------// | |
| 577 | + for(LineConfigSt cfgt : lineConfigList){ | |
| 578 | + if(cfgt.getLine().getLineCode().equals(linest.getLineCode())){ | |
| 579 | + LineConfig config = new LineConfig(); | |
| 580 | + BeanUtils.copyProperties(cfgt,config); //copy | |
| 581 | + config.setLine(line); | |
| 582 | + lineConfigRepository.save(config); | |
| 583 | + } | |
| 584 | + } | |
| 585 | + //-------------------线调 线路相关配置信息-----------------------// | |
| 449 | 586 | |
| 587 | + List<StationRouteSt> srstList = stationRouteStRepository.findByLine(linest.getLineCode()); | |
| 588 | + List<StationRoute> srstListAll = new ArrayList<>(); | |
| 589 | + for(StationRouteSt route : srstList){ | |
| 590 | + StationRoute srt = new StationRoute(); | |
| 591 | + BeanUtils.copyProperties(route,srt); //copy | |
| 592 | + srt.setLine(line); | |
| 593 | + srt.setLineCode(linecodeId.toString()); | |
| 594 | + srstListAll.add(srt); | |
| 595 | + } | |
| 596 | + stationRouteRepository.saveAll(srstListAll);//添加站点 | |
| 597 | + //-------------------站点-----------------------// | |
| 598 | + lineCodeStr += linecodeId.toString()+","; //线调线路 | |
| 599 | + inforealType(line); | |
| 600 | + } | |
| 601 | + RealControAuthority raty = new RealControAuthority(); | |
| 602 | + raty.setUserId(user.getId()); | |
| 603 | + raty.setLineCodeStr(lineCodeStr); | |
| 604 | + raty.setPattern(1); //可用 | |
| 605 | + realControAuthorityRepository.save(raty); | |
| 606 | + //-------------------分配本次线调权限-----------------------// | |
| 607 | + return true; | |
| 608 | + } | |
| 450 | 609 | } | ... | ... |
src/main/resources/static/pages/ddexam/index.html
| ... | ... | @@ -47,13 +47,13 @@ |
| 47 | 47 | overflow-y:hidden; |
| 48 | 48 | } |
| 49 | 49 | </style> |
| 50 | - | |
| 50 | +<script src="/assets/js/ajaxfileupload/ajaxfileupload.js"></script> | |
| 51 | +<link rel="stylesheet" href="/assets/js/ajaxfileupload/ajaxfileupload.css" /> | |
| 51 | 52 | <div class="row"> |
| 52 | 53 | <div class="col-md-12 st "> |
| 53 | 54 | <div class="portlet light porttlet-fit bordered at img1"> |
| 54 | 55 | <div class="tes"> |
| 55 | - | |
| 56 | - <label class="col-md-12 sizell">请输入账号格式:</label> | |
| 56 | + <label class="col-md-12 sizell">请输入学号:</label> | |
| 57 | 57 | <div class="col-md-9 scm"> |
| 58 | 58 | <input id="userName" type="text" class="form-control" name="rnumber" autocomplete="off" oninput="value=value.replace(/[^\d]/g,'')"/> |
| 59 | 59 | |
| ... | ... | @@ -68,6 +68,9 @@ |
| 68 | 68 | |
| 69 | 69 | <div class="col-md-12 nt" > |
| 70 | 70 | <button type="button" class="btn btn-primary textk" id="onckil">创建账号</button> |
| 71 | + <button type="button" class="btn btn-primary textk" id="upload"><i class="fa fa-file-excel-o"></i> | |
| 72 | + 批量创建 | |
| 73 | + </button> | |
| 71 | 74 | <button type="button" class="btn btn-primary textk" id="onckil2">初始化当天排班</button> |
| 72 | 75 | </div> |
| 73 | 76 | <div class="col-md-12 nt" > |
| ... | ... | @@ -212,6 +215,10 @@ |
| 212 | 215 | }) |
| 213 | 216 | } |
| 214 | 217 | |
| 218 | + //导入 | |
| 219 | + $("#upload").on("click", function(){ | |
| 220 | + $.get('upload.html', function(m){$(pjaxContainer).append(m);}); | |
| 221 | + }); | |
| 215 | 222 | |
| 216 | 223 | |
| 217 | 224 | </script> |
| 218 | 225 | \ No newline at end of file | ... | ... |
src/main/resources/static/pages/ddexam/upload.html
0 → 100644
| 1 | +<div class="modal fade" id="uploadFile" tabindex="-1" role="basic" | |
| 2 | + aria-hidden="true"> | |
| 3 | + <div class="modal-dialog"> | |
| 4 | + <div class="modal-content"> | |
| 5 | + <div class="modal-header"> | |
| 6 | + <button type="button" class="close" data-dismiss="modal" | |
| 7 | + aria-hidden="true"></button> | |
| 8 | + <h4 class="modal-title">导入Excel</h4> | |
| 9 | + </div> | |
| 10 | + <div class="modal-body"> | |
| 11 | + <form class="form-horizontal" role="form" id="excelFile" method="post" | |
| 12 | + action="" enctype="multipart/form-data"> | |
| 13 | + <input type="hidden" name="groupType" value="3"> | |
| 14 | + <div class="alert alert-danger display-hide"> | |
| 15 | + <button class="close" data-close="alert"></button> | |
| 16 | + 您的输入有误,请检查下面的输入项 | |
| 17 | + </div> | |
| 18 | + <div class="form-body"> | |
| 19 | + <div class="form-group"> | |
| 20 | + <label class="col-md-4 control-label">选择文件</label> | |
| 21 | + <div class="col-md-6"> | |
| 22 | + <input type="file" name="file" id="file" | |
| 23 | + accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/> | |
| 24 | + | |
| 25 | + </div> | |
| 26 | + </div> | |
| 27 | + </div> | |
| 28 | + </form> | |
| 29 | + </div> | |
| 30 | + <div class="modal-footer"> | |
| 31 | + <button type="button" class="btn default" data-dismiss="modal">取消</button> | |
| 32 | + <button type="button" class="btn btn-primary" id="submit">确认导入</button> | |
| 33 | + </div> | |
| 34 | + </div> | |
| 35 | + </div> | |
| 36 | +</div> | |
| 37 | + | |
| 38 | +</script> | |
| 39 | +<script data-exclude=1> | |
| 40 | + $(function() { | |
| 41 | + var form = $('#excelFile'); | |
| 42 | + var error = $('.alert-danger', form); | |
| 43 | + | |
| 44 | + | |
| 45 | + var curDate = new Date(); | |
| 46 | + var preDate = new Date(curDate.getTime() - 24*60*60*1000); | |
| 47 | + $("#date").val(preDate); | |
| 48 | + $("#date").datetimepicker({ | |
| 49 | + format : 'YYYY-MM-DD', | |
| 50 | + locale : 'zh-cn', | |
| 51 | + maxDate : preDate | |
| 52 | + }); | |
| 53 | + | |
| 54 | + //modal 显示事件 | |
| 55 | + $('#uploadFile').on('show.bs.modal', function(){ | |
| 56 | + }) | |
| 57 | + .modal('show'); | |
| 58 | + | |
| 59 | + $('#submit').on('click', function() { | |
| 60 | + | |
| 61 | + var j = layer.load(2); | |
| 62 | + var param = { | |
| 63 | + }; | |
| 64 | + $.ajaxFileUpload({ | |
| 65 | + url : '/ddexam/uploadFile', | |
| 66 | + secureuri : false, | |
| 67 | + fileElementId : 'file', | |
| 68 | + dataType : 'json', | |
| 69 | + data : param, | |
| 70 | + success : function(data) { | |
| 71 | + layer.close(j); | |
| 72 | + alert(data.result); | |
| 73 | +// alert("文件导入成功"); | |
| 74 | + $('#uploadFile').modal('hide'); | |
| 75 | + $('tr.filter .filter-submit').click(); | |
| 76 | + }, | |
| 77 | + error : function(data, status, e) { | |
| 78 | + layer.close(j); | |
| 79 | + alert("文件导入失败"); | |
| 80 | + } | |
| 81 | + }) | |
| 82 | + }); | |
| 83 | + | |
| 84 | + }); | |
| 85 | +</script> | |
| 0 | 86 | \ No newline at end of file | ... | ... |