| | |
| | | package org.springblade.modules.yw.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.DictBizCache; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.yw.entity.FirmInfo; |
| | | import org.springblade.modules.yw.entity.RiskSourceEntity; |
| | | import org.springblade.modules.yw.excel.RiskSourceExcel; |
| | | import org.springblade.modules.yw.service.IFirmInfoService; |
| | | import org.springblade.modules.yw.vo.RiskSourceVO; |
| | | import org.springblade.modules.yw.mapper.RiskSourceMapper; |
| | | import org.springblade.modules.yw.service.IRiskSourceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 风险源表 服务实现类 |
| | |
| | | @Service |
| | | public class RiskSourceServiceImpl extends ServiceImpl<RiskSourceMapper, RiskSourceEntity> implements IRiskSourceService { |
| | | |
| | | @Autowired |
| | | private IFirmInfoService firmInfoService; |
| | | |
| | | /** |
| | | * 自定义分页查询 |
| | | * @param page |
| | | * @param riskSource |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<RiskSourceVO> selectRiskSourcePage(IPage<RiskSourceVO> page, RiskSourceVO riskSource) { |
| | | return page.setRecords(baseMapper.selectRiskSourcePage(page, riskSource)); |
| | | List<RiskSourceVO> riskSourceVOS = baseMapper.selectRiskSourcePage(page, riskSource); |
| | | // for (RiskSourceVO riskSourceVO : riskSourceVOS) { |
| | | // if (!Strings.isBlank(riskSourceVO.getCategory())){ |
| | | // riskSourceVO.setCategory( |
| | | // DictBizCache.getValues("industry_category",riskSourceVO.getCategory()) |
| | | // ); |
| | | // } |
| | | // } |
| | | return page.setRecords(riskSourceVOS); |
| | | } |
| | | |
| | | /** |
| | | * 导入风险源信息 |
| | | * @param data |
| | | * @param isCovered |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String importRiskSource(List<RiskSourceExcel> data, boolean isCovered) { |
| | | for (RiskSourceExcel riskSourceExcel : data) { |
| | | // 数据拷贝 |
| | | RiskSourceEntity riskSourceEntity = Objects.requireNonNull(BeanUtil.copy(riskSourceExcel, RiskSourceEntity.class)); |
| | | // 风险等级转换 |
| | | if (!Strings.isBlank(riskSourceExcel.getRiskLevel())){ |
| | | riskSourceEntity.setRiskLevel(Integer.parseInt(riskSourceExcel.getRiskLevel())); |
| | | } |
| | | // 设置企业 |
| | | setFirm(riskSourceExcel,riskSourceEntity); |
| | | // 判断是否已经入库 |
| | | Long id = isSave(riskSourceExcel,riskSourceEntity); |
| | | if (null!=id){ |
| | | if (isCovered){ |
| | | // 覆盖更新 |
| | | riskSourceEntity.setId(id); |
| | | updateById(riskSourceEntity); |
| | | continue; |
| | | } |
| | | } |
| | | // 保存 |
| | | save(riskSourceEntity); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 设置企业信息 |
| | | * @param riskSourceExcel |
| | | * @param riskSourceEntity |
| | | */ |
| | | private void setFirm(RiskSourceExcel riskSourceExcel, RiskSourceEntity riskSourceEntity) { |
| | | QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name",riskSourceExcel.getFirmName()) |
| | | .eq("is_deleted",0); |
| | | FirmInfo firmInfo = firmInfoService.getOne(wrapper); |
| | | if (null!=firmInfo){ |
| | | riskSourceEntity.setFirmId(firmInfo.getId()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断是否已经入库 |
| | | * @param riskSourceExcel |
| | | * @return |
| | | */ |
| | | private Long isSave(RiskSourceExcel riskSourceExcel,RiskSourceEntity riskSourceEntity) { |
| | | QueryWrapper<RiskSourceEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("firm_id",riskSourceEntity.getFirmId()) |
| | | .eq("name",riskSourceExcel.getName()) |
| | | .eq("is_deleted",0); |
| | | RiskSourceEntity one = getOne(wrapper); |
| | | if (null!=one){ |
| | | return one.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 风险源统计查询 |
| | | * @param riskSource |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> getStatisticData(RiskSourceVO riskSource) { |
| | | // 风险源统计查询 |
| | | return baseMapper.getStatisticData(riskSource); |
| | | } |
| | | } |