Browse Source

fix:调整数据库表结构

master
白凤吉 5 days ago
parent
commit
3d764f2caf
  1. 2
      src/main/java/com/iflytop/handacid/app/controller/DeviceController.java
  2. 2
      src/main/java/com/iflytop/handacid/app/controller/FormulationController.java
  3. 2
      src/main/java/com/iflytop/handacid/app/controller/ReceiveRecordController.java
  4. 7
      src/main/java/com/iflytop/handacid/app/service/DeviceInitService.java
  5. 1
      src/main/java/com/iflytop/handacid/common/mapper/FormulationMapper.java
  6. 30
      src/main/java/com/iflytop/handacid/common/mapper/FormulationMapper.xml
  7. 16
      src/main/java/com/iflytop/handacid/common/service/FormulationService.java
  8. 158
      src/main/resources/sql/init.sql

2
src/main/java/com/iflytop/handacid/app/controller/DeviceController.java

@ -5,6 +5,7 @@ import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.app.model.bo.SyncOperationsChannel; import com.iflytop.handacid.app.model.bo.SyncOperationsChannel;
import com.iflytop.handacid.app.model.dto.SyncOperationsDTO; import com.iflytop.handacid.app.model.dto.SyncOperationsDTO;
import com.iflytop.handacid.common.result.Result; import com.iflytop.handacid.common.result.Result;
import com.iflytop.handacid.common.service.SolutionService;
import io.swagger.v3.oas.annotations.Operation; 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;
@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
@Slf4j @Slf4j
public class DeviceController { public class DeviceController {
private final DeviceState deviceState; private final DeviceState deviceState;
private final SolutionService solutionService;
@Operation(summary = "获取当前设备状态") @Operation(summary = "获取当前设备状态")
@GetMapping("/device-status") @GetMapping("/device-status")

2
src/main/java/com/iflytop/handacid/app/controller/FormulationController.java

@ -33,7 +33,7 @@ public class FormulationController {
@PostMapping("/page") @PostMapping("/page")
@Operation(summary = "获取分页数据") @Operation(summary = "获取分页数据")
public PageResult<FormulationVO> getPage(BasePageQuery query) { public PageResult<FormulationVO> getPage(BasePageQuery query) {
return PageResult.success(formulationService.selectPageVo(query));
return PageResult.success(null);
} }
/* @GetMapping("/list") /* @GetMapping("/list")

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

@ -57,7 +57,7 @@ public class ReceiveRecordController {
} }
@PostMapping @PostMapping
@Operation(summary = "新增记录")
@Operation(summary = "领取溶液")
public Result<String> create(@RequestBody ReceiveRecord receiveRecord) { public Result<String> create(@RequestBody ReceiveRecord receiveRecord) {
boolean flag = receiveRecordService.save(receiveRecord); boolean flag = receiveRecordService.save(receiveRecord);
return flag? Result.success("添加成功") : Result.failed("添加失败"); return flag? Result.success("添加成功") : Result.failed("添加失败");

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

@ -5,7 +5,9 @@ import com.iflytop.handacid.app.common.enums.ChannelCode;
import com.iflytop.handacid.app.core.state.ChannelState; import com.iflytop.handacid.app.core.state.ChannelState;
import com.iflytop.handacid.app.core.state.DeviceState; import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.common.model.entity.Channel; import com.iflytop.handacid.common.model.entity.Channel;
import com.iflytop.handacid.common.model.entity.Solution;
import com.iflytop.handacid.common.service.ChannelService; import com.iflytop.handacid.common.service.ChannelService;
import com.iflytop.handacid.common.service.SolutionService;
import com.iflytop.handacid.hardware.service.AppEventBusService; import com.iflytop.handacid.hardware.service.AppEventBusService;
import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent; import com.iflytop.handacid.hardware.type.appevent.A8kCanBusOnConnectEvent;
import com.iflytop.handacid.hardware.type.appevent.AppEvent; import com.iflytop.handacid.hardware.type.appevent.AppEvent;
@ -24,6 +26,8 @@ public class DeviceInitService {
private final DeviceState deviceState; private final DeviceState deviceState;
private final ObjectProvider<ChannelState> channelStateObjectProvider; private final ObjectProvider<ChannelState> channelStateObjectProvider;
private final ChannelService channelService; private final ChannelService channelService;
private final SolutionService solutionService;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -54,7 +58,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, channel.getVolume(), solution.getId(), solution.getName(), solution.getConcentration());
deviceState.getChannelStateMap().put(code, channelState); deviceState.getChannelStateMap().put(code, channelState);
} }
log.info("初始化 initDeviceState完毕"); log.info("初始化 initDeviceState完毕");

1
src/main/java/com/iflytop/handacid/common/mapper/FormulationMapper.java

@ -12,5 +12,4 @@ import org.apache.ibatis.annotations.*;
*/ */
@Mapper @Mapper
public interface FormulationMapper extends BaseMapper<Formulation> { public interface FormulationMapper extends BaseMapper<Formulation> {
IPage<FormulationVO> selectPageVo(IPage<Formulation> page);
} }

30
src/main/java/com/iflytop/handacid/common/mapper/FormulationMapper.xml

@ -1,30 +0,0 @@
<?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.iflytop.handacid.common.mapper.FormulationMapper">
<!-- 结果映射定义 -->
<resultMap id="FormulationVoMap" type="com.iflytop.handacid.common.model.vo.FormulationVO">
<id column="id" property="id"/>
<result column="volume" property="volume"/>
<result column="revolutions" property="revolutions"/>
<result column="solution_id" property="solutionId"/>
<result column="solution_name" property="solutionName"/>
<result column="concentration" property="concentration"/>
<result column="scale" property="scale"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<!-- 其他字段映射... -->
</resultMap>
<!-- 分页查询 -->
<select id="selectPageVo" resultMap="FormulationVoMap">
SELECT f.*,
s.name AS solution_name,
s.concentration AS concentration,
s.scale AS scale
FROM formulation f
LEFT JOIN solution s ON f.solution_id = s.id
<!-- 自动分页由MyBatis-Plus插件处理 -->
</select>
</mapper>

16
src/main/java/com/iflytop/handacid/common/service/FormulationService.java

@ -1,30 +1,16 @@
package com.iflytop.handacid.common.service; package com.iflytop.handacid.common.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytop.handacid.common.base.BasePageQuery;
import com.iflytop.handacid.common.mapper.FormulationMapper; import com.iflytop.handacid.common.mapper.FormulationMapper;
import com.iflytop.handacid.common.model.entity.Formulation; import com.iflytop.handacid.common.model.entity.Formulation;
import com.iflytop.handacid.common.model.vo.FormulationVO;
import com.iflytop.handacid.common.result.PageResult;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* 配方接口服务 * 配方接口服务
*/ */
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class FormulationService extends ServiceImpl<FormulationMapper, Formulation> { public class FormulationService extends ServiceImpl<FormulationMapper, Formulation> {
private final FormulationMapper formulationMapper;
public IPage<FormulationVO> selectPageVo(BasePageQuery query) {
IPage<Formulation> page = new Page<>();
page.setSize(query.getPageSize());
page.setCurrent(query.getPageNum());
return formulationMapper.selectPageVo(page);
}
} }

158
src/main/resources/sql/init.sql

@ -1,99 +1,74 @@
-- ----------------------------
-- Table structure for audit_record
-- ----------------------------
-- 审计记录(使用记录)
CREATE TABLE IF NOT EXISTS audit_record( CREATE TABLE IF NOT EXISTS audit_record(
id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER,
user_name TEXT,
solution_id INTEGER,
solution_name TEXT,
concentration TEXT,
channel_id INTEGER,
volume TEXT,
create_time DATE DEFAULT CURRENT_TIMESTAMP,
update_time DATE DEFAULT CURRENT_TIMESTAMP
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,--ID
user_nickname TEXT,--
solution_id INTEGER,--id
solution_name TEXT,--
concentration TEXT,--
channel_code TEXT,--code
volume TEXT,--使
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 领取记录(加液记录)
CREATE TABLE IF NOT EXISTS receive_record (
id INTEGER PRIMARY KEY AUTOINCREMENT,
receiver_id INTEGER,--id
receiver_nickname TEXT,--
solution_id INTEGER,--id
concentration TEXT,--
volume REAL,--
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Table structure for channel
-- ----------------------------
-- 通道
CREATE TABLE IF NOT EXISTS channel ( CREATE TABLE IF NOT EXISTS channel (
id INTEGER NOT NULL PRIMARY KEY,
name TEXT,
solution_id INTEGER,
solution_name TEXT,
concentration TEXT,
code TEXT,
volume DOUBLE,
create_time DATE DEFAULT CURRENT_TIMESTAMP,
update_time DATE DEFAULT CURRENT_TIMESTAMP
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,--
code TEXT,--code
solution_id INTEGER,--id
concentration TEXT,--
volume REAL,--
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Records of channel
-- ----------------------------
INSERT OR IGNORE INTO channel ( INSERT OR IGNORE INTO channel (
id, name, solution_id, solution_name, concentration, code, volume
id, name, solution_id, code, volume
) VALUES ) VALUES
(1, '通道一', 1, '盐酸', '15%', 'CHANNEL_1', 5000),
(2, '通道二', 1, '盐酸', '15%', 'CHANNEL_2', 5000),
(3, '通道三', 1, '盐酸', '15%', 'CHANNEL_3', 5000),
(4, '通道四', 1, '盐酸', '15%', 'CHANNEL_4', 5000);
(1, '通道一', 1, 'CHANNEL_1', 5000),
(2, '通道二', 1, 'CHANNEL_2', 5000),
(3, '通道三', 1, 'CHANNEL_3', 5000),
(4, '通道四', 1, 'CHANNEL_4', 5000);
-- ----------------------------
-- Table structure for formulation
-- ----------------------------
-- drop table IF EXISTS formulation;
-- 配方
CREATE TABLE IF NOT EXISTS formulation ( CREATE TABLE IF NOT EXISTS formulation (
id INTEGER NOT NULL PRIMARY KEY,
volume DOUBLE,
solution_id INTEGER,
revolutions DOUBLE,
create_time DATE DEFAULT CURRENT_TIMESTAMP,
update_time DATE DEFAULT CURRENT_TIMESTAMP
);
-- ----------------------------
-- Table structure for receive_record
-- ----------------------------
CREATE TABLE IF NOT EXISTS receive_record (
id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER,
user_name TEXT,
receiver TEXT,
receiver_id INTEGER,
solution_id INTEGER,
solution_name TEXT,
concentration TEXT,
channel_id INTEGER,
volume DOUBLE,
create_time DATE DEFAULT CURRENT_TIMESTAMP,
update_time DATE DEFAULT CURRENT_TIMESTAMP
id INTEGER PRIMARY KEY AUTOINCREMENT,
volume REAL,--
solution_id INTEGER,--id
concentration REAL,--
revolutions REAL,--
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Table structure for solution
-- ----------------------------
-- drop table IF EXISTS solution;
-- 溶液
CREATE TABLE IF NOT EXISTS solution ( CREATE TABLE IF NOT EXISTS solution (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
concentration DOUBLE,
scale DOUBLE,
name TEXT,--
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Records of solution
-- ----------------------------
INSERT OR IGNORE INTO solution (id, name, concentration, scale) VALUES INSERT OR IGNORE INTO solution (id, name, concentration, scale) VALUES
(1, '盐酸', 15, 1.1), (1, '盐酸', 15, 1.1),
(2, '硫酸', 10, 1.2); (2, '硫酸', 10, 1.2);
-- ----------------------------
-- Table structure for system_config
-- ----------------------------
-- 系统配置
CREATE TABLE IF NOT EXISTS system_config ( CREATE TABLE IF NOT EXISTS system_config (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT, key TEXT,
@ -102,15 +77,8 @@ CREATE TABLE IF NOT EXISTS system_config (
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Records of system_config
-- ----------------------------
-- ----------------------------
-- Table structure for system_log
-- ----------------------------
-- 系统日志
CREATE TABLE IF NOT EXISTS system_log ( CREATE TABLE IF NOT EXISTS system_log (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT, title TEXT,
@ -119,35 +87,29 @@ CREATE TABLE IF NOT EXISTS system_log (
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Table structure for user
-- ----------------------------
-- 用户
CREATE TABLE IF NOT EXISTS user ( CREATE TABLE IF NOT EXISTS user (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE,
nickname TEXT,
password TEXT,
role TEXT,
fixed_user TEXT DEFAULT 'DISABLE',
deleted TEXT DEFAULT 'DISABLE',
username TEXT UNIQUE, --
nickname TEXT,--
password TEXT,--
role TEXT,--
fixed_user TEXT DEFAULT 'DISABLE',--
deleted TEXT DEFAULT 'DISABLE',--
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT OR IGNORE INTO user ( INSERT OR IGNORE INTO user (
id, username, nickname, password, role, fixed_user, deleted id, username, nickname, password, role, fixed_user, deleted
) VALUES ) VALUES
(1, 'admin', 'Admin', '9973', 'ADMIN', 'ENABLE', 'DISABLE'), (1, 'admin', 'Admin', '9973', 'ADMIN', 'ENABLE', 'DISABLE'),
(2, 'test', 'test', '9973', 'ADMIN', 'ENABLE', 'DISABLE'); (2, 'test', 'test', '9973', 'ADMIN', 'ENABLE', 'DISABLE');
-- ----------------------------
-- Table structure for zapp_sub_module_reg_initial_value
-- ----------------------------
CREATE TABLE IF NOT EXISTS zapp_sub_module_reg_initial_value ( CREATE TABLE IF NOT EXISTS zapp_sub_module_reg_initial_value (
id INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY AUTOINCREMENT,
mid TEXT, mid TEXT,
regIndex TEXT, regIndex TEXT,
regInitVal INTEGER regInitVal INTEGER

Loading…
Cancel
Save