Commit 8526b84d2d22dd16771d55ac355d1c0aef97ebb4
1 parent
7c8b0155
场外加油导入
Showing
7 changed files
with
235 additions
and
1 deletions
src/main/java/com/bsth/controller/oil/CwjyController.java
| 1 | package com.bsth.controller.oil; | 1 | package com.bsth.controller.oil; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import java.io.File; | ||
| 4 | import java.util.Date; | 5 | import java.util.Date; |
| 5 | import java.util.HashMap; | 6 | import java.util.HashMap; |
| 6 | import java.util.List; | 7 | import java.util.List; |
| @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
| 11 | import org.springframework.web.bind.annotation.RequestMethod; | 12 | import org.springframework.web.bind.annotation.RequestMethod; |
| 12 | import org.springframework.web.bind.annotation.RequestParam; | 13 | import org.springframework.web.bind.annotation.RequestParam; |
| 13 | import org.springframework.web.bind.annotation.RestController; | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | +import org.springframework.web.multipart.MultipartFile; | ||
| 14 | 16 | ||
| 15 | import com.bsth.common.ResponseCode; | 17 | import com.bsth.common.ResponseCode; |
| 16 | import com.bsth.controller.BaseController; | 18 | import com.bsth.controller.BaseController; |
| @@ -22,6 +24,7 @@ import com.bsth.entity.sys.SysUser; | @@ -22,6 +24,7 @@ import com.bsth.entity.sys.SysUser; | ||
| 22 | import com.bsth.security.util.SecurityUtils; | 24 | import com.bsth.security.util.SecurityUtils; |
| 23 | import com.bsth.service.oil.CwjyService; | 25 | import com.bsth.service.oil.CwjyService; |
| 24 | import com.bsth.util.PageObject; | 26 | import com.bsth.util.PageObject; |
| 27 | +import com.google.common.io.Files; | ||
| 25 | 28 | ||
| 26 | @RestController | 29 | @RestController |
| 27 | @RequestMapping("cwjy") | 30 | @RequestMapping("cwjy") |
| @@ -95,4 +98,23 @@ public class CwjyController extends BaseController<Cwjy, Integer>{ | @@ -95,4 +98,23 @@ public class CwjyController extends BaseController<Cwjy, Integer>{ | ||
| 95 | return maps; | 98 | return maps; |
| 96 | } | 99 | } |
| 97 | 100 | ||
| 101 | + /* | ||
| 102 | + * 场外加油导入 | ||
| 103 | + */ | ||
| 104 | + @RequestMapping(value = "/uploadFile",method = RequestMethod.POST) | ||
| 105 | + public String uploadFile(MultipartFile file, String gsbm_, String gsName, | ||
| 106 | + String fgsbm_, String fgsName) throws Exception{ | ||
| 107 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 108 | + File newFile = new File( | ||
| 109 | + getDataImportClasspath() + File.separator + | ||
| 110 | + file.getOriginalFilename()); | ||
| 111 | + Files.write(file.getBytes(), newFile); | ||
| 112 | + String result = service.importExcel(newFile, gsbm_, gsName); | ||
| 113 | + return "{\"result\":" + "\""+result+"\"}"; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public String getDataImportClasspath(){ | ||
| 117 | + return this.getClass().getResource("/").getPath() + "/static/pages/oil"; | ||
| 118 | + } | ||
| 119 | + | ||
| 98 | } | 120 | } |
src/main/java/com/bsth/repository/oil/CwjyRepository.java
| @@ -33,5 +33,21 @@ public interface CwjyRepository extends BaseRepository<Cwjy, Integer>{ | @@ -33,5 +33,21 @@ public interface CwjyRepository extends BaseRepository<Cwjy, Integer>{ | ||
| 33 | @Query(value="select * from bsth_c_cwjy where nbbm like %?1% and gsdm like %?2% and fgsdm like %?3% and line =?4",nativeQuery=true) | 33 | @Query(value="select * from bsth_c_cwjy where nbbm like %?1% and gsdm like %?2% and fgsdm like %?3% and line =?4",nativeQuery=true) |
| 34 | List<Cwjy> selectAll_s(String nbbm,String gsdm,String fgsdm,String line); | 34 | List<Cwjy> selectAll_s(String nbbm,String gsdm,String fgsdm,String line); |
| 35 | 35 | ||
| 36 | + | ||
| 37 | + @Query(value="SELECT jzl FROM bsth_c_ylxxb where gsdm = ?1 and yyrq = ?2 and nbbm = ?3 and jylx = '1' ",nativeQuery=true) | ||
| 38 | + List<Double> import_queryBySame( String gsbm, String rq, String nbbm); | ||
| 39 | + | ||
| 40 | + @Transactional | ||
| 41 | + @Modifying | ||
| 42 | + @Query(value="INSERT INTO bsth_c_ylxxb("+ | ||
| 43 | + "gsdm, yyrq, nbbm, jzl, stationid, bz, createtime, nylx, jylx)" + | ||
| 44 | + " VALUES(" + | ||
| 45 | + "?1,str_to_date(?2,'%Y-%m-%d'),?3,?4,?5,?6,str_to_date(?7,'%Y-%m-%d %H:%i:%s'), '0', '1') ", nativeQuery=true) | ||
| 46 | + void import_insertData(String gsbm, String rq, String nbbm, String jzl, String jyz, String remarks, String createtime); | ||
| 47 | + | ||
| 48 | + @Transactional | ||
| 49 | + @Modifying | ||
| 50 | + @Query(value="UPDATE bsth_c_ylxxb set jzl = ?1 where gsdm = ?2 and yyrq = ?3 and nbbm = ?4 and jylx = '1' ",nativeQuery=true) | ||
| 51 | + void import_UpdateJzl(String jdl, String gsbm, String rq, String nbbm); | ||
| 36 | 52 | ||
| 37 | } | 53 | } |
src/main/java/com/bsth/service/oil/CwjyService.java
| 1 | package com.bsth.service.oil; | 1 | package com.bsth.service.oil; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import java.io.File; | ||
| 4 | import java.util.List; | 5 | import java.util.List; |
| 5 | import java.util.Map; | 6 | import java.util.Map; |
| 6 | 7 | ||
| @@ -18,4 +19,6 @@ public interface CwjyService extends BaseService<Cwjy, Integer>{ | @@ -18,4 +19,6 @@ public interface CwjyService extends BaseService<Cwjy, Integer>{ | ||
| 18 | Map<String, Object> savejzl(Map<String, Object> map) throws Exception ; | 19 | Map<String, Object> savejzl(Map<String, Object> map) throws Exception ; |
| 19 | 20 | ||
| 20 | int checkNbbm(Cwjy t); | 21 | int checkNbbm(Cwjy t); |
| 22 | + | ||
| 23 | + public String importExcel(File file, String gsbm_, String gsName); | ||
| 21 | } | 24 | } |
src/main/java/com/bsth/service/oil/impl/CwjyServiceImpl.java
| 1 | package com.bsth.service.oil.impl; | 1 | package com.bsth.service.oil.impl; |
| 2 | 2 | ||
| 3 | +import java.io.File; | ||
| 4 | +import java.io.FileInputStream; | ||
| 3 | import java.sql.ResultSet; | 5 | import java.sql.ResultSet; |
| 4 | import java.sql.SQLException; | 6 | import java.sql.SQLException; |
| 7 | +import java.text.DecimalFormat; | ||
| 5 | import java.text.ParseException; | 8 | import java.text.ParseException; |
| 6 | import java.text.SimpleDateFormat; | 9 | import java.text.SimpleDateFormat; |
| 7 | import java.util.ArrayList; | 10 | import java.util.ArrayList; |
| @@ -14,6 +17,11 @@ import java.util.Map; | @@ -14,6 +17,11 @@ import java.util.Map; | ||
| 14 | import javax.transaction.Transactional; | 17 | import javax.transaction.Transactional; |
| 15 | 18 | ||
| 16 | import org.apache.commons.lang3.StringEscapeUtils; | 19 | import org.apache.commons.lang3.StringEscapeUtils; |
| 20 | +import org.apache.poi.hssf.usermodel.HSSFCell; | ||
| 21 | +import org.apache.poi.hssf.usermodel.HSSFRow; | ||
| 22 | +import org.apache.poi.hssf.usermodel.HSSFSheet; | ||
| 23 | +import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
| 24 | +import org.apache.poi.poifs.filesystem.POIFSFileSystem; | ||
| 17 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
| 18 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 27 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -457,5 +465,79 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | @@ -457,5 +465,79 @@ public class CwjyServiceImpl extends BaseServiceImpl<Cwjy,Integer> implements Cw | ||
| 457 | } | 465 | } |
| 458 | 466 | ||
| 459 | 467 | ||
| 460 | - | 468 | + @Override |
| 469 | + public String importExcel(File file, String gsbm, String gsName) { | ||
| 470 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 471 | + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
| 472 | + DecimalFormat df = new DecimalFormat("######0.00"); | ||
| 473 | + List<String> textList = new ArrayList<String>(); | ||
| 474 | + try { | ||
| 475 | + POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); | ||
| 476 | + HSSFWorkbook wb = new HSSFWorkbook(fs); | ||
| 477 | + HSSFSheet sheet = wb.getSheetAt(0); | ||
| 478 | + // 取得总行数 | ||
| 479 | + int rowNum = sheet.getLastRowNum() + 1; | ||
| 480 | + // 取得总列数 | ||
| 481 | + int cellNum = sheet.getRow(0).getLastCellNum(); | ||
| 482 | + HSSFRow row = null; | ||
| 483 | + HSSFCell cell = null; | ||
| 484 | + for(int i = 2; i < rowNum; i++){ | ||
| 485 | + row = sheet.getRow(i); | ||
| 486 | + if (row == null){ | ||
| 487 | + continue; | ||
| 488 | + } | ||
| 489 | + String text = ""; | ||
| 490 | + for(int j = 0; j < cellNum; j++){ | ||
| 491 | + cell = row.getCell(j); | ||
| 492 | + if(cell == null){ | ||
| 493 | + text += ","; | ||
| 494 | + continue; | ||
| 495 | + } | ||
| 496 | + text += String.valueOf(cell) + ","; | ||
| 497 | + } | ||
| 498 | + String[] split = (text+";").split(","); | ||
| 499 | + String str = ""; | ||
| 500 | + for(int j = 0; j < split.length && j < 5; j++){ | ||
| 501 | + str += split[j]; | ||
| 502 | + } | ||
| 503 | + if(str.trim().length() == 0){ | ||
| 504 | + continue; | ||
| 505 | + } | ||
| 506 | + textList.add(text + ";"); | ||
| 507 | + } | ||
| 508 | + for(int i = 0; i < textList.size(); i++){ | ||
| 509 | + String text = textList.get(i); | ||
| 510 | + System.out.println(text); | ||
| 511 | + String[] split = text.split(","); | ||
| 512 | + String rq = split[0].trim(); | ||
| 513 | + String nbbm = split[1].trim(); | ||
| 514 | + double jzl = Double.valueOf(split[2].trim().length()!=0?split[2]:"0"); | ||
| 515 | + String jyz = split[3].trim(); | ||
| 516 | + String remarks = split[4].trim(); | ||
| 517 | + if(rq.trim().length() == 0){ | ||
| 518 | + rq = sdf.format(new Date()); | ||
| 519 | + } | ||
| 520 | + | ||
| 521 | + List<Double> jzl_ = repository.import_queryBySame(gsbm, rq, nbbm); | ||
| 522 | +// | ||
| 523 | + if(jzl_.size() == 0){ | ||
| 524 | + repository.import_insertData(gsbm, rq, nbbm, | ||
| 525 | + df.format(jzl), jyz, remarks, sd.format(new Date())); | ||
| 526 | + }else{ | ||
| 527 | + repository.import_UpdateJzl(df.format(jzl), gsbm, rq, nbbm); | ||
| 528 | + } | ||
| 529 | + } | ||
| 530 | + wb.close(); | ||
| 531 | + fs.close(); | ||
| 532 | + } catch (Exception e) { | ||
| 533 | + // TODO Auto-generated catch block | ||
| 534 | + e.printStackTrace(); | ||
| 535 | + return "文件导入失败"; | ||
| 536 | + } finally { | ||
| 537 | + file.delete(); | ||
| 538 | + } | ||
| 539 | + return "文件导入成功"; | ||
| 540 | + } | ||
| 541 | + | ||
| 542 | + | ||
| 461 | } | 543 | } |
src/main/resources/static/pages/forms/export/import_Jygl.xls
0 → 100644
No preview for this file type
src/main/resources/static/pages/oil/jyglList.html
| @@ -22,6 +22,9 @@ | @@ -22,6 +22,9 @@ | ||
| 22 | class="caption-subject font-dark sbold uppercase">场外加油管理</span> | 22 | class="caption-subject font-dark sbold uppercase">场外加油管理</span> |
| 23 | </div> | 23 | </div> |
| 24 | <div class="actions"> | 24 | <div class="actions"> |
| 25 | + <button type="button" class="btn btn-circle blue" id="upload"><i class="fa fa-file-excel-o"></i> | ||
| 26 | + 导入Excel | ||
| 27 | + </button> | ||
| 25 | <!-- <a class="btn btn-circle blue" href="cylAdd.html" data-pjax><i class="fa fa-plus"></i> 添加</a> --> | 28 | <!-- <a class="btn btn-circle blue" href="cylAdd.html" data-pjax><i class="fa fa-plus"></i> 添加</a> --> |
| 26 | <button type="button" class="btn btn-circle blue" id="saveButton"><i class="fa fa-minus-square"></i> 保存</button> | 29 | <button type="button" class="btn btn-circle blue" id="saveButton"><i class="fa fa-minus-square"></i> 保存</button> |
| 27 | <!-- <button type="button" class="btn btn-circle red" disabled="disabled" id="removeButton"><i class="fa fa-trash"></i> 删除用户</button> --> | 30 | <!-- <button type="button" class="btn btn-circle red" disabled="disabled" id="removeButton"><i class="fa fa-trash"></i> 删除用户</button> --> |
| @@ -112,6 +115,8 @@ | @@ -112,6 +115,8 @@ | ||
| 112 | </div> | 115 | </div> |
| 113 | </div> | 116 | </div> |
| 114 | 117 | ||
| 118 | +<script src="/assets/js/ajaxfileupload/ajaxfileupload.js"></script> | ||
| 119 | + | ||
| 115 | <script id="jygl_list_temp" type="text/html"> | 120 | <script id="jygl_list_temp" type="text/html"> |
| 116 | {{each list as obj i}} | 121 | {{each list as obj i}} |
| 117 | <tr> | 122 | <tr> |
| @@ -499,4 +504,10 @@ function changeEnabled(id,enabled){ | @@ -499,4 +504,10 @@ function changeEnabled(id,enabled){ | ||
| 499 | } | 504 | } |
| 500 | 505 | ||
| 501 | 506 | ||
| 507 | +//导入 | ||
| 508 | +$("#upload").on("click", function(){ | ||
| 509 | + $.get('upload.html', function(m){$(pjaxContainer).append(m);}); | ||
| 510 | +}); | ||
| 511 | + | ||
| 512 | + | ||
| 502 | </script> | 513 | </script> |
| 503 | \ No newline at end of file | 514 | \ No newline at end of file |
src/main/resources/static/pages/oil/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-3 control-label">选择文件</label> | ||
| 21 | + <div class="col-md-9"> | ||
| 22 | + <input type="file" name="file" id="file" | ||
| 23 | + accept="application/vnd.ms-excel"/> | ||
| 24 | + <input type=hidden name="gsbm_" id="gsbm_"> | ||
| 25 | + <input type="hidden" name="gsName" id="gsName"> | ||
| 26 | +<!-- <input type="hidden" name="fgsbm_" id="fgsbm_"> --> | ||
| 27 | +<!-- <input type="hidden" name="fgsName" id="fgsName"> --> | ||
| 28 | + </div> | ||
| 29 | + </div> | ||
| 30 | + </div> | ||
| 31 | + </form> | ||
| 32 | + </div> | ||
| 33 | + <div class="modal-footer"> | ||
| 34 | + <button type="button" class="btn default" id="downLoad">下载模板</button> | ||
| 35 | + <button type="button" class="btn default" data-dismiss="modal">取消</button> | ||
| 36 | + <button type="button" class="btn btn-primary" id="submit">确认导入</button> | ||
| 37 | + </div> | ||
| 38 | + </div> | ||
| 39 | + </div> | ||
| 40 | +</div> | ||
| 41 | +<script id="res_tbody_temp" type="text/html"> | ||
| 42 | + | ||
| 43 | +</script> | ||
| 44 | +<script data-exclude=1> | ||
| 45 | + $(function() { | ||
| 46 | + var form = $('#excelFile'); | ||
| 47 | + var error = $('.alert-danger', form); | ||
| 48 | + | ||
| 49 | + $('#gsbm_').val($("select[name=gsdm_like]").val()); | ||
| 50 | + $('#gsName').val($("select[name=gsdm_like]").find("option:selected").text()); | ||
| 51 | +// $('#fgsbm_').val($("#fgsbm").val()); | ||
| 52 | +// $('#fgsName').val($("#fgsbm").find("option:selected").text()); | ||
| 53 | + | ||
| 54 | + //modal 显示事件 | ||
| 55 | + $('#uploadFile').on('show.bs.modal', function(){ | ||
| 56 | + }) | ||
| 57 | + .modal('show'); | ||
| 58 | + | ||
| 59 | + //提交 | ||
| 60 | +// $('#submit').on('click', function() { | ||
| 61 | +// form.submit(); | ||
| 62 | +// }); | ||
| 63 | + | ||
| 64 | + $('#submit').on('click', function() { | ||
| 65 | + var j = layer.load(2); | ||
| 66 | + var param = {}; | ||
| 67 | + param.uploadDir = 'upload'; | ||
| 68 | + param["gsbm_"] = $('#gsbm_').val(); | ||
| 69 | + param["gsName"] = $('#gsName').val(); | ||
| 70 | +// param["fgsbm_"] = $('#fgsbm_').val(); | ||
| 71 | +// param["fgsName"] = $('#fgsName').val(); | ||
| 72 | + $.ajaxFileUpload({ | ||
| 73 | + url : '/cwjy/uploadFile', | ||
| 74 | + secureuri : false, | ||
| 75 | + fileElementId : 'file', | ||
| 76 | + dataType : 'json', | ||
| 77 | + data : param, | ||
| 78 | + success : function(data) { | ||
| 79 | + layer.close(j); | ||
| 80 | + alert(data.result); | ||
| 81 | +// alert("文件导入成功"); | ||
| 82 | + $('#uploadFile').modal('hide'); | ||
| 83 | + $('tr.filter .filter-submit').click(); | ||
| 84 | + }, | ||
| 85 | + error : function(data, status, e) { | ||
| 86 | + layer.close(j); | ||
| 87 | + alert("文件导入失败"); | ||
| 88 | + } | ||
| 89 | + }) | ||
| 90 | + }); | ||
| 91 | + | ||
| 92 | + $('#downLoad').on('click', function(){ | ||
| 93 | + window.open("/downloadFile/downloadModel?fileName=import_Jygl"); | ||
| 94 | + }); | ||
| 95 | + | ||
| 96 | + function getCurrSelNode(){ | ||
| 97 | + return $.jstree.reference("#modules_tree").get_selected(true); | ||
| 98 | + } | ||
| 99 | + }); | ||
| 100 | +</script> | ||
| 0 | \ No newline at end of file | 101 | \ No newline at end of file |