| | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.read.listener.ReadListener; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.example.entity.DataExcel; |
| | | import com.example.entity.Department; |
| | | import com.example.excel.DataExcelImport; |
| | | import com.example.mapper.DataExcelMapper; |
| | | import com.example.service.DataExcelService; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<DataExcel> getDataExcelPageNew(Long current, Long size, String unitCode, String transactionNo, String accountingPeriod) { |
| | | Page<DataExcel> page = new Page<>(current, size); |
| | | page.setOptimizeJoinOfCountSql(false); |
| | | page.setOptimizeCountSql(false); |
| | | LambdaQueryWrapper<DataExcel> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(unitCode != null && !unitCode.isEmpty(), DataExcel::getUnitCode, unitCode) |
| | | .like(transactionNo != null && !transactionNo.isEmpty(), DataExcel::getTransactionNo, transactionNo) |
| | | .eq(accountingPeriod != null && !accountingPeriod.isEmpty(), DataExcel::getAccountingPeriod, accountingPeriod) |
| | | .orderByDesc(DataExcel::getId); |
| | | return page(page, wrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<Department> getDepartmentTree() { |
| | | QueryWrapper<DataExcel> wrapper = new QueryWrapper<>(); |
| | | // 关键:两个字段去重(DISTINCT 作用于这两个字段的组合) |
| | | wrapper.select("distinct unit_code, unit_name"); |
| | | List<DataExcel> list = baseMapper.selectList(wrapper); |
| | | List<Department> resultList = new ArrayList<>(); |
| | | for (DataExcel dataExcel : list) { |
| | | Department department = new Department(); |
| | | department.setDeptCode(dataExcel.getUnitCode()); |
| | | department.setDeptName(dataExcel.getUnitName()); |
| | | resultList.add(department); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | | public String importData(MultipartFile file, List<String> permissionDeptCodes) { |
| | | List<DataExcel> insertList = new ArrayList<>(); |
| | | List<DataExcel> updateList = new ArrayList<>(); |
| | |
| | | errorMsgs.add("第" + data.getSeqNo() + "行单位编码为空"); |
| | | return; |
| | | } |
| | | if (!permissionDeptCodes.contains(data.getUnitCode())) { |
| | | errorMsgs.add("第" + data.getSeqNo() + "行无权限导入部门编码: " + data.getUnitCode()); |
| | | return; |
| | | } |
| | | |
| | | DataExcel entity = new DataExcel(); |
| | | entity.setSortNo(data.getSortNo()); |
| | | entity.setSeqNo(data.getSeqNo()); |
| | |
| | | entity.setBusinessRelation(data.getBusinessRelation()); |
| | | entity.setRemark(data.getRemark()); |
| | | entity.setStatus(1); |
| | | entity.setPkVoucher(data.getPkVoucher()); |
| | | |
| | | if (data.getSortNo() != null) { |
| | | DataExcel existData = baseMapper.selectBySortNo(data.getSortNo()); |