| | |
| | | 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.geo.domain.TubLog; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.javaweb.geo.mapper.TubLogMapper; |
| | | import com.javaweb.geo.domain.TubLog; |
| | | import com.javaweb.geo.service.ITubLogService; |
| | | import com.javaweb.common.core.text.Convert; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * 材料出入库记录Service业务层处理 |
| | |
| | | */ |
| | | @Service |
| | | public class TubLogServiceImpl implements ITubLogService { |
| | | |
| | | @Autowired |
| | | private TubLogMapper tubLogMapper; |
| | | |
| | | private String fileSaveDir = Global.getProfile() + "\\template\\" ; |
| | | |
| | | /** |
| | | * 查询材料出入库记录 |
| | |
| | | public int deleteTubLogById(Integer id) { |
| | | return tubLogMapper.deleteTubLogById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询数据库中id最大值 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer selectMaxTubLogId(String projectId) { |
| | | return tubLogMapper.selectMaxTubLogId(projectId); |
| | | } |
| | | |
| | | /** |
| | | * 导入管材出入库记录 |
| | | */ |
| | | @Override |
| | | public String importTubLog(String projectId, MultipartFile file, boolean updateSupport) { |
| | | // 关联code |
| | | Integer number = tubLogMapper.selectMaxTubLogId(projectId); |
| | | |
| | | try { |
| | | String dest = saveExcel(file); |
| | | List<TubLog> list = readData(dest); |
| | | for (TubLog item : list) { |
| | | // 转换项目信息 |
| | | item.setProjectId(projectId); |
| | | |
| | | // 转换number信息 |
| | | if (ObjectUtils.isEmpty(number)){ |
| | | number = 1; |
| | | }else { |
| | | number++; |
| | | } |
| | | String code = "ZTCJ" + String.format("%06d", number); |
| | | item.setCode(code); |
| | | |
| | | item.setCreateDate(DateUtils.getNowDate()); |
| | | insertTubLog(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<TubLog> readData(String filepath) { |
| | | ExcelReader reader = ExcelUtil.getReader(filepath, 0); |
| | | reader.addHeaderAlias("管材名称", "tubName"); |
| | | reader.addHeaderAlias("入库时间", "inboundDate"); |
| | | reader.addHeaderAlias("出库时间", "outboundDate"); |
| | | reader.addHeaderAlias("经办人", "optUser"); |
| | | reader.addHeaderAlias("负责人", "applyUser"); |
| | | reader.addHeaderAlias("出入库数量", "number"); |
| | | reader.addHeaderAlias("数据单位", "unit"); |
| | | reader.addHeaderAlias("备注", "remark"); |
| | | |
| | | List<TubLog> list = reader.readAll(TubLog.class); |
| | | return list; |
| | | } |
| | | } |