| | |
| | | package org.springblade.modules.yw.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.DictBizCache; |
| | | import org.springblade.common.utils.PositionUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.yw.entity.FirmInfo; |
| | | import org.springblade.modules.yw.excel.FirmInfoExcel; |
| | | import org.springblade.modules.yw.mapper.FirmInfoMapper; |
| | | import org.springblade.modules.yw.service.IFirmInfoService; |
| | | import org.springblade.modules.yw.vo.FirmInfoVO; |
| | | import org.springblade.modules.yw.vo.SearchVO; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 企业信息-接口服务层 |
| | |
| | | */ |
| | | @Override |
| | | public IPage<FirmInfoVO> selectFirmInfoPage(IPage<FirmInfoVO> page, FirmInfoVO firmInfo) { |
| | | return page.setRecords(baseMapper.selectFirmInfoPage(page,firmInfo)); |
| | | List<FirmInfoVO> firmInfoVOS = baseMapper.selectFirmInfoPage(page, firmInfo); |
| | | for (FirmInfoVO firmInfoVO : firmInfoVOS) { |
| | | if (!Strings.isBlank(firmInfoVO.getCategory())){ |
| | | firmInfoVO.setCategoryName(firmInfoVO.getCategory()); |
| | | } |
| | | } |
| | | return page.setRecords(firmInfoVOS); |
| | | } |
| | | |
| | | /** |
| | | * 企业信息导入 |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | public String importFirmInfo(List<FirmInfoExcel> data, Boolean isCovered) { |
| | | StringBuilder builder = new StringBuilder(); |
| | | int total = data.size(); |
| | | int successNum = 0; |
| | | int errorNum = 0; |
| | | // 遍历数据 |
| | | for (FirmInfoExcel firmInfoExcel : data) { |
| | | // 数据转换 |
| | | FirmInfo firmInfo = Objects.requireNonNull(BeanUtil.copy(firmInfoExcel, FirmInfo.class)); |
| | | // 经纬度转换 |
| | | // positionConvert(firmInfo); |
| | | // 判断信息是否已录入 |
| | | FirmInfo oldFirmInfo = isSave(firmInfo); |
| | | // 已存在并且不更新 |
| | | if (null!=oldFirmInfo && !isCovered){ |
| | | successNum++; |
| | | continue; |
| | | } |
| | | // 已存在,需要覆盖更新 |
| | | if (null!=oldFirmInfo && isCovered){ |
| | | firmInfo.setId(oldFirmInfo.getId()); |
| | | // 更新 |
| | | boolean update = updateById(firmInfo); |
| | | if (update){ |
| | | successNum++; |
| | | }else { |
| | | errorNum++; |
| | | } |
| | | continue; |
| | | } |
| | | // 保存 |
| | | boolean save = save(firmInfo); |
| | | if (save) { |
| | | successNum++; |
| | | } else { |
| | | errorNum++; |
| | | } |
| | | } |
| | | // 拼接消息 |
| | | builder.append("本次导入数据:").append(total).append(" 条") |
| | | .append("其中导入成功:").append(successNum).append(" 条") |
| | | .append("导入失败:").append(errorNum).append(" 条"); |
| | | // 返回 |
| | | return builder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 经纬度转换 |
| | | * @param firmInfo |
| | | */ |
| | | private void positionConvert(FirmInfo firmInfo) { |
| | | if (!Strings.isBlank(firmInfo.getLng())){ |
| | | firmInfo.setLng(PositionUtil.tranformPos(firmInfo.getLng()).toString()); |
| | | } |
| | | if (!Strings.isBlank(firmInfo.getLat())){ |
| | | firmInfo.setLat(PositionUtil.tranformPos(firmInfo.getLat()).toString()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断企业信息是否已录入 |
| | | * @param firmInfo |
| | | * @return |
| | | */ |
| | | public FirmInfo isSave(FirmInfo firmInfo){ |
| | | // 查询是否已存在 |
| | | QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name",firmInfo.getName()).eq("is_deleted",0); |
| | | // 返回 |
| | | return getOne(wrapper); |
| | | } |
| | | |
| | | /** |
| | | * 自定义详情查询 |
| | | * @param firmInfo |
| | | * @return |
| | | */ |
| | | @Override |
| | | public FirmInfoVO getDetail(FirmInfoVO firmInfo) { |
| | | FirmInfoVO detail = baseMapper.getDetail(firmInfo); |
| | | // 设置类型解析 |
| | | if (!Strings.isBlank(detail.getCategory())){ |
| | | detail.setCategoryName( |
| | | DictBizCache.getValues("industry_category",detail.getCategory()) |
| | | ); |
| | | } |
| | | // 返回 |
| | | return detail; |
| | | } |
| | | |
| | | /** |
| | | * 模糊查询企业名称、应急空间名称、风险源名称 |
| | | * @param firmInfo |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SearchVO> fuzzyQuery(FirmInfoVO firmInfo) { |
| | | return baseMapper.fuzzyQuery(firmInfo); |
| | | } |
| | | } |