¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.manage.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.manage.mapper.ManageRecordTotalMapper; |
| | | import com.ruoyi.manage.mapper.ManageRecordVerifyMapper; |
| | | import com.ruoyi.manage.pojo.ManageRecordTotal; |
| | | import com.ruoyi.manage.pojo.ManageRecordVerify; |
| | | import com.ruoyi.manage.service.ManageRecordVerifyService; |
| | | |
| | | import org.apache.poi.xwpf.usermodel.XWPFDocument; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTable; |
| | | import org.apache.poi.xwpf.usermodel.XWPFTableRow; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | | * 夿¥æä»¶ç¡®è®¤è®°å½ æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå
¬å¸ |
| | | * @since 2024-11-12 10:29:44 |
| | | */ |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ManageRecordVerifyServiceImpl extends ServiceImpl<ManageRecordVerifyMapper, ManageRecordVerify> implements ManageRecordVerifyService { |
| | | |
| | | @Resource |
| | | private ManageRecordVerifyMapper manageRecordVerifyMapper; |
| | | |
| | | @Resource |
| | | private ManageRecordTotalMapper manageRecordTotalMapper; |
| | | |
| | | @Override |
| | | public IPage<ManageRecordVerify> pageManageRecordVerify(Page page, ManageRecordVerify manageRecordVerify) { |
| | | if (ObjectUtils.isEmpty(manageRecordVerify.getManageRecordTotalId())) { |
| | | //è·åå½å年份 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | // å®ä¹æ¥ææ ¼å¼ |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); |
| | | // æ ¼å¼åå½åæ¥æ |
| | | String currentMonth = currentDate.format(formatter); |
| | | //æ¥è¯¢åå² |
| | | ManageRecordTotal manageRecordTotal = manageRecordTotalMapper.selectOne(Wrappers.<ManageRecordTotal>lambdaQuery().eq(ManageRecordTotal::getYear, currentMonth)); |
| | | manageRecordVerify.setManageRecordTotalId(manageRecordTotal.getId()); |
| | | } |
| | | return manageRecordVerifyMapper.pageManageRecordVerify(page, QueryWrappers.queryWrappers(manageRecordVerify)); |
| | | } |
| | | |
| | | @Override |
| | | public int addManageRecordVerify(ManageRecordVerify manageRecordVerify) { |
| | | //è·åå½å年份 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | // å®ä¹æ¥ææ ¼å¼ |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); |
| | | // æ ¼å¼åå½åæ¥æ |
| | | String currentMonth = currentDate.format(formatter); |
| | | ManageRecordTotal manageRecordTotal = manageRecordTotalMapper.selectOne(Wrappers.<ManageRecordTotal>lambdaQuery().eq(ManageRecordTotal::getYear, currentMonth)); |
| | | manageRecordVerify.setManageRecordTotalId(manageRecordTotal.getId()); |
| | | manageRecordVerifyMapper.insert(manageRecordVerify); |
| | | manageRecordTotal.setTotalNum(1 + manageRecordTotal.getTotalNum()); |
| | | return manageRecordTotalMapper.updateById(manageRecordTotal); |
| | | } |
| | | |
| | | @Override |
| | | public int delManageRecordVerify(Integer id) { |
| | | ManageRecordVerify manageRecordVerify = manageRecordVerifyMapper.selectById(id); |
| | | manageRecordVerifyMapper.deleteById(id); |
| | | ManageRecordTotal manageRecordTotal = manageRecordTotalMapper.selectById(manageRecordVerify.getManageRecordTotalId()); |
| | | manageRecordTotal.setTotalNum(manageRecordTotal.getTotalNum() - 1); |
| | | return manageRecordTotalMapper.updateById(manageRecordTotal); |
| | | } |
| | | |
| | | @Override |
| | | public int exportManageRecordVerify(MultipartFile file) { |
| | | List<ManageRecordVerify> manageRecordVerifyList = new ArrayList<>(); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | //è·åå½å年份 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | // å®ä¹æ¥ææ ¼å¼ |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); |
| | | // æ ¼å¼åå½åæ¥æ |
| | | String currentMonth = currentDate.format(formatter); |
| | | ManageRecordTotal manageRecordTotal = manageRecordTotalMapper.selectOne(Wrappers.<ManageRecordTotal>lambdaQuery().eq(ManageRecordTotal::getYear, currentMonth)); |
| | | try { |
| | | InputStream inputStream = file.getInputStream(); |
| | | XWPFDocument document = new XWPFDocument(inputStream); |
| | | List<XWPFTable> tables = document.getTables(); |
| | | if (tables.isEmpty()) { |
| | | throw new ErrorException("ææ¡£ä¸æ²¡æè¡¨æ ¼"); |
| | | } |
| | | |
| | | for (XWPFTable table : tables) { |
| | | List<XWPFTableRow> rows = table.getRows(); |
| | | if (rows.size() <= 1) { |
| | | throw new ErrorException("è¡¨æ ¼æ²¡ææ°æ®è¡"); |
| | | } |
| | | for (int i = 1; i < rows.size(); i++) { // ä»ç¬¬äºè¡å¼å§ï¼è·³è¿è¡¨å¤´ |
| | | XWPFTableRow row = rows.get(i); |
| | | if (row.getTableCells().size() != 8) { |
| | | System.out.println("è¡ " + (i + 1) + " çåæ°ä¸å¹é
ï¼è·³è¿è¯¥è¡"); |
| | | continue; |
| | | } |
| | | if (ObjectUtils.isNotEmpty(row.getCell(1).getText())) { |
| | | ManageRecordVerify manageRecordVerify = new ManageRecordVerify(); |
| | | manageRecordVerify.setDocumentName(row.getCell(1).getText()); |
| | | manageRecordVerify.setDocumentCode(row.getCell(2).getText()); |
| | | manageRecordVerify.setStandardName(row.getCell(3).getText()); |
| | | manageRecordVerify.setStandardCode(row.getCell(4).getText()); |
| | | try { |
| | | manageRecordVerify.setEffectiveDate(LocalDate.parse(row.getCell(5).getText(), dateTimeFormatter)); |
| | | } catch (Exception e) { |
| | | manageRecordVerify.setEffectiveDate(null); |
| | | } |
| | | try { |
| | | manageRecordVerify.setCancelDate(LocalDate.parse(row.getCell(6).getText(), dateTimeFormatter)); |
| | | } catch (Exception e) { |
| | | manageRecordVerify.setCancelDate(null); |
| | | } |
| | | manageRecordVerify.setNote(row.getCell(7).getText()); |
| | | manageRecordVerify.setManageRecordTotalId(manageRecordTotal.getId()); |
| | | if (manageRecordVerifyMapper.selectCount(Wrappers.<ManageRecordVerify>lambdaQuery() |
| | | .eq(ManageRecordVerify::getDocumentCode, manageRecordVerify.getDocumentCode()) |
| | | .eq(ManageRecordVerify::getDocumentName, manageRecordVerify.getDocumentName()) |
| | | .eq(ManageRecordVerify::getStandardName, manageRecordVerify.getStandardName()) |
| | | .eq(ManageRecordVerify::getStandardCode, manageRecordVerify.getStandardCode()) |
| | | .eq(ManageRecordVerify::getManageRecordTotalId, manageRecordVerify.getManageRecordTotalId())) <= 0) { |
| | | manageRecordVerifyList.add(manageRecordVerify); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | saveBatch(manageRecordVerifyList); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return 0; |
| | | } |
| | | } |