This commit is contained in:
parent
5a89c77c8a
commit
caf296d1e6
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bonus.material.basic.mapper;
|
package com.bonus.material.basic.mapper;
|
||||||
|
|
||||||
|
import com.bonus.material.back.domain.vo.MaCodeVo;
|
||||||
import com.bonus.material.basic.domain.*;
|
import com.bonus.material.basic.domain.*;
|
||||||
import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
|
import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
@ -166,4 +167,25 @@ public interface ComplexQueryMapper {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<RetainedEquipmentInfo> getToolsLedgerDetailsList(RetainedEquipmentInfo bean);
|
List<RetainedEquipmentInfo> getToolsLedgerDetailsList(RetainedEquipmentInfo bean);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据用户Id,查询班组
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
BmTeam getTeamData(String userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询班组下库存
|
||||||
|
* @param bmTeam
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<RetainedEquipmentInfo> getToolsLedgerListByTeam(BmTeam bmTeam);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工器具台账详情查询--班组
|
||||||
|
* @param bean1
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<RetainedEquipmentInfo> getToolsDetailsListByTeam(MaCodeVo bean1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||||
import com.alibaba.nacos.common.utils.StringUtils;
|
import com.alibaba.nacos.common.utils.StringUtils;
|
||||||
import com.bonus.common.biz.enums.MaTypeManageTypeEnum;
|
import com.bonus.common.biz.enums.MaTypeManageTypeEnum;
|
||||||
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
|
import com.bonus.material.back.domain.vo.MaCodeVo;
|
||||||
import com.bonus.material.basic.domain.*;
|
import com.bonus.material.basic.domain.*;
|
||||||
import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
|
import com.bonus.material.basic.domain.vo.MaTypeSelectInfo;
|
||||||
import com.bonus.material.basic.mapper.ComplexQueryMapper;
|
import com.bonus.material.basic.mapper.ComplexQueryMapper;
|
||||||
|
|
@ -525,7 +527,19 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
|
||||||
public List<RetainedEquipmentInfo> getToolsLedgerList(RetainedEquipmentInfo bean) {
|
public List<RetainedEquipmentInfo> getToolsLedgerList(RetainedEquipmentInfo bean) {
|
||||||
List<RetainedEquipmentInfo> list1 =new ArrayList<>();
|
List<RetainedEquipmentInfo> list1 =new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
List<RetainedEquipmentInfo> list = complexQueryMapper.getToolsLedgerList(bean);
|
//1、获取当前用户Id
|
||||||
|
String userId = SecurityUtils.getUserId().toString();
|
||||||
|
//2、判断用户是否为班组长,且对应的是否有班组
|
||||||
|
BmTeam bmTeam=complexQueryMapper.getTeamData(userId);
|
||||||
|
List<RetainedEquipmentInfo> list=new ArrayList<>();
|
||||||
|
if (bmTeam!=null){
|
||||||
|
//不为空,则 是班组长且对应的有班组
|
||||||
|
//查询班组下工器具库存
|
||||||
|
list = complexQueryMapper.getToolsLedgerListByTeam(bmTeam);
|
||||||
|
} else {
|
||||||
|
//没有班组,则查全部
|
||||||
|
list = complexQueryMapper.getToolsLedgerList(bean);
|
||||||
|
}
|
||||||
if (list.size()>0){
|
if (list.size()>0){
|
||||||
list1 = groupByThirdTypeId(list);
|
list1 = groupByThirdTypeId(list);
|
||||||
}
|
}
|
||||||
|
|
@ -543,46 +557,66 @@ public class ComplexQueryServiceImpl implements ComplexQueryService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RetainedEquipmentInfo> getToolsDetailsList(RetainedEquipmentInfo bean) {
|
public List<RetainedEquipmentInfo> getToolsDetailsList(RetainedEquipmentInfo bean) {
|
||||||
List<RetainedEquipmentInfo> list = complexQueryMapper.getToolsDetailsList(bean);
|
try {
|
||||||
if (!CollectionUtil.isEmpty(list)) {
|
//1、获取当前用户Id
|
||||||
for (RetainedEquipmentInfo retainedEquipmentInfo : list) {
|
String userId = SecurityUtils.getUserId().toString();
|
||||||
if (StringUtils.isNotBlank(retainedEquipmentInfo.getNextCheckTime())) {
|
//2、判断用户是否为班组长,且对应的是否有班组
|
||||||
String nextCheckTime = retainedEquipmentInfo.getNextCheckTime();
|
BmTeam bmTeam=complexQueryMapper.getTeamData(userId);
|
||||||
// 解析字符串日期(格式:yyyy-MM-dd)
|
List<RetainedEquipmentInfo> list = new ArrayList<>();
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
if (bmTeam!=null) {
|
||||||
LocalDate targetDate = LocalDate.parse(nextCheckTime, formatter);
|
//不为空,则 是班组长且对应的有班组
|
||||||
LocalDate currentDate = LocalDate.now(); // 当前日期
|
MaCodeVo bean1 = new MaCodeVo();
|
||||||
boolean isFuture = targetDate.isAfter(currentDate);
|
bean1.setTeamId(bmTeam.getId());
|
||||||
if (!isFuture) {
|
bean1.setTypeId(bean.getTypeId()+"");
|
||||||
// 已过期
|
list = complexQueryMapper.getToolsDetailsListByTeam(bean1);
|
||||||
retainedEquipmentInfo.setStatus("3");
|
} else {
|
||||||
continue;
|
//没有班组,则查全部
|
||||||
}
|
list = complexQueryMapper.getToolsDetailsList(bean);
|
||||||
Period period = Period.between(currentDate, targetDate);
|
}
|
||||||
int years = period.getYears();
|
if (!CollectionUtil.isEmpty(list)) {
|
||||||
int months = period.getMonths();
|
for (RetainedEquipmentInfo retainedEquipmentInfo : list) {
|
||||||
int days = period.getDays();
|
if (StringUtils.isNotBlank(retainedEquipmentInfo.getNextCheckTime())) {
|
||||||
// 计算累计月份差(向上取整)
|
String nextCheckTime = retainedEquipmentInfo.getNextCheckTime();
|
||||||
int totalMonths = years * 12 + months;
|
// 解析字符串日期(格式:yyyy-MM-dd)
|
||||||
if (days > 0 || targetDate.getDayOfMonth() > currentDate.getDayOfMonth()) {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
totalMonths++;
|
LocalDate targetDate = LocalDate.parse(nextCheckTime, formatter);
|
||||||
}
|
// 当前日期
|
||||||
if (totalMonths <= 1) {
|
LocalDate currentDate = LocalDate.now();
|
||||||
retainedEquipmentInfo.setStatus("2");
|
boolean isFuture = targetDate.isAfter(currentDate);
|
||||||
} else if (totalMonths <= 3) {
|
if (!isFuture) {
|
||||||
retainedEquipmentInfo.setStatus("1");
|
// 已过期
|
||||||
} else {
|
retainedEquipmentInfo.setStatus("3");
|
||||||
retainedEquipmentInfo.setStatus("0");
|
continue;
|
||||||
|
}
|
||||||
|
Period period = Period.between(currentDate, targetDate);
|
||||||
|
int years = period.getYears();
|
||||||
|
int months = period.getMonths();
|
||||||
|
int days = period.getDays();
|
||||||
|
// 计算累计月份差(向上取整)
|
||||||
|
int totalMonths = years * 12 + months;
|
||||||
|
if (days > 0 || targetDate.getDayOfMonth() > currentDate.getDayOfMonth()) {
|
||||||
|
totalMonths++;
|
||||||
|
}
|
||||||
|
if (totalMonths <= 1) {
|
||||||
|
retainedEquipmentInfo.setStatus("2");
|
||||||
|
} else if (totalMonths <= 3) {
|
||||||
|
retainedEquipmentInfo.setStatus("1");
|
||||||
|
} else {
|
||||||
|
retainedEquipmentInfo.setStatus("0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isNotBlank(bean.getStatus())) {
|
||||||
|
return list.stream().filter(item -> {
|
||||||
|
return item.getStatus().equals(bean.getStatus());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(bean.getStatus())) {
|
return list;
|
||||||
return list.stream().filter(item -> {
|
} catch (Exception e){
|
||||||
return item.getStatus().equals(bean.getStatus());
|
log.error("工器具台账详情查询失败", e);
|
||||||
}).collect(Collectors.toList());
|
return new ArrayList<>();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1197,6 +1197,124 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
mm.type_id=#{typeId}
|
mm.type_id=#{typeId}
|
||||||
and mm.ma_status='1'
|
and mm.ma_status='1'
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getTeamData" resultType="com.bonus.material.basic.domain.BmTeam">
|
||||||
|
SELECT bt.id,
|
||||||
|
bt.team_name as teamName
|
||||||
|
FROM sys_user su
|
||||||
|
LEFT JOIN sys_user_role sur on sur.user_id = su.user_id
|
||||||
|
LEFT JOIN sys_role sr on sr.role_id = sur.role_id
|
||||||
|
LEFT JOIN bm_team bt on bt.rel_name = su.user_name
|
||||||
|
WHERE su.user_id = #{userId}
|
||||||
|
and sr.role_name = '班组长'
|
||||||
|
and bt.id is not null LIMIT 1
|
||||||
|
</select>
|
||||||
|
<select id="getToolsLedgerListByTeam" resultType="com.bonus.material.basic.domain.RetainedEquipmentInfo">
|
||||||
|
SELECT
|
||||||
|
COALESCE(t1.typeName, t2.typeName) AS typeName,
|
||||||
|
COALESCE(t1.typeModelName, t2.typeModelName) AS typeModelName,
|
||||||
|
COALESCE(t1.typeId, t2.typeId) AS typeId,
|
||||||
|
COALESCE(t1.thirdTypeId, t2.thirdTypeId) AS thirdTypeId,
|
||||||
|
CASE COALESCE(t1.manageType, t2.manageType)
|
||||||
|
WHEN 0 THEN
|
||||||
|
'编码'
|
||||||
|
ELSE
|
||||||
|
'数量'
|
||||||
|
END manageType,
|
||||||
|
COALESCE(t1.buyPrice, t2.buyPrice) AS buyPrice,
|
||||||
|
COALESCE(t1.unit, t2.unit) AS unit,
|
||||||
|
COALESCE(t1.storeNum, 0) - COALESCE(t2.storeNum, 0) AS storeNum
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
mt2.type_name as typeName,
|
||||||
|
mt1.type_name as typeModelName,
|
||||||
|
lod.type_id as typeId,
|
||||||
|
mt2.type_id as thirdTypeId,
|
||||||
|
mt1.manage_type as manageType,
|
||||||
|
mt1.buy_price as buyPrice,
|
||||||
|
mt1.unit_name as unit,
|
||||||
|
SUM(lod.out_num) as storeNum
|
||||||
|
FROM lease_out_details lod
|
||||||
|
LEFT JOIN lease_apply_info lai ON lai.id = lod.parent_id
|
||||||
|
LEFT JOIN ma_type mt1 ON mt1.type_id = lod.type_id
|
||||||
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
||||||
|
WHERE lai.team_id = #{id}
|
||||||
|
AND lod.is_finished = '1'
|
||||||
|
GROUP BY lod.type_id
|
||||||
|
) AS t1
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
mt2.type_name as typeName,
|
||||||
|
mt1.type_name as typeModelName,
|
||||||
|
bcd.type_id as typeId,
|
||||||
|
mt2.type_id as thirdTypeId,
|
||||||
|
mt1.manage_type as manageType,
|
||||||
|
mt1.buy_price as buyPrice,
|
||||||
|
mt1.unit_name as unit,
|
||||||
|
SUM(bcd.back_num) as storeNum
|
||||||
|
FROM back_check_details bcd
|
||||||
|
LEFT JOIN back_apply_info bai ON bai.id = bcd.parent_id
|
||||||
|
LEFT JOIN tm_task tt ON tt.task_id = bai.task_id
|
||||||
|
LEFT JOIN tm_task_agreement tta ON tta.task_id = tt.task_id
|
||||||
|
LEFT JOIN bm_agreement_info bagi ON bagi.agreement_id = tta.agreement_id
|
||||||
|
LEFT JOIN ma_type mt1 ON mt1.type_id = bcd.type_id
|
||||||
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
||||||
|
WHERE bagi.team_id = #{id}
|
||||||
|
AND bcd.is_finished = '1'
|
||||||
|
GROUP BY bcd.type_id
|
||||||
|
) AS t2 ON t1.typeId = t2.typeId
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
COALESCE(t1.typeName, t2.typeName) AS typeName,
|
||||||
|
COALESCE(t1.typeModelName, t2.typeModelName) AS typeModelName,
|
||||||
|
COALESCE(t1.typeId, t2.typeId) AS typeId,
|
||||||
|
COALESCE(t1.thirdTypeId, t2.thirdTypeId) AS thirdTypeId,
|
||||||
|
COALESCE(t1.manageType, t2.manageType) AS manageType,
|
||||||
|
COALESCE(t1.buyPrice, t2.buyPrice) AS buyPrice,
|
||||||
|
COALESCE(t1.unit, t2.unit) AS unit,
|
||||||
|
COALESCE(t1.storeNum, 0) - COALESCE(t2.storeNum, 0) AS diff_num
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
mt2.type_name as typeName,
|
||||||
|
mt1.type_name as typeModelName,
|
||||||
|
lod.type_id as typeId,
|
||||||
|
mt2.type_id as thirdTypeId,
|
||||||
|
mt1.manage_type as manageType,
|
||||||
|
mt1.buy_price as buyPrice,
|
||||||
|
mt1.unit_name as unit,
|
||||||
|
SUM(lod.out_num) as storeNum
|
||||||
|
FROM lease_out_details lod
|
||||||
|
LEFT JOIN lease_apply_info lai ON lai.id = lod.parent_id
|
||||||
|
LEFT JOIN ma_type mt1 ON mt1.type_id = lod.type_id
|
||||||
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
||||||
|
WHERE lai.team_id = #{id}
|
||||||
|
AND lod.is_finished = '1'
|
||||||
|
GROUP BY lod.type_id
|
||||||
|
) AS t1
|
||||||
|
RIGHT JOIN (
|
||||||
|
SELECT
|
||||||
|
mt2.type_name as typeName,
|
||||||
|
mt1.type_name as typeModelName,
|
||||||
|
bcd.type_id as typeId,
|
||||||
|
mt2.type_id as thirdTypeId,
|
||||||
|
mt1.manage_type as manageType,
|
||||||
|
mt1.buy_price as buyPrice,
|
||||||
|
mt1.unit_name as unit,
|
||||||
|
SUM(bcd.back_num) as storeNum
|
||||||
|
FROM back_check_details bcd
|
||||||
|
LEFT JOIN back_apply_info bai ON bai.id = bcd.parent_id
|
||||||
|
LEFT JOIN tm_task tt ON tt.task_id = bai.task_id
|
||||||
|
LEFT JOIN tm_task_agreement tta ON tta.task_id = tt.task_id
|
||||||
|
LEFT JOIN bm_agreement_info bagi ON bagi.agreement_id = tta.agreement_id
|
||||||
|
LEFT JOIN ma_type mt1 ON mt1.type_id = bcd.type_id
|
||||||
|
LEFT JOIN ma_type mt2 ON mt2.type_id = mt1.parent_id
|
||||||
|
WHERE bagi.team_id = #{id}
|
||||||
|
AND bcd.is_finished = '1'
|
||||||
|
GROUP BY bcd.type_id
|
||||||
|
) AS t2 ON t1.typeId = t2.typeId
|
||||||
|
WHERE t1.typeId IS NULL
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getToolsDetailsList" resultType="com.bonus.material.basic.domain.RetainedEquipmentInfo">
|
<select id="getToolsDetailsList" resultType="com.bonus.material.basic.domain.RetainedEquipmentInfo">
|
||||||
SELECT
|
SELECT
|
||||||
|
|
@ -1215,5 +1333,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
AND mm.ma_code like concat('%',#{maCode},'%')
|
AND mm.ma_code like concat('%',#{maCode},'%')
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getToolsDetailsListByTeam" resultType="com.bonus.material.basic.domain.RetainedEquipmentInfo">
|
||||||
|
SELECT aa.typeName,
|
||||||
|
aa.typeModelName,
|
||||||
|
mm.ma_code as maCode,
|
||||||
|
msc.this_check_time as thisCheckTime,
|
||||||
|
msc.next_check_time as nextCheckTime
|
||||||
|
FROM (SELECT t1.maId,
|
||||||
|
t1.typeName,
|
||||||
|
t1.typeModelName,
|
||||||
|
t1.typeId,
|
||||||
|
t1.thirdTypeId,
|
||||||
|
t1.manageType
|
||||||
|
FROM (SELECT lod.ma_id as maId,
|
||||||
|
mt2.type_name as typeName,
|
||||||
|
mt1.type_name as typeModelName,
|
||||||
|
lod.type_id as typeId,
|
||||||
|
mt2.type_id as thirdTypeId,
|
||||||
|
mt1.manage_type as manageType,
|
||||||
|
mt1.buy_price as buyPrice,
|
||||||
|
mt1.unit_name as unit,
|
||||||
|
COUNT(*) as count
|
||||||
|
FROM
|
||||||
|
lease_out_details lod
|
||||||
|
LEFT JOIN lease_apply_info lai
|
||||||
|
on lai.id=lod.parent_id
|
||||||
|
LEFT JOIN ma_type mt1 on mt1.type_id=lod.type_id
|
||||||
|
LEFT JOIN ma_type mt2 on mt2.type_id=mt1.parent_id
|
||||||
|
WHERE
|
||||||
|
lai.team_id=#{teamId}
|
||||||
|
and lod.is_finished='1'
|
||||||
|
and lod.type_id=#{typeId}
|
||||||
|
GROUP BY lod.ma_id, lod.type_id) t1
|
||||||
|
LEFT JOIN (SELECT bcd.ma_id as maId,
|
||||||
|
COUNT(*) as count
|
||||||
|
FROM
|
||||||
|
back_check_details bcd
|
||||||
|
LEFT JOIN back_apply_info bai
|
||||||
|
on bai.id=bcd.parent_id
|
||||||
|
LEFT JOIN tm_task tt on tt.task_id = bai.task_id
|
||||||
|
LEFT JOIN tm_task_agreement tta on tta.task_id = tt.task_id
|
||||||
|
LEFT JOIN bm_agreement_info bagi on bagi.agreement_id = tta.agreement_id
|
||||||
|
WHERE
|
||||||
|
bagi.team_id=#{teamId}
|
||||||
|
and bcd.is_finished='1'
|
||||||
|
and bcd.type_id=#{typeId}
|
||||||
|
GROUP BY bcd.ma_id) t2 ON t1.maId = t2.maId
|
||||||
|
WHERE t1.count > IFNULL(t2.count, 0)) aa
|
||||||
|
LEFT JOIN ma_machine mm
|
||||||
|
on aa.maId = mm.ma_id
|
||||||
|
LEFT JOIN ma_station_code msc on mm.ma_code = msc.ma_code
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue