|  |  |  | 
|---|
|  |  |  | import com.doumee.dao.business.PlatformWaterGasMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.PlatformReason; | 
|---|
|  |  |  | import com.doumee.dao.business.model.PlatformWaterGas; | 
|---|
|  |  |  | import com.doumee.dao.openapi.request.GasByMonthRequest; | 
|---|
|  |  |  | import com.doumee.dao.openapi.request.WaterByMonthRequest; | 
|---|
|  |  |  | import com.doumee.dao.openapi.response.GasByMonthResponse; | 
|---|
|  |  |  | import com.doumee.dao.openapi.response.PlatformLastMonthListResponse; | 
|---|
|  |  |  | import com.doumee.dao.openapi.response.WaterByMonthResponse; | 
|---|
|  |  |  | import com.doumee.service.business.PlatformWaterGasService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 月台_用水用气信息记录表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | public Integer create(PlatformWaterGas platformWaterGas) { | 
|---|
|  |  |  | if(platformWaterGas.getTimeInfo() ==null || platformWaterGas.getNum()==null | 
|---|
|  |  |  | ||(Constants.equalsInteger(platformWaterGas.getType(),Constants.TWO) && StringUtils.isBlank(platformWaterGas.getCarCode()))){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该年月数据已存在,请勿重新录入,可以尝试搜索后进行数据修改!"); | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,参数错误!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if( platformWaterGasMapper.selectCount(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted, Constants.ZERO) | 
|---|
|  |  |  | .apply("to_days(time_info) = to_days('"+ DateUtil.getPlusTime2(platformWaterGas.getTimeInfo()) +"')") | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,platformWaterGas.getType()) | 
|---|
|  |  |  | .eq(Constants.equalsInteger(platformWaterGas.getType(),Constants.TWO),PlatformWaterGas::getCarCode,platformWaterGas.getCarCode()))>0){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该年月数据已存在,请勿重新录入,可以尝试搜索后进行数据修改!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | IPage<PlatformWaterGas> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<PlatformWaterGas> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | queryWrapper.lambda().eq(PlatformWaterGas::getIsdeleted, Constants.ZERO); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(PlatformWaterGas::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<PlatformWaterGas> wrapper = new QueryWrapper<>(platformWaterGas); | 
|---|
|  |  |  | return platformWaterGasMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public WaterByMonthResponse waterDataByMonth(WaterByMonthRequest param){ | 
|---|
|  |  |  | Date queryDate = (Objects.nonNull(param)&&Objects.nonNull(param.getTimeInfo()))?param.getTimeInfo():new Date(); | 
|---|
|  |  |  | //获取上个月日期 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(queryDate); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -1); | 
|---|
|  |  |  | Date beforMonth = calendar.getTime(); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -11); | 
|---|
|  |  |  | Date beforYearMonth = calendar.getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WaterByMonthResponse waterByMonthResponse = new WaterByMonthResponse(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<PlatformWaterGas> list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ZERO) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(queryDate,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | waterByMonthResponse.setCurrentMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ZERO) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforMonth,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | waterByMonthResponse.setLastMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ZERO) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforYearMonth,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | waterByMonthResponse.setLastYearMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return waterByMonthResponse; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public GasByMonthResponse gasDataByMonth(GasByMonthRequest param){ | 
|---|
|  |  |  | Date queryDate = (Objects.nonNull(param)&&Objects.nonNull(param.getTimeInfo()))?param.getTimeInfo():new Date(); | 
|---|
|  |  |  | //获取上个月日期 | 
|---|
|  |  |  | Calendar calendar = Calendar.getInstance(); | 
|---|
|  |  |  | calendar.setTime(queryDate); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -1); | 
|---|
|  |  |  | Date beforMonth = calendar.getTime(); | 
|---|
|  |  |  | calendar.add(Calendar.MONTH, -11); | 
|---|
|  |  |  | Date beforYearMonth = calendar.getTime(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GasByMonthResponse response = new GasByMonthResponse(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<PlatformWaterGas> list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ONE) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(queryDate,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | response.setCurrentMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ONE) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforMonth,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | response.setLastMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | list = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,Constants.ONE) | 
|---|
|  |  |  | .like(PlatformWaterGas::getTimeInfo,DateUtil.getDate(beforYearMonth,"yyyy-MM")) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(list)){ | 
|---|
|  |  |  | response.setLastYearMonth(list.stream().map(m->m.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return response; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param type 0用水 1用气 | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<PlatformLastMonthListResponse> getPlatformLastMonthListResponse(Integer type){ | 
|---|
|  |  |  | List<PlatformLastMonthListResponse> lastMonthListResponses = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<PlatformWaterGas> platformWaterGasList = platformWaterGasMapper.selectList(new QueryWrapper<PlatformWaterGas>().lambda() | 
|---|
|  |  |  | .eq(PlatformWaterGas::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(PlatformWaterGas::getType,type) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<String> monthList = DateUtil.getBeforMonth(new Date(),12); | 
|---|
|  |  |  | for (String str:monthList) { | 
|---|
|  |  |  | PlatformLastMonthListResponse platformLastMonthListResponse = new PlatformLastMonthListResponse(); | 
|---|
|  |  |  | platformLastMonthListResponse.setNum(platformWaterGasList.stream().filter(i->DateUtil.dateToString(i.getTimeInfo(),"yyyy-MM").equals(str)).map(i->i.getNum()).reduce(BigDecimal.ZERO,BigDecimal::add)); | 
|---|
|  |  |  | platformLastMonthListResponse.setTimeInfo(str); | 
|---|
|  |  |  | lastMonthListResponses.add(platformLastMonthListResponse); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return lastMonthListResponses; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|