问题修改
This commit is contained in:
parent
795cb20e49
commit
ca864ee291
|
|
@ -25,4 +25,6 @@ public class DevInfoPropertyVo {
|
|||
|
||||
private String inputType;
|
||||
|
||||
private String mustHave;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import com.bonus.common.core.utils.DateUtils;
|
|||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.devConfig.domain.EquipmentProperty;
|
||||
import com.bonus.material.devConfig.mapper.EquipmentPropertyMapper;
|
||||
import com.bonus.material.devConfig.service.EquipmentPropertyService;
|
||||
import com.bonus.material.devchange.domain.MaDevFile;
|
||||
import com.bonus.material.devchange.domain.MaDevInfo;
|
||||
import com.bonus.material.devchange.domain.MapBean;
|
||||
|
|
@ -21,6 +24,7 @@ import com.bonus.material.device.mapper.DevInfoMapper;
|
|||
import com.bonus.material.device.mapper.DevMergeMapper;
|
||||
import com.bonus.material.device.mapper.MaDevQcMapper;
|
||||
import com.bonus.material.device.service.DevMergeService;
|
||||
import com.bonus.material.device.service.MaDevQcService;
|
||||
import com.bonus.material.utils.FolderZipUtil;
|
||||
import com.bonus.system.api.RemoteFileService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -71,6 +75,9 @@ public class DevMergeServiceImpl implements DevMergeService {
|
|||
@Autowired
|
||||
private MaDevQcMapper qcMapper;
|
||||
|
||||
@Resource
|
||||
private EquipmentPropertyMapper equipmentPropertyMapper;
|
||||
|
||||
@Override
|
||||
public List<DevMergeVo> list(DevMergeVo devInfo) {
|
||||
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
||||
|
|
@ -454,6 +461,7 @@ public class DevMergeServiceImpl implements DevMergeService {
|
|||
return AjaxResult.error("导入失败,存在以下错误:" + String.join(" ", errorMessages));
|
||||
}
|
||||
|
||||
|
||||
// 4. 遍历数据,进行最终校验和导入
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
EquipmentImportDTO item = list.get(i);
|
||||
|
|
@ -475,7 +483,8 @@ public class DevMergeServiceImpl implements DevMergeService {
|
|||
// 5. 校验通过,执行导入逻辑
|
||||
try {
|
||||
MaDevInfo maDevInfo = new MaDevInfo();
|
||||
maDevInfo.setTypeId(devMergeMapper.getTypeId(item.getProfession()));
|
||||
Integer typeId = devMergeMapper.getTypeId(item.getProfession());
|
||||
maDevInfo.setTypeId(typeId);
|
||||
maDevInfo.setProductionDate(item.getProductionDate());
|
||||
maDevInfo.setPurchaseDate(item.getPurchaseDate());
|
||||
maDevInfo.setSpecificationModel(item.getSpecification());
|
||||
|
|
@ -491,6 +500,21 @@ public class DevMergeServiceImpl implements DevMergeService {
|
|||
maDevInfo.setCode(getString());
|
||||
|
||||
Integer insertResult = devMergeMapper.interDevice(maDevInfo);
|
||||
devInfoMapper.deleteDevInfoProperties(Long.valueOf(maDevInfo.getMaId()));
|
||||
List<EquipmentProperty> equipmentProperties = equipmentPropertyMapper.selectByType(Long.valueOf(typeId));
|
||||
if (equipmentProperties != null && !equipmentProperties.isEmpty()) {
|
||||
List<DevInfoPropertyVo> devInfoPropertyVos = new ArrayList<>();
|
||||
for (EquipmentProperty equipmentProperty : equipmentProperties) {
|
||||
DevInfoPropertyVo entity = new DevInfoPropertyVo();
|
||||
entity.setId(Math.toIntExact(equipmentProperty.getId()));
|
||||
entity.setPropertyName(equipmentProperty.getPropertyName());
|
||||
entity.setPropertyValue(null);
|
||||
devInfoPropertyVos.add(entity);
|
||||
}
|
||||
devInfoMapper.insertDevInfoProperties(Long.valueOf(maDevInfo.getMaId()), devInfoPropertyVos);
|
||||
|
||||
}
|
||||
|
||||
if (insertResult > 0) {
|
||||
MaDevQc maDevQc = new MaDevQc();
|
||||
maDevQc.setMaId(maDevInfo.getMaId());
|
||||
|
|
@ -501,6 +525,7 @@ public class DevMergeServiceImpl implements DevMergeService {
|
|||
.orElse(SecurityUtils.getLoginUser().getSysUser().getDeptId()).toString());
|
||||
maDevQc.setNextCheckTime(maDevInfo.getNextMaintenanceDate());
|
||||
qcMapper.insertDevQc(maDevQc);
|
||||
|
||||
devMergeMapper.insertOrderDevReal(orderId, Long.valueOf(maDevInfo.getMaId()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
package com.bonus.material.index.controller;
|
||||
|
||||
import com.bonus.common.biz.config.ListPagingUtil;
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.device.domain.vo.DevInfoVo;
|
||||
import com.bonus.material.index.service.IndexService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/index")
|
||||
public class IndexController extends BaseController {
|
||||
@Resource
|
||||
private IndexService indexService;
|
||||
|
||||
@ApiOperation(value = "数据总览")
|
||||
@GetMapping("/getDeviceNum")
|
||||
public AjaxResult getDeviceNum() {
|
||||
return indexService.getDeviceNum();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "使用情况")
|
||||
@GetMapping("/getUseDeviceNum")
|
||||
public AjaxResult getUseDeviceNum() {
|
||||
return indexService.getUseDeviceNum();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getReal")
|
||||
public AjaxResult getReal() {
|
||||
return indexService.getReal();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getDeviceByDept")
|
||||
public AjaxResult getDeviceByDept() {
|
||||
return indexService.getDeviceByDept();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getMaQc")
|
||||
public AjaxResult getMaQc() {
|
||||
return indexService.getMaQc();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getDeviceNumByMonth")
|
||||
public AjaxResult getDeviceNumByMonth() {
|
||||
return indexService.getDeviceNumByMonth();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getApprover")
|
||||
public AjaxResult getApprover() {
|
||||
return indexService.getApprover();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "实时情况")
|
||||
@GetMapping("/getShare")
|
||||
public AjaxResult getShare() {
|
||||
return indexService.getShare();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "导出装备信息")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response) {
|
||||
indexService.export(response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.bonus.material.index.domain;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 公司设备与工具统计实体类(用于Excel导出)
|
||||
* 对应SQL查询结果的字段映射,适配Hutool Excel导出
|
||||
*/
|
||||
@Data
|
||||
public class CompanyDevToolStatisticsExport {
|
||||
|
||||
/**
|
||||
* 公司名称(对应SQL中的companyName)
|
||||
* Hutool @Alias:导出时的表头名称
|
||||
*/
|
||||
@Alias("公司名称")
|
||||
private String companyName;
|
||||
|
||||
/**
|
||||
* 工具数量(对应SQL中的toolNum,已取整)
|
||||
*/
|
||||
@Alias("工具数量")
|
||||
private Integer toolNum;
|
||||
|
||||
/**
|
||||
* 设备数量(对应SQL中的maNum,已取整)
|
||||
*/
|
||||
@Alias("装备数量")
|
||||
private Integer maNum;
|
||||
|
||||
/**
|
||||
* 设备成本(对应SQL中的maCost,保留小数)
|
||||
*/
|
||||
@Alias("装备总价值")
|
||||
private BigDecimal maCost;
|
||||
|
||||
/**
|
||||
* 工具成本(对应SQL中的toolCost,保留小数)
|
||||
*/
|
||||
@Alias("工具总价值")
|
||||
private BigDecimal toolCost;
|
||||
|
||||
/**
|
||||
* manage_mode=0的工具有效数量总和(编码工具数量)
|
||||
*/
|
||||
@Alias("编码工具总数")
|
||||
private Integer toolCodeNum;
|
||||
|
||||
/**
|
||||
* manage_mode=1的工具有效数量总和(无编码工具有效数量)
|
||||
*/
|
||||
@Alias("数量工具总数")
|
||||
private Integer toolNoCodeNum;
|
||||
}
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
package com.bonus.material.index.domain;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import com.bonus.material.devchange.domain.MaDevFile;
|
||||
import com.bonus.material.device.domain.vo.DevInfoPropertyVo;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 装备Excel导出实体类
|
||||
* 存储装备导出所需的详细信息,含固定9组特征项
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MaDevInfoXlsxExport {
|
||||
|
||||
@Alias("产权单位")
|
||||
@ApiModelProperty(value = "专业")
|
||||
private String propertyUnit;
|
||||
|
||||
/**
|
||||
* 专业
|
||||
*/
|
||||
@Alias("专业")
|
||||
@ApiModelProperty(value = "专业")
|
||||
private String major;
|
||||
|
||||
/**
|
||||
* 工序(子工序)
|
||||
*/
|
||||
@Alias("工序")
|
||||
@ApiModelProperty(value = "工序")
|
||||
private String subProcess;
|
||||
|
||||
/**
|
||||
* 装备类目(小类目)
|
||||
*/
|
||||
@Alias("装备类目")
|
||||
@ApiModelProperty(value = "装备类目")
|
||||
private String subCategory;
|
||||
/**
|
||||
* 类型分支(装备分支)
|
||||
*/
|
||||
@Alias("装备名称")
|
||||
@ApiModelProperty(value = "类型分支")
|
||||
private String name;
|
||||
/**
|
||||
* 规格型号
|
||||
*/
|
||||
@Alias("规格型号")
|
||||
@ApiModelProperty(value = "规格型号")
|
||||
private String specificationModel;
|
||||
/**
|
||||
* 装备编码
|
||||
*/
|
||||
@Alias("装备编码")
|
||||
@ApiModelProperty(value = "装备编码")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 装备编码
|
||||
*/
|
||||
@Alias("装备原始编码")
|
||||
@ApiModelProperty(value = "装备编码")
|
||||
private String originalCode;
|
||||
|
||||
|
||||
/**
|
||||
* 装备编码
|
||||
*/
|
||||
@Alias("装备状态")
|
||||
@ApiModelProperty(value = "装备编码")
|
||||
private String status;
|
||||
/**
|
||||
* 使用年限
|
||||
*/
|
||||
@Alias("使用年限")
|
||||
@ApiModelProperty(value = "使用年限")
|
||||
private String serviceLife;
|
||||
|
||||
/**
|
||||
* 计量单位
|
||||
*/
|
||||
@Alias("计量单位")
|
||||
@ApiModelProperty(value = "计量单位")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 资产原值(元)
|
||||
*/
|
||||
@Alias("资产原值(元)")
|
||||
@ApiModelProperty(value = "资产原值(元)")
|
||||
private Integer originalValue;
|
||||
|
||||
|
||||
/**
|
||||
* 资产原值(元)
|
||||
*/
|
||||
@Alias("净值")
|
||||
@ApiModelProperty(value = "资产原值(元)")
|
||||
private Integer original;
|
||||
/**
|
||||
* 生产厂家
|
||||
*/
|
||||
@Alias("生产厂家")
|
||||
@ApiModelProperty(value = "生产厂家")
|
||||
private String manufacturer;
|
||||
|
||||
/**
|
||||
* 出厂日期
|
||||
*/
|
||||
@Alias("出厂日期")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
@ApiModelProperty(value = "出厂日期(yyyy-MM-dd)")
|
||||
private String productionDate;
|
||||
|
||||
|
||||
/**
|
||||
* 最大使用年限(年)
|
||||
*/
|
||||
@Alias("最大使用年限(年)")
|
||||
@ApiModelProperty(value = "最大使用年限(年)")
|
||||
private Integer maxServiceLifeYears;
|
||||
|
||||
/**
|
||||
* 最大使用年限(年)
|
||||
*/
|
||||
@Alias("录入人")
|
||||
@ApiModelProperty(value = "最大使用年限(年)")
|
||||
private String creator;
|
||||
|
||||
|
||||
/**
|
||||
* 最大使用年限(年)
|
||||
*/
|
||||
@Alias("录入时间")
|
||||
@ApiModelProperty(value = "最大使用年限(年)")
|
||||
private String createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.bonus.material.index.domain;
|
||||
|
||||
import cn.hutool.core.annotation.Alias;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ToolLedgerEntityExport {
|
||||
|
||||
/**
|
||||
* 4级父节点名称
|
||||
*/
|
||||
@Alias("工具专业")
|
||||
private String fourthParentName;
|
||||
|
||||
/**
|
||||
* 3级父节点名称
|
||||
*/
|
||||
@Alias("施工类型")
|
||||
private String greatGrandparentName;
|
||||
/**
|
||||
* 2级父节点名称
|
||||
*/
|
||||
@Alias("工具类型")
|
||||
private String grandparentTypeName;
|
||||
/**
|
||||
* 1级父节点名称
|
||||
*/
|
||||
@Alias("工具名称")
|
||||
private String parentTypeName;
|
||||
|
||||
@Alias("工具编码")
|
||||
private String code;
|
||||
|
||||
@Alias("管理模式")
|
||||
private String manageMode;
|
||||
|
||||
@Alias("计量单位")
|
||||
private String unitName;
|
||||
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("在库数量")
|
||||
private Integer availableNum;
|
||||
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("自用数量")
|
||||
private Integer inNum;
|
||||
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("共享数量")
|
||||
private Integer shareNum;
|
||||
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("维修数量")
|
||||
private Integer repairNum;
|
||||
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("退役数量")
|
||||
private Integer scrapNum;
|
||||
|
||||
/**
|
||||
* 总数量(非空,默认1.00)
|
||||
*/
|
||||
@Alias("资产原值")
|
||||
private Integer totalNum;
|
||||
|
||||
|
||||
/**
|
||||
* 最大使用年限(年)
|
||||
*/
|
||||
@Alias("录入人")
|
||||
@ApiModelProperty(value = "最大使用年限(年)")
|
||||
private String creator;
|
||||
|
||||
|
||||
/**
|
||||
* 最大使用年限(年)
|
||||
*/
|
||||
@Alias("录入时间")
|
||||
@ApiModelProperty(value = "最大使用年限(年)")
|
||||
private String createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.bonus.material.index.mapper;
|
||||
|
||||
import com.bonus.material.devchange.domain.MaDevInfo;
|
||||
import com.bonus.material.devchange.domain.MaDevInfoXlsx;
|
||||
import com.bonus.material.index.domain.CompanyDevToolStatisticsExport;
|
||||
import com.bonus.material.index.domain.MaDevInfoXlsxExport;
|
||||
import com.bonus.material.index.domain.ToolLedgerEntityExport;
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface IndexMapper {
|
||||
/**
|
||||
* 数据总览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getDeviceNum(String companyId);
|
||||
|
||||
Map<String, Object> getUseDeviceNum();
|
||||
|
||||
List<Map<String, Object>> getReal();
|
||||
|
||||
List<Map<String, Object>> getDeviceByDept();
|
||||
|
||||
Map<String, Object> getMaQc(String companyId);
|
||||
|
||||
Map<String, Object> getDeviceNumByMonth(String companyId);
|
||||
|
||||
List<Map<String, Object>> getApprover(@Param("userId") String userId, @Param("roles")Set<String> roles);
|
||||
|
||||
Map<String, Object> getShare(String companyId);
|
||||
|
||||
|
||||
List<CompanyDevToolStatisticsExport> getDeviceByDeptEX();
|
||||
|
||||
List<MaDevInfoXlsxExport> listXlsx();
|
||||
|
||||
|
||||
/**
|
||||
* 工具台账表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolLedgerEntityExport> listToolLedgerEntity();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.bonus.material.index.service;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public interface IndexService {
|
||||
/**
|
||||
* 数据总览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getDeviceNum();
|
||||
|
||||
/**
|
||||
* 使用情况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getUseDeviceNum();
|
||||
|
||||
/**
|
||||
* 实时情况
|
||||
* @return
|
||||
*/
|
||||
AjaxResult getReal();
|
||||
|
||||
AjaxResult getDeviceByDept();
|
||||
|
||||
AjaxResult getMaQc();
|
||||
|
||||
AjaxResult getDeviceNumByMonth();
|
||||
|
||||
AjaxResult getApprover();
|
||||
|
||||
AjaxResult getShare();
|
||||
|
||||
void export(HttpServletResponse response);
|
||||
}
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
package com.bonus.material.index.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.device.domain.vo.DevInfoVo;
|
||||
import com.bonus.material.index.domain.CompanyDevToolStatisticsExport;
|
||||
import com.bonus.material.index.domain.MaDevInfoXlsxExport;
|
||||
import com.bonus.material.index.domain.ToolLedgerEntityExport;
|
||||
import com.bonus.material.index.mapper.IndexMapper;
|
||||
import com.bonus.material.index.service.IndexService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
import static com.bonus.common.biz.constant.MaterialConstants.ADMIN_ID;
|
||||
import static com.bonus.common.biz.constant.MaterialConstants.PROVINCE_COMPANY_DEPT_ID;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IndexServiceImpl implements IndexService {
|
||||
@Resource
|
||||
private IndexMapper mapper;
|
||||
|
||||
/**
|
||||
* 数据总览
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getDeviceNum() {
|
||||
try {
|
||||
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
// 管理员和省公司可查看所有数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (userId != null && deptId != null
|
||||
&& !userId.equals(ADMIN_ID)
|
||||
&& !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
|
||||
|
||||
map = mapper.getDeviceNum(String.valueOf(deptId));
|
||||
} else {
|
||||
map = mapper.getDeviceNum(null);
|
||||
}
|
||||
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用情况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getUseDeviceNum() {
|
||||
try {
|
||||
Map<String, Object> map = mapper.getUseDeviceNum();
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时情况
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getReal() {
|
||||
try {
|
||||
List<Map<String, Object>> map = mapper.getReal();
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getDeviceByDept() {
|
||||
try {
|
||||
List<Map<String, Object>> map = mapper.getDeviceByDept();
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getMaQc() {
|
||||
try {
|
||||
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
// 管理员和省公司可查看所有数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (userId != null && deptId != null
|
||||
&& !userId.equals(ADMIN_ID)
|
||||
&& !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
|
||||
|
||||
map = mapper.getMaQc(String.valueOf(deptId));
|
||||
} else {
|
||||
map = mapper.getMaQc(null);
|
||||
}
|
||||
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getDeviceNumByMonth() {
|
||||
try {
|
||||
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
// 管理员和省公司可查看所有数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (userId != null && deptId != null
|
||||
&& !userId.equals(ADMIN_ID)
|
||||
&& !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
|
||||
|
||||
map = mapper.getDeviceNumByMonth(String.valueOf(deptId));
|
||||
} else {
|
||||
map = mapper.getDeviceNumByMonth(null);
|
||||
}
|
||||
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getApprover() {
|
||||
try {
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
Set<String> roles = SecurityUtils.getLoginUser().getRoles();
|
||||
// 管理员和省公司可查看所有数据
|
||||
List<Map<String, Object>> map = new ArrayList<>();
|
||||
if (userId != null
|
||||
&& !userId.equals(ADMIN_ID)) {
|
||||
|
||||
map = mapper.getApprover(String.valueOf(userId), roles);
|
||||
} else {
|
||||
map = mapper.getApprover(null, null);
|
||||
}
|
||||
|
||||
return AjaxResult.success(map);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getShare() {
|
||||
try {
|
||||
Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
// 管理员和省公司可查看所有数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (userId != null && deptId != null
|
||||
&& !userId.equals(ADMIN_ID)
|
||||
&& !deptId.equals(PROVINCE_COMPANY_DEPT_ID)) {
|
||||
|
||||
map = mapper.getShare(String.valueOf(deptId));
|
||||
} else {
|
||||
map = mapper.getShare(null);
|
||||
}
|
||||
|
||||
return ObjectUtil.isNotEmpty(map) ? AjaxResult.success(map) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param response
|
||||
*/
|
||||
@Override
|
||||
public void export(HttpServletResponse response) {
|
||||
// 1. 准备数据(省略,同前文)
|
||||
List<CompanyDevToolStatisticsExport> companyDevToolStatistics = mapper.getDeviceByDeptEX();
|
||||
List<MaDevInfoXlsxExport> maDevInfoXlsxExports = mapper.listXlsx();
|
||||
List<ToolLedgerEntityExport> toolLedgerEntityExports = mapper.listToolLedgerEntity();
|
||||
// 2. 初始化ExcelWriter
|
||||
ExcelWriter writer = ExcelUtil.getWriter();
|
||||
// 3. 写入多Sheet数据(省略)
|
||||
writer.setSheet("统计");
|
||||
writer.write(companyDevToolStatistics);
|
||||
writer.setSheet("装备信息");
|
||||
writer.write(maDevInfoXlsxExports);
|
||||
|
||||
writer.setSheet("工具信息");
|
||||
writer.write(toolLedgerEntityExports);
|
||||
|
||||
Workbook workbook = writer.getWorkbook();
|
||||
// 遍历Sheet,删除名称为Sheet1/Sheet0的空Sheet(Hutool默认名称)
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
String sheetName = sheet.getSheetName();
|
||||
// 判断是否为默认空Sheet(名称为Sheet1/Sheet0,且行数为0)
|
||||
if (("Sheet1".equals(sheetName) || "Sheet0".equals(sheetName)) && sheet.getLastRowNum() == -1) {
|
||||
workbook.removeSheetAt(i);
|
||||
break; // 只删除一个默认空Sheet,跳出循环
|
||||
}
|
||||
}
|
||||
// 4. 设置响应头(修复编码异常)
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
String fileName = null;
|
||||
try {
|
||||
// 捕获UnsupportedEncodingException异常
|
||||
fileName = URLEncoder.encode("多Sheet页导出", "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
// 5. 写入输出流并关闭
|
||||
writer.flush(response.getOutputStream(), true);
|
||||
writer.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常处理:使用默认名称,或抛出运行时异常
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -59,4 +59,11 @@ public class ToBeScrapController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("/getDetail/{id}")
|
||||
@ApiOperation(value = "获取报废详情明细")
|
||||
public AjaxResult getDetail(@PathVariable("id") String id) {
|
||||
return AjaxResult.success(toBeScrapService.getDetail(id));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,4 +83,6 @@ public interface ScrapMapper {
|
|||
* 根据设备类型和编号查询
|
||||
*/
|
||||
ToBeScrap selectByTypeIdAndCode(ToBeScrap toBeScrap);
|
||||
|
||||
List<ToBeScrap> getDetail(String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,4 +37,6 @@ public interface ToBeScrapService {
|
|||
* 获取报废详情明细
|
||||
*/
|
||||
List<ToBeScrap> getScrapDetailsList(ToBeScrap bean);
|
||||
|
||||
List<ToBeScrap> getDetail(String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,4 +250,14 @@ public class ToBeScrapServiceImpl implements ToBeScrapService {
|
|||
public List<ToBeScrap> getScrapDetailsList(ToBeScrap bean) {
|
||||
return scrapMapper.getScrapDetailsList(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ToBeScrap> getDetail(String id) {
|
||||
|
||||
return scrapMapper.getDetail(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,6 +272,7 @@
|
|||
mdip.property_name propertyName,
|
||||
mdip.property_value propertyValue,
|
||||
mtp.property_value AS value,
|
||||
mtp.must_have AS mustHave,
|
||||
mtp.input_type AS inputType
|
||||
from ma_dev_info_properties mdip
|
||||
LEFT JOIN ma_type_properties mtp ON mtp.id = mdip.property_id
|
||||
|
|
|
|||
|
|
@ -0,0 +1,503 @@
|
|||
<?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.index.mapper.IndexMapper">
|
||||
<select id="getDeviceNum" resultType="java.util.Map">
|
||||
SELECT IFNULL(toolNum,0) AS toolNum,
|
||||
IFNULL(maNum,0) AS maNum,
|
||||
IFNULL(totalSum,0) AS totalSum,
|
||||
IFNULL(ROUND((toolNum / totalSum) * 100, 2),0) AS toolPercent,
|
||||
IFNULL(ROUND((maNum / totalSum) * 100, 2),0) AS maPercent
|
||||
FROM (SELECT ROUND(t1.toolNum) AS toolNum,
|
||||
ROUND(t2.maNum) AS maNum,
|
||||
ROUND(t1.toolNum) + ROUND(t2.maNum) AS totalSum
|
||||
FROM (SELECT SUM(total_num - scrap_num) AS toolNum FROM tool_ledger
|
||||
<where>
|
||||
<if test="companyId != null">
|
||||
and company_id = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
) t1
|
||||
CROSS JOIN
|
||||
(SELECT COUNT(mdi.ma_id) AS maNum
|
||||
FROM ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
<where>
|
||||
mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1'
|
||||
AND mdi.ma_status != '99'
|
||||
<if test="companyId != null">
|
||||
and mdi.on_company = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
) t2) AS temp;
|
||||
</select>
|
||||
<select id="getUseDeviceNum" resultType="java.util.Map">
|
||||
SELECT ROUND(IFNULL(t1.available_num, 0) + IFNULL(t2.available_num, 0)) AS availableNum,
|
||||
ROUND(IFNULL(t1.in_num, 0) + IFNULL(t2.in_num, 0)) AS inNum,
|
||||
ROUND(IFNULL(t1.share_num, 0) + IFNULL(t2.share_num, 0)) AS shareNum,
|
||||
ROUND(IFNULL(t1.repair_num, 0) + IFNULL(t2.repair_num, 0)) AS repairNum,
|
||||
ROUND(IFNULL(t1.scrap_num, 0) + IFNULL(t2.scrap_num, 0)) AS scrapNum
|
||||
FROM (SELECT IFNULL(SUM(available_num), 0) AS available_num,
|
||||
IFNULL(SUM(in_num), 0) AS in_num,
|
||||
IFNULL(SUM(share_num), 0) AS share_num,
|
||||
IFNULL(SUM(repair_num), 0) AS repair_num,
|
||||
IFNULL(SUM(scrap_num), 0) AS scrap_num
|
||||
FROM tool_ledger) t1
|
||||
CROSS JOIN (SELECT IFNULL(COUNT(CASE WHEN mdi.ma_status = '1' THEN 1 END), 0) AS available_num,
|
||||
IFNULL(COUNT(CASE WHEN mdi.ma_status = '2' THEN 1 END), 0) AS in_num,
|
||||
IFNULL(COUNT(CASE WHEN mdi.ma_status = '3' THEN 1 END), 0) AS share_num,
|
||||
IFNULL(COUNT(CASE WHEN mdi.ma_status = '4' THEN 1 END), 0) AS repair_num,
|
||||
IFNULL(COUNT(CASE WHEN mdi.ma_status = '5' THEN 1 END), 0) AS scrap_num
|
||||
FROM ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
WHERE mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1') t2;
|
||||
</select>
|
||||
<select id="getReal" resultType="java.util.Map">
|
||||
-- 合并申请记录和审核记录,按时间降序排序
|
||||
SELECT t.applyTime,
|
||||
t.applyUser,
|
||||
t.businessName,
|
||||
t.statusType,
|
||||
t.deptAbbreviation
|
||||
FROM (
|
||||
-- 子查询1:申请记录(状态为0的当日申请)
|
||||
SELECT DATE_FORMAT(bap.apply_time, '%Y-%m-%d %H:%i:%s') AS applyTime,
|
||||
IFNULL(su.nick_name, '未知用户') AS applyUser,
|
||||
CASE bap.business_type
|
||||
WHEN 'EQUIPMENT_SCRAP' THEN '设备报废'
|
||||
WHEN 'EQUIPMENT_REPAIR' THEN '设备维修'
|
||||
WHEN 'EQUIPMENT_RETURN' THEN '设备退库'
|
||||
WHEN 'EQUIPMENT_OUT' THEN '设备出库'
|
||||
ELSE '未知业务类型'
|
||||
END AS businessName,
|
||||
'申请' AS statusType,
|
||||
sd.dept_abbreviation AS deptAbbreviation
|
||||
FROM bm_approval_instance bap
|
||||
LEFT JOIN sys_user su ON bap.apply_user_id = su.user_id
|
||||
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
||||
WHERE
|
||||
-- 筛选当日的申请时间(CURDATE() 是当日0点,小于次日0点)
|
||||
bap.apply_time >= CURDATE()
|
||||
AND bap.apply_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 子查询2:审核记录(关联申请实例获取业务类型)
|
||||
SELECT DATE_FORMAT(bar.create_time, '%Y-%m-%d %H:%i:%s') AS applyTime,
|
||||
IFNULL(su.nick_name, '系统') AS applyUser, -- 审核人作为用户维度
|
||||
CASE bap.business_type
|
||||
WHEN 'EQUIPMENT_SCRAP' THEN '设备报废'
|
||||
WHEN 'EQUIPMENT_REPAIR' THEN '设备维修'
|
||||
WHEN 'EQUIPMENT_RETURN' THEN '设备退库'
|
||||
WHEN 'EQUIPMENT_OUT' THEN '设备出库'
|
||||
ELSE '未知业务类型'
|
||||
END AS businessName,
|
||||
'审核' AS statusType,
|
||||
sd.dept_abbreviation AS deptAbbreviation
|
||||
FROM bm_approval_record bar
|
||||
LEFT JOIN bm_approval_instance bap ON bap.id = bar.instance_id
|
||||
LEFT JOIN sys_user su ON bar.approver_id = su.user_id
|
||||
LEFT JOIN sys_dept sd ON su.dept_id = sd.dept_id
|
||||
-- 可选:添加审核记录的时间筛选(与申请记录一致,筛选当日的审核记录)
|
||||
WHERE bar.create_time >= CURDATE()
|
||||
AND bar.create_time < DATE_ADD(CURDATE(), INTERVAL 1 DAY)) t
|
||||
-- 统一按时间降序排序(申请+审核记录一起排序)
|
||||
ORDER BY t.applyTime DESC;
|
||||
</select>
|
||||
<select id="getDeviceByDept" resultType="java.util.Map">
|
||||
SELECT sd.dept_abbreviation AS companyName, -- 公司名称
|
||||
-- 工具数量:无数据则为0,取整
|
||||
ROUND(IFNULL(SUM(temp.toolNum), 0)) AS toolNum,
|
||||
-- 设备数量:无数据则为0,取整
|
||||
ROUND(IFNULL(SUM(temp.maNum), 0)) AS maNum,
|
||||
-- 设备成本:无数据则为0(保留小数)
|
||||
IFNULL(SUM(temp.maCost), 0) AS maCost,
|
||||
-- 工具成本:无数据则为0(保留小数)
|
||||
IFNULL(SUM(temp.toolCost), 0) AS toolCost,
|
||||
-- 新增:manage_mode=0的工具有效数量总和(无数据则为0)
|
||||
IFNULL(SUM(temp.toolCodeNum), 0) AS toolCodeNum,
|
||||
-- 新增:manage_mode=1的工具有效数量总和(无数据则为0)
|
||||
IFNULL(SUM(temp.toolNoCodeNum), 0) AS toolNoCodeNum
|
||||
FROM sys_dept sd -- 所有公司的主表
|
||||
LEFT JOIN (
|
||||
-- 子查询:合并工具和设备的公司统计数据
|
||||
SELECT company_id,
|
||||
SUM(toolNum) AS toolNum,
|
||||
SUM(maNum) AS maNum,
|
||||
SUM(maCost) AS maCost,
|
||||
SUM(toolCost) AS toolCost,
|
||||
SUM(toolCodeNum) AS toolCodeNum, -- 合并工具编码数量统计值
|
||||
SUM(toolNoCodeNum) AS toolNoCodeNum -- 合并无工具编码数量统计值
|
||||
FROM (
|
||||
-- 工具台账的公司统计:核心统计工具相关数据
|
||||
SELECT company_id,
|
||||
SUM(total_num - scrap_num) AS toolNum, -- 工具总数量
|
||||
-- 工具成本:(总数量-报废数量)*原始成本(处理NULL)
|
||||
SUM((total_num - scrap_num) * IFNULL(origin_cost, 0)) AS toolCost,
|
||||
-- 统计manage_mode=0的工具有效数量(total_num - scrap_num)
|
||||
SUM(CASE WHEN manage_mode = 0 THEN (total_num - scrap_num) ELSE 0 END) AS toolCodeNum,
|
||||
-- 统计manage_mode=1的工具有效数量
|
||||
SUM(CASE WHEN manage_mode = 1 THEN (total_num - scrap_num) ELSE 0 END) AS toolNoCodeNum,
|
||||
0 AS maNum, -- 设备数量默认0(字段对齐)
|
||||
0 AS maCost -- 设备成本默认0(字段对齐)
|
||||
FROM tool_ledger
|
||||
GROUP BY company_id
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 设备信息的公司统计:核心统计设备相关数据,工具相关字段默认0
|
||||
SELECT on_company AS company_id,
|
||||
0 AS toolNum, -- 工具数量默认0
|
||||
0 AS toolCost, -- 工具成本默认0
|
||||
0 AS toolCodeNum, -- 工具编码数量默认0(字段对齐)
|
||||
0 AS toolNoCodeNum, -- 无工具编码数量默认0(字段对齐)
|
||||
COUNT(mdi.ma_id) AS maNum, -- 设备总数量
|
||||
-- 设备成本:采购价求和(处理NULL)
|
||||
SUM(IFNULL(mdi.buy_price, 0)) AS maCost
|
||||
FROM ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
WHERE mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1'
|
||||
AND mdi.ma_status != '99' -- 排除状态为99的设备
|
||||
GROUP BY on_company) t
|
||||
-- 按公司ID合并数据,避免同一公司多条记录
|
||||
GROUP BY company_id) temp ON sd.dept_id = temp.company_id -- 公司ID关联
|
||||
WHERE sd.dept_abbreviation is NOT null
|
||||
-- 按公司ID分组,确保每个公司只显示一行
|
||||
GROUP BY sd.dept_id,
|
||||
sd.dept_name
|
||||
-- 核心修改:按maNum排序(DESC降序/ASC升序,默认ASC)
|
||||
-- 推荐降序:设备数量多的公司排在前面
|
||||
ORDER BY maNum DESC, -- 优先按设备数量排序
|
||||
sd.dept_id ASC; -- 设备数量相同时,按公司ID排序(可选,保证排序稳定性)
|
||||
</select>
|
||||
<select id="getMaQc" resultType="java.util.Map">
|
||||
SELECT
|
||||
-- 一、装备使用年限相关统计
|
||||
IFNULL(t1.overdue_num,0)AS useYearOverdueNum, -- 使用年限已超期数量
|
||||
IFNULL(t1.expire_month_num,0) AS useYearExpireMonthNum, -- 使用年限一月内超期数量
|
||||
-- 二、装备维保检验日期相关统计
|
||||
IFNULL(t2.expire_month_num,0) AS maintainExpireMonthNum, -- 维保日期一月内到期数量
|
||||
IFNULL(t2.overdue_num,0) AS maintainOverdueNum -- 维保日期已超期数量
|
||||
FROM
|
||||
-- 子查询1:装备使用年限超期统计
|
||||
(
|
||||
SELECT
|
||||
SUM(CASE WHEN t.expire_type = '已超期' THEN 1 ELSE 0 END) AS overdue_num,
|
||||
SUM(CASE WHEN t.expire_type = '一月内超期' THEN 1 ELSE 0 END) AS expire_month_num
|
||||
FROM (
|
||||
SELECT
|
||||
mdi.ma_id,
|
||||
CASE
|
||||
WHEN ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, CURDATE()) / 365.25, 1) >= mdi.max_working_hours THEN '已超期'
|
||||
WHEN (mdi.max_working_hours - ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, CURDATE()) / 365.25, 1)) * 365.25
|
||||
<=
|
||||
30 THEN '一月内超期'
|
||||
ELSE '正常'
|
||||
END AS expire_type
|
||||
FROM
|
||||
ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
<where>
|
||||
mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1'
|
||||
AND mdi.ma_status != '99'
|
||||
AND mdi.production_date IS NOT NULL
|
||||
<if test="companyId != null">
|
||||
and mdi.on_company = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
) t
|
||||
) t1
|
||||
-- 笛卡尔积关联:两个单一行的统计结果合并为一行
|
||||
CROSS JOIN
|
||||
-- 子查询2:装备维保检验日期超期统计
|
||||
(
|
||||
SELECT
|
||||
COUNT(CASE
|
||||
WHEN mdq.next_check_time >= CURRENT_DATE()
|
||||
AND mdq.next_check_time <= DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH)
|
||||
THEN 1
|
||||
END) AS expire_month_num,
|
||||
COUNT(CASE
|
||||
WHEN mdq.next_check_time < CURRENT_DATE()
|
||||
THEN 1
|
||||
END) AS overdue_num
|
||||
FROM
|
||||
ma_dev_info mdi
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
ma_id,
|
||||
MAX(next_check_time) AS next_check_time
|
||||
FROM ma_dev_qc
|
||||
GROUP BY ma_id
|
||||
) mdq ON mdi.ma_id = mdq.ma_id
|
||||
<where>
|
||||
mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1'
|
||||
AND mdi.ma_status != '99'
|
||||
<if test="companyId != null">
|
||||
and mdi.on_company = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
) t2;
|
||||
</select>
|
||||
<select id="getDeviceNumByMonth" resultType="java.util.Map">
|
||||
SELECT
|
||||
-- 退库申请数量(类型1:原始退库申请)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '1' THEN cdcd.num ELSE 0 END),0) AS returnApplyNum,
|
||||
-- 自用申请数量(类型2:自用申请)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '2' THEN cdcd.num ELSE 0 END),0) AS selfUseApplyNum,
|
||||
-- 自用出库数量(类型2的实际出库数)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '2' THEN cdcd.real_num ELSE 0 END),0) AS selfUseOutNum,
|
||||
-- 自用审核数量(类型2+审核通过状态2的申请数)
|
||||
IFNULL(SUM(CASE WHEN cdc.review_status = 2 AND cdc.type = '2' THEN cdcd.num ELSE 0 END),0) AS selfUseAuditNum,
|
||||
-- 退库审核数量(类型1+审核通过状态2的申请数)
|
||||
IFNULL(SUM(CASE WHEN cdc.review_status = 2 AND cdc.type = '1' THEN cdcd.num ELSE 0 END),0) AS
|
||||
returnAuditApplyNum,
|
||||
-- 退库维修数量(类型1+审核通过状态2的实际维修数)
|
||||
IFNULL(SUM(CASE WHEN cdc.review_status = 2 AND cdc.type = '1' THEN cdcd.real_num ELSE 0 END),0) AS
|
||||
returnAuditRepairNum,
|
||||
-- 退库入库数量(类型1+审核通过状态2的申请数-实际维修数,即可入库数量)
|
||||
IFNULL(SUM(CASE WHEN cdc.review_status = 2 AND cdc.type = '1' THEN (cdcd.num - cdcd.real_num) ELSE 0 END),0) AS
|
||||
returnAuditStoreNum,
|
||||
-- 类型4:待维修数量(未审核通过/审核中 + 申请数)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '4' AND cdc.review_status != 2 THEN cdcd.num ELSE 0 END),0) AS repairPendingNum,
|
||||
-- 类型4:维修退役数量(审核通过 + 实际退役数)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '4' AND cdc.review_status = 2 THEN cdcd.real_num ELSE 0 END),0) AS
|
||||
repairRetireNum,
|
||||
-- 类型4:维修合格数量(审核通过 + 申请数-实际退役数,即可入库/复用数量)
|
||||
IFNULL(SUM(CASE WHEN cdc.type = '4' AND cdc.review_status = 2 THEN (cdcd.num - cdcd.real_num) ELSE 0 END),0) AS
|
||||
repairQualifiedNum
|
||||
FROM
|
||||
cs_device_change cdc
|
||||
-- 原LEFT JOIN + cdcd.id IS NOT NULL 等价于INNER JOIN,性能更优
|
||||
INNER JOIN cs_device_change_details cdcd
|
||||
ON cdcd.change_id = cdc.id
|
||||
AND cdcd.del_flag = '0' -- 子表未删除
|
||||
<where>
|
||||
cdc.del_flag = '0' -- 主表未删除
|
||||
-- 筛选本月数据(年、月与当前日期一致)
|
||||
AND DATE_FORMAT(cdc.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
||||
<if test="companyId != null">
|
||||
and cdc.company_id = #{companyId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<!-- MySQL版本:使用MyBatis的foreach循环拼接OR条件 -->
|
||||
<select id="getApprover" resultType="java.util.Map">
|
||||
SELECT
|
||||
cdc.id AS id,
|
||||
cdc.code AS code,
|
||||
DATE_FORMAT(cdc.create_time, '%Y-%m-%d %H:%i:%s') AS createTime,
|
||||
CASE bai.business_type
|
||||
WHEN 'EQUIPMENT_SCRAP' THEN '设备退役'
|
||||
WHEN 'EQUIPMENT_REPAIR' THEN '设备维修'
|
||||
WHEN 'EQUIPMENT_RETURN' THEN '设备退库'
|
||||
WHEN 'EQUIPMENT_OUT' THEN '设备出库'
|
||||
ELSE '未知业务类型'
|
||||
END AS businessName
|
||||
FROM
|
||||
bm_approval_instance bai
|
||||
LEFT JOIN bm_approval_node ban ON ban.id = bai.current_node_id
|
||||
LEFT JOIN cs_device_change cdc ON bai.business_id = cdc.id
|
||||
WHERE
|
||||
ban.auto_pass = '0'
|
||||
AND bai.STATUS = '1'
|
||||
AND cdc.id IS NOT NULL
|
||||
<!-- 核心:二选一场景,分别处理userId/roles,无OR拼接 -->
|
||||
<choose>
|
||||
<!-- 场景1:仅userId有值(审批人类型为1:用户) -->
|
||||
<when test="userId != null and userId != ''">
|
||||
AND ban.approver_type = '1'
|
||||
AND FIND_IN_SET(#{userId}, ban.approver_ids)
|
||||
</when>
|
||||
<!-- 场景2:仅roles有值(审批人类型为2:角色) -->
|
||||
<when test="roles != null and roles.size() > 0">
|
||||
AND ban.approver_type = '2'
|
||||
AND (
|
||||
<foreach collection="roles" item="role" separator="OR" open="" close="">
|
||||
FIND_IN_SET(#{role}, ban.approver_ids)
|
||||
</foreach>
|
||||
)
|
||||
</when>
|
||||
</choose>
|
||||
</select>
|
||||
<select id="getShare" resultType="java.util.Map">
|
||||
SELECT
|
||||
-- 1. 出售方订单数:companyId为空时统计所有,否则统计指定公司
|
||||
SUM(CASE
|
||||
WHEN #{companyId} IS NULL OR #{companyId} = '' THEN 1
|
||||
WHEN a.sellerDeptId = #{companyId} THEN 1
|
||||
ELSE 0
|
||||
END) AS sellerNum,
|
||||
-- 2. 购买方订单数:companyId为空时统计所有,否则统计指定公司
|
||||
SUM(CASE
|
||||
WHEN #{companyId} IS NULL OR #{companyId} = '' THEN 1
|
||||
WHEN a.buyerCompanyName = #{companyId} THEN 1
|
||||
ELSE 0
|
||||
END) AS buyerNum,
|
||||
-- 3. 出售设备总数:companyId为空时统计所有,否则统计指定公司的设备数
|
||||
SUM(CASE
|
||||
WHEN #{companyId} IS NULL OR #{companyId} = '' THEN a.equipmentTotalNum
|
||||
WHEN a.sellerDeptId = #{companyId} THEN a.equipmentTotalNum
|
||||
ELSE 0
|
||||
END) AS toolNum
|
||||
FROM (
|
||||
-- 内层查询:按订单维度统计出售方、购买方、设备总数(原逻辑不变)
|
||||
SELECT up.dept_id AS sellerDeptId,
|
||||
moi.buyer_company AS buyerCompanyName,
|
||||
SUM(hh.num) AS equipmentTotalNum
|
||||
FROM ma_order_details hh
|
||||
LEFT JOIN ma_order_info moi ON moi.order_id = hh.order_id
|
||||
LEFT JOIN ma_dev_info mdi ON hh.ma_id = mdi.ma_id
|
||||
LEFT JOIN sys_dept up ON up.dept_id = mdi.on_company
|
||||
|
||||
WHERE DATE_FORMAT(moi.create_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
|
||||
GROUP BY hh.order_id,
|
||||
up.dept_id,
|
||||
moi.buyer_company) a
|
||||
</select>
|
||||
<select id="getDeviceByDeptEX" resultType="com.bonus.material.index.domain.CompanyDevToolStatisticsExport">
|
||||
SELECT sd.dept_abbreviation AS companyName, -- 公司名称
|
||||
-- 工具数量:无数据则为0,取整
|
||||
ROUND(IFNULL(SUM(temp.toolNum), 0)) AS toolNum,
|
||||
-- 设备数量:无数据则为0,取整
|
||||
ROUND(IFNULL(SUM(temp.maNum), 0)) AS maNum,
|
||||
-- 设备成本:无数据则为0(保留小数)
|
||||
IFNULL(SUM(temp.maCost), 0) AS maCost,
|
||||
-- 工具成本:无数据则为0(保留小数)
|
||||
IFNULL(SUM(temp.toolCost), 0) AS toolCost,
|
||||
-- 新增:manage_mode=0的工具有效数量总和(无数据则为0)
|
||||
IFNULL(SUM(temp.toolCodeNum), 0) AS toolCodeNum,
|
||||
-- 新增:manage_mode=1的工具有效数量总和(无数据则为0)
|
||||
IFNULL(SUM(temp.toolNoCodeNum), 0) AS toolNoCodeNum
|
||||
FROM sys_dept sd -- 所有公司的主表
|
||||
LEFT JOIN (
|
||||
-- 子查询:合并工具和设备的公司统计数据
|
||||
SELECT company_id,
|
||||
SUM(toolNum) AS toolNum,
|
||||
SUM(maNum) AS maNum,
|
||||
SUM(maCost) AS maCost,
|
||||
SUM(toolCost) AS toolCost,
|
||||
SUM(toolCodeNum) AS toolCodeNum, -- 合并工具编码数量统计值
|
||||
SUM(toolNoCodeNum) AS toolNoCodeNum -- 合并无工具编码数量统计值
|
||||
FROM (
|
||||
-- 工具台账的公司统计:核心统计工具相关数据
|
||||
SELECT company_id,
|
||||
SUM(total_num - scrap_num) AS toolNum, -- 工具总数量
|
||||
-- 工具成本:(总数量-报废数量)*原始成本(处理NULL)
|
||||
SUM((total_num - scrap_num) * IFNULL(origin_cost, 0)) AS toolCost,
|
||||
-- 统计manage_mode=0的工具有效数量(total_num - scrap_num)
|
||||
SUM(CASE WHEN manage_mode = 0 THEN (total_num - scrap_num) ELSE 0 END) AS toolCodeNum,
|
||||
-- 统计manage_mode=1的工具有效数量
|
||||
SUM(CASE WHEN manage_mode = 1 THEN (total_num - scrap_num) ELSE 0 END) AS toolNoCodeNum,
|
||||
0 AS maNum, -- 设备数量默认0(字段对齐)
|
||||
0 AS maCost -- 设备成本默认0(字段对齐)
|
||||
FROM tool_ledger
|
||||
GROUP BY company_id
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 设备信息的公司统计:核心统计设备相关数据,工具相关字段默认0
|
||||
SELECT on_company AS company_id,
|
||||
0 AS toolNum, -- 工具数量默认0
|
||||
0 AS toolCost, -- 工具成本默认0
|
||||
0 AS toolCodeNum, -- 工具编码数量默认0(字段对齐)
|
||||
0 AS toolNoCodeNum, -- 无工具编码数量默认0(字段对齐)
|
||||
COUNT(mdi.ma_id) AS maNum, -- 设备总数量
|
||||
-- 设备成本:采购价求和(处理NULL)
|
||||
SUM(IFNULL(mdi.buy_price, 0)) AS maCost
|
||||
FROM ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
WHERE mdi.is_active = '1'
|
||||
AND mdi.entry_status = '1'
|
||||
AND mdi.ma_status != '99' -- 排除状态为99的设备
|
||||
GROUP BY on_company) t
|
||||
-- 按公司ID合并数据,避免同一公司多条记录
|
||||
GROUP BY company_id) temp ON sd.dept_id = temp.company_id -- 公司ID关联
|
||||
WHERE sd.dept_abbreviation is NOT null
|
||||
-- 按公司ID分组,确保每个公司只显示一行
|
||||
GROUP BY sd.dept_id,
|
||||
sd.dept_name
|
||||
-- 核心修改:按maNum排序(DESC降序/ASC升序,默认ASC)
|
||||
-- 推荐降序:设备数量多的公司排在前面
|
||||
ORDER BY maNum DESC, -- 优先按设备数量排序
|
||||
sd.dept_id ASC; -- 设备数量相同时,按公司ID排序(可选,保证排序稳定性)
|
||||
</select>
|
||||
<select id="listXlsx" resultType="com.bonus.material.index.domain.MaDevInfoXlsxExport">
|
||||
select sd.dept_name AS propertyUnit,
|
||||
mtv.proType AS major,
|
||||
CONCAT_WS('>', mtv.mainGx, mtv.childGx) AS subProcess,
|
||||
CONCAT_WS('>',mtv.devCategory, mtv.devSubcategory) AS subCategory,
|
||||
mdi.device_name AS name,
|
||||
mdi.item_type_model As specificationModel,
|
||||
mdi.code AS code,
|
||||
mdi.identify_code AS originalCode,
|
||||
CASE mdi.ma_status
|
||||
WHEN 1 THEN '在库'
|
||||
WHEN 2 THEN '自用'
|
||||
WHEN 3 THEN '共享'
|
||||
WHEN 5 THEN '维修'
|
||||
WHEN 99 THEN '退役'
|
||||
ELSE '未知状态'
|
||||
END AS status,
|
||||
TIMESTAMPDIFF(YEAR, mdi.production_date, CURDATE()) AS serviceLife,
|
||||
mdi.unit AS unit,
|
||||
mdi.buy_price AS originalValue,
|
||||
ms.supplier_name AS manufacturer,
|
||||
DATE_FORMAT(mdi.production_date, '%Y-%m-%d') AS productionDate,
|
||||
mdi.max_working_hours AS maxServiceLifeYears,
|
||||
su.nick_name AS creator,
|
||||
mdi.create_time AS createTime
|
||||
from ma_dev_info mdi
|
||||
INNER JOIN ma_type_view mtv ON mtv.typeId = mdi.type_id
|
||||
LEFT JOIN sys_dept sd ON sd.dept_id = mdi.on_company
|
||||
LEFT JOIN sys_user su ON su.user_id = mdi.creator
|
||||
LEFT JOIN ma_supplier ms ON ms.supplier_id = mdi.supplier_id
|
||||
<where>
|
||||
mdi.is_active = '1' and mdi.entry_status = '1'
|
||||
</where>
|
||||
</select>
|
||||
<select id="listToolLedgerEntity" resultType="com.bonus.material.index.domain.ToolLedgerEntityExport">
|
||||
SELECT IFNULL(tl.tool_code, '-') AS code,
|
||||
tt.type_name AS typeName,
|
||||
tt1.type_name AS parentTypeName,-- 1级父节点名称
|
||||
tt2.type_name AS grandparentTypeName,-- 2级父节点名称
|
||||
tt3.type_name AS greatGrandparentName,-- 3级父节点名称
|
||||
tt4.type_name AS fourthParentName,
|
||||
CASE
|
||||
tl.manage_mode
|
||||
WHEN 0 THEN
|
||||
'编码管理'
|
||||
WHEN 1 THEN
|
||||
'数量管理'
|
||||
ELSE '未知状态'
|
||||
END AS manageMode,
|
||||
COALESCE(tl.available_num, 0) AS availableNum,-- 在库
|
||||
COALESCE(tl.in_num, 0) AS inNum,-- 自用
|
||||
COALESCE(tl.share_num, 0) AS shareNum,-- 共享
|
||||
COALESCE(tl.repair_num, 0) AS repairNum,-- 维修
|
||||
COALESCE(tl.scrap_num, 0) AS scrapNum,-- 报废
|
||||
(tl.total_num - tl.scrap_num) * origin_cost AS totalNum, -- 总数
|
||||
su.nick_name AS creator,
|
||||
tt.create_time AS createTime
|
||||
FROM tool_ledger tl -- 关联1级父节点(直接父节点)
|
||||
INNER JOIN tool_type tt ON tt.type_id = tl.type_id
|
||||
LEFT JOIN sys_user su ON tt.create_by = su.user_id
|
||||
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id -- 关联2级父节点(祖父节点)
|
||||
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id -- 关联3级父节点(曾祖父节点)
|
||||
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id -- 关联4级父节点
|
||||
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
|
||||
WHERE tt.del_flag = '0'
|
||||
AND tt1.del_flag = '0'
|
||||
AND tt2.del_flag = '0'
|
||||
AND tt3.del_flag = '0'
|
||||
AND tt4.del_flag = '0'
|
||||
ORDER BY tl.create_time
|
||||
DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -377,6 +377,48 @@
|
|||
<select id="selectCountByChangeId" resultType="int">
|
||||
select count(1) from cs_device_change_details where change_id = #{changeId} and review_status = 0
|
||||
</select>
|
||||
<select id="getDetail" resultType="com.bonus.material.scrap.domain.ToBeScrap">
|
||||
SELECT CONCAT(mdi.ma_id, '-', '装备') as keyId,
|
||||
mdi.ma_id as id,
|
||||
'装备' as type,
|
||||
'1' as devType,
|
||||
mdi.type_id as typeId,
|
||||
CONCAT(mt2.type_name, '/', mt3.type_name, '/', mt4.type_name) AS groupName,
|
||||
mdi.device_name as typeName,
|
||||
mdi.item_type_model as typeModelName,
|
||||
'编码管理' as manageMode,
|
||||
mdi.`code` as `devCode`,
|
||||
mdi.device_count as inStockNum,
|
||||
mdi.production_date AS productionDate,
|
||||
mdi.max_working_hours AS expirationYears,
|
||||
CASE
|
||||
-- 告警2:已超期(剩余年限≤0)
|
||||
WHEN ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, NOW()) / 365.25, 1) >= mdi.max_working_hours
|
||||
THEN CONCAT('告警:已超最大使用年限', ROUND(
|
||||
ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, NOW()) / 365.25, 1) - mdi.max_working_hours,
|
||||
1
|
||||
), '年')
|
||||
-- 告警1:未超期,但剩余可用年限≤1年(相差小于等于1年)
|
||||
WHEN
|
||||
(mdi.max_working_hours - ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, NOW()) / 365.25, 1)) <=
|
||||
1
|
||||
THEN CONCAT('告警:即将超期,剩余可用年限', ROUND(
|
||||
mdi.max_working_hours - ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, NOW()) / 365.25, 1),
|
||||
1
|
||||
), '年')
|
||||
-- 正常:未超期,且剩余可用年限>1年(相差大于1年)
|
||||
ELSE CONCAT('正常:剩余可用年限', ROUND(
|
||||
mdi.max_working_hours - ROUND(TIMESTAMPDIFF(DAY, mdi.production_date, NOW()) / 365.25, 1),
|
||||
1
|
||||
), '年')
|
||||
END AS status
|
||||
FROM ma_dev_info mdi
|
||||
LEFT JOIN ma_type mt5 on mt5.type_id = mdi.type_id
|
||||
LEFT JOIN ma_type mt4 on mt4.type_id = mt5.parent_id
|
||||
LEFT JOIN ma_type mt3 on mt3.type_id = mt4.parent_id
|
||||
LEFT JOIN ma_type mt2 on mt2.type_id = mt3.parent_id
|
||||
WHERE mdi.ma_id = #{id}
|
||||
</select>
|
||||
|
||||
<update id="updateChangeStatus">
|
||||
update cs_device_change set review_status = #{reviewStatus} where id = #{changeId}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
<select id="list" resultType="com.bonus.material.toolLedger.domain.ToolLedgerEntity">
|
||||
SELECT
|
||||
|
||||
tt.type_id AS typeId,
|
||||
tt.type_name AS typeName,
|
||||
tt.unit_name AS unitName,
|
||||
|
|
|
|||
Loading…
Reference in New Issue