问题修复

This commit is contained in:
hongchao 2025-11-17 09:09:54 +08:00
parent 12fa25b605
commit b2c0bd357c
10 changed files with 587 additions and 3 deletions

View File

@ -517,6 +517,28 @@ public class PoiOutPage {
}
public static void excelForcheckRepairModel(HSSFWorkbook workbook,HSSFSheet sheet,List<Map<String, Object>> resultLease,List<String> listLease) {
sheet.setDefaultColumnWidth(15); // 设置列宽
// 创建样式
HSSFCellStyle titleStyle = createTitleStyle(workbook);
HSSFCellStyle headerStyle = createHeaderStyle(workbook);
HSSFCellStyle contentStyle = createCellStyleCost(workbook);
// 填充标题行
int rowNum = 0;
// 填充表头
rowNum = createHeaderRowTwo(sheet, rowNum, listLease, headerStyle);
// 填充数据行
if (resultLease != null && !resultLease.isEmpty()) {
rowNum = createDataRowsRepairModel(sheet, rowNum, resultLease, contentStyle, listLease.size());
}
}
/**
* 结算记录查询--导出全部明细
@ -1306,6 +1328,23 @@ public class PoiOutPage {
return rowNum;
}
private static int createDataRowsRepairModel(HSSFSheet sheet, int rowNum, List<Map<String, Object>> result,
HSSFCellStyle contentStyle, int nColumn) {
for (Map<String, Object> resultRow : result) {
HSSFRow row = sheet.createRow(rowNum++);
row.setHeightInPoints(15);
List<Object> rowData = map2List(resultRow);
for (int j = 0; j < nColumn; j++) {
HSSFCell cell = row.createCell(j);
Object data = rowData.get(j);
cell.setCellStyle(contentStyle);
setCellData(cell, data, contentStyle);
}
}
return rowNum;
}
private static int createDataRowsMonth(HSSFSheet sheet, int rowNum, List<Map<String, Object>> result,
HSSFCellStyle contentStyle, int nColumn) {
for (Map<String, Object> resultRow : result) {

View File

@ -1,5 +1,6 @@
package com.bonus.sgzb.material.controller;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -18,6 +19,8 @@ import com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.material.config.PoiOutPage;
import com.bonus.sgzb.material.domain.PurchaseInput;
import com.bonus.sgzb.material.domain.RepairPart;
import com.bonus.sgzb.material.domain.RepairPartAndType;
import com.bonus.sgzb.material.service.IPurchaseCheckInfoService;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.service.PurchaseCheckServiceCenterService;
@ -251,4 +254,141 @@ public class PurchaseCheckInfoController extends BaseController {
{
return purchaseCheckInfoService.importTbPeople(file);
}
/**
* 机具模板下载--all
*/
@ApiOperation(value = "维修导入模板下载")
@PostMapping("/downLoadRepairModel")
public void downLoadRepairModel(HttpServletResponse response, @RequestParam("params") String params) {
try {
// 创建工作簿
HSSFWorkbook workbook = new HSSFWorkbook();
int sheetIndex = 1;
// 创建工作表
HSSFSheet sheet = workbook.createSheet("维修导入模板");
//创建表头
ArrayList<String> list = new ArrayList<String>();
list.add("机具名称");
list.add("规格型号");
list.add("计量单位");
list.add("维修配件名称");
list.add("维修配件型号");
list.add("使用数量");
list.add("配件单价");
//数据转换
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("typeName",null );
map.put("modelName",null );
map.put("nuitName", null);
map.put("partName",null );
map.put("partModelName",null );
map.put("partNum", null);
map.put("partPrice", null);
List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
maps.add(map);
// 创建工作簿和工作表
PoiOutPage.excelForcheckRepairModel(workbook, sheet,maps,list);
sheetIndex++;
HSSFSheet sheetTwo = workbook.createSheet("维修配件类型规格");
//创建表头
ArrayList<String> listTwo = new ArrayList<String>();
listTwo.add("维修配件名称");
listTwo.add("维修配件规格");
listTwo.add("配件单价");
List<RepairPart> listType = purchaseCheckInfoService.selectPartList();
List<RepairPart> type = Convert.toList(RepairPart.class, listType);
List<Map<String, Object>> mapsType = new ArrayList<Map<String, Object>>();
//数据转换
if (type!= null) {
int sizeLease = type.size();
for (int i = 0; i < sizeLease; i++) {
RepairPart bean = type.get(i);
Map<String, Object> mapTwo = new LinkedHashMap<String, Object>();
mapTwo.put("partName",bean.getPartName());
mapTwo.put("partModelName",bean.getPartModelName() );
mapTwo.put("partPrice", bean.getPartPrice());
mapsType.add(mapTwo);
}
}else{
map.put("partName",null );
map.put("partModelName",null );
map.put("partPrice", null);
mapsType.add(map);
}
// 创建工作簿和工作表
PoiOutPage.excelForcheckEach(workbook, sheetTwo,mapsType,listTwo);
sheetIndex++;
HSSFSheet sheetThree = workbook.createSheet("机具类型规格");
//创建表头
ArrayList<String> listThree = new ArrayList<String>();
listThree.add("类型名称");
listThree.add("规格型号");
listThree.add("单位");
List<MaType> listTypeThree = purchaseCheckInfoService.selectMaTypeList();
List<MaType> typeThree = Convert.toList(MaType.class, listTypeThree);
List<Map<String, Object>> mapsTypeThree = new ArrayList<Map<String, Object>>();
//数据转换
if (typeThree!= null) {
int sizeLease = typeThree.size();
for (int i = 0; i < sizeLease; i++) {
MaType bean = typeThree.get(i);
Map<String, Object> mapThree = new LinkedHashMap<String, Object>();
mapThree.put("typeName",bean.getTypeName());
mapThree.put("modelName",bean.getModelName() );
mapThree.put("nuitName", bean.getUnitName());
mapsTypeThree.add(mapThree);
}
}else{
map.put("typeName",null );
map.put("modelName",null );
map.put("nuitName", null);
mapsTypeThree.add(map);
}
// 创建工作簿和工作表
PoiOutPage.excelForcheckEach(workbook, sheetThree,mapsTypeThree,listThree);
sheetIndex++;
OutputStream out = null;
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.addHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode("模板下载", "UTF-8") + ".xls");
response.setHeader("Pragma", "No-cache");
out = response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
} catch (Exception e) {
logger.error("模板下载失败", e);
}
}
/**
* 维修信息导入
* @param file
* @return
*/
@ApiOperation(value = "维修信息导入")
@PostMapping("/importRepairData")
public AjaxResult importRepairData(MultipartFile file) throws IOException {
return purchaseCheckInfoService.importRepairData(file);
}
/**
* 新增维修导入信息
*/
@ApiOperation("新增维修导入信息")
@PostMapping("/addRepairInputInfo")
public AjaxResult addRepairInputInfo(@RequestBody List<RepairPartAndType> infos) {
return toAjax(purchaseCheckInfoService.insertRepairInfo(infos));
}
}

