| | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.gkhy.hazmat.common.api.CommonPage; |
| | | import com.gkhy.hazmat.common.config.IdTableNameHandler; |
| | | import com.gkhy.hazmat.common.domain.entity.SysUser; |
| | | import com.gkhy.hazmat.common.enums.HazmatPackageEnum; |
| | | import com.gkhy.hazmat.common.enums.HazmatStatusEnum; |
| | | import com.gkhy.hazmat.common.enums.UserTypeEnum; |
| | | import com.gkhy.hazmat.common.excel.HazmatBasicUseExcelData; |
| | | import com.gkhy.hazmat.common.exception.ApiException; |
| | | import com.gkhy.hazmat.common.utils.PageUtils; |
| | | import com.gkhy.hazmat.common.utils.SecurityUtils; |
| | |
| | | import com.gkhy.hazmat.system.domain.vo.HzHomeDataVO; |
| | | import com.gkhy.hazmat.system.mapper.*; |
| | | import com.gkhy.hazmat.system.service.HzStatisticService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private HzWarningMapper warningMapper; |
| | | |
| | | @Override |
| | | public List<HzEntryRecordVO> entryStatic() { |
| | | public List<HzEntryRecordVO> entryStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | Date currentDate=new Date(); |
| | | DateTime endTime = DateUtil.endOfDay(currentDate); |
| | |
| | | dayEntryRecordList.add(entryRecordVO); |
| | | startTime=DateUtil.offsetDay(startTime,1); |
| | | } |
| | | List<HzEntryRecordVO> entryRecordVOList= entryRecordMapper.entryCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | //todo |
| | | List<HzEntryRecordVO> entryRecordVOList= entryRecordMapper.entryCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | if(!entryRecordVOList.isEmpty()) { |
| | | Map<String, HzEntryRecordVO> resMap = entryRecordVOList.stream().collect(Collectors.toMap(item -> item.getMonth()+"_"+item.getDay(), item -> item)); |
| | | for (HzEntryRecordVO er : dayEntryRecordList) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HzEntryRecordVO> useEverydayStatic() { |
| | | public List<HzEntryRecordVO> useEverydayStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | Date currentDate=new Date(); |
| | |
| | | dayEntryRecordList.add(entryRecordVO); |
| | | startTime=DateUtil.offsetDay(startTime,1); |
| | | } |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | List<HzEntryRecordVO> entryRecordVOList= hazmatMapper.useCountEverydayStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | List<HzEntryRecordVO> entryRecordVOList= hazmatMapper.useCountEverydayStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!entryRecordVOList.isEmpty()) { |
| | | Map<String, HzEntryRecordVO> resMap = entryRecordVOList.stream().collect(Collectors.toMap(item -> item.getDay(), item -> item)); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HzHazmatUseVO> maxUseStatic() { |
| | | public List<HzHazmatUseVO> maxUseStatic(Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | |
| | |
| | | DateTime startTime = DateUtil.beginOfDay(DateUtil.offsetDay(currentDate, -6)); |
| | | String startDate= DateUtil.format(startTime, DatePattern.NORM_DATETIME_FORMAT); |
| | | String endDate=DateUtil.format(endTime,DatePattern.NORM_DATETIME_FORMAT); |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.maxUseCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.maxUseCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!hazmatUseVOList.isEmpty()) { |
| | | List<Long> basicIds = hazmatUseVOList.stream().map(HzHazmatUseVO::getBasicId).collect(Collectors.toList()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public HzHomeDataVO homeDataStatistic() { |
| | | public HzHomeDataVO homeDataStatistic(Long companyid) { |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | Long companyId=currentUser.getCompanyId(); |
| | | Long companyId= null; |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | companyId = companyid; |
| | | }else { |
| | | companyId = currentUser.getCompanyId(); |
| | | } |
| | | Integer warehouseCount= Math.toIntExact(warehouseMapper.selectCount(Wrappers.<HzWarehouse>lambdaQuery() |
| | | .eq(true, HzWarehouse::getDelFlag, 0) |
| | | .eq(companyId!=null,HzWarehouse::getCompanyId,companyId))); |
| | |
| | | stateList.add(HazmatStatusEnum.USED.getCode()); |
| | | stateList.add(HazmatStatusEnum.DISCARD.getCode()); |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | Integer hazmatCount= Math.toIntExact(hazmatMapper.selectCount(Wrappers.<HzHazmat>lambdaQuery() |
| | | .notIn(true, HzHazmat::getState, stateList) |
| | | .eq(companyId!=null,HzHazmat::getCompanyId,companyId))); |
| | |
| | | |
| | | |
| | | @Override |
| | | public CommonPage useStatic(String startTime, String endTime) { |
| | | public CommonPage useStatic(String startTime, String endTime,Long companyId) { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | |
| | |
| | | }else{ |
| | | startDate=startTime; |
| | | endDate=endTime; |
| | | if(DateUtil.between(new Date(endDate),new Date(startTime), DateUnit.DAY)>90){ |
| | | if(DateUtil.between(DateUtil.parse(startDate),DateUtil.parse(startTime), DateUnit.DAY)>90){ |
| | | throw new ApiException("只能查询90天以内数据"); |
| | | } |
| | | } |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){ |
| | | IdTableNameHandler.setCurrentId(companyId); |
| | | |
| | | }else { |
| | | //设置分表id |
| | | //todo |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | } |
| | | PageUtils.startPage(); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.useCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.useCountStatic(startDate, endDate,currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode()) ? companyId:currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | if(!hazmatUseVOList.isEmpty()) { |
| | | List<Long> basicIds = hazmatUseVOList.stream().map(HzHazmatUseVO::getBasicId).collect(Collectors.toList()); |
| | |
| | | return CommonPage.restPage(hazmatUseVOList); |
| | | } |
| | | |
| | | @Override |
| | | public void importBaiscUse(HttpServletResponse response, String startTime, String endTime) throws IOException { |
| | | SysUser currentUser= SecurityUtils.getLoginUser().getUser(); |
| | | checkUserAllowed(currentUser); |
| | | OutputStream outputStream = response.getOutputStream(); |
| | | try { |
| | | String startDate=""; |
| | | String endDate=""; |
| | | if(StringUtils.isBlank(startTime)&&StringUtils.isBlank(endTime)){ |
| | | Date currentDate=new Date(); |
| | | startDate= DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.endOfDay(currentDate), -29)), DatePattern.NORM_DATETIME_FORMAT); |
| | | endDate=DateUtil.format(DateUtil.endOfDay(currentDate),DatePattern.NORM_DATETIME_FORMAT); |
| | | } else if (StringUtils.isBlank(startTime)&&StringUtils.isNotBlank(endTime)) { |
| | | startDate= DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.endOfDay(new Date(endTime)), -29)), DatePattern.NORM_DATETIME_FORMAT); |
| | | endDate=endTime; |
| | | }else if (StringUtils.isNotBlank(startTime)&&StringUtils.isBlank(endTime)){ |
| | | startDate=startTime; |
| | | endDate=DateUtil.format(DateUtil.beginOfDay(DateUtil.offsetDay(DateUtil.endOfDay(new Date(endTime)), 29)), DatePattern.NORM_DATETIME_FORMAT); |
| | | }else{ |
| | | startDate=startTime; |
| | | endDate=endTime; |
| | | if(DateUtil.between(DateUtil.parse(startDate),DateUtil.parse(startTime), DateUnit.DAY)>90){ |
| | | throw new ApiException("只能查询90天以内数据"); |
| | | } |
| | | } |
| | | //设置分表id |
| | | IdTableNameHandler.setCurrentId(currentUser.getCompanyId()); |
| | | // PageUtils.startPage(); |
| | | List<HzHazmatUseVO> hazmatUseVOList= hazmatMapper.useCountStatic(startDate, endDate,currentUser.getCompanyId()); |
| | | IdTableNameHandler.removeCurrentId(); |
| | | List<HazmatBasicUseExcelData> hazmatBasicUseExcelDatas = new ArrayList<>(); |
| | | if(!hazmatUseVOList.isEmpty()) { |
| | | List<Long> basicIds = hazmatUseVOList.stream().map(HzHazmatUseVO::getBasicId).collect(Collectors.toList()); |
| | | List<HzHazmatBasic> hzHazmatBasicList = hazmatBasicMapper.selectHazmatBasicListByIds(basicIds); |
| | | Map<Long, HzHazmatBasic> hazmatBasicMap = hzHazmatBasicList.stream().collect(Collectors.toMap(HzHazmatBasic::getId, item -> item)); |
| | | Integer index=1; |
| | | for (HzHazmatUseVO hu : hazmatUseVOList) { |
| | | HazmatBasicUseExcelData hazmatBasicUseExcelData = new HazmatBasicUseExcelData(); |
| | | hazmatBasicUseExcelData.setCount(hu.getCount()); |
| | | HzHazmatBasic hazmatBasic = hazmatBasicMap.get(hu.getBasicId()); |
| | | if (hazmatBasic != null) { |
| | | BeanUtils.copyProperties(hazmatBasic,hazmatBasicUseExcelData); |
| | | hazmatBasicUseExcelData.setIndex(index); |
| | | hazmatBasicUseExcelData.setProductType(hazmatBasic.getHazmatType()); |
| | | hazmatBasicUseExcelData.setProductCharacter(hazmatBasic.getHazmatCharacter()); |
| | | hazmatBasicUseExcelData.setProductFormat(hazmatBasic.getHazmatFormat()); |
| | | hazmatBasicUseExcelData.setMinPackage(HazmatPackageEnum.getInfoByCode(hazmatBasic.getMinPackage())); |
| | | } |
| | | index++; |
| | | hazmatBasicUseExcelDatas.add(hazmatBasicUseExcelData); |
| | | } |
| | | } |
| | | Date date = new Date(); |
| | | long time = date.getTime(); |
| | | String fileName = "危化品用量统计_"+time; |
| | | this.setExcelResponseProp(response,fileName); |
| | | |
| | | //使用 EasyExcel 导出数据 |
| | | EasyExcel.write(response.getOutputStream(), HazmatBasicUseExcelData.class) |
| | | .excelType(ExcelTypeEnum.XLSX) |
| | | .sheet("危化品使用记录统计表") // 设置 Sheet 名称 |
| | | .doWrite(hazmatBasicUseExcelDatas); // 写入数据 |
| | | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private void setExcelResponseProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { |
| | | //设置内容类型 |
| | | response.setContentType("application/vnd.vnd.ms-excel"); |
| | | //设置编码格式 |
| | | response.setCharacterEncoding("utf-8"); |
| | | //设置导出文件名称(避免乱码) |
| | | String fileName = URLEncoder.encode(rawFileName.concat(".xlsx"), "UTF-8"); |
| | | // 设置响应头 |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName); |
| | | } |
| | | |
| | | public void checkUserAllowed(SysUser user) { |
| | | if (user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) { |
| | | throw new ApiException("管理员不能操作"); |