首页查询接口
This commit is contained in:
parent
c50f276928
commit
5afdd83eed
|
|
@ -0,0 +1,77 @@
|
|||
package com.bonus.material.main.controller;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.main.domain.DemandAndSupplyVo;
|
||||
import com.bonus.material.main.service.MainService;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import static com.bonus.common.core.web.domain.AjaxResult.success;
|
||||
|
||||
|
||||
@Api(tags = "机具设备首页接口")
|
||||
@RestController
|
||||
@RequestMapping("/mainPage")
|
||||
@Slf4j
|
||||
public class MainController {
|
||||
|
||||
@Resource
|
||||
private MainService mainService;
|
||||
|
||||
/**
|
||||
* 查询机具设备管理列表
|
||||
*/
|
||||
|
||||
@GetMapping("/demandAndSupply")
|
||||
public AjaxResult demandAndSupply(DemandAndSupplyVo demandAndSupplyVo)
|
||||
{
|
||||
//Long userId = SecurityUtils.getUserId();
|
||||
//demandAndSupplyVo.setUserId(userId == 0 ? null : userId);
|
||||
if (demandAndSupplyVo.getStartTime() ==null || demandAndSupplyVo.getStartTime() ==" "){
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//获取当前时间
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
String currentDateStr = currentDate.format(formatter);
|
||||
// 获取本月第一天的日期
|
||||
LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1);
|
||||
String firstDayOfMonthStr = firstDayOfMonth.format(formatter);
|
||||
demandAndSupplyVo.setStartTime(firstDayOfMonthStr);
|
||||
demandAndSupplyVo.setEndTime(currentDateStr);
|
||||
}
|
||||
DemandAndSupplyVo demandAndSupplyVoRes = new DemandAndSupplyVo();
|
||||
//需求量
|
||||
BigDecimal demandNum = mainService.getDemandNum(demandAndSupplyVo);
|
||||
//需求增长量
|
||||
BigDecimal demandIncrease = mainService.getDemandIncrease(demandAndSupplyVo);
|
||||
//已供应数量
|
||||
BigDecimal suppliedQuantityNum = mainService.getSuppliedQuantityNum(demandAndSupplyVo);
|
||||
//已供应增长量
|
||||
BigDecimal suppliedQuantityIncrease = mainService.getSuppliedQuantityIncrease(demandAndSupplyVo);
|
||||
//待供应量
|
||||
BigDecimal suppliedToBeQuantityNum = mainService.getSuppliedToBeQuantityNum(demandAndSupplyVo);
|
||||
//待供应量增长量
|
||||
BigDecimal suppliedToBeQuantityIncrease = mainService.getSuppliedToBeQuantityIncrease(demandAndSupplyVo);
|
||||
//工程总数量
|
||||
Integer projectNum = mainService.getProjectNum(demandAndSupplyVo);
|
||||
//供应总件数
|
||||
|
||||
demandAndSupplyVoRes.setDemandNum(demandNum);
|
||||
demandAndSupplyVoRes.setDemandIncrease(demandIncrease);
|
||||
demandAndSupplyVoRes.setSuppliedQuantityNum(suppliedQuantityNum);
|
||||
demandAndSupplyVoRes.setSuppliedQuantityIncrease(suppliedQuantityIncrease);
|
||||
demandAndSupplyVoRes.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum);
|
||||
demandAndSupplyVoRes.setSuppliedToBeQuantityIncrease(suppliedToBeQuantityIncrease);
|
||||
demandAndSupplyVoRes.setProjectNum(projectNum);
|
||||
return success(demandAndSupplyVoRes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package com.bonus.material.main.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class DemandAndSupplyVo {
|
||||
|
||||
|
||||
/**
|
||||
* 需求量
|
||||
*/
|
||||
private BigDecimal demandNum;
|
||||
|
||||
/**
|
||||
* 需求增长量
|
||||
*/
|
||||
private BigDecimal demandIncrease;
|
||||
|
||||
/**
|
||||
* 已供应量
|
||||
*/
|
||||
private BigDecimal suppliedQuantityNum;
|
||||
|
||||
/**
|
||||
* 供应增长量
|
||||
*/
|
||||
private BigDecimal suppliedQuantityIncrease;
|
||||
|
||||
/**
|
||||
* 待供应量
|
||||
*/
|
||||
private BigDecimal suppliedToBeQuantityNum;
|
||||
|
||||
/**
|
||||
* 待供应增长量
|
||||
*/
|
||||
private BigDecimal suppliedToBeQuantityIncrease;
|
||||
|
||||
/**
|
||||
* 工程总数量
|
||||
*/
|
||||
private Integer projectNum;
|
||||
|
||||
/**
|
||||
* 供应总件数
|
||||
*/
|
||||
private BigDecimal suppliedQuantityAllNum;
|
||||
|
||||
/**
|
||||
* 供应总价值
|
||||
*/
|
||||
private BigDecimal suppliedQuantityPrice;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty(value = "开始时间")
|
||||
private String startTime;
|
||||
|
||||
@ApiModelProperty(value = "结束时间")
|
||||
private String endTime;
|
||||
|
||||
/**
|
||||
* 当前时间
|
||||
*/
|
||||
private LocalDate currentDate;
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.bonus.material.main.mapper;
|
||||
|
||||
import com.bonus.common.biz.domain.lease.LeasePublishInfo;
|
||||
import com.bonus.material.main.domain.DemandAndSupplyVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public interface MainMapper {
|
||||
List<LeasePublishInfo> getPublishList(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getPublishListNew(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
Integer getProjectNum();
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.bonus.material.main.service;
|
||||
|
||||
import com.bonus.material.main.domain.DemandAndSupplyVo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public interface MainService {
|
||||
BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getDemandIncrease(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getSuppliedQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getSuppliedToBeQuantityNum(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
BigDecimal getSuppliedToBeQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo);
|
||||
|
||||
Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo);
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
package com.bonus.material.main.service.impl;
|
||||
|
||||
import com.bonus.common.biz.domain.lease.LeasePublishInfo;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.main.domain.DemandAndSupplyVo;
|
||||
import com.bonus.material.main.mapper.MainMapper;
|
||||
import com.bonus.material.main.service.MainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MainServiceImpl implements MainService {
|
||||
|
||||
@Resource
|
||||
private MainMapper mainMapper;
|
||||
|
||||
/**
|
||||
* 需求量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
//获取领料的需求数量
|
||||
List<LeasePublishInfo> list = mainMapper.getPublishList(demandAndSupplyVo);
|
||||
BigDecimal preCountNum = list.stream().map(LeasePublishInfo::getPreCountNum)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
//获取领用的需求数量
|
||||
BigDecimal preCountNumNew = mainMapper.getPublishListNew(demandAndSupplyVo);
|
||||
preCountNum = preCountNum.add(preCountNumNew);
|
||||
return preCountNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需求增长量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getDemandIncrease(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo();
|
||||
BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew);
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//上个月的开始时间
|
||||
LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter);
|
||||
LocalDate lastStartTime = startTime.minusMonths(1);
|
||||
String lastStartTimeStr = lastStartTime.format(formatter);
|
||||
//上个月的结束时间
|
||||
LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter);
|
||||
LocalDate lastEndTime = endTime.minusMonths(1);
|
||||
String lastEndTimeStr = lastEndTime.format(formatter);
|
||||
//获取本月的需求数量
|
||||
BigDecimal preCountNum= this.getDemandNum(demandAndSupplyVoNew);
|
||||
//获取上个月需求量
|
||||
demandAndSupplyVoNew.setStartTime(lastStartTimeStr);
|
||||
demandAndSupplyVoNew.setEndTime(lastEndTimeStr);
|
||||
BigDecimal lastPreCountNum = this.getDemandNum(demandAndSupplyVoNew);
|
||||
//计算增长量
|
||||
BigDecimal demandIncrease= BigDecimal.ZERO;
|
||||
if (lastPreCountNum.compareTo(BigDecimal.ZERO)==0){
|
||||
demandIncrease = BigDecimal.valueOf(100);
|
||||
}else {
|
||||
demandIncrease = preCountNum.subtract(lastPreCountNum).divide(lastPreCountNum, 4, RoundingMode.HALF_UP);
|
||||
demandIncrease = demandIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
return demandIncrease;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已供应量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
//已供应量
|
||||
BigDecimal suppliedQuantityNum = mainMapper.getSuppliedQuantityNum(demandAndSupplyVo);
|
||||
return suppliedQuantityNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 供应增长量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getSuppliedQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo();
|
||||
BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew);
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//本月以供应量
|
||||
BigDecimal suppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVoNew);
|
||||
//上个月的开始时间
|
||||
LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter);
|
||||
LocalDate lastStartTime = startTime.minusMonths(1);
|
||||
String lastStartTimeStr = lastStartTime.format(formatter);
|
||||
//上个月的结束时间
|
||||
LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter);
|
||||
LocalDate lastEndTime = endTime.minusMonths(1);
|
||||
String lastEndTimeStr = lastEndTime.format(formatter);
|
||||
//获取上个月以供应量
|
||||
demandAndSupplyVoNew.setStartTime(lastStartTimeStr);
|
||||
demandAndSupplyVoNew.setEndTime(lastEndTimeStr);
|
||||
BigDecimal lastSuppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVoNew);
|
||||
//计算增长量
|
||||
BigDecimal suppliedQuantityIncrease = BigDecimal.ZERO;
|
||||
if (lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO)==0){
|
||||
suppliedQuantityIncrease = BigDecimal.valueOf(100);
|
||||
}else {
|
||||
suppliedQuantityIncrease = suppliedQuantityNum.subtract(lastSuppliedQuantityNum).divide(lastSuppliedQuantityNum, 4, RoundingMode.HALF_UP);
|
||||
suppliedQuantityIncrease = suppliedQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
return suppliedQuantityIncrease;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待供应量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getSuppliedToBeQuantityNum(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
//需求量
|
||||
BigDecimal preCountNum = this.getDemandNum(demandAndSupplyVo);
|
||||
//以供应量
|
||||
BigDecimal suppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVo);
|
||||
//待供应量
|
||||
BigDecimal suppliedToBeQuantityNum = preCountNum.subtract(suppliedQuantityNum);
|
||||
|
||||
return suppliedToBeQuantityNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 待供应增长量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BigDecimal getSuppliedToBeQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo();
|
||||
BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew);
|
||||
//本月待供应量
|
||||
BigDecimal suppliedToBeQuantityNum = this.getSuppliedToBeQuantityNum(demandAndSupplyVoNew);
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
//上个月的开始时间
|
||||
LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter);
|
||||
LocalDate lastStartTime = startTime.minusMonths(1);
|
||||
String lastStartTimeStr = lastStartTime.format(formatter);
|
||||
//上个月的结束时间
|
||||
LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter);
|
||||
LocalDate lastEndTime = endTime.minusMonths(1);
|
||||
String lastEndTimeStr = lastEndTime.format(formatter);
|
||||
//获取上个月以供应量
|
||||
demandAndSupplyVoNew.setStartTime(lastStartTimeStr);
|
||||
demandAndSupplyVoNew.setEndTime(lastEndTimeStr);
|
||||
BigDecimal lastSuppliedToBeQuantityNum = this.getSuppliedToBeQuantityNum(demandAndSupplyVoNew);
|
||||
//计算增长量
|
||||
BigDecimal suppliedToBeQuantityIncrease = BigDecimal.ZERO;
|
||||
if (lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO)==0){
|
||||
suppliedToBeQuantityIncrease = BigDecimal.valueOf(100);
|
||||
}else {
|
||||
suppliedToBeQuantityIncrease = suppliedToBeQuantityNum.subtract(lastSuppliedToBeQuantityNum).divide(lastSuppliedToBeQuantityNum, 4, RoundingMode.HALF_UP);
|
||||
suppliedToBeQuantityIncrease = suppliedToBeQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
return suppliedToBeQuantityIncrease;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工程总量
|
||||
* @param demandAndSupplyVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo) {
|
||||
return mainMapper.getProjectNum();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.material.main.mapper.MainMapper">
|
||||
|
||||
|
||||
<select id="getPublishList" resultType="com.bonus.common.biz.domain.lease.LeasePublishInfo">
|
||||
select
|
||||
IFNULL(sum(lad.pre_num),0) as preCountNum
|
||||
from
|
||||
lease_apply_info lai
|
||||
left join tm_task tt on lai.task_id = tt.task_id
|
||||
left join lease_apply_details lad on lai.id = lad.parent_id
|
||||
left join tm_task_agreement tta on lai.task_id = tta.task_id
|
||||
left join bm_unit bu on bu.unit_id = lai.unit_id
|
||||
left join bm_project bp on bp.pro_id = lai.project_id
|
||||
left join sys_dept sd on sd.dept_id = bp.imp_unit
|
||||
left join sys_dict_data sda on tt.task_status = sda.dict_value
|
||||
and sda.dict_type = 'lease_task_status'
|
||||
left join ma_type mt on lad.type_id = mt.type_id and mt.del_flag = '0'
|
||||
left join ma_type mt1 on mt.parent_id = mt1.type_id and mt1.del_flag = '0'
|
||||
<if test="userId != null">
|
||||
JOIN ma_type_keeper mtk ON mtk.type_id = lad.type_id AND mtk.user_id = #{userId}
|
||||
</if>
|
||||
where tt.task_status = 3
|
||||
and tt.task_type =2
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lai.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
GROUP BY lai.id
|
||||
ORDER BY tt.task_status,tt.create_time desc
|
||||
|
||||
</select>
|
||||
<select id="getPublishListNew" resultType="java.math.BigDecimal">
|
||||
select
|
||||
IFNULL(sum(lpd.num),0) as preCountNum
|
||||
from
|
||||
lease_publish_details lpd
|
||||
<if test="userId != null">
|
||||
JOIN ma_type_keeper mtk ON mtk.type_id = lpd.type_id AND mtk.user_id = #{userId}
|
||||
</if>
|
||||
where 1=1
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lpd.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getSuppliedQuantityNum" resultType="java.math.BigDecimal">
|
||||
select
|
||||
IFNULL(sum(lod.out_num),0) as preCountNum
|
||||
from
|
||||
lease_out_details lod
|
||||
<if test="userId != null">
|
||||
JOIN ma_type_keeper mtk ON mtk.type_id = lod.type_id AND mtk.user_id = #{userId}
|
||||
</if>
|
||||
where 1=1
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lod.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
</select>
|
||||
<select id="getProjectNum" resultType="java.lang.Integer">
|
||||
select
|
||||
count(bp.pro_id) as projectNum
|
||||
from
|
||||
bm_project bp
|
||||
where bp.pro_status in ('0','1','3')
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
AND DATE_FORMAT( lod.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue