重构编码设备库存逻辑

This commit is contained in:
sxu 2024-08-20 15:45:36 +08:00
parent 5ba4540133
commit dc64b2ff4d
32 changed files with 482 additions and 160 deletions

View File

@ -163,6 +163,8 @@ public class LeaseOutDetails implements Serializable {
@ApiModelProperty(value = "数量出库 -> 操作前库存量")
private Integer num;
/** 操作前库存 */
private int preStoreNum;
/** 操作后库存 */
private int postStoreNum;
}

View File

@ -1,4 +1,4 @@
package com.bonus.sgzb.material.domain;
package com.bonus.sgzb.base.api.domain;
import lombok.Data;
@ -29,4 +29,13 @@ public class RepairTestInputDto{
private String params;
/** 维修数量 */
private int repairNum;
/** 操作前库存 */
private int preStoreNum;
/** 操作后库存 */
private int postStoreNum;
}

View File

@ -261,9 +261,9 @@ public class LogAspect
BmStorageLog bmStorageLog = new BmStorageLog();
bmStorageLog.setTypeId(Objects.isNull(maInputRecord.getTypeId()) ? 0 : maInputRecord.getTypeId().intValue());
bmStorageLog.setTypeName(maInputRecord.getMaCode());
bmStorageLog.setPreStoreNum(Objects.isNull(maInputRecord.getNum()) ? 0: maInputRecord.getNum().intValue());
bmStorageLog.setPostStoreNum(Objects.isNull(maInputRecord.getNum()) ? 0: maInputRecord.getNum().intValue());
bmStorageLog.setInNum(Objects.isNull(maInputRecord.getInputNum()) ? 0: maInputRecord.getInputNum().intValue());
bmStorageLog.setPostStoreNum(bmStorageLog.getPreStoreNum() + bmStorageLog.getInNum());
bmStorageLog.setPreStoreNum(bmStorageLog.getPostStoreNum() - bmStorageLog.getInNum());
bmStorageLog.setTaskId(String.valueOf(maInputRecord.getTaskId()));
bmStorageLogList.add(bmStorageLog);
}
@ -291,7 +291,7 @@ public class LogAspect
bmStorageLog.setTaskId(String.valueOf(lod.getTaskId()));
bmStorageLog.setTypeId(lod.getTypeId());
bmStorageLog.setTypeName(lod.getMaCode());
bmStorageLog.setPreStoreNum(lod.getNum());
bmStorageLog.setPreStoreNum(lod.getPreStoreNum());
bmStorageLog.setOutNum(Objects.isNull(lod.getInputNum()) ? 0 : lod.getInputNum().intValue());
bmStorageLog.setPostStoreNum(lod.getPostStoreNum());
bmStorageLogList.add(bmStorageLog);
@ -303,7 +303,7 @@ public class LogAspect
bmStorageLog.setTaskId(String.valueOf(lod.getTaskId()));
bmStorageLog.setTypeId(lod.getTypeId());
bmStorageLog.setTypeName(lod.getMaCode());
bmStorageLog.setPreStoreNum(lod.getNum());
bmStorageLog.setPreStoreNum(lod.getPreStoreNum());
bmStorageLog.setOutNum(Objects.isNull(lod.getInputNum()) ? 0 : lod.getInputNum().intValue());
bmStorageLog.setPostStoreNum(lod.getPostStoreNum());
bmStorageLogList.add(bmStorageLog);
@ -323,6 +323,17 @@ public class LogAspect
bmStorageLog.setPostStoreNum(bai.getPostStoreNum());
bmStorageLogList.add(bmStorageLog);
}
// 修试后入库-入库操作, 因数据类型问题暂停等更新过数据类型后再放开
// if (joinPoint.getArgs()[0] instanceof RepairTestInputDto) {
// RepairTestInputDto rti = (RepairTestInputDto)joinPoint.getArgs()[0];
// BmStorageLog bmStorageLog = new BmStorageLog();
// bmStorageLog.setTaskId(String.valueOf(rti.getTaskId()));
// bmStorageLog.setTypeId(Integer.parseInt(rti.getTypeId()));
// bmStorageLog.setPreStoreNum(rti.getPreStoreNum());
// bmStorageLog.setInNum(rti.getRepairNum());
// bmStorageLog.setPostStoreNum(rti.getPostStoreNum());
// bmStorageLogList.add(bmStorageLog);
// }
// 二级库出入库, 不影响ma_type库存变化暂时不加库存监控日志
// if (joinPoint.getArgs()[0] instanceof TeamLeaseInfo) {
// TeamLeaseInfo tli = (TeamLeaseInfo)joinPoint.getArgs()[0];
@ -338,24 +349,6 @@ public class LogAspect
}
}
/**
* 获取注解中对方法的描述信息 用于Controller层注解
*
* @param log 日志
* @param materialLog 物资日志
* @throws Exception
*/
// public void getControllerMethodDescriptionByMaterial(JoinPoint joinPoint, Log log, BmNumLogs materialLog, Object jsonResult) throws Exception
// {
// // 设置标题
// materialLog.setModelTitle(log.title());
// // 获取参数的信息传入到数据库中
// setRequestValue(joinPoint, materialLog, log.excludeParamNames());
// // 保存response参数和值
// if (StringUtils.isNotNull(jsonResult)) {
// materialLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000));
// }
// }
/**
* 获取请求的参数放到log中
@ -376,42 +369,6 @@ public class LogAspect
}
}
/**
* 获取请求的参数放到log中
*
* @param numLog 物资日志
* @throws Exception 异常
*/
// private void setRequestValue(JoinPoint joinPoint, BmNumLogs numLog, String[] excludeParamNames) throws Exception {
// String requestMethod = numLog.getRequestMethod();
// Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
// if (StringUtils.isEmpty(paramsMap)) {
// if ((HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod))){
// String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
// numLog.setDescription(StringUtils.substring(params, 0, 2000));
// }
// } else {
// if (paramsMap.containsKey("num")) {
// if (paramsMap.get("num") instanceof Integer) {
// numLog.setNum(String.valueOf(paramsMap.get("num")));
// } else if (paramsMap.get("num") instanceof String) {
// numLog.setNum((String) paramsMap.get("num"));
// }
// }
// if (paramsMap.containsKey("taskId")) {
// numLog.setTask(String.valueOf(paramsMap.get("taskId")));
// }
// if (paramsMap.containsKey("typeId")) {
// if (paramsMap.get("typeId") instanceof Integer) {
// numLog.setTypeId((Integer) paramsMap.get("typeId"));
// } else if (paramsMap.get("typeId") instanceof String) {
// numLog.setTypeId(Integer.valueOf((String) paramsMap.get("typeId")));
// }
// }
// numLog.setDescription(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter(excludeParamNames)), 0, 2000));
// }
// }
/**
* 参数拼装
*/

