Browse Source

fix:调整数据库表结构、实体结构

master
白凤吉 4 days ago
parent
commit
dde45a4e9b
  1. 100
      src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java
  2. 9
      src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java
  3. 18
      src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java
  4. 3
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
  5. 14
      src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java
  6. 4
      src/main/resources/sql/init.sql

100
src/main/java/com/iflytop/handacid/app/controller/AuditRecordController.java

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytop.handacid.app.common.utils.UsbDriverUtil; import com.iflytop.handacid.app.common.utils.UsbDriverUtil;
import com.iflytop.handacid.common.base.BasePageQuery; import com.iflytop.handacid.common.base.BasePageQuery;
import com.iflytop.handacid.common.model.entity.AuditRecord; import com.iflytop.handacid.common.model.entity.AuditRecord;
import com.iflytop.handacid.common.model.entity.Formulation;
import com.iflytop.handacid.common.result.PageResult; import com.iflytop.handacid.common.result.PageResult;
import com.iflytop.handacid.common.result.Result; import com.iflytop.handacid.common.result.Result;
import com.iflytop.handacid.common.service.AuditRecordService; import com.iflytop.handacid.common.service.AuditRecordService;
@ -12,7 +11,6 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
@ -22,11 +20,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* 审计 * 审计
*/ */
@ -60,7 +58,7 @@ public class AuditRecordController {
@PostMapping @PostMapping
@Operation(summary = "增加记录") @Operation(summary = "增加记录")
public Result<String> create(@RequestBody AuditRecord auditRecord) { public Result<String> create(@RequestBody AuditRecord auditRecord) {
boolean flag= auditRecordService.save(auditRecord);
boolean flag = auditRecordService.save(auditRecord);
return flag ? Result.success("添加成功") : Result.failed("添加失败"); return flag ? Result.success("添加成功") : Result.failed("添加失败");
} }
@ -68,7 +66,7 @@ public class AuditRecordController {
@Operation(summary = "修改记录") @Operation(summary = "修改记录")
public Result<String> update(@RequestBody AuditRecord auditRecord) { public Result<String> update(@RequestBody AuditRecord auditRecord) {
boolean flag = auditRecordService.updateById(auditRecord); boolean flag = auditRecordService.updateById(auditRecord);
return flag ? Result.success("修改成功"): Result.failed("修改失败");
return flag ? Result.success("修改成功") : Result.failed("修改失败");
} }
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
@ -77,57 +75,57 @@ public class AuditRecordController {
boolean success = auditRecordService.removeBatchByIds( boolean success = auditRecordService.removeBatchByIds(
Arrays.stream(ids.split(",")).map(Long::valueOf).toList() Arrays.stream(ids.split(",")).map(Long::valueOf).toList()
); );
return success ? Result.success("删除成功"): Result.failed("删除失败");
return success ? Result.success("删除成功") : Result.failed("删除失败");
} }
@GetMapping("/export") @GetMapping("/export")
@Operation(summary = "导出记录") @Operation(summary = "导出记录")
public Result<String> export() { public Result<String> export() {
String usbPath = UsbDriverUtil.findPath();
if(usbPath==null){
}
List<AuditRecord> list= auditRecordService.list();
if(list.isEmpty()){
return Result.failed("无审计记录");
}
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("审计记录");
Row headerRow = sheet.createRow(0);
String[] headers = {"ID", "用户名", "溶液名称", "浓度", "通道ID", "体积", "创建时间", "更新时间"};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
}
// 填充数据
for (int i = 0; i < list.size(); i++) {
AuditRecord record = list.get(i);
Row row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(record.getId());
row.createCell(1).setCellValue(record.getUserName());
row.createCell(2).setCellValue(record.getSolutionName());
row.createCell(3).setCellValue(record.getConcentration());
row.createCell(4).setCellValue(record.getChannelId() != null ? record.getChannelId() : 0);
row.createCell(5).setCellValue(record.getVolume());
row.createCell(6).setCellValue(record.getCreateTime() != null ? record.getCreateTime().toString() : "");
row.createCell(7).setCellValue(record.getUpdateTime() != null ? record.getUpdateTime().toString() : "");
}
// 自动调整列宽
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}
// 生成文件名
String fileName = "审计记录_" + System.currentTimeMillis() + ".xlsx";
// 尝试保存到U盘
String filePath = usbPath + File.separator + fileName;
try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
workbook.write(fileOut);
workbook.close();
return Result.success("导出成功,文件已保存到: " + filePath);
} catch (IOException e) {
log.error(e.getMessage());
return Result.failed("导出失败"+e.getMessage());
//throw new RuntimeException(e);
}
String usbPath = UsbDriverUtil.findPath();
if (usbPath == null) {
}
List<AuditRecord> list = auditRecordService.list();
if (list.isEmpty()) {
return Result.failed("无审计记录");
}
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("审计记录");
Row headerRow = sheet.createRow(0);
String[] headers = {"ID", "用户名", "溶液名称", "浓度", "通道ID", "体积", "创建时间", "更新时间"};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
}
// 填充数据
for (int i = 0; i < list.size(); i++) {
AuditRecord record = list.get(i);
Row row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(record.getId());
row.createCell(1).setCellValue(record.getUserNickname());
row.createCell(2).setCellValue(record.getSolutionName());
row.createCell(3).setCellValue(record.getConcentration());
row.createCell(4).setCellValue(record.getChannelCode());
row.createCell(5).setCellValue(record.getUsedVolume());
row.createCell(6).setCellValue(record.getCreateTime() != null ? record.getCreateTime().toString() : "");
row.createCell(7).setCellValue(record.getUpdateTime() != null ? record.getUpdateTime().toString() : "");
}
// 自动调整列宽
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
}
// 生成文件名
String fileName = "审计记录_" + System.currentTimeMillis() + ".xlsx";
// 尝试保存到U盘
String filePath = usbPath + File.separator + fileName;
try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
workbook.write(fileOut);
workbook.close();
return Result.success("导出成功,文件已保存到: " + filePath);
} catch (IOException e) {
log.error(e.getMessage());
return Result.failed("导出失败" + e.getMessage());
//throw new RuntimeException(e);
}
} }

9
src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java

@ -103,12 +103,12 @@ public class ReceiveRecordController {
ReceiveRecord record = list.get(i); ReceiveRecord record = list.get(i);
Row row = sheet.createRow(i + 1); Row row = sheet.createRow(i + 1);
row.createCell(0).setCellValue(record.getId()); row.createCell(0).setCellValue(record.getId());
row.createCell(1).setCellValue(record.getUserName());
row.createCell(2).setCellValue(record.getReceiver());
row.createCell(1).setCellValue(record.getIssuerNickname());
row.createCell(2).setCellValue(record.getReceiverNickname());
row.createCell(3).setCellValue(record.getSolutionName()); row.createCell(3).setCellValue(record.getSolutionName());
row.createCell(4).setCellValue(record.getConcentration()); row.createCell(4).setCellValue(record.getConcentration());
row.createCell(5).setCellValue(record.getChannelId());
row.createCell(6).setCellValue(record.getVolume());
row.createCell(5).setCellValue(record.getChannelCode());
row.createCell(6).setCellValue(record.getReceivedVolume());
row.createCell(7).setCellValue(record.getCreateTime() != null ? record.getCreateTime().toString() : ""); row.createCell(7).setCellValue(record.getCreateTime() != null ? record.getCreateTime().toString() : "");
row.createCell(8).setCellValue(record.getUpdateTime() != null ? record.getUpdateTime().toString() : ""); row.createCell(8).setCellValue(record.getUpdateTime() != null ? record.getUpdateTime().toString() : "");
} }
@ -129,7 +129,6 @@ public class ReceiveRecordController {
return Result.failed("导出失败" + e.getMessage()); return Result.failed("导出失败" + e.getMessage());
//throw new RuntimeException(e); //throw new RuntimeException(e);
} }
} }
} }

18
src/main/java/com/iflytop/handacid/app/core/state/ChannelState.java

