|
@@ -1,10 +1,14 @@
|
|
|
package com.business.slfh.manager.forestdevicemanager.service.impl;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import com.business.slfh.manager.forestdevicemanager.domain.TResForestdevice;
|
|
|
import com.business.slfh.manager.forestdevicemanager.mapper.TResForestdeviceMapper;
|
|
|
+import com.business.slfh.tools.UUID_Tools;
|
|
|
import com.business.slfh.tools.UserInfoUtil;
|
|
|
import com.sooka.common.annotation.DataScope;
|
|
|
+import com.sooka.common.core.domain.AjaxResult;
|
|
|
import com.sooka.common.core.text.Convert;
|
|
|
import com.sooka.common.utils.DateUtils;
|
|
|
import com.sooka.system.domain.SysUser;
|
|
@@ -70,6 +74,67 @@ public class TResForestdeviceServiceImpl implements ITResForestdeviceService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 新增【请填写功能名称】
|
|
|
+ *
|
|
|
+ * @param tResForestdevice 【请填写功能名称】
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public AjaxResult importExcel(TResForestdevice tResForestdevice)
|
|
|
+ {
|
|
|
+ int lsSize;//导入数据条数
|
|
|
+ int breakLine = 0;//此处数不完整
|
|
|
+ try{
|
|
|
+ System.out.println("importExcel Controller");
|
|
|
+ System.out.println(tResForestdevice.getFilename()+"=filename");
|
|
|
+ List<String[]> ls = com.business.slfh.tools.ExcelUtil.readExcel(tResForestdevice.getFilename(),"Sheet1");//filename,sheetname
|
|
|
+ final int num = 10;
|
|
|
+ boolean isLengthLegal = true;
|
|
|
+ for (int i = 0; i < ls.size(); i++) {//检查每行数据长度一致性
|
|
|
+ String[] row = ls.get(i);
|
|
|
+ if(num != row.length){
|
|
|
+ isLengthLegal = false;
|
|
|
+ breakLine = i;//此行数据不完整 行数按照数据所在行号计算
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isLengthLegal){
|
|
|
+ lsSize = ls.size();
|
|
|
+ for (int i = 1; i < ls.size(); i++) {
|
|
|
+ String[] row = ls.get(i);
|
|
|
+ TResForestdevice tResForestdeviceInsert = new TResForestdevice();
|
|
|
+ tResForestdeviceInsert.setId(UUID_Tools.getUUID());
|
|
|
+ tResForestdeviceInsert.setCode(row[0]);//设备编号
|
|
|
+ tResForestdeviceInsert.setName(row[1]);//名称
|
|
|
+ tResForestdeviceInsert.setLongitude(row[2]);//经度
|
|
|
+ tResForestdeviceInsert.setLatitude(row[3]);//纬度
|
|
|
+ tResForestdeviceInsert.setManager(row[4]);//管理人
|
|
|
+ tResForestdeviceInsert.setPurchase(row[5]);//采购人
|
|
|
+ String purchaseTime = row[6];
|
|
|
+ purchaseTime = stringToDate(purchaseTime);
|
|
|
+ tResForestdeviceInsert.setPurchaseTime(new SimpleDateFormat("dd-MM-yyyy").parse(purchaseTime));//采购时间 20-五月-2021
|
|
|
+ tResForestdeviceInsert.setMaintenance((long)Double.parseDouble(row[7]));//保养周期
|
|
|
+ String nextMaintenance = row[8];
|
|
|
+ nextMaintenance = stringToDate(nextMaintenance);
|
|
|
+ tResForestdeviceInsert.setNextMaintenance(new SimpleDateFormat("dd-MM-yyyy").parse(nextMaintenance));//下次保养时间 20-五月-2021
|
|
|
+ tResForestdeviceInsert.setRemarks(row[9]);//备注
|
|
|
+ SysUser sysUser = userInfoUtil.getLoginUserInfo();
|
|
|
+ tResForestdeviceInsert.setDeptId(sysUser.getDeptId());//当前部门
|
|
|
+ tResForestdeviceInsert.setForestdeviceStatus("forestdevice_status_2");//使用状态 使用中
|
|
|
+ System.out.println(row.length);
|
|
|
+ tResForestdeviceMapper.insertTResForestdevice(tResForestdeviceInsert);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(lsSize+"条数据导入成功!");
|
|
|
+ }else {
|
|
|
+ return AjaxResult.error("请检查,第"+breakLine+"行数据不完整!");
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return AjaxResult.error("导入失败,请稍后尝试!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 修改【请填写功能名称】
|
|
|
*
|
|
|
* @param tResForestdevice 【请填写功能名称】
|
|
@@ -105,4 +170,24 @@ public class TResForestdeviceServiceImpl implements ITResForestdeviceService
|
|
|
{
|
|
|
return tResForestdeviceMapper.deleteTResForestdeviceById(id);
|
|
|
}
|
|
|
+
|
|
|
+ private String stringToDate(String date){
|
|
|
+ date = date.replace("月","");
|
|
|
+ if(date.contains("十一")||date.contains("十二")){
|
|
|
+ date = date.replace("十一","11");
|
|
|
+ date = date.replace("十二","12");
|
|
|
+ }else {
|
|
|
+ date = date.replace("一","1");
|
|
|
+ date = date.replace("二","2");
|
|
|
+ date = date.replace("三","3");
|
|
|
+ date = date.replace("四","4");
|
|
|
+ date = date.replace("五","5");
|
|
|
+ date = date.replace("六","6");
|
|
|
+ date = date.replace("七","7");
|
|
|
+ date = date.replace("八","8");
|
|
|
+ date = date.replace("九","9");
|
|
|
+ date = date.replace("十","10");
|
|
|
+ }
|
|
|
+ return date;
|
|
|
+ }
|
|
|
}
|