|
@@ -4,32 +4,30 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.platform.common.exception.BusinessException;
|
|
|
import com.platform.common.model.UserInfo;
|
|
|
-import com.platform.common.util.BeanConverterUtil;
|
|
|
-import com.platform.common.util.BigDecimalUtil;
|
|
|
-import com.platform.common.util.IdGeneratorUtils;
|
|
|
-import com.platform.common.util.SecurityUtils;
|
|
|
+import com.platform.common.util.*;
|
|
|
import com.platform.dao.bean.MyVOPage;
|
|
|
import com.platform.dao.dto.sqarepartmanage.SparePartUsedDTO;
|
|
|
-import com.platform.dao.dto.store.OutStoreFormDTO;
|
|
|
import com.platform.dao.entity.sqarepartmanage.SparePartUsed;
|
|
|
import com.platform.dao.entity.store.SpareStore;
|
|
|
-import com.platform.dao.enums.DelFlagEnum;
|
|
|
import com.platform.dao.enums.SparePartUsedStatusEnum;
|
|
|
import com.platform.dao.mapper.sqarepartmanage.SparePartUsedMapper;
|
|
|
import com.platform.dao.mapper.store.SpareStoreMapper;
|
|
|
import com.platform.dao.mapper.store.SpareStoreSecondMapper;
|
|
|
+import com.platform.dao.vo.report.SparePartInfoReportVO;
|
|
|
import com.platform.dao.vo.spare.SparePartUsedVO;
|
|
|
import com.platform.service.base.impl.BaseServiceImpl;
|
|
|
import com.platform.service.sqarepartmanage.SparePartUsedService;
|
|
|
-import com.platform.service.store.SpareStoreService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import tk.mybatis.mapper.weekend.Weekend;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Description 备件使用表 service 实现类
|
|
@@ -155,4 +153,75 @@ public class SparePartUsedServiceImpl extends BaseServiceImpl<SparePartUsedMappe
|
|
|
public List<SparePartUsedVO> selectSparePartUsedListByRepairId(String repairId) {
|
|
|
return mapper.selectSparePartUsedListByRepairId(repairId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SparePartInfoReportVO> getMonthReport(SparePartUsedDTO sparePartUsedDTO, Integer searchYear, LocalDate startMonth, LocalDate endMonth) {
|
|
|
+ List<Map<String, LocalDateTime>> monthStartAndEndList = null;
|
|
|
+ LocalDateTime searchStartTime = null;
|
|
|
+ LocalDateTime searchEndTime = null;
|
|
|
+ if(searchYear != null){
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ int year = localDate.getYear();
|
|
|
+ // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
|
|
|
+ int month = localDate.getMonthValue();
|
|
|
+ if(searchYear<year){
|
|
|
+ month = 12;
|
|
|
+ year = searchYear;
|
|
|
+ }
|
|
|
+ monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(year, month);
|
|
|
+ // 当前年份只统计到当前月,历史年份统计全年
|
|
|
+ searchStartTime = DateUtils.getFirstDayOfThisYear(year);
|
|
|
+ searchEndTime = DateUtils.getLastDayOfMonth(year, month);
|
|
|
+ }else{
|
|
|
+ monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(startMonth, endMonth);
|
|
|
+ searchStartTime = DateUtils.getFirstDayOfMonth(startMonth);
|
|
|
+ searchEndTime = DateUtils.getLastDayOfMonth(endMonth);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 总数
|
|
|
+ sparePartUsedDTO.setSearchStartTime(searchStartTime.toLocalDate());
|
|
|
+ sparePartUsedDTO.setSearchEndTime(searchEndTime.toLocalDate());
|
|
|
+ List<SparePartUsedVO> list = mapper.selectVOList(sparePartUsedDTO);
|
|
|
+
|
|
|
+ List<SparePartInfoReportVO> result = new ArrayList<>();
|
|
|
+ for(Map<String, LocalDateTime> map: monthStartAndEndList){
|
|
|
+ SparePartInfoReportVO vo = new SparePartInfoReportVO();
|
|
|
+ List<SparePartUsedVO> detailList = new ArrayList<>();
|
|
|
+ vo.setYear(map.get("searchStartTimeMonth").getYear());
|
|
|
+ vo.setMonth(map.get("searchStartTimeMonth").getMonthValue());
|
|
|
+ BigDecimal totalNum = new BigDecimal(0); // 更换数目
|
|
|
+ BigDecimal totalPrice = new BigDecimal(0.0); // 更换金额
|
|
|
+ for(SparePartUsedVO useVO: list){
|
|
|
+ if(useVO.getStartDate().isAfter(map.get("searchStartTimeMonth").toLocalDate()) &&
|
|
|
+ useVO.getStartDate().isBefore(map.get("searchEndTimeMonth").toLocalDate())){
|
|
|
+ totalNum = totalNum.add(useVO.getNum());
|
|
|
+ totalPrice = totalPrice.add(useVO.getPrice());
|
|
|
+ detailList.add(useVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setTotalNum(totalNum);
|
|
|
+ vo.setTotalPrice(totalPrice);
|
|
|
+ vo.setDetailList(detailList);
|
|
|
+ result.add(vo);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SparePartUsedVO> getMonthReportMonth(SparePartUsedDTO sparePartUsedDTO, Integer year, Integer month) {
|
|
|
+ LocalDateTime searchStartTimeMonth = DateUtils.getFirstDayOfMonth(year, month);
|
|
|
+ LocalDateTime searchEndTimeMonth = DateUtils.getLastDayOfMonth(year, month);
|
|
|
+ // 总数
|
|
|
+ sparePartUsedDTO.setSearchStartTime(searchStartTimeMonth.toLocalDate());
|
|
|
+ sparePartUsedDTO.setSearchEndTime(searchEndTimeMonth.toLocalDate());
|
|
|
+ return mapper.selectVOList(sparePartUsedDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ int year = localDate.getYear();
|
|
|
+ // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
|
|
|
+ int month = localDate.getMonthValue();
|
|
|
+ System.out.println(month);
|
|
|
+ }
|
|
|
}
|