@ -25,12 +25,6 @@ public class ChannelState {
@Schema(description = "是否已预充") @Schema(description = "是否已预充")
private volatile boolean pre = false; private volatile boolean pre = false;
@Schema(description = "剩余容量(单位:mL)")
private volatile Double remainingVolume;
@Schema(description = "加液量(单位:mL)")
private Double volume;
@Schema(description = "溶液id") @Schema(description = "溶液id")
private volatile Long solutionId; private volatile Long solutionId;
@ -46,11 +40,19 @@ public class ChannelState {
@Schema(description = "目标加液量(单位:mL)") @Schema(description = "目标加液量(单位:mL)")
private volatile Double targetVolume; private volatile Double targetVolume;
public ChannelState(ChannelCode channelCode, Double remainingVolume, Long solutionId, String solutionName, String concentration) {
@Schema(description = "当前溶液量(单位:mL)")
private volatile Double currentVolume;
@Schema(description = "领取溶液量(单位:mL)")
private volatile Double receivedVolume;
public ChannelState(ChannelCode channelCode, Long solutionId, String solutionName, String concentration, Double targetVolume, Double receivedVolume, Double currentVolume) {
this.channelCode = channelCode; this.channelCode = channelCode;
this.remainingVolume = remainingVolume;
this.solutionId = solutionId; this.solutionId = solutionId;
this.solutionName = solutionName; this.solutionName = solutionName;
this.concentration = concentration; this.concentration = concentration;
this.targetVolume = targetVolume;
this.receivedVolume = receivedVolume;
this.currentVolume = currentVolume;
} }
} }

3
src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java

@ -56,7 +56,8 @@ public class DeviceInitService {
for (ChannelCode code : ChannelCode.values()) { for (ChannelCode code : ChannelCode.values()) {
//初始化通道 //初始化通道
Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code)); Channel channel = channelService.getOne(new LambdaQueryWrapper<>(new Channel()).eq(Channel::getCode, code));
ChannelState channelState = channelStateObjectProvider.getObject(code, channel.getVolume(), channel.getSolutionId(), channel.getSolutionName(), channel.getConcentration());
Solution solution = solutionService.getById(channel.getSolutionId());
ChannelState channelState = channelStateObjectProvider.getObject(code, solution.getId(), solution.getName(), channel.getConcentration(), channel.getTargetVolume(), channel.getReceivedVolume(), channel.getCurrentVolume());
deviceState.getChannelStateMap().put(code, channelState); deviceState.getChannelStateMap().put(code, channelState);
} }
log.info("初始化 initDeviceState完毕"); log.info("初始化 initDeviceState完毕");

14
src/main/java/com/iflytop/handacid/common/model/entity/ReceiveRecord.java

@ -14,6 +14,14 @@ import lombok.EqualsAndHashCode;
@Schema(description = "领取记录") @Schema(description = "领取记录")
public class ReceiveRecord extends BaseEntity { public class ReceiveRecord extends BaseEntity {
@TableField("issuer_id")
@Schema(description = "发放人ID")
private Long issuerId;
@TableField("issuer_nickname")
@Schema(description = "发放人昵称")
private String issuerNickname;
@Schema(description = "领取人ID") @Schema(description = "领取人ID")
private Long receiverId; private Long receiverId;
@ -23,9 +31,15 @@ public class ReceiveRecord extends BaseEntity {
@Schema(description = "溶液ID") @Schema(description = "溶液ID")
private Long solutionId; private Long solutionId;
@Schema(description = "溶液名称")
private String solutionName;
@Schema(description = "溶液浓度") @Schema(description = "溶液浓度")
private Integer concentration; private Integer concentration;
@Schema(description = "领取溶液量") @Schema(description = "领取溶液量")
private Double receivedVolume; private Double receivedVolume;
@Schema(description = "通道Code")
private String channelCode;
} }

4
src/main/resources/sql/init.sql

@ -15,11 +15,15 @@ CREATE TABLE IF NOT EXISTS audit_record(
-- 领取记录(加液记录) -- 领取记录(加液记录)
CREATE TABLE IF NOT EXISTS receive_record ( CREATE TABLE IF NOT EXISTS receive_record (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
issuer_id INTEGER,--id
issuer_nickname INTEGER,--
receiver_id INTEGER,--id receiver_id INTEGER,--id
receiver_nickname TEXT,-- receiver_nickname TEXT,--
solution_id INTEGER,--id solution_id INTEGER,--id
solution_name TEXT,--
concentration INTEGER,-- concentration INTEGER,--
received_volume REAL,-- received_volume REAL,--
channel_code TEXT,--code
create_time TEXT DEFAULT CURRENT_TIMESTAMP, create_time TEXT DEFAULT CURRENT_TIMESTAMP,
update_time TEXT DEFAULT CURRENT_TIMESTAMP update_time TEXT DEFAULT CURRENT_TIMESTAMP
); );

Loading…
Cancel
Save