View File

@ -38,6 +38,12 @@ public class RepairPart {
*/
@ApiModelProperty(value = "配件名称")
private String partName;
/**
* 配件规格
*/
@ApiModelProperty(value = "配件规格")
private String partModelName;
/**
* 返厂id
*/
@ -97,4 +103,6 @@ public class RepairPart {
private Long repairer;
@ApiModelProperty(value = "维修数量")
private int repairNum;
private Long parentId;
}

View File

@ -0,0 +1,112 @@
package com.bonus.sgzb.material.domain;
import com.bonus.sgzb.common.core.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author c liu
* @date 2023/12/11
*/
@Data
@ApiModel(value="维修配件")
public class RepairPartAndType {
/**
* 任务ID
*/
@ApiModelProperty(value = "任务ID")
private String taskId;
/**
* 机具ID
*/
@ApiModelProperty(value = "机具ID")
private String maId;
/**
* 规格ID
*/
@ApiModelProperty(value = "规格ID")
private Integer typeId;
/**
* 配件ID
*/
@ApiModelProperty(value = "配件ID")
private Long partId;
/**
* 配件名称
*/
@ApiModelProperty(value = "配件名称")
@Excel(name = "维修配件名称")
private String partName;
/**
* 配件规格
*/
@ApiModelProperty(value = "配件规格")
@Excel(name = "维修配件型号")
private String partModelName;
/**
* 配件数量
*/
@ApiModelProperty(value = "配件数量")
@Excel(name = "使用数量")
private int partNum;
/**
* 配件费用
*/
@ApiModelProperty(value = "配件费用")
private BigDecimal partAllCosts;
/**
* 配件单价
*/
@ApiModelProperty(value = "配件单价")
@Excel(name = "配件单价")
private BigDecimal partPrice;
/**
* 类型0不收费1收费
*/
@ApiModelProperty(value = "类型0不收费1收费")
private String partType;
/**
* 创建者
*/
@ApiModelProperty(value = "创建者")
private String createBy;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private String createTime;
/**
* 更新者
*/
@ApiModelProperty(value = "更新者")
private String updateBy;
/**
* 更新时间
*/
@ApiModelProperty(value = "更新时间")
private String updateTime;
/**
* 备注
*/
@ApiModelProperty(value = "备注")
private String remark;
private Long parentId;
@Excel(name = "机具名称")
private String typeName;
@Excel(name = "规格型号")
private String modelName;
@Excel(name = "计量单位")
private String unitName;
private Integer agreementId;
}

View File

@ -1,6 +1,7 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.material.domain.PurchaseCheckDetails;
import com.bonus.sgzb.material.domain.RepairPartAndType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -153,4 +154,6 @@ public interface PurchaseCheckDetailsMapper {
int updateByTaskId(@Param("taskId") Long taskId,@Param("typeId") Long typeId);
int uploadPic(PurchaseCheckDetails purchaseCheckDetails);
int insertRepairDetailsList(@Param("repairPartAndTypeList") List<RepairPartAndType> repairPartAndTypeList);
}

View File

@ -1,10 +1,8 @@
package com.bonus.sgzb.material.mapper;
import com.bonus.sgzb.base.api.domain.MaType;
import com.bonus.sgzb.material.domain.BmNoticeInfo;
import com.bonus.sgzb.material.domain.*;
import com.bonus.sgzb.base.api.domain.MachinePart;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.domain.PurchaseInput;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -133,4 +131,9 @@ public interface PurchaseCheckInfoMapper {
List<MaType> selectMaTypeList();
List<MaType> selectTypeDetail(MaType type);
List<RepairPart> selectPartList();
List<RepairPart> selectPartDetail(RepairPart type);
}

View File

@ -5,9 +5,12 @@ import com.bonus.sgzb.base.api.domain.MachinePart;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.PurchaseCheckInfo;
import com.bonus.sgzb.material.domain.PurchaseInput;
import com.bonus.sgzb.material.domain.RepairPart;
import com.bonus.sgzb.material.domain.RepairPartAndType;
import com.bonus.sgzb.material.vo.NoticeInfoVO;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
@ -130,4 +133,19 @@ public interface IPurchaseCheckInfoService
* @return
*/
AjaxResult importTbPeople(MultipartFile file);
/**
* 查询维修配件类型规格
* @return
*/
List<RepairPart> selectPartList();
/**
* 维修信息导入
* @param file
* @return
*/
AjaxResult importRepairData(MultipartFile file) throws IOException;
public int insertRepairInfo(List<RepairPartAndType> infos);
}

