Browse Source

调整 项目上传代码结构

master
jianjun 4 years ago
parent
commit
c5947de75c
  1. 205
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java

205
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectDataServiceImpl.java

@ -33,11 +33,11 @@ import com.epmet.constant.DataSourceConstant;
import com.epmet.dao.evaluationindex.screen.ScreenProjectDataDao;
import com.epmet.dao.evaluationindex.screen.ScreenProjectImgDataDao;
import com.epmet.dto.screen.ScreenProjectDataDTO;
import com.epmet.dto.screen.ScreenProjectImgDataDTO;
import com.epmet.dto.screen.form.ScreenProjectDataInfoFormDTO;
import com.epmet.dto.screencoll.ScreenCollFormDTO;
import com.epmet.entity.evaluationindex.screen.ScreenProjectCategoryEntity;
import com.epmet.entity.evaluationindex.screen.ScreenProjectDataEntity;
import com.epmet.entity.evaluationindex.screen.ScreenProjectImgDataEntity;
import com.epmet.entity.stats.CustomerProjectCategoryDictEntity;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.OperCrmOpenFeignClient;
@ -47,6 +47,7 @@ import com.epmet.service.evaluationindex.screen.ScreenProjectCategoryService;
import com.epmet.service.evaluationindex.screen.ScreenProjectDataService;
import com.epmet.service.stats.CustomerProjectCategoryDictService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
@ -56,7 +57,6 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -66,6 +66,7 @@ import java.util.stream.Collectors;
* @author qu qu@elink-cn.com
* @since v1.0.0 2021-02-23
*/
@Slf4j
@Service
@DataSource(value = DataSourceConstant.EVALUATION_INDEX)
public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectDataDao, ScreenProjectDataEntity> implements ScreenProjectDataService {
@ -136,76 +137,13 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectD
}
@Override
@Transactional(rollbackFor = Exception.class)
@DataSource(value = DataSourceConstant.EVALUATION_INDEX, datasourceNameFromArg = true)
public void collect(ScreenCollFormDTO<ScreenProjectDataInfoFormDTO> param) {
/*if (param.getIsFirst()) {
int affectedRows = baseDao.deleteByDateIdAndCustomerId(param.getCustomerId(), param.getDateId());
while (affectedRows > 0) {
affectedRows = baseDao.deleteByDateIdAndCustomerId(param.getCustomerId(), param.getDateId());
}
}*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date today = new Date();
List<ScreenProjectDataEntity> projectList = new ArrayList<>();
param.getDataList().forEach(item -> {
String projectStatusCode = item.getProjectStatusCode();
//2021.3.8 epmet中,调用方传level,这边不再计算
if(item.getProjectLevel() == null){
//todo 动态获取超时时间
//如果结案 结案时间立项时间;
if ("closed_case".equals(projectStatusCode)) {
Date createTime = item.getProjectCreateTime();
Date closeCaseTime = item.getCloseCaseTime();
if (closeCaseTime.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 4) {
//如果结案时间-立项时间小于等于4天 未超期 level3
item.setProjectLevel(3);
} else if (closeCaseTime.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 5) {
//如果结案时间-立项时间大于4天小于5天 即将超期 level2
item.setProjectLevel(2);
} else {
//大于5天 已超期 level1
item.setProjectLevel(1);
}
} else if ("pending".equals(projectStatusCode)) {
//如果处理中 当前时间-立项时间;
Date createTime = item.getProjectCreateTime();
if (today.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 4) {
//如果当前时间-立项时间小于等于4天 未超期 level3
item.setProjectLevel(3);
} else if (today.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 5) {
//如果当前时间-立项时间大于4天小于5天 即将超期 level2
item.setProjectLevel(2);
} else {
//大于5天 已超期 level1
item.setProjectLevel(1);
}
}
}
//先删除该projectId对应的旧数据
baseDao.deleteByProjectId(param.getCustomerId(), item.getProjectId());
screenProjectImgDataDao.deleteByProjectId(param.getCustomerId(), item.getProjectId());
//如果orgType未知,获取一下
// if ("unknown".equals(item.getOrgType())){
// ScreenCustomerAgencyEntity screenCustomerAgencyEntity = agencyDao.selectById(item.getOrgId());
// if (screenCustomerAgencyEntity != null){
// item.setOrgType("agency");
// }else {
// ScreenCustomerDeptEntity screenCustomerDeptEntity = deptDao.selectById(item.getOrgId());
// if (screenCustomerDeptEntity!=null){
// item.setOrgType("department");
// }else {
// ScreenCustomerGridEntity screenCustomerGridEntity = gridDao.selectById(item.getOrgId());
// if (screenCustomerGridEntity != null){
// item.setOrgType("grid");
// }
// }
// }
// }
setLevelByCreateTime(item, projectStatusCode);
//插入项目表
ScreenProjectDataEntity screenProjectDataEntity = ConvertUtils.sourceToTarget(item, ScreenProjectDataEntity.class);
@ -215,23 +153,67 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectD
if(StringUtils.isNotBlank(agencyId)) {
screenProjectDataEntity.setAllParentIds(agencyId.concat(StrConstant.COMMA).concat(screenProjectDataEntity.getAllParentIds()));
}
baseDao.insert(screenProjectDataEntity);
projectList.add(screenProjectDataEntity);
//插入图片表
String[] projectImgUrl = item.getProjectImgUrl();
if (ArrayUtils.isNotEmpty(projectImgUrl)) {
for (int i = 0; i < projectImgUrl.length; i++) {
ScreenProjectImgDataEntity screenProjectImgDataEntity = new ScreenProjectImgDataEntity();
screenProjectImgDataEntity.setCustomerId(param.getCustomerId());
screenProjectImgDataEntity.setProjectId(item.getProjectId());
screenProjectImgDataEntity.setProjectImgUrl(projectImgUrl[i]);
screenProjectImgDataEntity.setSort(i);
screenProjectImgDataDao.insert(screenProjectImgDataEntity);
}
}
//删除 并插入新的项目数据
delAndInsertProjectData(param, item, screenProjectDataEntity);
});
}
@Transactional(rollbackFor = Exception.class)
public void delAndInsertProjectData(ScreenCollFormDTO<ScreenProjectDataInfoFormDTO> param, ScreenProjectDataInfoFormDTO item, ScreenProjectDataEntity screenProjectDataEntity) {
//先删除该projectId对应的旧数据
baseDao.deleteByProjectId(param.getCustomerId(), item.getProjectId());
screenProjectImgDataDao.deleteByProjectId(param.getCustomerId(), item.getProjectId());
baseDao.insert(screenProjectDataEntity);
saveCategory(param.getCustomerId(), Collections.singletonList(screenProjectDataEntity))
//插入该项目图片表
String[] projectImgUrl = item.getProjectImgUrl();
if (ArrayUtils.isNotEmpty(projectImgUrl)) {
List<ScreenProjectImgDataDTO> imgList = new ArrayList<>();
for (int i = 0; i < projectImgUrl.length; i++) {
ScreenProjectImgDataDTO screenProjectImgDataEntity = new ScreenProjectImgDataDTO();
screenProjectImgDataEntity.setCustomerId(param.getCustomerId());
screenProjectImgDataEntity.setProjectId(item.getProjectId());
screenProjectImgDataEntity.setProjectImgUrl(projectImgUrl[i]);
screenProjectImgDataEntity.setSort(i);
imgList.add(screenProjectImgDataEntity)
}
screenProjectImgDataDao.insertBatch(imgList);
}
}
saveCategory(param.getCustomerId(), projectList);
private void setLevelByCreateTime(ScreenProjectDataInfoFormDTO item, String projectStatusCode) {
if(item.getProjectLevel() == null){
//todo 动态获取超时时间
//如果结案 结案时间立项时间;
if ("closed_case".equals(projectStatusCode)) {
Date createTime = item.getProjectCreateTime();
Date closeCaseTime = item.getCloseCaseTime();
if (closeCaseTime.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 4L) {
//如果结案时间-立项时间小于等于4天 未超期 level3
item.setProjectLevel(3);
} else if (closeCaseTime.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 5L) {
//如果结案时间-立项时间大于4天小于5天 即将超期 level2
item.setProjectLevel(2);
} else {
//大于5天 已超期 level1
item.setProjectLevel(1);
}
} else if ("pending".equals(projectStatusCode)) {
//如果处理中 当前时间-立项时间;
Date createTime = item.getProjectCreateTime();
Date today = new Date();
if (today.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 4L) {
//如果当前时间-立项时间小于等于4天 未超期 level3
item.setProjectLevel(3);
} else if (today.getTime() - createTime.getTime() <= 1000 * 60 * 60 * 24 * 5L) {
//如果当前时间-立项时间大于4天小于5天 即将超期 level2
item.setProjectLevel(2);
} else {
//大于5天 已超期 level1
item.setProjectLevel(1);
}
}
}
}
@ -278,7 +260,7 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectD
//复采集时数不会重复
if(!CollectionUtils.isEmpty(meta)){
int affectedRows = baseDao.deleteByProjectTimeAndCustomerId(customerId,dateId);
while (affectedRows > 0) {
while (affectedRows > NumConstant.ZERO) {
affectedRows = baseDao.deleteByProjectTimeAndCustomerId(customerId, dateId);
}
List<List<ScreenProjectDataDTO>> partition = ListUtils.partition(meta, NumConstant.ONE_HUNDRED);
@ -359,32 +341,43 @@ public class ScreenProjectDataServiceImpl extends BaseServiceImpl<ScreenProjectD
List<ScreenProjectCategoryEntity> projectCategoryList = new ArrayList<>();
projectList.forEach(project -> {
//分类为空不作处理
if (StringUtils.isNotBlank(project.getCategoryCode())) {
List<String> categoryList = Arrays.asList(project.getCategoryCode().split(StrConstant.COMMA));
categoryList.forEach(category -> {
ScreenProjectCategoryEntity entity = new ScreenProjectCategoryEntity();
entity.setCustomerId(customerId);
entity.setProjectId(project.getProjectId());
entity.setOriginCategoryCode(category);
CustomerProjectCategoryDictEntity categoryEntity = customerProjectCategoryDictService.getByCategoryCode(customerId, category);
if (null != categoryEntity) {
//
if ("external".equals(categoryEntity.getCustomerType())) {
entity.setCategoryCode(categoryEntity.getEpmetCategoryCode());
CustomerProjectCategoryDictEntity parent = customerProjectCategoryDictService.getByCategoryCode(parentCustomer.getData(), categoryEntity.getEpmetCategoryCode());
entity.setParentCategoryCode(parent.getParentCategoryCode());
entity.setLevel(parent.getLevel());
} else {
entity.setCategoryCode(categoryEntity.getCategoryCode());
entity.setParentCategoryCode(categoryEntity.getParentCategoryCode());
entity.setLevel(categoryEntity.getLevel());
}
}
projectCategoryList.add(entity);
});
if (StringUtils.isBlank(project.getCategoryCode())) {
return;
}
List<String> categoryList = Arrays.asList(project.getCategoryCode().split(StrConstant.COMMA));
categoryList.forEach(category -> {
ScreenProjectCategoryEntity entity = new ScreenProjectCategoryEntity();
entity.setCustomerId(customerId);
entity.setProjectId(project.getProjectId());
entity.setOriginCategoryCode(category);
CustomerProjectCategoryDictEntity categoryEntity = customerProjectCategoryDictService.getByCategoryCode(customerId, category);
if (null != categoryEntity) {
log.error("customerId:{} categoryCode:{} is not exist in ProjectCategoryDict", customerId, category);
return;
}
if ("external".equals(categoryEntity.getCustomerType())) {
entity.setCategoryCode(categoryEntity.getEpmetCategoryCode());
CustomerProjectCategoryDictEntity parent = customerProjectCategoryDictService.getByCategoryCode(parentCustomer.getData(), categoryEntity.getEpmetCategoryCode());
entity.setParentCategoryCode(parent.getParentCategoryCode());
entity.setLevel(parent.getLevel());
} else {
entity.setCategoryCode(categoryEntity.getCategoryCode());
entity.setParentCategoryCode(categoryEntity.getParentCategoryCode());
entity.setLevel(categoryEntity.getLevel());
}
projectCategoryList.add(entity);
//如果分类数据已经超过100了 就插入一批
if (projectCategoryList.size() > NumConstant.ONE_HUNDRED){
screenProjectCategoryService.insertBatch(projectCategoryList);
projectCategoryList.clear();
}
});
});
screenProjectCategoryService.insertBatch(projectCategoryList);
//如果不为空 则插入剩余的那一部分
if (projectCategoryList.size() > NumConstant.ZERO){
screenProjectCategoryService.insertBatch(projectCategoryList);
}
}
}

Loading…
Cancel
Save