| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.AuxiliaryOutputWorkingHoursDto; |
| | | import com.yuanchu.mom.dto.AuxiliaryWorkingHoursDayDto; |
| | | import com.yuanchu.mom.mapper.AuxiliaryWorkingHoursDayMapper; |
| | | import com.yuanchu.mom.mapper.PowerMapper; |
| | | import com.yuanchu.mom.mapper.UserMapper; |
| | | import com.yuanchu.mom.pojo.AuxiliaryOutputWorkingHours; |
| | | import com.yuanchu.mom.mapper.AuxiliaryOutputWorkingHoursMapper; |
| | | import com.yuanchu.mom.pojo.AuxiliaryWorkingHoursDay; |
| | | import com.yuanchu.mom.pojo.Power; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import com.yuanchu.mom.service.AuxiliaryOutputWorkingHoursService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper; |
| | | |
| | | @Resource |
| | | GetLook getLook; |
| | | |
| | | @Resource |
| | | AuxiliaryWorkingHoursDayMapper auxiliaryWorkingHoursDayMapper; |
| | | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | @Resource |
| | | PowerMapper powerMapper; |
| | | |
| | | @Override |
| | | public Map<String, Object> selectAuxiliaryOutputWorkingHours(Page page, AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours) { |
| | | public Map<String, Object> selectAuxiliaryOutputWorkingHours(Page page, AuxiliaryOutputWorkingHoursDto auxiliaryOutputWorkingHoursDto) { |
| | | String dates = auxiliaryOutputWorkingHoursDto.getDateTime(); |
| | | String week = auxiliaryOutputWorkingHoursDto.getWeek(); |
| | | auxiliaryOutputWorkingHoursDto.setDateTime(null); |
| | | auxiliaryOutputWorkingHoursDto.setWeek(null); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(AuxiliaryOutputWorkingHours.class)); |
| | | map.put("body", auxiliaryOutputWorkingHoursMapper.selectAuxiliaryOutputWorkingHours(page, QueryWrappers.queryWrappers(auxiliaryOutputWorkingHours))); |
| | | List<Integer> ids = null; |
| | | map.put("head", PrintChina.printChina(AuxiliaryOutputWorkingHoursDto.class)); |
| | | //判断组长,组员,管理员权限 |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectAuxiliaryOutputWorkingHours"); |
| | | User user = userMapper.selectById(map1.get("userId")); |
| | | Integer roleId = user.getRoleId(); |
| | | Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "leader")); |
| | | if (ObjectUtils.isEmpty(power)) { |
| | | //不是组长 |
| | | if (map1.get("look") == 1) { |
| | | //是组员 |
| | | auxiliaryOutputWorkingHoursDto.setCheck(map1.get("userId")); |
| | | } else { |
| | | //管理员(不添加限制条件所有人都可以看) |
| | | } |
| | | } else { |
| | | //是组长 |
| | | //查询组长下的组员 |
| | | List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().like(User::getDepartLimsId, user.getDepartLimsId())); |
| | | if (ObjectUtils.isNotEmpty(users)) { |
| | | ids = users.stream().map(User::getId).distinct().collect(Collectors.toList()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(dates)) { |
| | | String[] split = dates.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(","); |
| | | if (ObjectUtils.isNotEmpty(week)){ |
| | | String[] weeks = week.replaceAll("\\[", "").replaceAll("]", "").replaceAll("\"", "").split(","); |
| | | map.put("body", auxiliaryOutputWorkingHoursMapper.selectAuxiliaryOutputWorkingHours(page, |
| | | QueryWrappers.queryWrappers(auxiliaryOutputWorkingHoursDto) |
| | | .ge("date_time", split[0]).le("date_time", split[1] + " 23:59:59") |
| | | .ge("week", weeks[0]).le("week", weeks[1] ), ids)); |
| | | } |
| | | map.put("body", auxiliaryOutputWorkingHoursMapper.selectAuxiliaryOutputWorkingHours(page, QueryWrappers.queryWrappers(auxiliaryOutputWorkingHoursDto).ge("date_time", split[0]).le("date_time", split[1] + " 23:59:59"), ids)); |
| | | } else { |
| | | map.put("body", auxiliaryOutputWorkingHoursMapper.selectAuxiliaryOutputWorkingHours(page, QueryWrappers.queryWrappers(auxiliaryOutputWorkingHoursDto), ids)); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | //统计产量工时汇总和辅助工时汇总 |
| | | @Override |
| | | public Map<String, Object> collectWorkingHours() { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Double sumOutputWorkTime = 0.0; |
| | | Double sumApprovedWorkingHour = 0.0; |
| | | List<Integer> ids = null; |
| | | //判断是组长还是组员还是管理员 |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectAuxiliaryOutputWorkingHours"); |
| | | User user = userMapper.selectById(map1.get("userId")); |
| | | Integer roleId = user.getRoleId(); |
| | | Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "leader")); |
| | | if (ObjectUtils.isEmpty(power)) { |
| | | //不是组长 |
| | | if (map1.get("look") == 1) { |
| | | //是组员 |
| | | ids.add(map1.get("userId")); |
| | | } else { |
| | | //管理员(不添加限制条件所有人都可以看) |
| | | } |
| | | } else { |
| | | //是组长 |
| | | //查询组长下的组员 |
| | | List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().like(User::getDepartLimsId, user.getDepartLimsId())); |
| | | if (ObjectUtils.isNotEmpty(users)) { |
| | | ids = users.stream().map(User::getId).distinct().collect(Collectors.toList()); |
| | | } |
| | | } |
| | | //统计当前用户的产品工时 |
| | | List<AuxiliaryOutputWorkingHours> auxiliaryOutputWorkingHours = auxiliaryOutputWorkingHoursMapper.selectListByIds(ids); |
| | | if (ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours)) { |
| | | Map<String, Double> sumMap = new HashMap<>(); |
| | | for (AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHour : auxiliaryOutputWorkingHours) { |
| | | if (!sumMap.containsKey(auxiliaryOutputWorkingHour.getManHourGroup())) { |
| | | sumMap.put(auxiliaryOutputWorkingHour.getManHourGroup(), auxiliaryOutputWorkingHour.getOutputWorkTime()); |
| | | } |
| | | } |
| | | sumOutputWorkTime = sumMap.values().stream().mapToDouble(Double::doubleValue).sum(); |
| | | } |
| | | map.put("产量工时汇总", sumOutputWorkTime); |
| | | //统计当前用户的辅助工时 |
| | | List<AuxiliaryWorkingHoursDay> auxiliaryWorkingHoursDays = auxiliaryWorkingHoursDayMapper.selectListByIds(ids); |
| | | if (ObjectUtils.isNotEmpty(auxiliaryWorkingHoursDays)) { |
| | | for (AuxiliaryWorkingHoursDay auxiliaryWorkingHoursDay : auxiliaryWorkingHoursDays) { |
| | | sumApprovedWorkingHour += auxiliaryWorkingHoursDay.getNonproductiveTime(); |
| | | } |
| | | } |
| | | map.put("辅助工时汇总", sumApprovedWorkingHour); |
| | | return map; |
| | | } |
| | | |
| | | //导出 |
| | | @Override |
| | | public void exportWorkingHours(HttpServletResponse response) throws IOException { |
| | | List<AuxiliaryOutputWorkingHoursDto> auxiliaryOutputWorkingHoursDtos = null; |
| | | List<AuxiliaryWorkingHoursDayDto> auxiliaryWorkingHoursDayDtos = null; |
| | | List<Integer> ids = null; |
| | | //判断是组长还是组员还是管理员 |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectAuxiliaryOutputWorkingHours"); |
| | | User user = userMapper.selectById(map1.get("userId")); |
| | | Integer roleId = user.getRoleId(); |
| | | Power power = powerMapper.selectOne(Wrappers.<Power>lambdaQuery().eq(Power::getRoleId, roleId).eq(Power::getMenuMethod, "leader")); |
| | | if (ObjectUtils.isEmpty(power)) { |
| | | //不是组长 |
| | | if (map1.get("look") == 1) { |
| | | //是组员 |
| | | ids.add(map1.get("userId")); |
| | | } else { |
| | | //管理员(不添加限制条件所有人都可以看) |
| | | } |
| | | } else { |
| | | //是组长 |
| | | //查询组长下的组员 |
| | | List<User> users = userMapper.selectList(Wrappers.<User>lambdaQuery().like(User::getDepartLimsId, user.getDepartLimsId())); |
| | | if (ObjectUtils.isNotEmpty(users)) { |
| | | ids = users.stream().map(User::getId).distinct().collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |
| | | //查询辅助工时 |
| | | auxiliaryWorkingHoursDayDtos = auxiliaryWorkingHoursDayMapper.selectDataByUser(ids); |
| | | // if (auxiliaryWorkingHoursDayDtos == null || auxiliaryWorkingHoursDayDtos.size() == 0) { |
| | | // throw new RuntimeException("暂无数据"); |
| | | // } |
| | | //查询统计工时 |
| | | auxiliaryOutputWorkingHoursDtos = auxiliaryOutputWorkingHoursMapper.selectDataByUser(ids); |
| | | // if (auxiliaryOutputWorkingHoursDtos == null || auxiliaryOutputWorkingHoursDtos.size() == 0) { |
| | | // throw new RuntimeException("暂无数据"); |
| | | // } |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("工时管理导出", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | try { |
| | | // 新建ExcelWriter |
| | | ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); |
| | | |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(0, "辅助工时导出").head(AuxiliaryWorkingHoursDayDto.class).build(); |
| | | excelWriter.write(auxiliaryWorkingHoursDayDtos, mainSheet); |
| | | |
| | | WriteSheet mainSheet1 = EasyExcel.writerSheet(1, "产量工时导出").head(AuxiliaryOutputWorkingHoursDto.class).build(); |
| | | excelWriter.write(auxiliaryOutputWorkingHoursDtos, mainSheet1); |
| | | // 关闭流 |
| | | excelWriter.finish(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | } |
| | | } |