利用AI完成开学考试
1.数据库设计
(1) 根据文档内容,设计需要的四个表的建表语句。
基于您提供的文档内容,我将使用 Spring Boot 框架帮您分析仓储管理系统需求,并提供相应的表结构和 SQL 语句。由于文档中未明确说明数据库类型,我将假设使用 MySQL 数据库。
项目功能模块
根据文档,项目主要包含以下功能模块:
基础信息管理
仓库管理:新增、删除、修改仓库信息
物资类别管理:新增、删除、修改物资类别信息
库存管理
入库操作:记录物资入库信息,生成入库单
出库操作:记录物资出库信息,生成出库单
查询统计
按物资编码查询库存信息
按物资类别汇总库存信息
查询入库单信息
查询出库单信息
以下为建表语句:
CREATE TABLE warehouse (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
location VARCHAR(100)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
CREATE TABLE material_category (
id INT AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(20) UNIQUE NOT NULL,
name VARCHAR(50) NOT NULL,
specification VARCHAR(50),
material VARCHAR(50),
supplier VARCHAR(50),
brand VARCHAR(50)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
CREATE TABLE material_inventory (
id INT AUTO_INCREMENT PRIMARY KEY,
material_id INT NOT NULL,
warehouse_id INT NOT NULL,
operation_type VARCHAR(10) NOT NULL,
quantity INT NOT NULL,
unit VARCHAR(20),
location VARCHAR(50),
operation_date DATE NOT NULL,
remark VARCHAR(255),
FOREIGN KEY (material_id) REFERENCES material_category(id),
FOREIGN KEY (warehouse_id) REFERENCES warehouse(id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `user_role` (
`id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` VARCHAR(50) NOT NULL COMMENT '用户名',
`password` VARCHAR(255) NOT NULL COMMENT '密码',
`role` ENUM('ADMIN', 'WAREHOUSEMAN') NOT NULL COMMENT '角色',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户角色表';
-- 初始化管理员用户
INSERT INTO `user_role` (`username`, `password`, `role`) VALUES ('admin', 'admin123', 'ADMIN');
-- 初始化仓库管理人员用户
INSERT INTO `user_role` (`username`, `password`, `role`) VALUES ('warehouseman', 'warehouseman123', 'WAREHOUSEMAN');
2. 完成sprinboot下的实体类代码
AI根据建表语句完成springboot框架下的实体类的代码书写(根据以上数据库内容给出实体类代码)
用户类
package com.example.day0221.pojo;
import jakarta.persistence.*;
@Entity
@Table(name = "user_role")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, unique = true, length = 50)
private String username;
@Column(nullable = false, length = 255)
private String password;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Role role;
// Getters and Setters
public enum Role {
ADMIN, WAREHOUSEMAN
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
}
仓库类
package com.example.day0221.pojo;
import jakarta.persistence.*;
import lombok.Data;
@Data
@Entity
@Table(name = "warehouse")
public class Ware {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, length = 50)
private String name;
@Column(length = 100)
private String location;
}
物资类
package com.example.day0221.pojo;
import lombok.Data;
import jakarta.persistence.*;
@Data
@Entity
@Table(name = "material_category")
public class Material {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "code", nullable = false, unique = true, length = 20)
private String code;
@Column(name = "name", nullable = false, length = 50)
private String name;
@Column(name = "specification", length = 50)
private String specification;
@Column(name = "material", length = 50)
private String material;
@Column(name = "supplier", length = 50)
private String supplier;
@Column(name = "brand", length = 50)
private String brand;
}
物资台账类
package com.example.day0221.pojo;
import jakarta.persistence.*;
import lombok.Data;
import java.util.Date;
@Data
@Entity
@Table(name = "material_inventory")
public class MaterialInventory {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
@ManyToOne
@JoinColumn(name = "material_id", nullable = false)
private Material material;
@ManyToOne
@JoinColumn(name = "warehouse_id", nullable = false)
private Ware ware;
@Column(name = "operation_type", nullable = false, length = 10)
private String operationType;
@Column(name = "quantity", nullable = false)
private Integer quantity;
@Column(name = "unit", length = 20)
private String unit;
@Column(name = "location", length = 50)
private String location;
@Column(name = "operation_date", nullable = false)
@Temporal(TemporalType.DATE)
private Date operationDate;
@Column(name = "remark", length = 255)
private String remark;
}
3.controller层代码的书写
要求AI根据用户的实体类代码,使用springboot的框架写出完成登录功能的controller层代码。根据仓库和物资类别(需要满足不同的物资名称、规格、材质的物资不能设立相同的物资编码)实体类代码,完成增加、删除、修改数据功能的controller层代码。根据物资台账的实体类代码完成增加、修改、根据物资编码查询全部数据的基础功能。
用户
package com.example.day0221.controller;
import com.example.day0221.pojo.User;
import com.example.day0221.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api")
public class UserController {
@Autowired
private UserService userService;
@PostMapping("/login")
public ResponseEntity<String> login(@RequestBody User user) {
User foundUser = userService.findByUsername(user.getUsername());
if (foundUser == null || !foundUser.getPassword().equals(user.getPassword())) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("用户名或密码错误");
}
return ResponseEntity.ok(foundUser.getRole().name());
}
}
仓库
package com.example.day0221.controller;
import com.example.day0221.pojo.Ware;
import com.example.day0221.service.WareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
//@RequestMapping("/api")
@CrossOrigin(origins = {"http://127.0.0.1:5500", "http://127.0.0.1:5500"}, allowCredentials = "true")
public class WareController {
@Autowired
private WareService wareService;
@PostMapping("/wares")
public ResponseEntity<Ware> addWare(@RequestBody Ware ware) {
Ware savedWare = wareService.saveWare(ware);
if (savedWare != null) {
return new ResponseEntity<>(savedWare, HttpStatus.CREATED);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
// 删除仓库
@DeleteMapping("/wares/{id}")
public ResponseEntity<Void> deleteWare(@PathVariable Integer id) {
try {
wareService.deleteWareById(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// 修改仓库
@PutMapping("/wares/{id}")
public ResponseEntity<Ware> updateWare(@PathVariable Integer id, @RequestBody Ware ware) {
ware.setId(id);
Ware updatedWare = wareService.updateWare(ware);
if (updatedWare != null) {
return new ResponseEntity<>(updatedWare, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
物资类别
package com.example.day0221.controller;
import com.example.day0221.pojo.Material;
import com.example.day0221.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/materials")
public class MaterialController {
@Autowired
private MaterialService materialService;
// 新增物料分类
@PostMapping("/add")
public ResponseEntity<Material> createMaterial(@RequestBody Material material) {
Material savedMaterial = materialService.saveMaterial(material);
return new ResponseEntity<>(savedMaterial, HttpStatus.CREATED);
}
// 删除物料分类
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteMaterial(@PathVariable("id") int id) {
boolean isDeleted = materialService.deleteMaterialById(id);
if (isDeleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
// 修改物料分类
@PutMapping("/update/{id}")
public ResponseEntity<Material> updateMaterial(@PathVariable("id") int id, @RequestBody Material material) {
// 设置要修改的物料分类的ID
material.setId(id);
// 调用服务层的方法进行修改
Material updatedMaterial = materialService.updateMaterial(material);
if (updatedMaterial != null) {
return new ResponseEntity<>(updatedMaterial, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
物资台账
package com.example.day0221.controller;
import com.example.day0221.pojo.MaterialInventory;
import com.example.day0221.service.MaterialInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/material-inventory")
public class MaterialInventoryController {
@Autowired
private MaterialInventoryService materialInventoryService;
// 新增物资台账记录
@PostMapping("/add")
public ResponseEntity<MaterialInventory> createMaterialInventory(@RequestBody MaterialInventory materialInventory) {
MaterialInventory savedMaterialInventory = materialInventoryService.saveMaterialInventory(materialInventory);
return new ResponseEntity<>(savedMaterialInventory, HttpStatus.CREATED);
}
// 删除物资台账记录
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteMaterialInventory(@PathVariable("id") int id) {
boolean isDeleted = materialInventoryService.deleteMaterialInventoryById(id);
if (isDeleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
// 修改物资台账记录
@PutMapping("/update/{id}")
public ResponseEntity<MaterialInventory> updateMaterialInventory(@PathVariable("id") int id, @RequestBody MaterialInventory materialInventory) {
materialInventory.setId(id);
MaterialInventory updatedMaterialInventory = materialInventoryService.updateMaterialInventory(materialInventory);
if (updatedMaterialInventory != null) {
return new ResponseEntity<>(updatedMaterialInventory, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
// 根据ID查询物资台账记录
@GetMapping("/{id}")
public ResponseEntity<MaterialInventory> getMaterialInventoryById(@PathVariable("id") int id) {
MaterialInventory materialInventory = materialInventoryService.getMaterialInventoryById(id);
if (materialInventory != null) {
return new ResponseEntity<>(materialInventory, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
// 查询所有物资台账记录
@GetMapping("/all")
public ResponseEntity<List<MaterialInventory>> getAllMaterialInventories() {
List<MaterialInventory> materialInventories = materialInventoryService.getAllMaterialInventories();
return new ResponseEntity<>(materialInventories, HttpStatus.OK);
}
}
4. service层代码和mapper层代码的书写
根据AI给出的controller层代码补充service层代码,根据service层代码补充mapper层代码,最终实现以上功能。
service层代码
UserService
package com.example.day0221.service;
import com.example.day0221.mapper.UserMapper;
import com.example.day0221.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserMapper userMapper;
public User login(String username, String password) {
User user = userMapper.findByUsername(username);
if (user != null && user.getPassword().equals(password)) {
return user;
}
return null;
}
public User findByUsername(String username) {
return userMapper.findByUsername(username);
}
}
WareService
package com.example.day0221.service;
import com.example.day0221.mapper.WareMapper;
import com.example.day0221.pojo.Ware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class WareService {
@Autowired
private WareMapper wareMapper;
public Ware saveWare(Ware ware) {
int result = wareMapper.save(ware);
if (result > 0) {
return ware;
}
return null;
}
public void deleteWareById(Integer id) {
wareMapper.deleteById(id);
}
public Ware updateWare(Ware ware) {
int result = wareMapper.update(ware);
if (result > 0) {
return ware;
}
return null;
}
}
MaterialService
package com.example.day0221.service;
import com.example.day0221.mapper.MaterialMapper;
import com.example.day0221.pojo.Material;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MaterialService {
@Autowired
private MaterialMapper materialMapper;
/**
* 保存物料分类信息
*
* @param material 物料分类对象
* @return 保存后的物料分类对象,如果插入失败则返回null
*/
public Material saveMaterial(Material material) {
// 调用Mapper层的insertMaterialCategory方法插入物料分类信息
int result = materialMapper.insertMaterialCategory(material);
// 如果插入成功,返回物料分类对象,否则返回null
return result > 0 ? material : null;
}
public boolean deleteMaterialById(int id) {
// 调用Mapper层的deleteMaterialCategoryById方法删除物料分类信息
int result = materialMapper.deleteMaterialCategoryById(id);
// 如果删除的行数大于0,表示删除成功
return result > 0;
}
public Material updateMaterial(Material material) {
// 调用Mapper层的updateMaterialCategory方法更新物料分类信息
int result = materialMapper.updateMaterialCategory(material);
// 如果更新成功,返回物料分类对象,否则返回null
return result > 0 ? material : null;
}
}
MaterialInventoryService
package com.example.day0221.service;
import com.example.day0221.mapper.InventoryMapper;
import com.example.day0221.pojo.MaterialInventory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MaterialInventoryService {
@Autowired
private InventoryMapper inventoryMapper;
/**
* 保存物资台账记录
*
* @param materialInventory 物资台账对象
* @return 保存后的物资台账对象,如果插入失败则返回null
*/
public MaterialInventory saveMaterialInventory(MaterialInventory materialInventory) {
int result = inventoryMapper.insertMaterialInventory(materialInventory);
return result > 0 ? materialInventory : null;
}
/**
* 根据ID删除物资台账记录
*
* @param id 物资台账ID
* @return 删除成功返回true,否则返回false
*/
public boolean deleteMaterialInventoryById(int id) {
int result = inventoryMapper.deleteMaterialInventoryById(id);
return result > 0;
}
/**
* 更新物资台账记录
*
* @param materialInventory 物资台账对象
* @return 更新后的物资台账对象,如果更新失败则返回null
*/
public MaterialInventory updateMaterialInventory(MaterialInventory materialInventory) {
int result = inventoryMapper.updateMaterialInventory(materialInventory);
return result > 0 ? materialInventory : null;
}
/**
* 根据ID查询物资台账记录
*
* @param id 物资台账ID
* @return 查询到的物资台账对象,如果未找到则返回null
*/
public MaterialInventory getMaterialInventoryById(int id) {
return inventoryMapper.getMaterialInventoryById(id);
}
/**
* 查询所有物资台账记录
*
* @return 所有物资台账对象的列表
*/
public List<MaterialInventory> getAllMaterialInventories() {
return inventoryMapper.getAllMaterialInventories();
}
}
mapper层
UserMapper
package com.example.day0221.mapper;
import com.example.day0221.pojo.Material;
import org.apache.ibatis.annotations.*;
@Mapper
public interface MaterialMapper {
@Insert("INSERT INTO material_category (code, name, specification, material, supplier, brand) " +
"VALUES (#{code}, #{name}, #{specification}, #{material}, #{supplier}, #{brand})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int insertMaterialCategory(Material material);
@Delete("DELETE FROM material_category WHERE id = #{id}")
int deleteMaterialCategoryById(int id);
@Update("UPDATE material_category SET code = #{code}, name = #{name}, specification = #{specification}, " +
"material = #{material}, supplier = #{supplier}, brand = #{brand} WHERE id = #{id}")
int updateMaterialCategory(Material material);
}
WareMapper
package com.example.day0221.mapper;
import com.example.day0221.pojo.Ware;
import org.apache.ibatis.annotations.*;
@Mapper
public interface WareMapper {
// 新增仓库
@Insert("INSERT INTO warehouse (name, location) VALUES (#{name}, #{location})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int save(Ware ware);
// 删除仓库
@Delete("DELETE FROM warehouse WHERE id = #{id}")
void deleteById(Integer id);
// 修改仓库
@Update("UPDATE warehouse SET name = #{name}, location = #{location} WHERE id = #{id}")
int update(Ware ware);
}
MaterialMapper
package com.example.day0221.mapper;
import com.example.day0221.pojo.Material;
import org.apache.ibatis.annotations.*;
@Mapper
public interface MaterialMapper {
@Insert("INSERT INTO material_category (code, name, specification, material, supplier, brand) " +
"VALUES (#{code}, #{name}, #{specification}, #{material}, #{supplier}, #{brand})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int insertMaterialCategory(Material material);
@Delete("DELETE FROM material_category WHERE id = #{id}")
int deleteMaterialCategoryById(int id);
@Update("UPDATE material_category SET code = #{code}, name = #{name}, specification = #{specification}, " +
"material = #{material}, supplier = #{supplier}, brand = #{brand} WHERE id = #{id}")
int updateMaterialCategory(Material material);
}
InventoryMapper
package com.example.day0221.mapper;
import com.example.day0221.pojo.Material;
import org.apache.ibatis.annotations.*;
@Mapper
public interface MaterialMapper {
@Insert("INSERT INTO material_category (code, name, specification, material, supplier, brand) " +
"VALUES (#{code}, #{name}, #{specification}, #{material}, #{supplier}, #{brand})")
@Options(useGeneratedKeys = true, keyProperty = "id")
int insertMaterialCategory(Material material);
@Delete("DELETE FROM material_category WHERE id = #{id}")
int deleteMaterialCategoryById(int id);
@Update("UPDATE material_category SET code = #{code}, name = #{name}, specification = #{specification}, " +
"material = #{material}, supplier = #{supplier}, brand = #{brand} WHERE id = #{id}")
int updateMaterialCategory(Material material);
}
5.细节处理:
在新增物资类别的代码块部分添加细节,完成验证物资分类编码唯一,不同的物资名称、规格、材质的物资不能设立相同的物资编码两个条件,满足才可添加的功能。
添加根据物资类别查询的功能,根据获取到的数量进行比较,如果输入出库数量大于库存余额,提示用户无法进行出库,要求修改出库数量,单独生成一条台账明细记录。
增加根据物资编码查看该类物资的详细入库单信息和出库单信息的功能。
6.页面设计(html)
要求AI根据文档要求:设计登录页面,和管理员以及仓库管理员登录的页面
登录页面,要求页面风格整洁,布局清晰。
管理员页面要求展现以下功能:
管理员功能页:管理员可以实现仓库的新增、删除、修改基本信息管理,可以实现对物资类别的新增、删除、修改基本信息管理;
仓库管理员页面要求展现以下功能:
仓库管理人员:入库操作,出库操作,统计查询功能。
细节要求:
每类物资进行入库操作时,需要单独生成一条台账明细记录,保证相同的物资存放到同一仓库中,新物资入库时,则需要仓库人员选择存放仓库。库操作时,选择物资类别,自动显示该类物资的数量余额,如果输入出库数量大于库存余额,提示用户无法进行出库,要求修改出库数量,单独生成一条台账明细记录。
7.补充前端的javascript代码
要求AI根据后端的每一段controller层代码补充前端的javascript代码,在前端完成一系列的功能实现,完成前后端连接。
前端代码
主页
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f0f2f5;
}
.login-container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
text-align: center;
}
.login-container h1 {
margin-bottom: 20px;
font-size: 24px;
color: #333;
}
.login-container input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
.login-container button {
width: 100%;
padding: 10px;
background-color: #007bff;
border: none;
border-radius: 4px;
color: #fff;
font-size: 16px;
cursor: pointer;
}
.login-container button:hover {
background-color: #0056b3;
}
.message {
margin-top: 20px;
color: #d9534f;
}
</style>
</head>
<body>
<div class="login-container">
<h1>Login</h1>
<form id="loginForm">
<input type="text" id="username" name="username" placeholder="Username" required>
<input type="password" id="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
<p id="message" class="message"></p>
</div>
<script>
document.getElementById('loginForm').addEventListener('submit', function(event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
fetch('http://localhost:8080/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username: username, password: password })
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
document.getElementById('message').innerText = data;
localStorage.setItem('username', username);
localStorage.setItem('role', data);
alert('登录成功!欢迎 ' + data);
window.location.href = "./admin.html";
})
.catch(error => {
console.error('Error:', error);
document.getElementById('message').innerText = '登录失败,请重试。';
});
});
// 检查登录状态
window.onload = function() {
const username = localStorage.getItem('username');
const role = localStorage.getItem('role');
if (username && role) {
document.getElementById('message').innerText = `已登录为 ${role}`;
}
};
</script>
</body>
</html>
管理员页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f2f5;
margin: 0;
display: flex;
}
.sidebar {
width: 200px;
background-color: #007bff;
color: #fff;
height: 100vh;
padding: 20px;
box-sizing: border-box;
}
.sidebar a {
color: #fff;
text-decoration: none;
display: block;
margin: 10px 0;
}
.sidebar a:hover {
background-color: #0056b3;
padding-left: 10px;
}
.content {
flex: 1;
padding: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input,.form-group select {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
.form-group button {
padding: 10px 15px;
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
}
.form-group button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="sidebar">
<h2>Admin Menu</h2>
<a href="#" onclick="showSection('warehouseManagement')">仓库管理</a>
<a href="#" onclick="showSection('materialCategoryManagement')">物资类别管理</a>
<a href="#" onclick="showSection('userManagement')">用户管理</a>
</div>
<div class="content">
<div id="warehouseManagement" class="section" style="display: none;">
<h2>仓库管理</h2>
<div class="form-group">
<label for="warehouseName">仓库名称</label>
<input type="text" id="warehouseName" name="warehouseName">
</div>
<div class="form-group">
<label for="warehouseLocation">仓库位置</label>
<input type="text" id="warehouseLocation" name="warehouseLocation">
</div>
<div class="form-group">
<button onclick="addWarehouse()">新增仓库</button>
<button onclick="updateWarehouse()">修改仓库</button>
<button onclick="deleteWarehouse()">删除仓库</button>
</div>
</div>
<div id="materialCategoryManagement" class="section" style="display: none;">
<h2>物资类别管理</h2>
<div class="form-group">
<label for="materialCode">物资编码</label>
<input type="text" id="materialCode" name="materialCode">
</div>
<div class="form-group">
<label for="materialName">物资名称</label>
<input type="text" id="materialName" name="materialName">
</div>
<div class="form-group">
<label for="materialSpecification">规格</label>
<input type="text" id="materialSpecification" name="materialSpecification">
</div>
<div class="form-group">
<label for="material">材质</label>
<input type="text" id="material" name="material">
</div>
<div class="form-group">
<label for="supplier">供应商</label>
<input type="text" id="supplier" name="supplier">
</div>
<div class="form-group">
<label for="brand">品牌</label>
<input type="text" id="brand" name="brand">
</div>
<div class="form-group">
<button onclick="addMaterial()">新增物资</button>
<button onclick="updateMaterial()">修改物资</button>
<button onclick="deleteMaterial()">删除物资</button>
</div>
</div>
<div id="userManagement" class="section" style="display: none;">
<h2>用户管理</h2>
<!-- 用户管理内容 -->
</div>
</div>
<script>
function showSection(sectionId) {
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
section.style.display = 'none';
});
document.getElementById(sectionId).style.display = 'block';
}
function addWarehouse() {
const warehouseName = document.getElementById('warehouseName').value;
const warehouseLocation = document.getElementById('warehouseLocation').value;
fetch('/wares', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: warehouseName, location: warehouseLocation })
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(data => {
alert('新增仓库成功');
})
.catch(error => {
alert('新增仓库失败');
});
}
function updateWarehouse() {
const warehouseId = prompt('请输入要修改的仓库ID');
const warehouseName = document.getElementById('warehouseName').value;
const warehouseLocation = document.getElementById('warehouseLocation').value;
fetch(`/wares/${warehouseId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: warehouseName, location: warehouseLocation })
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(data => {
alert('修改仓库成功');
})
.catch(error => {
alert('修改仓库失败');
});
}
function deleteWarehouse() {
const warehouseId = prompt('请输入要删除的仓库ID');
fetch(`/wares/${warehouseId}`, {
method: 'DELETE'
})
.then(response => {
if (response.status === 204) {
alert('删除仓库成功');
} else {
alert('删除仓库失败');
}
})
.catch(error => {
alert('删除仓库失败');
});
}
function addMaterial() {
const materialCode = document.getElementById('materialCode').value;
const materialName = document.getElementById('materialName').value;
const materialSpecification = document.getElementById('materialSpecification').value;
const material = document.getElementById('material').value;
const supplier = document.getElementById('supplier').value;
const brand = document.getElementById('brand').value;
fetch('/api/materials', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
code: materialCode,
name: materialName,
specification: materialSpecification,
material: material,
supplier: supplier,
brand: brand
})
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(data => {
alert('新增物资成功');
})
.catch(error => {
alert('新增物资失败');
});
}
function updateMaterial() {
const materialId = prompt('请输入要修改的物资ID');
const materialCode = document.getElementById('materialCode').value;
const materialName = document.getElementById('materialName').value;
const materialSpecification = document.getElementById('materialSpecification').value;
const material = document.getElementById('material').value;
const supplier = document.getElementById('supplier').value;
const brand = document.getElementById('brand').value;
fetch(`/api/materials/${materialId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: materialId,
code: materialCode,
name: materialName,
specification: materialSpecification,
material: material,
supplier: supplier,
brand: brand
})
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
})
.then(data => {
alert('修改物资成功');
})
.catch(error => {
alert('修改物资失败');
});
}
function deleteMaterial() {
const materialId = prompt('请输入要删除的物资ID');
fetch(`/api/materials/${materialId}`, {
method: 'DELETE'
})
.then(response => {
if (response.status === 204) {
alert('删除物资成功');
} else {
alert('删除物资失败');
}
})
.catch(error => {
alert('删除物资失败');
});
}
</script>
</body>
</html>
仓库管理员页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Warehouseman Dashboard</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f2f5;
margin: 0;
display: flex;
}
.sidebar {
width: 200px;
background-color: #007bff;
color: #fff;
height: 100vh;
padding: 20px;
box-sizing: border-box;
}
.sidebar a {
color: #fff;
text-decoration: none;
display: block;
margin: 10px 0;
}
.sidebar a:hover {
background-color: #0056b3;
padding-left: 10px;
}
.content {
flex: 1;
padding: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
}
.form-group input, .form-group select {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
.form-group button {
padding: 10px 15px;
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
}
.form-group button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<div class="sidebar">
<h2>Warehouseman Menu</h2>
<a href="#" onclick="showSection('stockIn')">入库</a>
<a href="#" onclick="showSection('stockOut')">出库</a>
<a href="#" onclick="showSection('inventoryQuery')">库存查询</a>
</div>
<div class="content">
<div id="stockIn" class="section" style="display: none;">
<h2>入库</h2>
<div class="form-group">
<label for="stockInMaterialCode">物资编码</label>
<input type="text" id="stockInMaterialCode" name="stockInMaterialCode">
</div>
<div class="form-group">
<label for="stockInQuantity">数量</label>
<input type="number" id="stockInQuantity" name="stockInQuantity">
</div>
<div class="form-group">
<button onclick="stockIn()">入库</button>
</div>
</div>
<div id="stockOut" class="section" style="display: none;">
<h2>出库</h2>
<div class="form-group">
<label for="stockOutMaterialCode">物资编码</label>
<input type="text" id="stockOutMaterialCode" name="stockOutMaterialCode">
</div>
<div class="form-group">
<label for="stockOutQuantity">数量</label>
<input type="number" id="stockOutQuantity" name="stockOutQuantity">
</div>
<div class="form-group">
<button onclick="stockOut()">出库</button>
</div>
</div>
<div id="inventoryQuery" class="section" style="display: none;">
<h2>库存查询</h2>
<div class="form-group">
<label for="queryMaterialCode">物资编码</label>
<input type="text" id="queryMaterialCode" name="queryMaterialCode">
</div>
<div class="form-group">
<button onclick="queryInventory()">查询</button>
</div>
<div id="queryResult" class="form-group" style="display: none;">
<h3>查询结果</h3>
<p id="inventoryResult"></p>
</div>
</div>
</div>
<script>
function showSection(sectionId) {
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
section.style.display = 'none';
});
document.getElementById(sectionId).style.display = 'block';
}
function stockIn() {
const materialCode = document.getElementById('stockInMaterialCode').value;
const quantity = document.getElementById('stockInQuantity').value;
fetch('/api/stock/in', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ materialCode: materialCode, quantity: quantity })
})
.then(response => response.json())
.then(data => {
alert('入库成功');
})
.catch(error => {
alert('入库失败');
});
}
function stockOut() {
const materialCode = document.getElementById('stockOutMaterialCode').value;
const quantity = document.getElementById('stockOutQuantity').value;
fetch('/api/stock/out', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ materialCode: materialCode, quantity: quantity })
})
.then(response => response.json())
.then(data => {
alert('出库成功');
})
.catch(error => {
alert('出库失败');
});
}
function queryInventory() {
const materialCode = document.getElementById('queryMaterialCode').value;
fetch(`/api/inventory/${materialCode}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
document.getElementById('queryResult').style.display = 'block';
document.getElementById('inventoryResult').innerText = `物资编码: ${data.materialCode}, 数量: ${data.quantity}`;
})
.catch(error => {
alert('查询失败');
});
}
</script>
</body>
</html>
总结
在本次仓储管理系统的开发过程中,我借助 AI 工具完成了从数据库设计、实体类编写、前后端代码实现到页面设计的全流程开发任务。通过这次实践,我深刻体会到 AI 在软件开发中的强大辅助能力,同时也对 AI 工具的使用有了更深入的理解。以下是我的心得体会:
- AI 在数据库设计中的高效性
在数据库设计阶段,我根据需求文档向 AI 提供了功能模块的描述,AI 快速生成了四个核心表的建表语句(warehouse、material_category、material_inventory、user_role)。AI 不仅能够准确理解需求,还能根据常见的数据库设计规范生成符合 MySQL 标准的 SQL 语句,极大地提高了设计效率。此外,AI 还帮助我完成了表之间的外键关联设计,确保了数据的一致性和完整性。
心得:AI 在数据库设计中的表现非常出色,能够快速生成高质量的 SQL 语句,但开发者仍需对生成的代码进行审查,确保其符合实际业务需求。
- 实体类代码的自动生成
在 Spring Boot 框架下,AI 根据数据库表结构自动生成了对应的实体类代码(如 User、Ware、Material、MaterialInventory)。AI 不仅能够正确使用 JPA 注解(如 @Entity、@Table、@Id、@Column 等),还能处理复杂的关联关系(如 @ManyToOne 和 @JoinColumn)。这让我从繁琐的代码编写中解放出来,专注于业务逻辑的实现。
心得:AI 在实体类代码生成方面表现优异,但开发者需要确保生成的代码与实际业务逻辑一致,尤其是关联关系的处理。
- Controller 层代码的快速实现
AI 根据实体类代码快速生成了 Controller 层的代码,包括用户登录、仓库管理、物资类别管理和物资台账管理的接口。AI 生成的代码结构清晰,符合 RESTful 风格,并且能够正确处理 HTTP 请求和响应。例如,在用户登录功能中,AI 生成了基于 ResponseEntity 的返回值处理逻辑,确保了接口的规范性。
心得:AI 能够快速生成高质量的 Controller 层代码,但开发者需要根据实际需求对生成的代码进行调整,例如添加权限验证、异常处理等。
- Service 层和 Mapper 层的无缝衔接
在 Service 层和 Mapper 层的代码生成中,AI 展现了强大的逻辑推理能力。它能够根据 Controller 层的需求,自动生成对应的 Service 方法和 Mapper 接口,并确保两者之间的无缝衔接。例如,在物资类别管理中,AI 生成了 saveMaterial、deleteMaterialById、updateMaterial 等方法,并提供了详细的注释说明。
心得:AI 在 Service 层和 Mapper 层的代码生成中表现出色,但开发者需要确保生成的 SQL 语句和业务逻辑符合实际需求,尤其是复杂查询和事务处理。
- 前端页面的快速搭建
AI 不仅能够完成后端代码的生成,还能根据需求快速搭建前端页面。例如,在登录页面和管理员页面的设计中,AI 生成了简洁美观的 HTML 和 CSS 代码,并通过 JavaScript 实现了与后端接口的交互。AI 还提供了详细的页面布局和样式建议,极大地提升了前端开发效率。
心得:AI 在前端页面设计方面表现优异,但开发者需要根据实际需求对页面进行优化,例如响应式设计、用户体验优化等。
- 细节处理的智能化
在开发过程中,AI 帮助我完成了许多细节处理任务。例如,在物资类别管理中,AI 生成了验证物资编码唯一性的逻辑;在物资台账管理中,AI 提供了库存余额检查和出库数量验证的功能。这些细节处理不仅提高了系统的健壮性,还减少了潜在的错误。
心得:AI 在细节处理方面表现出色,但开发者需要结合实际业务场景对生成的逻辑进行测试和优化。
- AI 工具的局限性
尽管 AI 在开发过程中展现了强大的能力,但它仍有一些局限性。例如,AI 生成的代码有时需要根据实际需求进行调整,尤其是在复杂的业务逻辑和异常处理方面。此外,AI 无法完全替代开发者的思考和设计能力,开发者仍需对生成的代码进行审查和优化。
心得:AI 是开发者的得力助手,但不能完全依赖 AI。开发者需要结合自身经验,对 AI 生成的代码进行审查和优化,以确保系统的质量和性能。
- 总结与展望
通过本次开发实践,我深刻体会到 AI 在软件开发中的巨大潜力。AI 不仅能够提高开发效率,还能帮助开发者解决复杂的技术问题。未来,我将继续探索 AI 在软件开发中的应用,尤其是在自动化测试、性能优化和智能运维等方面。同时,我也会不断提升自身的技术能力,以更好地利用 AI 工具,开发出更高质量的软件系统。

浙公网安备 33010602011771号