| | |
| | | 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.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.log.AssetImportLogDetailDto; |
| | | import com.java110.dto.system.ComponentValidateResult; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.intf.common.IAssetImportLogDetailInnerServiceSMO; |
| | | import com.java110.intf.common.IAssetImportLogInnerServiceSMO; |
| | | 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.utils.factory.ApplicationContextFactory; |
| | | import com.java110.utils.util.*; |
| | | import com.java110.vo.ResultVo; |
| | | import importData.IImportDataCleaningAdapt; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.slf4j.Logger; |
| | | import com.java110.core.log.LoggerFactory; |
| | |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.Calendar; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 导入最大行数 |
| | | */ |
| | | public static final int MAX_LINE = 2000; |
| | | public static final int MAX_LINE = 5000; |
| | | |
| | | /** |
| | | * 导入最大行数 |
| | |
| | | @Autowired |
| | | private IUserImportDataV1InnerServiceSMO userImportDataV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IUserInnerServiceSMO iUserInnerServiceSMOImpl; |
| | | |
| | | @Override |
| | | public ResponseEntity<String> importExcelData(IPageData pd, MultipartFile uploadFile) throws Exception { |
| | | JSONObject paramIn = JSONObject.parseObject(pd.getReqData()); |
| | | paramIn.put("userId", pd.getUserId()); |
| | | Assert.hasKeyAndValue(paramIn, "importAdapt", "未包含模板"); |
| | | String importAdapt = paramIn.getString("importAdapt") + "DataCleaning"; |
| | | |
| | |
| | | } |
| | | try { |
| | | ComponentValidateResult result = this.validateStoreStaffCommunityRelationship(pd, restTemplate); |
| | | paramIn.put("storeId", result.getStoreId()); |
| | | |
| | | Workbook workbook = null; //工作簿 |
| | | //工作表 |
| | |
| | | |
| | | // todo 适配器封装数据 |
| | | List datas = importDataCleaningAdapt.analysisExcel(workbook, paramIn, result); |
| | | |
| | | |
| | | if (datas == null || datas.size() > MAX_LINE) { |
| | | throw new IllegalArgumentException("数据为空,或者数据行数大于" + MAX_LINE); |
| | |
| | | * @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()); |
| | | } |
| | | } |
| | | assetImportLogInnerServiceSMOImpl.saveAssetImportLog(assetImportLogPo); |
| | | |
| | | List<AssetImportLogDetailPo> assetImportLogDetailPos = new ArrayList<>(); |
| | | AssetImportLogDetailPo assetImportLogDetailPo = null; |
| | | int flag = 0; |
| | | Calendar createTimeCal = Calendar.getInstance(); |
| | | for (Object data : datas) { |
| | | createTimeCal.add(Calendar.SECOND,1); |
| | | assetImportLogDetailPo = new AssetImportLogDetailPo(); |
| | | assetImportLogDetailPo.setDetailId(GenerateCodeFactory.getGeneratorId("11")); |
| | | assetImportLogDetailPo.setLogId(logId); |
| | |
| | | assetImportLogDetailPo.setMessage("待导入"); |
| | | assetImportLogDetailPo.setCommunityId(result.getCommunityId()); |
| | | assetImportLogDetailPo.setContent(JSONObject.toJSONString(data)); |
| | | assetImportLogDetailPo.setCreateTime(DateUtil.getFormatTimeStringA(createTimeCal.getTime())); |
| | | assetImportLogDetailPos.add(assetImportLogDetailPo); |
| | | if (assetImportLogDetailPos.size() > DEFAULT_ROWS) { |
| | | flag = assetImportLogDetailInnerServiceSMOImpl.saveAssetImportLogDetails(assetImportLogDetailPos); |
| | |
| | | } |
| | | return ResultVo.error("导入失败"); |
| | | } |
| | | |
| | | |
| | | |
| | | } |