| | |
| | | package com.javaweb.geo.service.impl; |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | |
| | | import cn.hutool.poi.excel.ExcelReader; |
| | | import cn.hutool.poi.excel.ExcelUtil; |
| | | import com.javaweb.common.config.Global; |
| | | import com.javaweb.common.utils.DateUtils; |
| | | import com.javaweb.common.utils.IdGenerate; |
| | | import com.javaweb.geo.domain.*; |
| | | import com.javaweb.geo.mapper.*; |
| | | import com.javaweb.geo.service.*; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import com.javaweb.common.core.text.Convert; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 钻孔Service业务层处理 |
| | | * |
| | | * |
| | | * @author zmk |
| | | * @date 2022-10-20 |
| | | */ |
| | |
| | | @Autowired |
| | | private HoleYantuMapper holeYantuMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private IProjectService projectService; |
| | | |
| | | private String fileSaveDir = Global.getProfile() + "\\template\\" ; |
| | | |
| | | /** |
| | | * 查询钻孔 |
| | | * |
| | | * |
| | | * @param ids 钻孔ID |
| | | * @return 钻孔 |
| | | */ |
| | | @Override |
| | | public Hole selectHoleById(String ids) |
| | | { |
| | | public Hole selectHoleById(String ids) { |
| | | return holeMapper.selectHoleById(ids); |
| | | } |
| | | |
| | | /** |
| | | * 查询钻孔列表 |
| | | * |
| | | * |
| | | * @param hole 钻孔 |
| | | * @return 钻孔 |
| | | */ |
| | | @Override |
| | | public List<Hole> selectHoleList(Hole hole) |
| | | { |
| | | public List<Hole> selectHoleList(Hole hole) { |
| | | return holeMapper.selectHoleList(hole); |
| | | } |
| | | |
| | | /** |
| | | * 新增钻孔 |
| | | * |
| | | * |
| | | * @param hole 钻孔 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertHole(Hole hole) |
| | | { |
| | | public int insertHole(Hole hole) { |
| | | if(ObjectUtils.isEmpty(hole.getIds())){ |
| | | hole.setIds(IdGenerate.nextId()); |
| | | } |
| | | hole.setCreateTime(DateUtils.getNowDate()); |
| | | return holeMapper.insertHole(hole); |
| | | } |
| | | |
| | | /** |
| | | * 修改钻孔 |
| | | * |
| | | * |
| | | * @param hole 钻孔 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateHole(Hole hole) |
| | | { |
| | | public int updateHole(Hole hole) { |
| | | hole.setUpdateTime(DateUtils.getNowDate()); |
| | | return holeMapper.updateHole(hole); |
| | | } |
| | | |
| | | /** |
| | | * 删除钻孔对象 |
| | | * |
| | | * |
| | | * @param ids 需要删除的数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteHoleByIds(String ids) { |
| | | |
| | | // 批量删除钻孔下面的关联数据 |
| | | String[] strings = Convert.toStrArray(ids); |
| | | if (!ObjectUtils.isEmpty(strings)){ |
| | | for (String holeId : strings) { |
| | | |
| | | // =======标贯========== |
| | | List<HoleBiaoguan> biaoguans = holeBiaoguanMapper.selectHoleBiaoguanByHoleId(holeId); |
| | | String[] biaoguanIds = biaoguans.stream().map(HoleBiaoguan::getIds).toArray(String[]::new); |
| | | |
| | | // =======回次========== |
| | | List<HoleHuici> holeHuicis = holeHuiciMapper.selectHoleHuiciByHoleId(holeId); |
| | | String[] huiCiIds = holeHuicis.stream().map(HoleHuici::getIds).toArray(String[]::new); |
| | | |
| | | // =======人员========== |
| | | List<HolePerson> persons = holePersonMapper.selectHolePersonByHoleId(holeId); |
| | | String[] personIds = persons.stream().map(HolePerson::getIds).toArray(String[]::new); |
| | | |
| | | // =======取土========== |
| | | List<HoleQutu> qutus = holeQutuMapper.selectHoleQutuByHoleId(holeId); |
| | | String[] qutuIds = qutus.stream().map(HoleQutu::getIds).toArray(String[]::new); |
| | | |
| | | // =======水位========== |
| | | List<HoleShuiwei> shuiweis = holeShuiweiMapper.selectHoleShuiWeiByHoleId(holeId); |
| | | String[] shuiweiIds = shuiweis.stream().map(HoleShuiwei::getIds).toArray(String[]::new); |
| | | |
| | | // =======岩土========== |
| | | List<HoleYantu> yantus = holeYantuMapper.selectHoleYantuListByHoleId(holeId); |
| | | String[] yantusIds = yantus.stream().map(HoleYantu::getIds).toArray(String[]::new); |
| | | |
| | | holeBiaoguanMapper.deleteHoleBiaoguanByIds(biaoguanIds); |
| | | holeHuiciMapper.deleteHoleHuiciByIds(huiCiIds); |
| | | holePersonMapper.deleteHolePersonByIds(personIds); |
| | | holeQutuMapper.deleteHoleQutuByIds(qutuIds); |
| | | holeShuiweiMapper.deleteHoleShuiweiByIds(shuiweiIds); |
| | | holeYantuMapper.deleteHoleYantuByIds(yantusIds); |
| | | } |
| | | } |
| | | // String[] strings = Convert.toStrArray(ids); |
| | | // if (!ObjectUtils.isEmpty(strings)) { |
| | | // for (String holeId : strings) { |
| | | // |
| | | // // =======标贯========== |
| | | // List<HoleBiaoguan> biaoguans = holeBiaoguanMapper.selectHoleBiaoguanByHoleId(holeId); |
| | | // String[] biaoguanIds = biaoguans.stream().map(HoleBiaoguan::getIds).toArray(String[]::new); |
| | | // |
| | | // // =======回次========== |
| | | // List<HoleHuici> holeHuicis = holeHuiciMapper.selectHoleHuiciByHoleId(holeId); |
| | | // String[] huiCiIds = holeHuicis.stream().map(HoleHuici::getIds).toArray(String[]::new); |
| | | // |
| | | // // =======人员========== |
| | | // List<HolePerson> persons = holePersonMapper.selectHolePersonByHoleId(holeId); |
| | | // String[] personIds = persons.stream().map(HolePerson::getIds).toArray(String[]::new); |
| | | // |
| | | // // =======取土========== |
| | | // List<HoleQutu> qutus = holeQutuMapper.selectHoleQutuByHoleId(holeId); |
| | | // String[] qutuIds = qutus.stream().map(HoleQutu::getIds).toArray(String[]::new); |
| | | // |
| | | // // =======水位========== |
| | | // List<HoleShuiwei> shuiweis = holeShuiweiMapper.selectHoleShuiWeiByHoleId(holeId); |
| | | // String[] shuiweiIds = shuiweis.stream().map(HoleShuiwei::getIds).toArray(String[]::new); |
| | | // |
| | | // // =======岩土========== |
| | | // List<HoleYantu> yantus = holeYantuMapper.selectHoleYantuListByHoleId(holeId); |
| | | // String[] yantusIds = yantus.stream().map(HoleYantu::getIds).toArray(String[]::new); |
| | | // |
| | | // holeBiaoguanMapper.deleteHoleBiaoguanByIds(biaoguanIds); |
| | | // holeHuiciMapper.deleteHoleHuiciByIds(huiCiIds); |
| | | // holePersonMapper.deleteHolePersonByIds(personIds); |
| | | // holeQutuMapper.deleteHoleQutuByIds(qutuIds); |
| | | // holeShuiweiMapper.deleteHoleShuiweiByIds(shuiweiIds); |
| | | // holeYantuMapper.deleteHoleYantuByIds(yantusIds); |
| | | // } |
| | | // } |
| | | |
| | | return holeMapper.deleteHoleByIds(Convert.toStrArray(ids)); |
| | | } |
| | | |
| | | /** |
| | | * 删除钻孔信息 |
| | | * |
| | | * |
| | | * @param ids 钻孔ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteHoleById(String ids) |
| | | { |
| | | public int deleteHoleById(String ids) { |
| | | return holeMapper.deleteHoleById(ids); |
| | | } |
| | | |
| | | /** |
| | | * 导入钻孔 |
| | | */ |
| | | @Override |
| | | public String importHole(String projectId, MultipartFile file, boolean updateSupport) { |
| | | try { |
| | | String dest = saveExcel(file); |
| | | List<Hole> list = readData(dest); |
| | | if(!ObjectUtils.isEmpty(list)){ |
| | | for (Hole item : list) { |
| | | item.setProjectId(projectId); |
| | | insertHole(item); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | return e.toString(); |
| | | } |
| | | return "导入完毕" ; |
| | | } |
| | | |
| | | private String saveExcel(MultipartFile file) { |
| | | String filename = file.getOriginalFilename(); |
| | | File dir = new File(fileSaveDir); |
| | | if (!dir.exists()) { |
| | | dir.mkdir(); |
| | | } |
| | | String addr = fileSaveDir + filename; |
| | | try { |
| | | File dest = new File(addr); |
| | | file.transferTo(dest); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | return addr; |
| | | } |
| | | |
| | | private List<Hole> readData(String filepath) { |
| | | ExcelReader reader = ExcelUtil.getReader(filepath, 0); |
| | | reader.addHeaderAlias("钻孔编号", "code"); |
| | | reader.addHeaderAlias("孔口高程(m)", "elevation"); |
| | | reader.addHeaderAlias("设计孔深(m)", "depth"); |
| | | reader.addHeaderAlias("钻孔经度", "longitude"); |
| | | reader.addHeaderAlias("钻孔纬度", "latitude"); |
| | | reader.addHeaderAlias("总进尺(m)", "footage"); |
| | | reader.addHeaderAlias("已完成进尺(m)", "footageCpl"); |
| | | |
| | | List<Hole> list = reader.readAll(Hole.class); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | |
| | | } |