| | |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageVO; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.ReportingStatusEnum; |
| | | import com.ruoyi.common.enums.UserTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.CollUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.domain.TbBasicData; |
| | | import com.ruoyi.system.domain.TbDept; |
| | | import com.ruoyi.system.dto.update.DeptFocusDTO; |
| | | import com.ruoyi.system.handler.DeptVerifyHandler; |
| | | import com.ruoyi.system.importExcel.DeptExcel; |
| | | import com.ruoyi.system.mapper.TbDeptMapper; |
| | | import com.ruoyi.system.query.DeptQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TbBasicDataService; |
| | | import com.ruoyi.system.service.TbDeptService; |
| | | import com.ruoyi.system.vo.DeptVO; |
| | | import java.io.InputStream; |
| | | import java.time.Instant; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class TbDeptServiceImpl extends ServiceImpl<TbDeptMapper, TbDept> implements TbDeptService { |
| | | |
| | | private final DeptVerifyHandler deptVerifyHandler; |
| | | private final HttpServletResponse response; |
| | | private final ISysUserService sysUserService; |
| | | private final TbBasicDataService tbBasicDataService; |
| | | |
| | | @Override |
| | | public PageVO<DeptVO> queryPage(DeptQuery query) { |
| | | Page<TbDept> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | LambdaQueryWrapper<TbDept> queryWrapper = new LambdaQueryWrapper<TbDept>() |
| | | .like(StringUtils.isNotEmpty(query.getAreaName()), TbDept::getAreaName, query.getAreaName()) |
| | | .like(StringUtils.isNotEmpty(query.getAccount()), TbDept::getAccount, query.getAccount()) |
| | | .like(StringUtils.isNotEmpty(query.getPhone()), TbDept::getPhone, query.getPhone()) |
| | | .orderByDesc(TbDept::getCreateTime); |
| | | Page<TbDept> deptPage = this.baseMapper.selectPage(page, queryWrapper); |
| | | PageVO<DeptVO> pageVO = new PageVO<>(); |
| | | pageVO.setPageNo(deptPage.getPages()); |
| | | pageVO.setPageSize(deptPage.getSize()); |
| | | pageVO.setTotalPages(deptPage.getTotal()); |
| | | pageVO.setTotalCount(deptPage.getTotal()); |
| | | IPage<DeptVO> convert = deptPage.convert(result -> { |
| | | DeptVO deptVO = new DeptVO(); |
| | | BeanUtils.copyBeanProp(deptVO, result); |
| | | return deptVO; |
| | | }); |
| | | pageVO.setRecords(convert.getRecords()); |
| | | return pageVO; |
| | | public PageDTO<DeptVO> queryPage(DeptQuery query) { |
| | | Page<SysUser> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | Page<SysUser> userPage = sysUserService.lambdaQuery() |
| | | .eq(SysUser::getUserType, UserTypeEnum.DEPARTMENT.getCode()) |
| | | .like(StringUtils.isNotEmpty(query.getAreaName()), SysUser::getAreaName, |
| | | query.getAreaName()) |
| | | .like(StringUtils.isNotEmpty(query.getUserName()), SysUser::getUserName, |
| | | query.getUserName()) |
| | | .like(StringUtils.isNotEmpty(query.getPhone()), SysUser::getPhoneNumber, |
| | | query.getPhone()) |
| | | .orderByDesc(SysUser::getCreateTime) |
| | | .page(page); |
| | | |
| | | if (CollUtils.isEmpty(userPage.getRecords())) { |
| | | return PageDTO.empty(page); |
| | | } |
| | | return PageDTO.of(userPage, DeptVO.class); |
| | | } |
| | | |
| | | @Override |
| | |
| | | //使用自定义校验规则 |
| | | importParams.setVerifyHandler(deptVerifyHandler); |
| | | InputStream inputStream = file.getInputStream(); |
| | | ExcelImportResult<TbDept> result = ExcelImportUtil.importExcelMore(inputStream, TbDept.class, importParams); |
| | | ExcelImportResult<DeptExcel> result = ExcelImportUtil.importExcelMore(inputStream, |
| | | DeptExcel.class, importParams); |
| | | inputStream.close(); |
| | | List<TbDept> list = result.getList(); |
| | | if (Objects.requireNonNull(result).isVerfiyFail() || CollectionUtils.isEmpty(list)) { |
| | | throw new RuntimeException("文件校验失败,请检查数据填写是否完整"); |
| | | List<DeptExcel> list = result.getList(); |
| | | |
| | | if (result.isVerifyFail() || CollectionUtils.isEmpty(list)) { |
| | | throw new ServiceException("文件校验失败,请检查数据填写是否完整"); |
| | | } |
| | | List<String> strings = hasDuplicateAreaCode(list); |
| | | if (!CollectionUtils.isEmpty(strings)) { |
| | | throw new RuntimeException(String.format("区划代码%s重复,请修改后重新导入", String.join(",", strings))); |
| | | }else { |
| | | throw new ServiceException( |
| | | String.format("区划代码%s重复,请修改后重新导入", String.join(",", strings))); |
| | | } else { |
| | | List<TbDept> tbDeptList = BeanUtils.copyList(list, TbDept.class); |
| | | this.remove(null); |
| | | this.saveBatch(list); |
| | | tbDeptList.forEach(dept -> { |
| | | dept.setPassword(SecurityUtils.encryptPassword(dept.getPassword())); |
| | | }); |
| | | this.saveBatch(tbDeptList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验区划代码是否重复 |
| | | * @param deptList |
| | | * @return |
| | | * |
| | | * @param deptList 部门列表 |
| | | * @return 重复的区划代码 |
| | | */ |
| | | public List<String> hasDuplicateAreaCode(List<TbDept> deptList) { |
| | | public List<String> hasDuplicateAreaCode(List<DeptExcel> deptList) { |
| | | Set<String> areaCodes = new HashSet<>(); |
| | | List<String> result = new ArrayList<>(); |
| | | for (TbDept dept : deptList) { |
| | | for (DeptExcel dept : deptList) { |
| | | if (!areaCodes.add(dept.getAreaCode())) { |
| | | result.add(dept.getAreaCode()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void focus(DeptFocusDTO dto) { |
| | | Optional<SysUser> sysUser = sysUserService.lambdaQuery() |
| | | .eq(SysUser::getUserId, dto.getUserId()).oneOpt(); |
| | | if (sysUser.isPresent()) { |
| | | sysUserService.lambdaUpdate() |
| | | .eq(SysUser::getUserId, dto.getUserId()) |
| | | .set(SysUser::getFocussed, dto.getFocussed()) |
| | | .update(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public R<Void> reportingMessage() { |
| | | Date date = new Date(); |
| | | Date quarterStart = DateUtil.beginOfQuarter(date); |
| | | Date quarterEnd = DateUtil.endOfQuarter(date); |
| | | //判断当前时间是否在季度初1-15号 |
| | | Instant instant = quarterStart.toInstant(); |
| | | LocalDate quarterStartLocalDate = instant.atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | LocalDate fifteenDaysLimit = quarterStartLocalDate.plusDays(14); |
| | | LocalDate now = LocalDate.now(); |
| | | //如果当前时间不在规定范围内:季度初1-15号 |
| | | if (now.isAfter(quarterStartLocalDate) || now.isBefore(fifteenDaysLimit)) { |
| | | //查询所有的部门 |
| | | List<SysUser> list = sysUserService.lambdaQuery() |
| | | .eq(SysUser::getUserType, UserTypeEnum.DEPARTMENT.getCode()).list(); |
| | | Set<String> deptAreaCodeList = list.stream().map(SysUser::getAreaCode) |
| | | .collect(Collectors.toSet()); |
| | | //查询当前季度填报了数据的部门 |
| | | List<TbBasicData> filledBasicData = tbBasicDataService.lambdaQuery() |
| | | .between(TbBasicData::getReportingTime, quarterStartLocalDate, fifteenDaysLimit) |
| | | .eq(TbBasicData::getStatus, ReportingStatusEnum.FILLED).list(); |
| | | Set<String> filledDeptCodes = filledBasicData.stream().map(TbBasicData::getDeptAreaCode) |
| | | .collect(Collectors.toSet()); |
| | | if (!filledDeptCodes.containsAll(deptAreaCodeList)) { |
| | | return R.fail("有部门未上传季度数据"); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |