|
@@ -65,22 +65,24 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
private ExcelUtil excelUtil;
|
|
|
@Autowired
|
|
|
private DataUtil dateUtil;
|
|
|
+ @Autowired
|
|
|
+ private TxtUtil txtUtil;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
- * @Method : listEarmark
|
|
|
+ * @Method : listEarmark
|
|
|
* @Description : 展示列表
|
|
|
- * @Params : [pageSize]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/29
|
|
|
- * @Time : 21:14
|
|
|
+ * @Params : [pageSize]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 21:14
|
|
|
*/
|
|
|
@Override
|
|
|
public Result listEarmark(int pageSize) {
|
|
|
//
|
|
|
List<EtEarmarkEntity> earmarkEntityList = earmarkRepo.listEarmark(pageSize);
|
|
|
- return new Result(ResultCode.SUCCESS,earmarkEntityList);
|
|
|
+ return new Result(ResultCode.SUCCESS, earmarkEntityList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -125,19 +127,18 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
return criteriaQuery.orderBy(orders).getRestriction();
|
|
|
};
|
|
|
//分页
|
|
|
- Pageable pageable = PageRequest.of( pageNo - 1, pageSize);
|
|
|
+ Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
|
|
|
return new Result(ResultCode.SUCCESS, earmarkRepo.findAll(sf, pageable));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : getEarmark
|
|
|
+ * @Method : getEarmark
|
|
|
* @Description : 下载耳标号
|
|
|
- * @Params : [applyId]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/29
|
|
|
- * @Time : 21:14
|
|
|
+ * @Params : [applyId]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 21:14
|
|
|
*/
|
|
|
@Override
|
|
|
public Result getEarmark(int applyId) throws IOException {
|
|
@@ -146,17 +147,17 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
// System.out.println("requestXML="+requestXML);
|
|
|
|
|
|
// 调用接口返回结果
|
|
|
- String earMarkReponseXML = soap.callSoap(requestXML,webServiceUrl);
|
|
|
+ String earMarkReponseXML = soap.callSoap(requestXML, webServiceUrl);
|
|
|
// System.out.println("earMarkReponseXML="+earMarkReponseXML);
|
|
|
|
|
|
// 解析结果
|
|
|
JSONArray downloadEarmarkJa = earmarkTask.parseEarMarkReponseXML(earMarkReponseXML);
|
|
|
// 耳标入库
|
|
|
JSONArray newEarmarkJa = filterEarmark(downloadEarmarkJa);
|
|
|
- if(newEarmarkJa.size() == 0){
|
|
|
- return new Result(Const.CODE_NO_NEW_EARMARK,Const.NO_NEW_EARMARK,false);
|
|
|
+ if (newEarmarkJa.size() == 0) {
|
|
|
+ return new Result(Const.CODE_NO_NEW_EARMARK, Const.NO_NEW_EARMARK, false);
|
|
|
}
|
|
|
- for(int a=0;a<newEarmarkJa.size();a++){
|
|
|
+ for (int a = 0; a < newEarmarkJa.size(); a++) {
|
|
|
JSONObject earmarkJo = newEarmarkJa.getJSONObject(a);
|
|
|
EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
earmarkEntity.setEarmarkId(earmarkJo.getString("earmarkId"));
|
|
@@ -170,18 +171,17 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
earmarkEntity.setSetUploadState(0);
|
|
|
earmarkRepo.saveAndFlush(earmarkEntity);
|
|
|
}
|
|
|
- return new Result(Const.CODE_OK,"本次下载"+newEarmarkJa.size()+"个新耳标号数据.",false);
|
|
|
+ return new Result(Const.CODE_OK, "本次下载" + newEarmarkJa.size() + "个新耳标号数据.", false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setUpdateDownState
|
|
|
+ * @Method : setUpdateDownState
|
|
|
* @Description : 设置耳标已下载状态
|
|
|
- * @Params : [earmarkIDs]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/29
|
|
|
- * @Time : 23:00
|
|
|
+ * @Params : [earmarkIDs]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 23:00
|
|
|
*/
|
|
|
@Override
|
|
|
public Result setUpdateDownState(String earmarkIDs) throws UnsupportedEncodingException {
|
|
@@ -189,31 +189,31 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
String requestXML = earmarkTask.getUpdateDownStateRequestXML(earmarkIDs);
|
|
|
//远程调用返回结果
|
|
|
String reponseXML = "";
|
|
|
- reponseXML = soap.callSoap(requestXML,webServiceUrl);
|
|
|
+ reponseXML = soap.callSoap(requestXML, webServiceUrl);
|
|
|
// test
|
|
|
// reponseXML = earmarkTask.TestParseUpdateDownStateXML();
|
|
|
//解析
|
|
|
String updateDownState = earmarkTask.parseUpdateDownStateXML(reponseXML);
|
|
|
// 入库
|
|
|
- if(updateDownState.trim().equalsIgnoreCase("false")){
|
|
|
- return new Result(Const.CODE_UPDATE_EARMARK_DOWN_STATE_FAIL,Const.UPDATE_EARMARK_DOWN_STATE_FAIL,false);
|
|
|
- }else{
|
|
|
+ if (updateDownState.trim().equalsIgnoreCase("false")) {
|
|
|
+ return new Result(Const.CODE_UPDATE_EARMARK_DOWN_STATE_FAIL, Const.UPDATE_EARMARK_DOWN_STATE_FAIL, false);
|
|
|
+ } else {
|
|
|
String[] earmarkIDArray = earmarkIDs.split(",");
|
|
|
- for(int a=0;a<earmarkIDArray.length;a++){
|
|
|
+ for (int a = 0; a < earmarkIDArray.length; a++) {
|
|
|
EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
earmarkEntity.setEarmarkId(earmarkIDArray[a]);
|
|
|
ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("earmark_id" ,ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
- Example example = Example.of(earmarkEntity,matcher);
|
|
|
- Optional optional= earmarkRepo.findOne(example);
|
|
|
- if (optional.isPresent()){
|
|
|
- EtEarmarkEntity earmarkEntity1 = (EtEarmarkEntity) optional.get();
|
|
|
+ .withMatcher("earmark_id", ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
+ Example example = Example.of(earmarkEntity, matcher);
|
|
|
+ Optional optional = earmarkRepo.findOne(example);
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ EtEarmarkEntity earmarkEntity1 = (EtEarmarkEntity) optional.get();
|
|
|
earmarkEntity1.setSetDownState(1);
|
|
|
// earmarkEntity1.setSetDownDate(new Timestamp(new Date().getTime()));
|
|
|
earmarkEntity1.setSetDownDate(new Timestamp(System.currentTimeMillis()));
|
|
|
earmarkRepo.saveAndFlush(earmarkEntity1);
|
|
|
- }else{
|
|
|
- return new Result(Const.CODE_NO_RECORD,Const.NO_RECORD,false);
|
|
|
+ } else {
|
|
|
+ return new Result(Const.CODE_NO_RECORD, Const.NO_RECORD, false);
|
|
|
}
|
|
|
}
|
|
|
return new Result(ResultCode.SUCCESS);
|
|
@@ -221,19 +221,18 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setProduceState
|
|
|
+ * @Method : setProduceState
|
|
|
* @Description : 设置生产状态
|
|
|
- * @Params : [ids]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/29
|
|
|
- * @Time : 23:56
|
|
|
+ * @Params : [ids]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 23:56
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result setProduceState(String ids,int state) {
|
|
|
+ public Result setProduceState(String ids, int state) {
|
|
|
String[] idArray = ids.split(",");
|
|
|
- for(int a=0;a<idArray.length;a++){
|
|
|
+ for (int a = 0; a < idArray.length; a++) {
|
|
|
Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
earmarkEntity.setSetWriteState(state);
|
|
@@ -244,19 +243,18 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setWriteState
|
|
|
+ * @Method : setWriteState
|
|
|
* @Description : 设置写入时间
|
|
|
- * @Params : [ids, state]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/30
|
|
|
- * @Time : 0:02
|
|
|
+ * @Params : [ids, state]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/30
|
|
|
+ * @Time : 0:02
|
|
|
*/
|
|
|
@Override
|
|
|
public Result setWriteState(String ids, int state) {
|
|
|
String[] idArray = ids.split(",");
|
|
|
- for(int a=0;a<idArray.length;a++){
|
|
|
+ for (int a = 0; a < idArray.length; a++) {
|
|
|
Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
earmarkEntity.setSetWriteState(state);
|
|
@@ -267,19 +265,18 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : setPrintState
|
|
|
+ * @Method : setPrintState
|
|
|
* @Description : 设置打码状态
|
|
|
- * @Params : [ids, state]
|
|
|
- * @Return : com.huimv.manage.util.Result
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/10/30
|
|
|
- * @Time : 0:04
|
|
|
+ * @Params : [ids, state]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/30
|
|
|
+ * @Time : 0:04
|
|
|
*/
|
|
|
@Override
|
|
|
public Result setPrintState(String ids, int state) {
|
|
|
String[] idArray = ids.split(",");
|
|
|
- for(int a=0;a<idArray.length;a++){
|
|
|
+ for (int a = 0; a < idArray.length; a++) {
|
|
|
Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
earmarkEntity.setSetPrintState(state);
|
|
@@ -293,16 +290,16 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
//过滤已经存在的耳标号
|
|
|
private JSONArray filterEarmark(JSONArray downloadEarmarkJa) {
|
|
|
JSONArray newEarmarkJa = new JSONArray();
|
|
|
- for(int a=0;a<downloadEarmarkJa.size();a++){
|
|
|
+ for (int a = 0; a < downloadEarmarkJa.size(); a++) {
|
|
|
JSONObject downloadEarmarkJo = downloadEarmarkJa.getJSONObject(a);
|
|
|
String earmarkId = downloadEarmarkJo.getString("earmarkId");
|
|
|
|
|
|
EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
earmarkEntity.setEarmarkId(earmarkId);
|
|
|
ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("earmark_id" ,ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
- Example example = Example.of(earmarkEntity,matcher);
|
|
|
- if(!earmarkRepo.exists(example)){
|
|
|
+ .withMatcher("earmark_id", ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
+ Example example = Example.of(earmarkEntity, matcher);
|
|
|
+ if (!earmarkRepo.exists(example)) {
|
|
|
newEarmarkJa.add(downloadEarmarkJo);
|
|
|
}
|
|
|
}
|
|
@@ -310,17 +307,51 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Method : exportEarmarkByApply
|
|
|
+ * @Method : exportEarmarkByApply
|
|
|
* @Description : 通过任务号导出耳标号
|
|
|
- * @Params : [applyId]
|
|
|
- * @Return : void
|
|
|
- *
|
|
|
- * @Author : ZhuoNing
|
|
|
- * @Date : 2021/11/9
|
|
|
- * @Time : 14:11
|
|
|
+ * @Params : [applyId]
|
|
|
+ * @Return : void
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/11/9
|
|
|
+ * @Time : 14:11
|
|
|
*/
|
|
|
@Override
|
|
|
- public void exportEarmarkByApply(Integer applyId,Integer printState,Integer quantity, HttpServletResponse response) throws IOException {
|
|
|
+ public void exportEarmarkByApply(Integer applyId, Integer printState, Integer quantity, HttpServletResponse response, HttpServletRequest request) throws IOException, ArchiveException {
|
|
|
+ Specification<EtEarmarkEntity> specific = (Specification<EtEarmarkEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ //
|
|
|
+ List<Predicate> predList = new ArrayList<>();
|
|
|
+ if (null != applyId) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("applyId").as(Integer.class), applyId));
|
|
|
+ }
|
|
|
+ if (null != printState && printState != 0) {
|
|
|
+ predList.add(criteriaBuilder.equal(root.get("printState").as(Integer.class), printState));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ Predicate[] pred = new Predicate[predList.size()];
|
|
|
+ Predicate and = criteriaBuilder.and(predList.toArray(pred));
|
|
|
+ criteriaQuery.where(and);
|
|
|
+ //
|
|
|
+ List<Order> orders = new ArrayList<>();
|
|
|
+ orders.add(criteriaBuilder.asc(root.get("id")));
|
|
|
+ return criteriaQuery.orderBy(orders).getRestriction();
|
|
|
+ };
|
|
|
+ //
|
|
|
+ List<EtEarmarkEntity> dataList = earmarkRepo.findAll(specific);
|
|
|
+ log.info("导出数据数量=" + dataList.size());
|
|
|
+ //
|
|
|
+// excelUtil.exportEarmarkExcel(response, Const.EXPORT_EARMARK_EXCEL, String.valueOf(applyId), dataList, quantity);
|
|
|
+ // test
|
|
|
+// excelUtil.exportEarmarkExcel(String.valueOf(applyId),dataList,quantity);
|
|
|
+ if(dataList.size()>0){
|
|
|
+ //导出耳标数据到文本文件
|
|
|
+ txtUtil.exportEarmarkToTxt(response,String.valueOf(applyId), dataList, quantity,request);
|
|
|
+ }else{
|
|
|
+ //导出空数据到文本文件
|
|
|
+ txtUtil.exportEmptyEarmarkToTxt(response,String.valueOf(applyId),request);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void exportEarmarkByApply_old(Integer applyId, Integer printState, Integer quantity, HttpServletResponse response) throws IOException {
|
|
|
Specification<EtEarmarkEntity> specific = (Specification<EtEarmarkEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
@@ -341,23 +372,23 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
};
|
|
|
//
|
|
|
List<EtEarmarkEntity> dataList = earmarkRepo.findAll(specific);
|
|
|
- log.info("导出数据数量="+dataList.size());
|
|
|
+ log.info("导出数据数量=" + dataList.size());
|
|
|
//
|
|
|
- excelUtil.exportEarmarkExcel(response,Const.EXPORT_EARMARK_EXCEL,String.valueOf(applyId),dataList,quantity);
|
|
|
+ excelUtil.exportEarmarkExcel(response, Const.EXPORT_EARMARK_EXCEL, String.valueOf(applyId), dataList, quantity);
|
|
|
// test
|
|
|
// excelUtil.exportEarmarkExcel(String.valueOf(applyId),dataList,quantity);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void exportEarmarkByEarmark(String ids, Integer printState,Integer quantity, HttpServletResponse response) throws IOException {
|
|
|
+ public void exportEarmarkByEarmark(String ids, Integer printState, Integer quantity, HttpServletResponse response) throws IOException {
|
|
|
Specification<EtEarmarkEntity> specific = (Specification<EtEarmarkEntity>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
//
|
|
|
List<Predicate> predList = new ArrayList<>();
|
|
|
if (null != ids && !ids.trim().equalsIgnoreCase("null")) {
|
|
|
- String[] idsArray = ids.split(",");
|
|
|
+ String[] idsArray = ids.split(",");
|
|
|
Integer[] idArrInt = new Integer[idsArray.length];
|
|
|
- for(int a=0;a<idsArray.length;a++){
|
|
|
- idArrInt[a]=Integer.parseInt(idsArray[a]);
|
|
|
+ for (int a = 0; a < idsArray.length; a++) {
|
|
|
+ idArrInt[a] = Integer.parseInt(idsArray[a]);
|
|
|
}
|
|
|
// predList.add(criteriaBuilder.equal(root.get("id").as(Integer.class), applyId));
|
|
|
predList.add(root.get("id").as(Integer.class).in(idArrInt));
|
|
@@ -373,14 +404,14 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
};
|
|
|
//
|
|
|
List<EtEarmarkEntity> dataList = earmarkRepo.findAll(specific);
|
|
|
- log.info("导出数据数量:"+dataList.size());
|
|
|
+ log.info("导出数据数量:" + dataList.size());
|
|
|
String applyId = null;
|
|
|
- if(dataList.size() > 0){
|
|
|
+ if (dataList.size() > 0) {
|
|
|
EtEarmarkEntity earmarkEntity = dataList.get(0);
|
|
|
applyId = earmarkEntity.getApplyId();
|
|
|
}
|
|
|
//
|
|
|
- excelUtil.exportEarmarkExcel(response,Const.EXPORT_EARMARK_EXCEL,applyId,dataList,quantity);
|
|
|
+ excelUtil.exportEarmarkExcel(response, Const.EXPORT_EARMARK_EXCEL, applyId, dataList, quantity);
|
|
|
// test
|
|
|
// excelUtil.exportEarmarkExcel(applyId,dataList,quantity);
|
|
|
}
|
|
@@ -390,7 +421,6 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
public void exportEarmarkByApplyToTxt(Integer applyId, Integer printState, Integer quantity, HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -424,10 +454,11 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
//Windows
|
|
|
// String rootPath = "D:\\";
|
|
|
String basePath = rootPath + "temp_download";
|
|
|
- System.out.println("basePath>>"+basePath);
|
|
|
+ System.out.println("basePath>>" + basePath);
|
|
|
//创建文件
|
|
|
File file = new File(basePath);
|
|
|
//判断文件是否存在,如果不存在,则创建此文件夹
|
|
|
+ System.out.println("file.exists() 11.>>" + file.exists());
|
|
|
if (!file.exists()) {
|
|
|
file.mkdir();
|
|
|
}
|
|
@@ -437,7 +468,7 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
// String studentResourcePath = new File(basePath, "student/student.txt").getAbsolutePath();
|
|
|
// File txtFile1 = new File(basePath, "eartag\\earmark_1.txt");
|
|
|
File txtFile1 = new File(basePath, "eartag/earmark_1.txt");
|
|
|
- System.out.println("txtFile1.exists()>>"+txtFile1.exists());
|
|
|
+ System.out.println("txtFile1.exists()>>" + txtFile1.exists());
|
|
|
// String studentResourcePath = txtFile1.getAbsolutePath();
|
|
|
// System.out.println("studentResourcePath = " + studentResourcePath);
|
|
|
// 保证目录一定存在
|
|
@@ -470,7 +501,7 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
// String fileName = "耳标数据下载" + "_" + dateUtil.formatLongTimeForTime(new Date().getTime());
|
|
|
String fileName = "耳标数据下载";
|
|
|
String zipFileName = fileName + ".zip";
|
|
|
- System.out.println("zipFileName>>"+zipFileName);
|
|
|
+ System.out.println("zipFileName>>" + zipFileName);
|
|
|
|
|
|
// File filex = new File(basePath + "\\newFile.txt");
|
|
|
// System.out.println("###### filex.exists>>"+filex.exists());
|
|
@@ -485,9 +516,9 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
// File zipFile = null;
|
|
|
// String zipPath = basePath + "\\eartag\\" + zipFileName;
|
|
|
String zipPath = basePath + "/eartag/" + zipFileName;
|
|
|
- System.out.println("zipPath>>"+zipPath);
|
|
|
+ System.out.println("zipPath>>" + zipPath);
|
|
|
File zipFile = new File(zipPath);
|
|
|
- System.out.println("zipFileexists.exists>>"+zipFile.exists());
|
|
|
+ System.out.println("zipFileexists.exists>>" + zipFile.exists());
|
|
|
FileOutputStream zipFos = new FileOutputStream(zipFile);
|
|
|
ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
|
|
|
if (archOut instanceof ZipArchiveOutputStream) {
|
|
@@ -520,7 +551,7 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
@Override
|
|
|
public void exportTest2(Integer applyId, Integer printState, Integer quantity, HttpServletResponse response, HttpServletRequest request) throws IOException {
|
|
|
String basePath = getResourceBasePath(request);
|
|
|
- System.out.println("basePath>>"+basePath);
|
|
|
+ System.out.println("basePath>>" + basePath);
|
|
|
// String studentResourcePath = new File(basePath, "student/student.txt").getAbsolutePath();
|
|
|
File txtFile = new File(basePath, "eartag/earmark_1.txt");
|
|
|
String studentResourcePath = txtFile.getAbsolutePath();
|
|
@@ -551,6 +582,81 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
ZipUtils.downloadZip(response.getOutputStream(), txtFile);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void export1(Integer applyId, Integer printState, Integer quantity, HttpServletResponse response, HttpServletRequest request) throws IOException, ArchiveException {
|
|
|
+ //定义根路径
|
|
|
+ //Linux
|
|
|
+ String rootPath = request.getRealPath("/");
|
|
|
+ //Windows
|
|
|
+// String rootPath = "D:\\";
|
|
|
+ String basePath = rootPath + "temp_download";
|
|
|
+ System.out.println("basePath>>" + basePath);
|
|
|
+ //创建文件
|
|
|
+ File file = new File(basePath);
|
|
|
+ //判断文件是否存在,如果不存在,则创建此文件夹
|
|
|
+ System.out.println("file.exists() 11.>>" + file.exists());
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ File t1File = new File(basePath + "/t1.txt");
|
|
|
+ if (!t1File.exists()) {
|
|
|
+ // t1File.delete();
|
|
|
+ t1File.createNewFile();
|
|
|
+ }
|
|
|
+ System.out.println("t1File.exists()>>"+t1File.exists());
|
|
|
+ BufferedWriter bw = new BufferedWriter(new FileWriter(t1File));
|
|
|
+ String ss = "测试数据";
|
|
|
+ bw.write(ss);
|
|
|
+ bw.newLine(); //换行用
|
|
|
+ //关闭流
|
|
|
+ bw.close();
|
|
|
+ System.out.println("写入成功");
|
|
|
+
|
|
|
+ List<File> txtList = new ArrayList();
|
|
|
+ txtList.add(t1File);
|
|
|
+ for(int a=0;a<txtList.size();a++){
|
|
|
+ System.out.println(">>"+txtList.get(a));
|
|
|
+ }
|
|
|
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ String name = "耳标文件压缩包下载";
|
|
|
+ String fileName = name + "_" + dateUtil.formatLongTimeForTime(new Date().getTime());
|
|
|
+ String zipFileName = fileName + ".zip";
|
|
|
+ File zipFile = null;
|
|
|
+// String path = rootPath + "temp_download";
|
|
|
+ // 打成压缩包
|
|
|
+ zipFile = new File(basePath + "/" + zipFileName);
|
|
|
+ FileOutputStream zipFos = new FileOutputStream(zipFile);
|
|
|
+ ArchiveOutputStream archOut = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, zipFos);
|
|
|
+ if (archOut instanceof ZipArchiveOutputStream) {
|
|
|
+ ZipArchiveOutputStream zos = (ZipArchiveOutputStream) archOut;
|
|
|
+ for (File txtFile : txtList) {
|
|
|
+ ZipArchiveEntry zipEntry = new ZipArchiveEntry(txtFile, txtFile.getName());
|
|
|
+ zos.putArchiveEntry(zipEntry);
|
|
|
+ zos.write(FileUtils.readFileToByteArray(txtFile));
|
|
|
+ zos.closeArchiveEntry();
|
|
|
+ zos.flush();
|
|
|
+ }
|
|
|
+ zos.close();
|
|
|
+ }
|
|
|
+ // 输出到客户端
|
|
|
+ OutputStream out = null;
|
|
|
+ out = response.getOutputStream();
|
|
|
+ response.reset();
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes("GB2312"), "ISO-8859-1"));
|
|
|
+ response.setContentType("application/octet-stream; charset=utf-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ out.write(FileUtils.readFileToByteArray(zipFile));
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ System.out.println("zipFile.exists()>>"+zipFile.exists());
|
|
|
+ // 输出客户端结束后,删除压缩包
|
|
|
+// if (zipFile.exists()) {
|
|
|
+// zipFile.delete();
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取项目根路径
|
|
|
*
|
|
@@ -581,15 +687,14 @@ public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
file.mkdir();
|
|
|
}
|
|
|
String pathStr = file.getAbsolutePath();
|
|
|
- System.out.println("pathStr>>"+pathStr);
|
|
|
+ System.out.println("pathStr>>" + pathStr);
|
|
|
return pathStr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 保证拷贝的文件的目录一定要存在
|
|
|
*
|
|
|
- * @param filePath
|
|
|
- * 文件路径
|
|
|
+ * @param filePath 文件路径
|
|
|
*/
|
|
|
public static void ensureDirectory(String filePath) {
|
|
|
if (StringUtils.isEmpty(filePath)) {
|