| | |
| | | package com.java110.api.smo.assetImport.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.core.JsonParseException; |
| | | import com.fasterxml.jackson.databind.JsonMappingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.java110.api.importData.DefaultImportDataAdapt; |
| | | import com.java110.api.importData.IImportDataCleaningAdapt; |
| | | import com.java110.api.smo.DefaultAbstractComponentSMO; |
| | | import com.java110.api.smo.assetImport.IAssetImportSMO; |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.dto.PropertyWhiteListFlowDto; |
| | | import com.java110.dto.log.AssetImportLogDetailDto; |
| | | import com.java110.dto.payFee.PayFeeBatchDto; |
| | | import com.java110.dto.system.ComponentValidateResult; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.intf.IImportPropertyWhiteListfFlowServiceSMO; |
| | | import com.java110.intf.common.IAssetImportLogDetailInnerServiceSMO; |
| | | import com.java110.intf.common.IAssetImportLogInnerServiceSMO; |
| | | import com.java110.intf.fee.IPayFeeBatchV1InnerServiceSMO; |
| | | import com.java110.intf.job.IUserImportDataV1InnerServiceSMO; |
| | | import com.java110.intf.user.IMenuUserV1InnerServiceSMO; |
| | | import com.java110.intf.user.IUserInnerServiceSMO; |
| | | import com.java110.po.log.AssetImportLogDetailPo; |
| | | import com.java110.po.log.AssetImportLogPo; |
| | | import com.java110.po.payFee.PayFeeBatchPo; |
| | | import com.java110.utils.factory.ApplicationContextFactory; |
| | | import com.java110.utils.util.*; |
| | | import com.java110.vo.ResultVo; |
| | | import com.java110.api.importData.IImportDataCleaningAdapt; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.slf4j.Logger; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 导入最大行数 |
| | | */ |
| | | public static final int MAX_LINE = 2000; |
| | | @Value("${import.line.max}") |
| | | public int MAX_LINE; |
| | | |
| | | /** |
| | | * 导入最大行数 |
| | |
| | | @Autowired |
| | | private IUserImportDataV1InnerServiceSMO userImportDataV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IUserInnerServiceSMO iUserInnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IImportPropertyWhiteListfFlowServiceSMO importPropertyWhiteListfFlowServiceSMO; |
| | | |
| | | |
| | | @Autowired |
| | | private IPayFeeBatchV1InnerServiceSMO payFeeBatchV1InnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public ResponseEntity<String> importExcelData(IPageData pd, MultipartFile uploadFile) throws Exception { |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | if (paramIn.getString("userId").isEmpty() || paramIn.getString("userId").equals("null")){ |
| | | throw new IllegalArgumentException("userId为空"); |
| | | } |
| | | paramIn.put("userId", pd.getUserId()); |
| | | Assert.hasKeyAndValue(paramIn, "importAdapt", "未包含模板"); |
| | | Assert.hasKeyAndValue(paramIn, "userId", "未包含userId"); |
| | | String importAdapt = paramIn.getString("importAdapt") + "DataCleaning"; |
| | | |
| | | importDataCleaningAdapt = ApplicationContextFactory.getBean(importAdapt, IImportDataCleaningAdapt.class); |
| | |
| | | } |
| | | try { |
| | | ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate); |
| | | paramIn.put("storeId", result.getStoreId()); |
| | | |
| | | Workbook workbook = null; //工作簿 |
| | | //工作表 |
| | | String[] headers = null; //表头信息 |
| | | workbook = ImportExcelUtils.createWorkbook(uploadFile); |
| | | if(uploadFile == null || uploadFile.getSize() == 0){ |
| | | |
| | | // todo 适配器封装数据 |
| | | List datas = importDataCleaningAdapt.analysisExcel(workbook, paramIn, result); |
| | | PropertyWhiteListFlowDto propertyWhiteListFlowDto = new PropertyWhiteListFlowDto(); |
| | | propertyWhiteListFlowDto.setCommunityId((String) JSONObject.parseObject(pd.getReqData()).get("communityId")); |
| | | // todo 适配器封装数据 |
| | | List<PropertyWhiteListFlowDto> datas = importPropertyWhiteListfFlowServiceSMO.queryPropertyWhiteListFlow(propertyWhiteListFlowDto); |
| | | PayFeeBatchPo payFeeBatchPo = new PayFeeBatchPo(); |
| | | payFeeBatchPo.setBatchId(GenerateCodeFactory.getGeneratorId("12")); |
| | | payFeeBatchPo.setCommunityId(paramIn.getString("communityId")); |
| | | payFeeBatchPo.setCreateUserId(paramIn.getString("userId")); |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserId(paramIn.getString("userId")); |
| | | List<UserDto> userDtos = iUserInnerServiceSMOImpl.getUsers(userDto); |
| | | |
| | | if (datas == null || datas.size() > MAX_LINE) { |
| | | throw new IllegalArgumentException("数据为空,或者数据行数大于" + MAX_LINE); |
| | | Assert.listOnlyOne(userDtos, "用户不存在"); |
| | | payFeeBatchPo.setCreateUserName(userDtos.get(0).getUserName()); |
| | | payFeeBatchPo.setState(PayFeeBatchDto.STATE_NORMAL); |
| | | payFeeBatchPo.setMsg("正常"); |
| | | int flag = payFeeBatchV1InnerServiceSMOImpl.savePayFeeBatch(payFeeBatchPo); |
| | | |
| | | if (flag < 1) { |
| | | throw new IllegalArgumentException("生成批次失败"); |
| | | } |
| | | |
| | | paramIn.put("batchId", payFeeBatchPo.getBatchId()); |
| | | |
| | | for (PropertyWhiteListFlowDto importRoomFee : datas) { |
| | | importRoomFee.setUserId(paramIn.getString("userId")); |
| | | importRoomFee.setStoreId(paramIn.getString("storeId")); |
| | | importRoomFee.setCommunityId(paramIn.getString("communityId")); |
| | | importRoomFee.setBatchId(paramIn.getString("batchId")); |
| | | importRoomFee.setObjType(paramIn.getString("objType")); |
| | | } |
| | | |
| | | if (datas == null || datas.size() > MAX_LINE) { |
| | | throw new IllegalArgumentException("数据为空,或者数据行数大于" + MAX_LINE); |
| | | } |
| | | |
| | | // 保存数据 |
| | | return saveLogAndImportData(pd, datas, result, paramIn.getString("importAdapt")); |
| | | } |
| | | else{ |
| | | workbook = ImportExcelUtils.createWorkbook(uploadFile); |
| | | result.setImportFileName(uploadFile.getOriginalFilename()); |
| | | // todo 适配器封装数据 |
| | | List datas = importDataCleaningAdapt.analysisExcel(workbook, paramIn, result); |
| | | |
| | | // 保存数据 |
| | | return saveLogAndImportData(pd, datas, result, paramIn.getString("importAdapt")); |
| | | |
| | | if (datas == null || datas.size() > MAX_LINE) { |
| | | throw new IllegalArgumentException("数据为空,或者数据行数大于" + MAX_LINE); |
| | | } |
| | | |
| | | // 保存数据 |
| | | return saveLogAndImportData(pd, datas, result, paramIn.getString("importAdapt")); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("导入失败 ", e); |
| | | return new ResponseEntity<String>("非常抱歉,您填写的模板数据有误:" + e.getMessage(), HttpStatus.BAD_REQUEST); |
| | |
| | | * @param datas 数据 |
| | | */ |
| | | private ResponseEntity<String> saveLogAndImportData(IPageData pd, |
| | | List datas, |
| | | ComponentValidateResult result, String logType) { |
| | | List datas, |
| | | ComponentValidateResult result, String logType) { |
| | | ResponseEntity<String> responseEntity = null; |
| | | |
| | | String logId = GenerateCodeFactory.getGeneratorId("10"); |
| | |
| | | assetImportLogPo.setLogType(logType); |
| | | assetImportLogPo.setErrorCount("0"); |
| | | assetImportLogPo.setSuccessCount("0"); |
| | | String userId = null; |
| | | userId = pd.getUserId(); |
| | | if(userId != null) { |
| | | UserDto userDto = new UserDto(); |
| | | userDto.setUserId(userId); |
| | | List<UserDto> users = iUserInnerServiceSMOImpl.getUsers(userDto); |
| | | if(users != null && users.size() > 0) { |
| | | assetImportLogPo.setUserName(users.get(0).getUserName()); |
| | | } |
| | | } |
| | | assetImportLogPo.setImportFileName(result.getImportFileName()); |
| | | assetImportLogInnerServiceSMOImpl.saveAssetImportLog(assetImportLogPo); |
| | | |
| | | List<AssetImportLogDetailPo> assetImportLogDetailPos = new ArrayList<>(); |
| | |
| | | } |
| | | return ResultVo.error("导入失败"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |