|
@@ -1,5 +1,7 @@
|
|
|
package com.fdkankan.agent.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
@@ -8,14 +10,13 @@ import com.fdkankan.agent.entity.AgentNewCamera;
|
|
|
import com.fdkankan.agent.entity.Camera;
|
|
|
import com.fdkankan.agent.entity.CameraDetail;
|
|
|
import com.fdkankan.agent.exception.BusinessException;
|
|
|
-import com.fdkankan.agent.service.IAgentNewCameraService;
|
|
|
-import com.fdkankan.agent.service.ICameraDetailService;
|
|
|
-import com.fdkankan.agent.service.ICameraService;
|
|
|
-import com.fdkankan.agent.service.IExcelService;
|
|
|
+import com.fdkankan.agent.request.AuthModelingParam;
|
|
|
+import com.fdkankan.agent.service.*;
|
|
|
import com.fdkankan.agent.util.ExcelErrorUtil;
|
|
|
import com.fdkankan.agent.util.ExcelUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.velocity.util.ArrayListWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -45,6 +46,8 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
ICameraService cameraService;
|
|
|
@Autowired
|
|
|
ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ IAgentAuthorizeModelingService agentAuthorizeModelingService;
|
|
|
|
|
|
public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,ExcelWriter excelWriter) throws Exception {
|
|
|
response.setContentType("application/vnd.ms-excel");
|
|
@@ -56,26 +59,6 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
excelWriter.write(result, writeSheet);
|
|
|
}
|
|
|
|
|
|
- public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,Class<?> clazz) throws Exception {
|
|
|
- response.setContentType("application/vnd.ms-excel");
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
- String fileName = name + ".xlsx";
|
|
|
- fileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
- response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
|
- ExcelWriter excelWriter = null;
|
|
|
- try {
|
|
|
- excelWriter = EasyExcel.write(response.getOutputStream(), clazz).build();
|
|
|
- WriteSheet writeSheet = EasyExcel.writerSheet(name).build();
|
|
|
- excelWriter.write(result, writeSheet);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }finally {
|
|
|
- if(excelWriter != null){
|
|
|
- excelWriter.finish();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public Integer uploadExcel(MultipartFile file, Integer agentId,Integer subAgentId) {
|
|
@@ -143,6 +126,72 @@ public class ExcelServiceImpl implements IExcelService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Integer uploadAuthModelExcel(MultipartFile file, Integer agentId) {
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ assert originalFilename != null;
|
|
|
+ String fileType=originalFilename.substring(originalFilename.lastIndexOf(".")+1);
|
|
|
+ if (!fileType.equalsIgnoreCase("xlsx")) {
|
|
|
+ throw new BusinessException(ResultCode.FILE_TYPE_ERROR);
|
|
|
+ }
|
|
|
+ List<HashMap<Integer, String>> excelRowList = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ excelRowList = ExcelUtil.getExcelRowList(file);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("uploadExcel-error:{}",e);
|
|
|
+ throw new BusinessException(ResultCode.TEMPLATE_TYPE_ERROR);
|
|
|
+ }
|
|
|
+ List<Integer> errorIndex = new ArrayList<>();
|
|
|
+ List<AuthModelingParam> params = new ArrayList();
|
|
|
+ Integer index = 0;
|
|
|
+ for (HashMap<Integer, String> map : excelRowList) {
|
|
|
+ index ++;
|
|
|
+ if(map.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(index <2){ //从第四行开始
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String authSn = map.get(0);
|
|
|
+ String type = map.get(1);
|
|
|
+ String createDate = map.get(2);
|
|
|
+ String activated = map.get(3);
|
|
|
+ String activateDate = map.get(4);
|
|
|
+ String disabled = map.get(5);
|
|
|
+ String transfer = map.get(6);
|
|
|
+ String borrow = map.get(7);
|
|
|
+ String startDate = map.get(8);
|
|
|
+ String endDate = map.get(9);
|
|
|
+ String expirationDay = map.get(10);
|
|
|
+ if(StringUtils.isBlank(authSn) ){
|
|
|
+ log.info("数据错误:{}",map);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ AuthModelingParam param = new AuthModelingParam();
|
|
|
+ if(StringUtils.isNotBlank(activateDate) && StringUtils.isNotBlank(expirationDay)){
|
|
|
+ try {
|
|
|
+ DateTime parse = DateUtil.parse(activateDate, "yyyy/MM/dd HH:mm:ss");
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(parse, Integer.parseInt(expirationDay));
|
|
|
+ param.setStartTime(parse);
|
|
|
+ param.setEndTime(dateTime);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("解析激活时间错误:{},{}",activateDate,expirationDay);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ param.setAuthCode(authSn);
|
|
|
+ param.setAgentId(agentId);
|
|
|
+ params.add(param);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(!params.isEmpty()){
|
|
|
+ agentAuthorizeModelingService.addByParam(params);
|
|
|
+ }
|
|
|
+ this.toExcelError(errorIndex);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
public void toExcelError(List<Integer> errorList) {
|
|
|
String resultIn = ExcelErrorUtil.getResultIn(errorList);
|
|
|
if(StringUtils.isNotBlank(resultIn)){
|