View File

@ -11,6 +11,7 @@ import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -190,6 +191,7 @@ public class BackReceiveController extends BaseController {
}
@Log(title = "退料接收-结束任务", businessType = BusinessType.MATERIAL)
@PreventRepeatSubmit
@PostMapping("endBack")
public AjaxResult endBack(@RequestBody BackApplyInfo record) {
try {

View File

@ -11,6 +11,7 @@ import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@ -63,6 +64,7 @@ public class LeaseOutDetailsController extends BaseController {
* 根据二维码绑定设备
*/
@ApiOperation(value = "根据二维码绑定设备-app")
@PreventRepeatSubmit
@PostMapping("bindMachineByQrCode")
@Log(title = "APP机具设备标签二维码绑定", businessType = BusinessType.MATERIAL)
public AjaxResult bindMachineByQrCode(@RequestBody MaMachine maMachine) {
@ -130,6 +132,7 @@ public class LeaseOutDetailsController extends BaseController {
* @param record 出库内容
*/
@Log(title = "领料出库", businessType = BusinessType.MATERIAL)
@PreventRepeatSubmit
@PostMapping("/submitOut")
public AjaxResult submitOut(@RequestBody LeaseOutDetails record) {
return leaseOutDetailsService.submitOut(record);
@ -140,6 +143,7 @@ public class LeaseOutDetailsController extends BaseController {
* @return
*/
@Log(title = "领料出库", businessType = BusinessType.MATERIAL)
@PreventRepeatSubmit
@PostMapping("/submitOutRfid")
public AjaxResult submitOutRfid(@RequestBody List<LeaseOutDetails> recordList) {
if (CollUtil.isEmpty(recordList)){

View File

@ -92,6 +92,8 @@ public interface LeaseOutDetailsMapper {
MaType selectByTypeId(@Param("record") LeaseOutDetails record);
int getCountOfCodeMachine(@Param("record") LeaseOutDetails record);
LeaseApplyDetails getOutboundNum(LeaseOutDetails record);
List<TmTask> getMaTypeDetails(LeaseOutDetails record);

View File

@ -149,6 +149,7 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService {
try {
// 1判断是否重复提交
res = checkRepeatSubmit(record);
record.setPreStoreNum(getStorageNum(record));
if (res > 0) {
if ((record.getManageType() == 1 || record.getManageType() == 2) && record.getInputNum() != null) {
record.setOutNum(record.getInputNum().doubleValue());
@ -201,7 +202,11 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService {
//判断(ma_type 设备规格表)中的库存够不够出库的
MaType maType = leaseOutDetailsMapper.selectByTypeId(record);
if (maType != null) {
return maType.getNum().intValue();
if ("1".equals(maType.getManageType())) {
return maType.getNum().intValue();
} else if ("0".equals(maType.getManageType())) {
return leaseOutDetailsMapper.getCountOfCodeMachine(record);
}
}
return 0;
}
@ -274,8 +279,15 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService {
//判断(ma_type 设备规格表)中的库存够不够出库的
MaType maType = leaseOutDetailsMapper.selectByTypeId(record);
if (maType != null) {
if (maType.getNum() == null || maType.getNum().compareTo(BigDecimal.valueOf(record.getOutNum())) < 0) {
return 0;
if ("0".equals(maType.getManageType())) {
int count = leaseOutDetailsMapper.getCountOfCodeMachine(record);
if (BigDecimal.valueOf(count).compareTo(BigDecimal.valueOf(record.getOutNum())) < 0) {
return 0;
}
} else if ("1".equals(maType.getManageType())) {
if (maType.getNum() == null || maType.getNum().compareTo(BigDecimal.valueOf(record.getOutNum())) < 0) {
return 0;
}
}
}
return 1;

View File

@ -8,6 +8,7 @@ import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -80,6 +81,7 @@ public class MaLabelBindController extends BaseController
* 新增机具设备标签ma_label_bind
*/
@ApiOperation(value = "新增机具标签绑定管理列表")
@PreventRepeatSubmit
@Log(title = "机具设备标签二维码绑定", businessType = BusinessType.MATERIAL)
@PostMapping
public AjaxResult add(@RequestBody MaLabelBindVO maLabelBindVO)

View File

@ -5,6 +5,7 @@ import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.material.domain.PutInStorageBean;
import com.bonus.sgzb.base.api.domain.SavePutInfoDto;
import com.bonus.sgzb.material.service.InventoryAndWarehousingService;
@ -47,6 +48,7 @@ public class InventoryAndWarehousingController extends BaseController {
* @return
*/
@ApiOperation(value = "新增入库盘点")
@PreventRepeatSubmit
@PostMapping("/addList")
@Log(title = "盘点入库操作", businessType = BusinessType.MATERIAL)
public AjaxResult savePutInfo(@RequestBody SavePutInfoDto dto) {

View File

@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.material.service.IPurchaseMacodeInfoService;
import com.bonus.sgzb.material.domain.PurchaseMacodeInfo;
import com.bonus.sgzb.base.api.domain.MaInputVO;
@ -119,6 +120,7 @@ public class PurchaseMacodeInfoController extends BaseController {
* 通过/不通过
*/
@ApiOperation(value = "新购入库审核")
@PreventRepeatSubmit
@Log(title = "新购验收任务", businessType = BusinessType.MATERIAL)
@PutMapping("/manageStatus")
public AjaxResult modifyManageStatus(@RequestBody MaInputVO maInputVO) throws Exception {

View File

@ -6,8 +6,9 @@ import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.base.api.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import com.bonus.sgzb.material.service.RepairTestInputService;
import io.swagger.annotations.ApiOperation;
@ -60,6 +61,8 @@ public class RepairTestInputController extends BaseController {
}
@ApiOperation(value = "修试后入库-入库操作")
@PreventRepeatSubmit
//@Log(title = "修试后入库-入库操作", businessType = BusinessType.MATERIAL)
@PostMapping("inputByType")
public AjaxResult inputByType(@RequestBody RepairTestInputDto dto){
return service.inputByType(dto);

View File

@ -1,8 +1,8 @@
package com.bonus.sgzb.system.controller;
package com.bonus.sgzb.material.controller;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.system.service.SelectService;
import com.bonus.sgzb.material.domain.SelectDto;
import com.bonus.sgzb.material.service.SelectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

View File

@ -0,0 +1,20 @@
package com.bonus.sgzb.material.domain;
import lombok.Data;
/**
* @author 10488
* 协议信息
*/
@Data
public class AgreementVo {
/** 协议ID*/
private Integer agreementId;
/** 协议编号*/
private String agreementCode;
/** 是否结算*/
private String isSlt;
}

View File

@ -1,9 +1,7 @@
package com.bonus.sgzb.system.domain;
package com.bonus.sgzb.material.domain;
import lombok.Data;
import java.util.List;
/**
* @author 10488
*/

View File

@ -1,4 +1,4 @@
package com.bonus.sgzb.system.domain;
package com.bonus.sgzb.material.domain;
import lombok.Data;

View File

@ -0,0 +1,41 @@
package com.bonus.sgzb.material.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @author 10488
* 下拉树-实体类
*/
@Data
public class TreeNode {
private long id;
private String label;
private long parentId;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String level;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String unitName;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String companyId;
private String code;
private float num;
private String modelCode;
private String manageType;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeNode> children = new ArrayList<>();
}

View File

@ -284,4 +284,6 @@ public interface PurchaseMacodeInfoMapper {
List<PurchaseMacodeInfo> selectPurchaseMacodeInfoListDetails(PurchaseMacodeInfo purchaseMacodeInfo);
List<String> selectKeepUser(Integer typeId);
int getCountOfMachineByTypeId(Long typeId);
}

View File

@ -1,5 +1,6 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.base.api.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -121,4 +122,6 @@ public interface RepairTestInputMapper {
List<RepairTestInputDetailVo> exportList(RepairTestInputDto bean);
int addRepaieAudit(RepairAuditDetails bean);
int getCountOfMachineByTypeId(String typeId);
}

View File

@ -1,9 +1,9 @@
package com.bonus.sgzb.system.mapper;
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.system.domain.AgreementVo;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.system.domain.SelectVo;
import com.bonus.sgzb.system.domain.TreeNode;
import com.bonus.sgzb.material.domain.AgreementVo;
import com.bonus.sgzb.material.domain.SelectDto;
import com.bonus.sgzb.material.domain.SelectVo;
import com.bonus.sgzb.material.domain.TreeNode;
import org.springframework.stereotype.Repository;
import java.util.List;

View File

@ -2,7 +2,7 @@ package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.RepairTestInputDetailVo;
import com.bonus.sgzb.material.domain.RepairTestInputDto;
import com.bonus.sgzb.base.api.domain.RepairTestInputDto;
import com.bonus.sgzb.material.domain.RepairTestInputVo;
import java.util.List;

View File

@ -1,7 +1,7 @@
package com.bonus.sgzb.system.service;
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.material.domain.SelectDto;
/**
* @author 10488

View File

@ -334,6 +334,11 @@ public class PurchaseMacodeInfoServiceImpl implements IPurchaseMacodeInfoService
.add(maType.getNum() == null ? new BigDecimal(0) : maType.getNum()));
purchaseMacodeInfoMapper.updateTypeByTypeId(maType);
if ("0".equals(maType.getManageType())) { //编码设备
int countOfMachineByTypeId = purchaseMacodeInfoMapper.getCountOfMachineByTypeId(typeId);
maInputRecord.setNum((double) countOfMachineByTypeId);
}
//判断是否是成套机具是的话配件库存也要增加
if ("2".equals(maType.getManageType())){
PurchaseCheckInfo purchaseCheckInfo = new PurchaseCheckInfo();

View File

@ -1,6 +1,7 @@
package com.bonus.sgzb.material.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.bonus.sgzb.base.api.domain.RepairTestInputDto;
import com.bonus.sgzb.common.core.constant.HttpStatus;
import com.bonus.sgzb.common.core.exception.ServiceException;
import com.bonus.sgzb.common.core.utils.DateTimeHelper;
@ -15,7 +16,6 @@ import com.bonus.sgzb.material.mapper.RepairTestInputMapper;
import com.bonus.sgzb.material.mapper.TaskMapper;
import com.bonus.sgzb.material.mapper.TmTaskAgreementMapper;
import com.bonus.sgzb.material.service.RepairTestInputService;
import com.bonus.sgzb.material.vo.GlobalContants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
@ -114,11 +114,27 @@ public class RepairTestInputServiceImpl implements RepairTestInputService {
String repairNum = StringUtils.isNotEmpty(dto.getRepairNum()) ? dto.getRepairNum() : "0";
double num = countNum(map.get("num"), repairNum);
mapper.updateMaTypeNum(dto.getTypeId(), num);
int codeMachinePreStoreNum = 0;
if (Objects.equals("0", dto.getType())) {
codeMachinePreStoreNum = mapper.getCountOfMachineByTypeId(dto.getTypeId());
// 查询机具状态-在库的id管理方式为编号的需更新机具设备的机具状态
int dicId = mapper.getDicByMaStatusId("ma_status", "在库");
mapper.updateMaMachineStatus(dicId, dto.getMaId());
//int dicId = mapper.getDicByMaStatusId("ma_status", "在库");
mapper.updateMaMachineStatus(15, dto.getMaId());
}
// try {
// if (Objects.equals("0", dto.getType())) {
// repairTestInputDto.setPreStoreNum(codeMachinePreStoreNum);
// repairTestInputDto.setRepairNum(Integer.parseInt(repairNum));
// repairTestInputDto.setPostStoreNum(mapper.getCountOfMachineByTypeId(dto.getTypeId()));
// }
// else if (Objects.equals("1", dto.getType())) {
// repairTestInputDto.setPreStoreNum((Integer) map.get("num"));
// repairTestInputDto.setRepairNum(Integer.parseInt(repairNum));
// repairTestInputDto.setPostStoreNum((int) num);
// }
// } catch (Exception e) {
// log.error("修试后入库-入库操作-获取库存日志失败", e);
// }
}
}
RepairTestWarehousingDto dto = list.get(0);

View File

@ -1,15 +1,14 @@
package com.bonus.sgzb.system.service.impl;
package com.bonus.sgzb.material.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.bonus.sgzb.common.core.utils.GlobalConstants;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.system.domain.AgreementVo;
import com.bonus.sgzb.system.domain.SelectDto;
import com.bonus.sgzb.system.domain.SelectVo;
import com.bonus.sgzb.system.domain.TreeNode;
import com.bonus.sgzb.system.mapper.SelectMapper;
import com.bonus.sgzb.system.service.SelectService;
import com.bonus.sgzb.system.util.TreeBuild;
import com.bonus.sgzb.material.domain.AgreementVo;
import com.bonus.sgzb.material.domain.SelectDto;
import com.bonus.sgzb.material.domain.SelectVo;
import com.bonus.sgzb.material.domain.TreeNode;
import com.bonus.sgzb.material.mapper.SelectMapper;
import com.bonus.sgzb.material.service.SelectService;
import com.bonus.sgzb.material.utils.TreeBuild;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

View File

@ -0,0 +1,79 @@
package com.bonus.sgzb.material.utils;
import com.bonus.sgzb.material.domain.TreeNode;
import java.util.ArrayList;
import java.util.List;
/**
* BuildTree 构建树形结构
* @author 10488
*/
public class TreeBuild {
public List<TreeNode> nodeList = new ArrayList<>();
/**
* 构造方法
* @param nodeList 将数据集合赋值给nodeList即所有数据作为所有节点
*/
public TreeBuild(List<TreeNode> nodeList){
this.nodeList = nodeList;
}
/**
* 获取需构建的所有根节点顶级节点 "0"
* @return 所有根节点List集合
*/
public List<TreeNode> getRootNode(){
// 保存所有根节点所有根节点的数据
List<TreeNode> rootNodeList = new ArrayList<>();
// treeNode查询出的每一条数据节点
for (TreeNode treeNode : nodeList){
// 判断当前节点是否为根节点此处注意若parentId类型是String则要采用equals()方法判断
if (0 == treeNode.getParentId()) {
// 添加
rootNodeList.add(treeNode);
}
}
return rootNodeList;
}
/**
* 根据每一个顶级节点根节点进行构建树形结构
* @return 构建整棵树
*/
public List<TreeNode> buildTree(){
// treeNodes保存一个顶级节点所构建出来的完整树形
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
// getRootNode()获取所有的根节点
for (TreeNode treeRootNode : getRootNode()) {
// 将顶级节点进行构建子树
treeRootNode = buildChildTree(treeRootNode);
// 完成一个顶级节点所构建的树形增加进来
treeNodes.add(treeRootNode);
}
return treeNodes;
}
/**
* 递归-----构建子树形结构
* @param pNode 根节点顶级节点
* @return 整棵树
*/
public TreeNode buildChildTree(TreeNode pNode){
List<TreeNode> childTree = new ArrayList<TreeNode>();
// nodeList所有节点集合所有数据
for (TreeNode treeNode : nodeList) {
// 判断当前节点的父节点ID是否等于根节点的ID即当前节点为其下的子节点
if (treeNode.getParentId() == pNode.getId()) {
// 再递归进行判断当前节点的情况调用自身方法
childTree.add(buildChildTree(treeNode));
}
}
// for循环结束即节点下没有任何节点树形构建结束设置树结果
pNode.setChildren(childTree);
return pNode;
}
}

View File

@ -169,6 +169,8 @@
type_id = #{typeId}
AND
ma_id IS NULL
AND
status = '0'
AND
DATE(start_time) = CURDATE();
</select>
@ -176,6 +178,17 @@
select * from ma_type WHERE
type_id = #{record.typeId}
</select>
<select id="getCountOfCodeMachine" resultType="java.lang.Integer">
select count(mm.ma_id)
FROM ma_type mt
left join ma_machine mm on mm.type_id=mt.type_id
WHERE
mm.type_id = #{record.typeId}
and mm.ma_code is not null
and mm.ma_status in (15)
and mt.`level` = 4
and mt.del_flag = '0'
</select>
<update id="updateLeaseApplyDetailsOutNum">
UPDATE

View File

@ -978,12 +978,27 @@
SELECT
lad.*, mt.type_name AS typeModelName, mt1.type_name AS typeName,mt.unit_name as unitName, mt.manage_type as manageType,
case WHEN mt.manage_type = '0' then '编号' else '计数' end manageTypeName,
mt.num, (lad.pre_num - IF(lad.al_num IS NULL,'0',lad.al_num)) AS outNum,mm.ma_code as maCode
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num,
(lad.pre_num - IF(lad.al_num IS NULL,'0',lad.al_num)) AS outNum,subquery0.ma_code as maCode
FROM
lease_apply_details lad
LEFT JOIN ma_type mt ON lad.type_id = mt.type_id
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
LEFT JOIN ma_machine mm ON lad.type_id = mm.type_id
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
mm.ma_code,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
WHERE
lad.parennt_id = #{record.id}
GROUP BY

View File

@ -571,43 +571,123 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mt.type_name like concat('%', #{keyWord}, '%'))
</if>
</select>
<!-- <select id="getUseTypeTree" resultType="com.bonus.sgzb.material.domain.TypeTreeNode">-->
<!-- WITH RECURSIVE type_hierarchy AS (&#45;&#45; 基础情况:从第四级开始-->
<!-- SELECT-->
<!-- mt.type_id,-->
<!-- mt.type_name,-->
<!-- mt.parent_id,-->
<!-- mt.unit_name as unitNames,-->
<!-- mt.company_id,-->
<!-- SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS num,-->
<!-- mt.LEVEL-->
<!-- FROM-->
<!-- ma_type mt-->
<!-- LEFT JOIN slt_agreement_info sai ON mt.type_id = sai.type_id-->
<!-- WHERE-->
<!-- EXISTS ( SELECT 1 FROM slt_agreement_info sai2 WHERE sai2.type_id = mt.type_id AND sai2.agreement_id = #{agreementId} AND sai2.STATUS = '0' and sai.lease_type = 0)-->
<!-- GROUP BY-->
<!-- mt.type_id UNION ALL&#45;&#45; 递归情况:向上查找父级-->
<!-- SELECT-->
<!-- mt.type_id,-->
<!-- mt.type_name,-->
<!-- mt.parent_id,-->
<!-- mt.unit_name,-->
<!-- mt.company_id,-->
<!-- 0 AS num,&#45;&#45; 父级没有直接关联的 num可以设为0或NULL-->
<!-- mt.LEVEL-->
<!-- FROM-->
<!-- ma_type mt-->
<!-- INNER JOIN type_hierarchy th ON mt.type_id = th.parent_id-->
<!-- ) &#45;&#45; 查询结果,包括从第四级到第一级的所有元素-->
<!-- SELECT-->
<!-- *-->
<!-- FROM-->
<!-- type_hierarchy-->
<!-- GROUP BY-->
<!-- type_id-->
<!-- ORDER BY-->
<!-- LEVEL ASC;-->
<!-- </select>-->
<select id="getUseTypeTree" resultType="com.bonus.sgzb.material.domain.TypeTreeNode">
WITH RECURSIVE type_hierarchy AS (-- 基础情况:从第四级开始
SELECT
mt.type_id,
mt.type_name,
mt.parent_id,
mt.unit_name as unitNames,
mt.company_id,
SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS num,
mt.LEVEL
FROM
ma_type mt
LEFT JOIN slt_agreement_info sai ON mt.type_id = sai.type_id
WHERE
EXISTS ( SELECT 1 FROM slt_agreement_info sai2 WHERE sai2.type_id = mt.type_id AND sai2.agreement_id = #{agreementId} AND sai2.STATUS = '0' and sai.lease_type = 0)
GROUP BY
mt.type_id UNION ALL-- 递归情况:向上查找父级
SELECT
mt.type_id,
mt.type_name,
mt.parent_id,
mt.unit_name,
mt.company_id,
0 AS num,-- 父级没有直接关联的 num可以设为0或NULL
mt.LEVEL
FROM
ma_type mt
INNER JOIN type_hierarchy th ON mt.type_id = th.parent_id
) -- 查询结果,包括从第四级到第一级的所有元素
-- 查询从第四级到第一级的所有类型及相关信息
SELECT
*
t4.type_id,
t4.type_name,
t4.parent_id,
t4.unit_name,
t4.company_id,
COALESCE(SUM(CASE WHEN sai.agreement_id = #{agreementId} AND sai.status = '0' THEN sai.num ELSE 0 END), 0) AS num,
4 AS LEVEL
FROM
type_hierarchy
ma_type t4
LEFT JOIN slt_agreement_info sai ON t4.type_id = sai.type_id
WHERE
t4.level = 4
AND EXISTS (
SELECT 1 FROM slt_agreement_info sai2
WHERE sai2.type_id = t4.type_id AND sai2.agreement_id = #{agreementId} AND sai2.status = '0'
)
GROUP BY
type_id
t4.type_id
UNION ALL
SELECT
t3.type_id,
t3.type_name,
t3.parent_id,
t3.unit_name,
t3.company_id,
0 AS num,
3 AS LEVEL
FROM
ma_type t3
INNER JOIN (
SELECT DISTINCT t4.parent_id
FROM ma_type t4
WHERE t4.level = 4
) AS parent_t4 ON t3.type_id = parent_t4.parent_id
UNION ALL
SELECT
t2.type_id,
t2.type_name,
t2.parent_id,
t2.unit_name,
t2.company_id,
0 AS num,
2 AS LEVEL
FROM
ma_type t2
INNER JOIN (
SELECT DISTINCT t3.parent_id
FROM ma_type t3
WHERE t3.level = 3
) AS parent_t3 ON t2.type_id = parent_t3.parent_id
UNION ALL
SELECT
t1.type_id,
t1.type_name,
t1.parent_id,
t1.unit_name,
t1.company_id,
0 AS num,
1 AS LEVEL
FROM
ma_type t1
INNER JOIN (
SELECT DISTINCT t2.parent_id
FROM ma_type t2
WHERE t2.level = 2
) AS parent_t2 ON t1.type_id = parent_t2.parent_id
ORDER BY
LEVEL ASC;
LEVEL ASC, type_id;
</select>
<select id="exportList" resultType="com.bonus.sgzb.base.api.domain.BackApplyInfo">

View File

@ -239,6 +239,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="companyId != null">company_id,</if>
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="taskId != null">#{taskId},</if>
@ -253,6 +254,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="companyId != null">#{companyId},</if>
now()
</trim>
</insert>
<insert id="insertMaMachineLabel" parameterType="com.bonus.sgzb.base.api.domain.MaMachineLabel" useGeneratedKeys="true" keyProperty="labelId">
@ -568,4 +570,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
UPDATE ma_type
SET num = ifnull( num, 0 ) + #{partNum} WHERE type_id = #{typeId}
</update>
<select id="getCountOfMachineByTypeId" resultType="java.lang.Integer">
SELECT
count(mm.ma_id)
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
AND mt.type_id = #{typeId}
</select>
</mapper>

View File

@ -259,4 +259,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
values (#{taskId},#{repairId},#{maId},#{typeId},#{repairNum},#{repairedNum},#{scrapNum},#{status},#{createBy},now(),#{updateBy},now(),#{companyId});
</insert>
<select id="getCountOfMachineByTypeId" resultType="java.lang.Integer">
SELECT
count(mm.ma_id)
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
AND mt.type_id = #{typeId}
</select>
</mapper>

View File

@ -2,10 +2,10 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.system.mapper.SelectMapper">
<mapper namespace="com.bonus.sgzb.material.mapper.SelectMapper">
<!--往来单位-->
<select id="getUnitData" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getUnitData" resultType="com.bonus.sgzb.material.domain.SelectVo">
/*根据标段工程id关联协议查询往来单位*/
<if test="id != null and id != ''">
SELECT DISTINCT bui.unit_id AS id,
@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!--标段工程-->
<select id="getProData" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getProData" resultType="com.bonus.sgzb.material.domain.SelectVo">
/*根据往来单位id关联协议查询工程*/
<if test="id != null and id != ''">
SELECT DISTINCT bpl.lot_id AS id,
@ -43,21 +43,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<!--机具类型-->
<select id="getMaTypeData" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getMaTypeData" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT type_id AS id,
type_name AS `name`
FROM ma_type
WHERE `level` = #{type} AND del_flag = '0'
</select>
<!--数据字典下拉选-->
<select id="getDictByPidCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getDictByPidCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT sd2.id,sd2.`name`
FROM sys_dic sd
LEFT JOIN sys_dic sd2 ON sd.id = sd2.p_id
WHERE sd.`value` = #{parentValue} AND sd.p_id = 0
</select>
<!--单位树/归属部门/所属上级-->
<select id="getDeptTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
<select id="getDeptTree" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT dept_id AS id,
parent_id AS parentId,
dept_name AS label
@ -66,7 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY order_num
</select>
<!--岗位下拉选-->
<select id="getPostCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getPostCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT post_id AS id,
post_name AS `name`
FROM sys_post
@ -74,7 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY post_sort
</select>
<!--角色下拉选-->
<select id="getRoleCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getRoleCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT role_id AS id,
role_name AS `name`
FROM sys_role
@ -82,40 +82,54 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY role_sort
</select>
<!--单位类型下拉选-->
<select id="getUnitTypeCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getUnitTypeCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT sd2.id,sd2.`name`
FROM sys_dic sd
LEFT JOIN sys_dic sd2 ON sd.id = sd2.p_id
WHERE sd.`value` = #{parentValue} AND sd.p_id = 0
</select>
<!--设备类型树-->
<select id="getDeviceTypeTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
SELECT type_id AS id,
type_name AS label,
parent_id AS parentId,
unit_name AS unitName,
company_id AS companyId,
code,
num,
model_code AS modelCode,
manage_type AS manageType
FROM ma_type
WHERE del_flag = '0'
<select id="getDeviceTypeTree" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT mt.type_id AS id,
mt.type_name AS label,
mt.parent_id AS parentId,
mt.unit_name AS unitName,
mt.company_id AS companyId,
mt.code,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num,
mt.model_code AS modelCode,
mt.manage_type AS manageType
FROM ma_type mt
left join (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
WHERE mt.del_flag = '0'
<if test="level!=null and level!=''">
<if test="level == 2">
AND level IN ('1','2')
AND mt.level IN ('1','2')
</if>
<if test="level == 3">
AND level IN ('1','2','3')
AND mt.level IN ('1','2','3')
</if>
<if test="level == 4">
AND level IN ('1','2','3','4')
AND mt.level IN ('1','2','3','4')
</if>
</if>
ORDER BY create_time
ORDER BY mt.create_time
</select>
<!--资产属性-->
<select id="getAssetAttributesCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getAssetAttributesCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT prop_id AS id,
prop_name AS `name`
FROM ma_prop_info
@ -123,7 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY create_time
</select>
<!--机具厂家-->
<select id="getDeviceFactoryCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getDeviceFactoryCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT supplier_id AS id,
supplier AS `name`
FROM ma_supplier_info
@ -131,7 +145,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY create_time
</select>
<!--工程项目-->
<select id="getProCbx" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getProCbx" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT pro_id AS id,
pro_name AS `name`
FROM bm_project_info
@ -139,7 +153,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY create_time
</select>
<!--配件所属上级树-->
<select id="getAccessoryTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
<select id="getAccessoryTree" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT pa_id AS id,
pa_name AS label,
parent_id AS parentId,
@ -150,7 +164,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY create_time
</select>
<select id="getPartTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
<select id="getPartTree" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT pa_id AS id,
pa_name AS label,
parent_id AS parentId,
@ -160,7 +174,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY create_time
</select>
<!--货架-->
<select id="getGoodsShelvesCbx" resultType="com.bonus.sgzb.system.domain.TreeNode">
<select id="getGoodsShelvesCbx" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT house_id AS id,
house_name AS label,
parent_id AS parentId
@ -168,7 +182,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE del_flag = '0' AND status = '0'
</select>
<!--用户/维修员/库管员/采购员-下拉选-->
<select id="getUserByRoleIdCbxSelect" resultType="com.bonus.sgzb.system.domain.SelectVo">
<select id="getUserByRoleIdCbxSelect" resultType="com.bonus.sgzb.material.domain.SelectVo">
SELECT su.user_id AS id,
su.nick_name AS `name`
FROM sys_role sr
@ -177,7 +191,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE sr.role_key = #{roleKey} AND sr.del_flag = '0'
</select>
<!--用户/维修员/库管员/采购员--->
<select id="getUserByRoleIdCbxTree" resultType="com.bonus.sgzb.system.domain.TreeNode">
<select id="getUserByRoleIdCbxTree" resultType="com.bonus.sgzb.material.domain.TreeNode">
SELECT dept_id AS id,
parent_id AS parentId,
dept_name AS label
@ -193,7 +207,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE sr.role_key = #{roleKey} AND sr.del_flag = '0'
</select>
<!--往来单位id和标段工程id获取协议信息-->
<select id="getAgreementInfoById" resultType="com.bonus.sgzb.system.domain.AgreementVo">
<select id="getAgreementInfoById" resultType="com.bonus.sgzb.material.domain.AgreementVo">
SELECT agreement_id AS agreementId,
agreement_code AS agreementCode,
is_slt AS isSlt

View File

@ -8,12 +8,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
SELECT mt2.type_name as typeName,
mt.type_name as typeModelName,
mt.unit_name as unit,
IFNULL(mt.num, 0) as num,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)
ELSE
IFNULL(mt.num, 0)
END as num,
IFNULL(subquery1.usNum, 0) as usNum,
IFNULL(subquery2.repairNum, 0) as repairNum,
IFNULL(subquery3.repairInputNum, 0) as repairInputNum,
IFNULL(subquery4.inputNum, 0) as inputNum,
IFNULL(mt.num, 0) + IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0) as allNum,
CASE mt.manage_type
WHEN 0 THEN
IFNULL(subquery0.num, 0)+ IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0)
ELSE
IFNULL(mt.num, 0)+ IFNULL(subquery1.usNum, 0) + IFNULL(subquery2.repairNum, 0) + IFNULL(subquery3.repairInputNum, 0)
END as allNum,
CASE mt.manage_type
WHEN 0 THEN
'否'
@ -22,6 +32,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
END manageType
FROM ma_type mt
LEFT JOIN (SELECT mt.type_id,
mt2.type_name AS typeName,
mt.type_name AS typeModelName,
count(mm.ma_id) num
FROM ma_machine mm
LEFT JOIN ma_type mt ON mt.type_id = mm.type_id
LEFT JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mm.ma_code is not null and mm.ma_status in (15)
GROUP BY mt.type_id) AS subquery0 ON subquery0.type_id = mt.type_id
LEFT JOIN (SELECT subquery1.type_id,
subquery1.typeName,
subquery1.typeModelName,