View File

@ -500,4 +500,208 @@ public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService {
String.format("第 %d 行,第 %d 列数据为空,请检查后重新导入", rowIndex + 1, colIndex + 1));
}
}
@Override
public List<RepairPart> selectPartList() {
List<RepairPart> listType = purchaseCheckInfoMapper.selectPartList();
return listType;
}
/**
* 维修信息导入
* @param file
* @return
*/
@Override
public AjaxResult importRepairData(MultipartFile file) throws IOException {
String fileName = file.getOriginalFilename();
if (fileName != null) {
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
if (!MaterialConstants.XLSX.equalsIgnoreCase(fileExtension)) {
// 文件后缀名不符合要求
return AjaxResult.error("导入失败:文件后缀名不符合要求,必须为xlsx结尾");
}
}
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
Workbook workbook = new XSSFWorkbook(inputStream); // 处理.xlsx文件
Sheet sheet = workbook.getSheetAt(0);
// 得到Excel的行数
int totalRows = sheet.getPhysicalNumberOfRows();
// 检查是否有行数
if (totalRows <= 1) {
throw new IllegalArgumentException("导入失败Excel文件中没有数据请检查后重新导入");
}
// 读取第一行表头
Row headerRow = sheet.getRow(0);
if (headerRow == null) {
throw new IllegalArgumentException("导入失败:文件中没有表头");
}
// 获取表头的列数
int totalCells = headerRow.getPhysicalNumberOfCells();
// 预期的表头列数为11列可以根据实际需求修改这个条件
if (totalCells != 7) {
throw new IllegalArgumentException("导入失败:表头列数与预期不符,请检查导入模板");
}
// 读取表头内容并验证每一列
extractedTextRepair(headerRow, totalCells);
//读取Excel表格数据做非空及格式判断
extractedCellRepair(sheet, totalRows, totalCells);
ExcelUtil<RepairPartAndType> util = new ExcelUtil<>(RepairPartAndType.class);
List<RepairPartAndType> maDevList = util.importExcel(file.getInputStream());
List<RepairPartAndType> templateVos = new ArrayList<>();
// 判断装备类目是否为空查询装备id及价格
if (!CollectionUtils.isEmpty(maDevList)) {
int i = 1;
for (RepairPartAndType devTemplateVo : maDevList) {
i++;
if (StringUtils.isNotBlank(devTemplateVo.getTypeName()) && StringUtils.isNotBlank(devTemplateVo.getModelName()) && StringUtils.isNotBlank(devTemplateVo.getUnitName())) {
// 根据物资类型详情
MaType type = new MaType();
type.setTypeName(devTemplateVo.getTypeName());
type.setModelName(devTemplateVo.getModelName());
type.setUnitName(devTemplateVo.getUnitName());
List<MaType> list = purchaseCheckInfoMapper.selectTypeDetail(type);
if (!CollectionUtils.isEmpty(list)) {
if (list.size() != 1) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "" + i + "行数据有误,请检查");
}
MaType devType = list.get(0);
devTemplateVo.setTypeId(Math.toIntExact(devType.getTypeId()));
} else {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "" + i + "行数据有误,请检查");
}
// 根据维修配件名称查询维修配件id
RepairPart part = new RepairPart();
part.setPartName(devTemplateVo.getPartName());
part.setPartModelName(devTemplateVo.getPartModelName());
List<RepairPart> listPart = purchaseCheckInfoMapper.selectPartDetail(part);
if (!CollectionUtils.isEmpty(listPart)) {
if (listPart.size() != 1) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "" + i + "行数据有误,请检查");
}
RepairPart devPart = listPart.get(0);
devTemplateVo.setPartId(devPart.getPartId());
} else {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "" + i + "行数据有误,请检查");
}
templateVos.add(devTemplateVo);
}
}
}
inputStream.close();
return AjaxResult.success(templateVos);
} catch (IOException e) {
e.printStackTrace();
} finally {
inputStream.close();
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 读取Excel表格数据做非空及格式判断
* @param headerRow
* @param totalCells
*/
private void extractedTextRepair(Row headerRow, int totalCells) {
for (int cellNum = 0; cellNum < totalCells; cellNum++) {
Cell cell = headerRow.getCell(cellNum);
// 获取单元格内容并去除首尾空格
String headerValue = cell.getStringCellValue().trim();
// 根据列索引进行验证
switch (cellNum) {
case 0:
if (!"机具名称".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 1:
if (!"规格型号".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 2:
if (!"计量单位".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 3:
if (!"维修配件名称".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 4:
if (!"维修配件型号".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 5:
if (!"使用数量".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
case 6:
if (!"配件单价".equals(headerValue)) {
throw new IllegalArgumentException("" + (cellNum + 1) + " 列表头列名与预期不符,请检查导入模板");
}
break;
default:
break;
}
}
}
/**
* 读取Excel表格数据做非空判断
* @param sheet
* @param totalRows
* @param totalCells
*/
private void extractedCellRepair(Sheet sheet, int totalRows, int totalCells) {
//读取Excel表格数据做非空判断
// 循环Excel行数
DataFormatter dataFormatter = new DataFormatter();
for (int r = 1; r < totalRows; r++) {
Row row = sheet.getRow(r);
// 循环Excel列数
for (int c = 0; c < totalCells; c++) {
Cell cell = row.getCell(c);
String cellValue = "";
if (cell != null && cell.getCellType() == CellType.STRING) {
cellValue = cell.getStringCellValue();
}
if (c == 5 || c == 6) {
cellValue = dataFormatter.formatCellValue(row.getCell(c));
}
checkBlank(cellValue, r, c);
}
}
}
/**
* 新增维修导入信息
*
* @param details 新增维修导入信息
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int insertRepairInfo(List<RepairPartAndType> details) {
long userId = SecurityUtils.getLoginUser().getUserid();
if (details != null) {
for (RepairPartAndType repairPartAndType : details) {
repairPartAndType.setCreateBy(String.valueOf(userId));
}
return purchaseCheckDetailsMapper.insertRepairDetailsList(details);
}else {
throw new IllegalArgumentException("维修导入信息不能为空");
}
}
}

View File

@ -280,4 +280,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
where id = #{id}
</update>
<insert id="insertRepairDetailsList">
<foreach item="checkDetails" collection="repairPartAndTypeList" open="" separator=";" close="">
insert into repair_input_part
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="checkDetails.agreementId != null">agreementId,</if>
<if test="checkDetails.typeId != null">type_id,</if>
<if test="checkDetails.partName != null">part_name,</if>
<if test="checkDetails.partModelName != null">part_model_name,</if>
<if test="checkDetails.partNum != null">part_num,</if>
<if test="checkDetails.partPrice != null">part_price,</if>
<if test="checkDetails.partAllCosts != null">part_cost,</if>
<if test="checkDetails.createBy != null">create_by,</if>
<if test="checkDetails.createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="checkDetails.agreementId != null">#{checkDetails.agreementId},</if>
<if test="checkDetails.typeId != null">#{checkDetails.typeId},</if>
<if test="checkDetails.partName != null">#{checkDetails.partName},</if>
<if test="checkDetails.partModelName != null">#{checkDetails.partModelName},</if>
<if test="checkDetails.partNum != null">#{checkDetails.partNum},</if>
<if test="checkDetails.partPrice != null">#{checkDetails.partPrice},</if>
<if test="checkDetails.partAllCosts != null">#{checkDetails.partAllCosts},</if>
<if test="checkDetails.createBy != null">#{checkDetails.createBy},</if>
<if test="checkDetails.createTime != null">now(),</if>
</trim>
</foreach>
</insert>
</mapper>

View File

@ -376,4 +376,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and mt1.status = '0'
and mt1.del_flag = '0'
</select>
<select id="selectPartList" resultType="com.bonus.sgzb.material.domain.RepairPart">
select
mpt.pa_id as partId,
mpt2.pa_id as parentId,
mpt2.pa_name as partName,
mpt.pa_name as partModelName,
mpt.buy_price as partPrice
from ma_part_type mpt
left join ma_part_type mpt2 on mpt.parent_id = mpt2.pa_id and mpt2.del_flag = 0
where
mpt.level = 3 and mpt.del_flag = 0
</select>
<select id="selectPartDetail"
resultType="com.bonus.sgzb.material.domain.RepairPart">
select
mpt.pa_id as partId,
mpt2.pa_id as parentId,
mpt2.pa_name as partName,
mpt.pa_name as partModelName,
mpt.buy_price as partPrice
from ma_part_type mpt
left join ma_part_type mpt2 on mpt.parent_id = mpt2.pa_id and mpt2.del_flag = 0
where
mpt.level = 3 and mpt.del_flag = 0
and mpt2.pa_name = #{partName}
and mpt.pa_name = #{partModelName}
</select>
</mapper>