|
|
@ -1,6 +1,7 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
@ -21,22 +22,19 @@ import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dao.*; |
|
|
|
import com.epmet.dto.IcEnterpriseChangeRecordDTO; |
|
|
|
import com.epmet.dto.SysDictDataDTO; |
|
|
|
import com.epmet.dto.form.EnterpriseFormDTO; |
|
|
|
import com.epmet.dto.form.EnterprisePageFormDTO; |
|
|
|
import com.epmet.dto.form.EnterprisePatrolFormDTO; |
|
|
|
import com.epmet.dto.form.ImportTaskCommonFormDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.IcEnterpriseChangeRecordEntity; |
|
|
|
import com.epmet.entity.IcEnterpriseEntity; |
|
|
|
import com.epmet.entity.IcEnterprisePatrolAttachmentEntity; |
|
|
|
import com.epmet.entity.IcEnterprisePatrolRecordEntity; |
|
|
|
import com.epmet.entity.*; |
|
|
|
import com.epmet.excel.EnterpriseImportExcelDTO; |
|
|
|
import com.epmet.excel.handler.IcEnterpriseExcelImportListener; |
|
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
@ -98,6 +96,10 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
private CustomerGridDao customerGridDao; |
|
|
|
@Autowired |
|
|
|
private IcEnterpriseChangeRecordService icEnterpriseChangeRecordService; |
|
|
|
@Autowired |
|
|
|
private EpmetAdminOpenFeignClient epmetAdminOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private LoginUserUtil loginUserUtil; |
|
|
|
|
|
|
|
/** |
|
|
|
* 企事业单位巡查】新增/编辑 |
|
|
@ -114,18 +116,18 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
} |
|
|
|
AgencyInfoCache agencyInfoCache = CustomerOrgRedis.getAgencyInfo(formDTO.getAgencyId()); |
|
|
|
if (null == agencyInfoCache) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"组织信息查询异常","组织信息查询异常"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "组织信息查询异常", "组织信息查询异常"); |
|
|
|
} |
|
|
|
IcEnterpriseEntity enterpriseEntity = ConvertUtils.sourceToTarget(formDTO, IcEnterpriseEntity.class); |
|
|
|
enterpriseEntity.setAgencyPids(agencyInfoCache.getPids()); |
|
|
|
if(StringUtils.isBlank(formDTO.getEnterpriseId())){ |
|
|
|
if (StringUtils.isBlank(formDTO.getEnterpriseId())) { |
|
|
|
enterpriseEntity.setLatestResult(StrConstant.EPMETY_STR); |
|
|
|
enterpriseEntity.setSourceType(CommonOperateTypeEnum.ADD.getCode()); |
|
|
|
baseDao.insert(enterpriseEntity); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
//如果是编辑判断下权限
|
|
|
|
IcEnterpriseEntity origin=baseDao.selectById(formDTO.getEnterpriseId()); |
|
|
|
CustomerStaffInfoCacheResult staffInfo=CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(),formDTO.getCurrentStaffId()); |
|
|
|
IcEnterpriseEntity origin = baseDao.selectById(formDTO.getEnterpriseId()); |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getCurrentStaffId()); |
|
|
|
if (!staffInfo.getAgencyId().equals(origin.getAgencyId())) { |
|
|
|
AgencyInfoCache orginAgencyInfo = CustomerOrgRedis.getAgencyInfo(origin.getAgencyId()); |
|
|
|
String agencyName = null != orginAgencyInfo ? orginAgencyInfo.getOrganizationName() : StrConstant.EPMETY_STR; |
|
|
@ -133,7 +135,7 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
} |
|
|
|
|
|
|
|
// 历史记录
|
|
|
|
log(origin,"UPD"); |
|
|
|
log(origin, formDTO, "UPD"); |
|
|
|
|
|
|
|
enterpriseEntity.setId(formDTO.getEnterpriseId()); |
|
|
|
//获取一下最新的巡检时间和巡检结果
|
|
|
@ -158,14 +160,14 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public String addOrUpdatePatrol(EnterprisePatrolFormDTO formDTO) { |
|
|
|
IcEnterprisePatrolRecordEntity patrolRecordEntity=ConvertUtils.sourceToTarget(formDTO,IcEnterprisePatrolRecordEntity.class); |
|
|
|
if(StringUtils.isBlank(formDTO.getPatrolId())){ |
|
|
|
IcEnterprisePatrolRecordEntity patrolRecordEntity = ConvertUtils.sourceToTarget(formDTO, IcEnterprisePatrolRecordEntity.class); |
|
|
|
if (StringUtils.isBlank(formDTO.getPatrolId())) { |
|
|
|
enterprisePatrolRecordDao.insert(patrolRecordEntity); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
patrolRecordEntity.setId(formDTO.getPatrolId()); |
|
|
|
enterprisePatrolRecordDao.updateById(patrolRecordEntity); |
|
|
|
//删除之前的图片
|
|
|
|
enterprisePatrolAttachmentDao.deleteByPatrolId(formDTO.getPatrolId(),formDTO.getUserId()); |
|
|
|
enterprisePatrolAttachmentDao.deleteByPatrolId(formDTO.getPatrolId(), formDTO.getUserId()); |
|
|
|
} |
|
|
|
int sort = 1; |
|
|
|
for (String imgUrl : formDTO.getImgList()) { |
|
|
@ -180,7 +182,7 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
sort++; |
|
|
|
} |
|
|
|
// 更新主表的最新结果和最新检查时间
|
|
|
|
baseDao.updateLatestPatrol(formDTO.getEnterpriseId(),patrolRecordEntity.getPatrolTime(),patrolRecordEntity.getResult(),formDTO.getUserId()); |
|
|
|
baseDao.updateLatestPatrol(formDTO.getEnterpriseId(), patrolRecordEntity.getPatrolTime(), patrolRecordEntity.getResult(), formDTO.getUserId()); |
|
|
|
return patrolRecordEntity.getId(); |
|
|
|
} |
|
|
|
|
|
|
@ -191,26 +193,27 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void delPatrol(String patrolId,String currentUserId) { |
|
|
|
IcEnterprisePatrolRecordEntity origin=enterprisePatrolRecordDao.selectById(patrolId); |
|
|
|
if(null==origin){ |
|
|
|
public void delPatrol(String patrolId, String currentUserId) { |
|
|
|
IcEnterprisePatrolRecordEntity origin = enterprisePatrolRecordDao.selectById(patrolId); |
|
|
|
if (null == origin) { |
|
|
|
return; |
|
|
|
} |
|
|
|
//1、删除巡查记录
|
|
|
|
enterprisePatrolRecordDao.deleteById(patrolId); |
|
|
|
//2、删除之前的图片
|
|
|
|
enterprisePatrolAttachmentDao.deleteByPatrolId(patrolId,currentUserId); |
|
|
|
enterprisePatrolAttachmentDao.deleteByPatrolId(patrolId, currentUserId); |
|
|
|
//3、如果是记录清空,那主表的最近一次巡查时间和最新结果也置空
|
|
|
|
LambdaQueryWrapper<IcEnterprisePatrolRecordEntity> queryWrapper=new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(IcEnterprisePatrolRecordEntity::getEnterpriseId,origin.getEnterpriseId()); |
|
|
|
LambdaQueryWrapper<IcEnterprisePatrolRecordEntity> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(IcEnterprisePatrolRecordEntity::getEnterpriseId, origin.getEnterpriseId()); |
|
|
|
if (NumConstant.ZERO == enterprisePatrolRecordDao.selectCount(queryWrapper)) { |
|
|
|
baseDao.updateLatestPatrol(origin.getEnterpriseId(),null,StrConstant.EPMETY_STR,currentUserId); |
|
|
|
baseDao.updateLatestPatrol(origin.getEnterpriseId(), null, StrConstant.EPMETY_STR, currentUserId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 巡查记录列表 |
|
|
|
* 暂时不分页 |
|
|
|
* |
|
|
|
* @param enterpriseId |
|
|
|
* @return |
|
|
|
*/ |
|
|
@ -242,9 +245,9 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
resultDto.setAgencyName(gridInfoCache.getAgencyName()); |
|
|
|
} |
|
|
|
String placeTypeName = coverageCategoryDictDao.selectCategoryName(customerId, CoveragePlaceTypeEnum.ENTERPRISE_PATROL.getCode(), resultDto.getPlaceType()); |
|
|
|
if(StringUtils.isNotBlank(placeTypeName)){ |
|
|
|
if (StringUtils.isNotBlank(placeTypeName)) { |
|
|
|
resultDto.setPlaceTypeName(placeTypeName); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
resultDto.setPlaceTypeName(coverageCategoryDictDao.selectCategoryName(Constant.DEFAULT_CUSTOMER, CoveragePlaceTypeEnum.ENTERPRISE_PATROL.getCode(), resultDto.getPlaceType())); |
|
|
|
} |
|
|
|
//规模名称
|
|
|
@ -279,7 +282,7 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
} |
|
|
|
|
|
|
|
// 历史记录
|
|
|
|
log(origin,"DEL"); |
|
|
|
log(origin, null, "DEL"); |
|
|
|
|
|
|
|
baseDao.deleteById(enterpriseId); |
|
|
|
} |
|
|
@ -313,9 +316,9 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
detailDTO.setAgencyName(gridInfoCache.getAgencyName()); |
|
|
|
} |
|
|
|
String placeTypeName = coverageCategoryDictDao.selectCategoryName(formDTO.getCustomerId(), CoveragePlaceTypeEnum.ENTERPRISE_PATROL.getCode(), detailDTO.getPlaceType()); |
|
|
|
if(StringUtils.isNotBlank(placeTypeName)){ |
|
|
|
if (StringUtils.isNotBlank(placeTypeName)) { |
|
|
|
detailDTO.setPlaceTypeName(placeTypeName); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
detailDTO.setPlaceTypeName(coverageCategoryDictDao.selectCategoryName(Constant.DEFAULT_CUSTOMER, CoveragePlaceTypeEnum.ENTERPRISE_PATROL.getCode(), detailDTO.getPlaceType())); |
|
|
|
} |
|
|
|
detailDTO.setScaleName(dictMap.containsKey(detailDTO.getScale()) ? dictMap.get(detailDTO.getScale()) : StrConstant.EPMETY_STR); |
|
|
@ -326,26 +329,26 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
|
|
|
|
@Async |
|
|
|
@Override |
|
|
|
public void execAsyncExcelImport(Path filePath, String importTaskId,String customerId,String userId) { |
|
|
|
public void execAsyncExcelImport(Path filePath, String importTaskId, String customerId, String userId) { |
|
|
|
try { |
|
|
|
//获取当前登录用户所属组织id
|
|
|
|
CustomerStaffInfoCacheResult staffInfo= queryCurrentStaff(customerId,userId); |
|
|
|
CustomerStaffInfoCacheResult staffInfo = queryCurrentStaff(customerId, userId); |
|
|
|
|
|
|
|
//1、查询 ic_coverage_category_dict 注意key:场所的名称 value:编码
|
|
|
|
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(customerId, CoveragePlaceTypeEnum.ENTERPRISE_PATROL.getCode()); |
|
|
|
Map<String, String> placeTypeMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getLabel, IcCoverageCategoryDictListResultDTO::getValue)); |
|
|
|
//2、规模名称
|
|
|
|
Result<List<SysDictDataDTO>> dictMapRes = adminOpenFeignClient.dictDataList(DictTypeEnum.SCALE.getCode()); |
|
|
|
Map<String, String> scaleMap = dictMapRes.success() && CollectionUtils.isNotEmpty(dictMapRes.getData()) ? dictMapRes.getData().stream().collect(Collectors.toMap(SysDictDataDTO::getDictLabel,SysDictDataDTO::getDictValue)) : new HashMap<>(); |
|
|
|
Map<String, String> scaleMap = dictMapRes.success() && CollectionUtils.isNotEmpty(dictMapRes.getData()) ? dictMapRes.getData().stream().collect(Collectors.toMap(SysDictDataDTO::getDictLabel, SysDictDataDTO::getDictValue)) : new HashMap<>(); |
|
|
|
//3、当前工作人员所属组织下的网格列表
|
|
|
|
List<GridListResultDTO> gridList = customerGridDao.selectGridList(staffInfo.getAgencyId()); |
|
|
|
if (CollectionUtils.isEmpty(gridList)) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "当前组织下没有网格", "当前组织下没有直属网格"); |
|
|
|
} |
|
|
|
Map<String,String> gridMap=gridList.stream().collect(Collectors.toMap(GridListResultDTO::getGridName,GridListResultDTO::getGridId)); |
|
|
|
Map<String, String> gridMap = gridList.stream().collect(Collectors.toMap(GridListResultDTO::getGridName, GridListResultDTO::getGridId)); |
|
|
|
|
|
|
|
|
|
|
|
IcEnterpriseExcelImportListener listener = new IcEnterpriseExcelImportListener(customerId,staffInfo, this,placeTypeMap,scaleMap,gridMap); |
|
|
|
IcEnterpriseExcelImportListener listener = new IcEnterpriseExcelImportListener(customerId, staffInfo, this, placeTypeMap, scaleMap, gridMap); |
|
|
|
EasyExcel.read(filePath.toFile(), EnterpriseImportExcelDTO.class, listener).headRowNumber(1).sheet(0).doRead(); |
|
|
|
|
|
|
|
Path errorDescFile = null; |
|
|
@ -426,14 +429,14 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
return getPageData(page, EnterpriseDetailDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<IcEnterpriseEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
String placeOrgName = (String)params.get("placeOrgName"); |
|
|
|
String mobile = (String)params.get("mobile"); |
|
|
|
String gridId = (String)params.get("gridId"); |
|
|
|
String placeType = (String)params.get("placeType"); |
|
|
|
String scale = (String)params.get("scale"); |
|
|
|
String result = (String)params.get("result"); |
|
|
|
private QueryWrapper<IcEnterpriseEntity> getWrapper(Map<String, Object> params) { |
|
|
|
String id = (String) params.get(FieldConstant.ID_HUMP); |
|
|
|
String placeOrgName = (String) params.get("placeOrgName"); |
|
|
|
String mobile = (String) params.get("mobile"); |
|
|
|
String gridId = (String) params.get("gridId"); |
|
|
|
String placeType = (String) params.get("placeType"); |
|
|
|
String scale = (String) params.get("scale"); |
|
|
|
String result = (String) params.get("result"); |
|
|
|
|
|
|
|
QueryWrapper<IcEnterpriseEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
@ -456,7 +459,7 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
} |
|
|
|
|
|
|
|
public List<IcEnterpriseEntity> selectForUniqueName(String gridId, String placeOrgName, String enterpriseId) { |
|
|
|
return baseDao.selectForUniqueName(gridId, placeOrgName, enterpriseId); |
|
|
|
return baseDao.selectForUniqueName(gridId, placeOrgName, enterpriseId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -468,9 +471,50 @@ public class IcEnterpriseServiceImpl extends BaseServiceImpl<IcEnterpriseDao, Ic |
|
|
|
* @author zhy |
|
|
|
* @date 2022/8/16 15:36 |
|
|
|
*/ |
|
|
|
private void log(IcEnterpriseEntity origin, String type){ |
|
|
|
private void log(IcEnterpriseEntity origin, EnterpriseFormDTO formDTO, String type) { |
|
|
|
// 历史记录
|
|
|
|
IcEnterpriseChangeRecordEntity record = ConvertUtils.sourceToTarget(origin, IcEnterpriseChangeRecordEntity.class); |
|
|
|
|
|
|
|
if (formDTO != null) { |
|
|
|
if (!origin.getPlaceType().equals(formDTO.getPlaceType())) { |
|
|
|
record.setPlaceType(record.getPlaceType().concat("->").concat(formDTO.getPlaceType())); |
|
|
|
List<IcCoverageCategoryDictListResultDTO> categoryList = coverageService.dictMap(loginUserUtil.getLoginUserCustomerId(), "enterprise_patrol"); |
|
|
|
Map<String, String> categoryMap = categoryList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getValue, IcCoverageCategoryDictListResultDTO::getLabel)); |
|
|
|
record.setPlaceType(categoryMap.get(record.getPlaceType()).concat("->").concat(categoryMap.get(formDTO.getPlaceType()))); |
|
|
|
} |
|
|
|
|
|
|
|
if (!origin.getGridId().equals(formDTO.getGridId())) { |
|
|
|
CustomerGridEntity originGrid = customerGridDao.selectById(record.getGridId()); |
|
|
|
CustomerGridEntity thisGrid = customerGridDao.selectById(formDTO.getGridId()); |
|
|
|
record.setGridId(record.getGridId().concat("->").concat(thisGrid.getGridName())); |
|
|
|
if (originGrid != null && thisGrid != null) { |
|
|
|
record.setGridId(originGrid.getGridName().concat("->").concat(formDTO.getGridId())); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!origin.getPlaceOrgName().equals(formDTO.getPlaceOrgName())) { |
|
|
|
record.setPlaceOrgName(record.getPlaceOrgName().concat("->").concat(record.getPlaceOrgName())); |
|
|
|
} |
|
|
|
if (!origin.getScale().equals(formDTO.getScale())) { |
|
|
|
record.setScale(record.getScale().concat("->").concat(formDTO.getScale())); |
|
|
|
Result<Map<String, String>> result = epmetAdminOpenFeignClient.dictMap(DictTypeEnum.SCALE.getCode()); |
|
|
|
if (!result.success() || null == result.getData()) { |
|
|
|
throw new EpmetException("查询字典信息失败" + JSON.toJSONString(result)); |
|
|
|
} else { |
|
|
|
Map<String, String> scaleMap = result.getData(); |
|
|
|
record.setScale(scaleMap.get(record.getScale()).concat("->").concat(scaleMap.get(formDTO.getScale()))); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!origin.getPersonInCharge().equals(formDTO.getPersonInCharge())) { |
|
|
|
record.setPersonInCharge(record.getPersonInCharge().concat("->").concat(formDTO.getPersonInCharge())); |
|
|
|
} |
|
|
|
if (!origin.getMobile().equals(formDTO.getMobile())) { |
|
|
|
record.setMobile(record.getMobile().concat("->").concat(formDTO.getMobile())); |
|
|
|
} |
|
|
|
if (!origin.getAddress().equals(formDTO.getAddress())) { |
|
|
|
record.setAddress(record.getAddress().concat("->").concat(formDTO.getAddress())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
record.setId(null); |
|
|
|
record.setCreatedBy(null); |
|
|
|
record.setCreatedTime(null); |
|
|
|