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.core.tool.utils.BeanUtil;
|
import org.springblade.modules.system.entity.Region;
|
import org.springblade.modules.system.service.IRegionService;
|
import org.springblade.modules.yw.entity.IndParkInfoEntity;
|
import org.springblade.modules.yw.excel.IndParkInfoExcel;
|
import org.springblade.modules.yw.vo.IndParkInfoVO;
|
import org.springblade.modules.yw.mapper.IndParkInfoMapper;
|
import org.springblade.modules.yw.service.IIndParkInfoService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 园区基本信息表 服务实现类
|
*
|
* @author BladeX
|
* @since 2024-10-28
|
*/
|
@Service
|
public class IndParkInfoServiceImpl extends ServiceImpl<IndParkInfoMapper, IndParkInfoEntity> implements IIndParkInfoService {
|
|
@Autowired
|
private IRegionService regionService;
|
|
/**
|
* 自定义分页查询
|
* @param page
|
* @param indParkInfo
|
* @return
|
*/
|
@Override
|
public IPage<IndParkInfoVO> selectIndParkInfoPage(IPage<IndParkInfoVO> page, IndParkInfoVO indParkInfo) {
|
return page.setRecords(baseMapper.selectIndParkInfoPage(page, indParkInfo));
|
}
|
|
/**
|
* 导入园区信息
|
* @param data
|
* @param isCovered 是否覆盖
|
* @return
|
*/
|
@Override
|
public String importIndParkInfo(List<IndParkInfoExcel> data, boolean isCovered) {
|
for (IndParkInfoExcel parkInfoExcel : data) {
|
// 数据转换
|
IndParkInfoEntity indParkInfoEntity = Objects.requireNonNull(BeanUtil.copy(parkInfoExcel, IndParkInfoEntity.class));
|
// 区划转换
|
if (!Strings.isBlank(parkInfoExcel.getAreaCode())) {
|
String adCode = shiftResidentResidentAdCode(parkInfoExcel.getAreaCode());
|
// 转换行政区code
|
indParkInfoEntity.setAreaCode(adCode);
|
}
|
// 判断是否已经录入
|
Long id = isSave(indParkInfoEntity);
|
if (null!=id){
|
// 更新
|
if (isCovered){
|
indParkInfoEntity.setId(id);
|
updateById(indParkInfoEntity);
|
continue;
|
}
|
}
|
// 保存
|
boolean save = save(indParkInfoEntity);
|
}
|
return null;
|
}
|
|
/**
|
* 判断是否已保存
|
* @param indParkInfoEntity
|
* @return
|
*/
|
private Long isSave(IndParkInfoEntity indParkInfoEntity) {
|
QueryWrapper<IndParkInfoEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("name",indParkInfoEntity.getName()).eq("is_deleted",0);
|
IndParkInfoEntity one = getOne(wrapper);
|
if (null!=one){
|
return one.getId();
|
}
|
return null;
|
}
|
|
|
/**
|
* 根据名称转成code
|
*
|
* @param areaCode 行政区划
|
*/
|
public String shiftResidentResidentAdCode(String areaCode) {
|
String[] split = areaCode.split("-");
|
// 根据省市县三级查询对应的区县code
|
QueryWrapper<Region> wrapper = new QueryWrapper<>();
|
wrapper.eq("province_name", split[0])
|
.eq("city_name", split[1]);
|
List<Region> list = regionService.list(wrapper);
|
if (list.size() > 0) {
|
return list.get(0).getProvinceCode()+","+list.get(0).getCityCode();
|
}
|
return "";
|
}
|
}
|