3.5日报 kimi训练敲代码(deepseek太emm了)

所花时间:120分钟
以下是我输入的语句:
接下来,你是一位非常厉害的java工程师,请按照以下要求帮我写一个系统。

先写sql语句要求如下:
(1)仓库表(支持多个仓库,每个仓库具有唯一编码
(2)物资台账明细表(除了需求描述的要求外,需要有台账编号(唯一标识,四位年两位月两位日+顺序号(四位)例如:202402210022),操作类别(入库或者出库)数量,计量单位,存放地点(仓库号)等基本信息)
(3)物资类别表:需要满足不同的物资名称、规格、材质的物资不能设立相同的物资编码;

对应sql语句写出java定义的语句 。

以下是要实现的功能:
仓库类:
(1)新增仓库:增加新的仓库信息;
(2)删除仓库:删除仓库基本信息时,必须验证没有相关物资存储在该仓库中,提示用户不允许删除。
(3)修改仓库:仓库编号唯一不允许修改,并且验证没有相关物资存储在该仓库中,否则不允许修改仓库信息。

物资管理类
(1)新增物资类别:需要验证物资分类编码唯一,不同的物资名称、规格、材质的物资不能设立相同的物资编码两个条件,满足才可添加;
(2)删除物资类别信息:删除物资类别基本信息时,验证物资台账明细表中是否存在该类物资,如果存在提示用户不允许删除。
(3)修改物资类别基本信息:物资类别编号唯一不允许修改,并且验证物资台账明细表中是否存在该类物资,如果存在不允许修改该物资类别信息。

然后是出入库以及统计操作:
(7)入库操作:每类物资进行入库操作时,需要单独生成一条台账明细记录,保证相同的物资存放到同一仓库中,新物资入库时,则需要仓库人员选择存放仓库。
(8)出库操作:仓库人员进行出库操作时,选择物资类别,自动显示该类物资的数量余额,如果输入出库数量大于库存余额,提示用户无法进行出库,要求修改出库数量,单独生成一条台账明细记录。
(9)统计查询:仓库人员可输入物资编码查询该类物资的库存信息,显示物资类别编码、库存余额、计量单位,存放仓库等基本信息,点击该类物资编码,可以查看该类物资的详细入库单信息和出库单信息。

完成增删改查基本功能后,根据以下页面要求给出前端代码
(1)WEB管理系统界面要求采用统一风格的模板。
(2)管理员、仓库管理人员统一登录界面登录后,显示各自不同的菜单项。
(2)管理员功能页:管理员可以实现仓库的新增、删除、修改基本信息管理,可以实现对物资类别的新增、删除、修改基本信息管理;
(3)仓库管理人员:入库操作,出库操作,统计查询功能。

以下是生成的代码
CREATE TABLE Warehouse (
warehouse_code VARCHAR(20) NOT NULL COMMENT '唯一编码',
warehouse_name VARCHAR(100) NOT NULL COMMENT '仓库名称',
address VARCHAR(255) COMMENT '仓库地址',
capacity INT COMMENT '仓库容量',
PRIMARY KEY (warehouse_code)
) COMMENT='仓库表';
CREATE TABLE MaterialLedger (
ledger_id VARCHAR(15) NOT NULL COMMENT '台账编号(格式:YYYYMMDDNNNN)',
operation_type ENUM('入库', '出库') NOT NULL COMMENT '操作类别',
quantity DECIMAL(10, 2) NOT NULL COMMENT '数量',
unit VARCHAR(20) NOT NULL COMMENT '计量单位',
warehouse_code VARCHAR(20) NOT NULL COMMENT '存放地点(仓库号)',
material_code VARCHAR(20) NOT NULL COMMENT '物资编码',
description TEXT COMMENT '需求描述',
operation_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '操作时间',
PRIMARY KEY (ledger_id),
CONSTRAINT FK_Warehouse FOREIGN KEY (warehouse_code) REFERENCES Warehouse(warehouse_code),
CONSTRAINT FK_Material FOREIGN KEY (material_code) REFERENCES MaterialCategory(material_code)
) COMMENT='物资台账明细表';
CREATE TABLE MaterialCategory (
material_code VARCHAR(20) NOT NULL COMMENT '物资编码(唯一)',
material_name VARCHAR(100) NOT NULL COMMENT '物资名称',
specification VARCHAR(50) COMMENT '规格',
material_type VARCHAR(50) COMMENT '材质',
PRIMARY KEY (material_code),
UNIQUE KEY UQ_Material UNIQUE (material_name, specification, material_type)
) COMMENT='物资类别表';

`import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseUtil {
private static final String URL = "jdbc:mysql://localhost:3306/your_database_name";
private static final String USER = "your_username";
private static final String PASSWORD = "your_password";

static {
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

public static Connection getConnection() throws SQLException {
    return DriverManager.getConnection(URL, USER, PASSWORD);
}

}```
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Warehouse {
private String warehouseCode;
private String warehouseName;
private String address;
private int capacity;

// 构造方法
public Warehouse(String warehouseCode, String warehouseName, String address, int capacity) {
    this.warehouseCode = warehouseCode;
    this.warehouseName = warehouseName;
    this.address = address;
    this.capacity = capacity;
}

// Getter 和 Setter 方法
public String getWarehouseCode() {
    return warehouseCode;
}

public void setWarehouseCode(String warehouseCode) {
    this.warehouseCode = warehouseCode;
}

public String getWarehouseName() {
    return warehouseName;
}

public void setWarehouseName(String warehouseName) {
    this.warehouseName = warehouseName;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public int getCapacity() {
    return capacity;
}

public void setCapacity(int capacity) {
    this.capacity = capacity;
}

// 新增仓库
public static void addWarehouse(Warehouse warehouse) {
    String sql = "INSERT INTO Warehouse (warehouse_code, warehouse_name, address, capacity) VALUES (?, ?, ?, ?)";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql)) {
        pstmt.setString(1, warehouse.getWarehouseCode());
        pstmt.setString(2, warehouse.getWarehouseName());
        pstmt.setString(3, warehouse.getAddress());
        pstmt.setInt(4, warehouse.getCapacity());
        pstmt.executeUpdate();
        System.out.println("仓库新增成功!");
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("仓库新增失败!");
    }
}

// 删除仓库
public static void deleteWarehouse(String warehouseCode) {
    String checkSql = "SELECT COUNT(*) FROM MaterialLedger WHERE warehouse_code = ?";
    String deleteSql = "DELETE FROM Warehouse WHERE warehouse_code = ?";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement checkStmt = conn.prepareStatement(checkSql);
         PreparedStatement deleteStmt = conn.prepareStatement(deleteSql)) {
        checkStmt.setString(1, warehouseCode);
        ResultSet rs = checkStmt.executeQuery();
        if (rs.next() && rs.getInt(1) > 0) {
            System.out.println("该仓库中存在物资,不允许删除!");
            return;
        }
        deleteStmt.setString(1, warehouseCode);
        int rowsAffected = deleteStmt.executeUpdate();
        if (rowsAffected > 0) {
            System.out.println("仓库删除成功!");
        } else {
            System.out.println("仓库删除失败,未找到该仓库!");
        }
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("仓库删除失败!");
    }
}

// 修改仓库
public static void updateWarehouse(Warehouse warehouse) {
    String checkSql = "SELECT COUNT(*) FROM MaterialLedger WHERE warehouse_code = ?";
    String updateSql = "UPDATE Warehouse SET warehouse_name = ?, address = ?, capacity = ? WHERE warehouse_code = ?";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement checkStmt = conn.prepareStatement(checkSql);
         PreparedStatement updateStmt = conn.prepareStatement(updateSql)) {
        checkStmt.setString(1, warehouse.getWarehouseCode());
        ResultSet rs = checkStmt.executeQuery();
        if (rs.next() && rs.getInt(1) > 0) {
            System.out.println("该仓库中存在物资,不允许修改!");
            return;
        }
        updateStmt.setString(1, warehouse.getWarehouseName());
        updateStmt.setString(2, warehouse.getAddress());
        updateStmt.setInt(3, warehouse.getCapacity());
        updateStmt.setString(4, warehouse.getWarehouseCode());
        int rowsAffected = updateStmt.executeUpdate();
        if (rowsAffected > 0) {
            System.out.println("仓库修改成功!");
        } else {
            System.out.println("仓库修改失败,未找到该仓库!");
        }
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("仓库修改失败!");
    }
}

// 获取所有仓库信息(可选)
public static List<Warehouse> getAllWarehouses() {
    String sql = "SELECT * FROM Warehouse";
    List<Warehouse> warehouses = new ArrayList<>();
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql);
         ResultSet rs = pstmt.executeQuery()) {
        while (rs.next()) {
            Warehouse warehouse = new Warehouse(
                    rs.getString("warehouse_code"),
                    rs.getString("warehouse_name"),
                    rs.getString("address"),
                    rs.getInt("capacity")
            );
            warehouses.add(warehouse);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return warehouses;
}

}
public class Main {
public static void main(String[] args) {
// 新增仓库
Warehouse warehouse1 = new Warehouse("WH001", "仓库1", "地址1", 1000);
Warehouse.addWarehouse(warehouse1);

    // 修改仓库
    warehouse1.setWarehouseName("仓库1更新");
    warehouse1.setAddress("地址1更新");
    warehouse1.setCapacity(1200);
    Warehouse.updateWarehouse(warehouse1);

    // 删除仓库
    Warehouse.deleteWarehouse("WH001");
}

}
public class Main {
public static void main(String[] args) {
// 新增物资类别
MaterialCategory category1 = new MaterialCategory("MC001", "物资1", "规格1", "材质1");
MaterialCategory.addMaterialCategory(category1);

    // 修改物资类别
    category1.setMaterialName("物资1更新");
    category1.setSpecification("规格1更新");
    category1.setMaterialType("材质1更新");
    MaterialCategory.updateMaterialCategory(category1);

    // 删除物资类别
    MaterialCategory.deleteMaterialCategory("MC001");
}

}
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class MaterialLedger {
private String ledgerId; // 台账编号
private String materialCode; // 物资编码
private String warehouseCode; // 仓库编码
private String operationType; // 操作类型(入库/出库)
private double quantity; // 数量
private String unit; // 计量单位
private String description; // 描述

// 构造方法
public MaterialLedger(String ledgerId, String materialCode, String warehouseCode, String operationType, double quantity, String unit, String description) {
    this.ledgerId = ledgerId;
    this.materialCode = materialCode;
    this.warehouseCode = warehouseCode;
    this.operationType = operationType;
    this.quantity = quantity;
    this.unit = unit;
    this.description = description;
}

// Getter 和 Setter 方法
public String getLedgerId() {
    return ledgerId;
}

public void setLedgerId(String ledgerId) {
    this.ledgerId = ledgerId;
}

public String getMaterialCode() {
    return materialCode;
}

public void setMaterialCode(String materialCode) {
    this.materialCode = materialCode;
}

public String getWarehouseCode() {
    return warehouseCode;
}

public void setWarehouseCode(String warehouseCode) {
    this.warehouseCode = warehouseCode;
}

public String getOperationType() {
    return operationType;
}

public void setOperationType(String operationType) {
    this.operationType = operationType;
}

public double getQuantity() {
    return quantity;
}

public void setQuantity(double quantity) {
    this.quantity = quantity;
}

public String getUnit() {
    return unit;
}

public void setUnit(String unit) {
    this.unit = unit;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

// 入库操作
public static boolean addMaterialToWarehouse(String materialCode, String warehouseCode, double quantity, String unit, String description) {
    String ledgerId = generateLedgerId(); // 生成台账编号
    String insertSql = "INSERT INTO MaterialLedger (ledger_id, material_code, warehouse_code, operation_type, quantity, unit, description) VALUES (?, ?, ?, '入库', ?, ?, ?)";
    String updateSql = "INSERT INTO Inventory (material_code, warehouse_code, quantity, unit) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE quantity = quantity + VALUES(quantity)";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement insertStmt = conn.prepareStatement(insertSql);
         PreparedStatement updateStmt = conn.prepareStatement(updateSql)) {
        conn.setAutoCommit(false); // 开启事务

        // 插入台账记录
        insertStmt.setString(1, ledgerId);
        insertStmt.setString(2, materialCode);
        insertStmt.setString(3, warehouseCode);
        insertStmt.setDouble(4, quantity);
        insertStmt.setString(5, unit);
        insertStmt.setString(6, description);
        insertStmt.executeUpdate();

        // 更新库存信息
        updateStmt.setString(1, materialCode);
        updateStmt.setString(2, warehouseCode);
        updateStmt.setDouble(3, quantity);
        updateStmt.setString(4, unit);
        updateStmt.executeUpdate();

        conn.commit(); // 提交事务
        System.out.println("入库操作成功!");
        return true;
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("入库操作失败!");
        return false;
    }
}

// 出库操作
public static boolean removeMaterialFromWarehouse(String materialCode, String warehouseCode, double quantity) {
    String ledgerId = generateLedgerId(); // 生成台账编号
    String insertSql = "INSERT INTO MaterialLedger (ledger_id, material_code, warehouse_code, operation_type, quantity, unit, description) VALUES (?, ?, ?, '出库', ?, ?, ?)";
    String checkSql = "SELECT quantity, unit FROM Inventory WHERE material_code = ? AND warehouse_code = ?";
    String updateSql = "UPDATE Inventory SET quantity = quantity - ? WHERE material_code = ? AND warehouse_code = ?";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement checkStmt = conn.prepareStatement(checkSql);
         PreparedStatement updateStmt = conn.prepareStatement(updateSql);
         PreparedStatement insertStmt = conn.prepareStatement(insertSql)) {
        conn.setAutoCommit(false); // 开启事务

        // 检查库存余额
        checkStmt.setString(1, materialCode);
        checkStmt.setString(2, warehouseCode);
        ResultSet rs = checkStmt.executeQuery();
        if (!rs.next()) {
            System.out.println("该仓库中没有该类物资,无法出库!");
            return false;
        }
        double inventoryQuantity = rs.getDouble("quantity");
        String unit = rs.getString("unit");

        if (quantity > inventoryQuantity) {
            System.out.println("出库数量大于库存余额,无法出库!");
            return false;
        }

        // 插入台账记录
        insertStmt.setString(1, ledgerId);
        insertStmt.setString(2, materialCode);
        insertStmt.setString(3, warehouseCode);
        insertStmt.setDouble(4, quantity);
        insertStmt.setString(5, unit);
        insertStmt.setString(6, "出库操作");
        insertStmt.executeUpdate();

        // 更新库存信息
        updateStmt.setDouble(1, quantity);
        updateStmt.setString(2, materialCode);
        updateStmt.setString(3, warehouseCode);
        updateStmt.executeUpdate();

        conn.commit(); // 提交事务
        System.out.println("出库操作成功!");
        return true;
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("出库操作失败!");
        return false;
    }
}

// 生成台账编号(格式:YYYYMMDDNNNN)
private static String generateLedgerId() {
    // 获取当前日期
    java.util.Date date = new java.util.Date();
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
    String datePart = sdf.format(date);

    // 获取当前最大顺序号
    String sql = "SELECT MAX(CAST(SUBSTRING(ledger_id, 9) AS UNSIGNED)) FROM MaterialLedger WHERE ledger_id LIKE ?";
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql)) {
        pstmt.setString(1, datePart + "%");
        ResultSet rs = pstmt.executeQuery();
        int maxSeq = 0;
        if (rs.next()) {
            maxSeq = rs.getInt(1);
        }
        maxSeq++;
        return datePart + String.format("%04d", maxSeq);
    } catch (SQLException e) {
        e.printStackTrace();
        return "000000000000";
    }
}

// 查询物资库存信息
public static List<MaterialInventory> queryMaterialInventory(String materialCode) {
    String sql = "SELECT material_code, warehouse_code, quantity, unit FROM Inventory WHERE material_code = ?";
    List<MaterialInventory> inventoryList = new ArrayList<>();
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql)) {
        pstmt.setString(1, materialCode);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MaterialInventory inventory = new MaterialInventory(
                    rs.getString("material_code"),
                    rs.getString("warehouse_code"),
                    rs.getDouble("quantity"),
                    rs.getString("unit")
            );
            inventoryList.add(inventory);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return inventoryList;
}

// 查询物资详细入库单信息
public static List<MaterialLedger> queryMaterialInboundDetails(String materialCode) {
    String sql = "SELECT * FROM MaterialLedger WHERE material_code = ? AND operation_type = '入库'";
    List<MaterialLedger> inboundList = new ArrayList<>();
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql)) {
        pstmt.setString(1, materialCode);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MaterialLedger ledger = new MaterialLedger(
                    rs.getString("ledger_id"),
                    rs.getString("material_code"),
                    rs.getString("warehouse_code"),
                    rs.getString("operation_type"),
                    rs.getDouble("quantity"),
                    rs.getString("unit"),
                    rs.getString("description")
            );
            inboundList.add(ledger);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return inboundList;
}

// 查询物资详细出库单信息
public static List<MaterialLedger> queryMaterialOutboundDetails(String materialCode) {
    String sql = "SELECT * FROM MaterialLedger WHERE material_code = ? AND operation_type = '出库'";
    List<MaterialLedger> outboundList = new ArrayList<>();
    try (Connection conn = DatabaseUtil.getConnection();
         PreparedStatement pstmt = conn.prepareStatement(sql))

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}

header {
background-color: #333;
color: #fff;
padding: 10px 20px;
text-align: center;
}

nav {
background-color: #444;
color: #fff;
padding: 10px;
}

nav ul {
list-style: none;
padding: 0;
}

nav ul li {
display: inline;
margin-right: 20px;
}

nav ul li a {
color: #fff;
text-decoration: none;
}

main {
padding: 20px;
}

form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

form label {
display: block;
margin-bottom: 5px;
}

form input, form select {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}

form button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}

form button:hover {
background-color: #555;
}

table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 10px;
text-align: left;
}

th {
background-color: #f2f2f2;
}

footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}

物资管理系统 - 登录

物资管理系统

© 2025 物资管理系统

管理员页面

物资管理系统 - 管理员

仓库管理

物资类别管理

© 2025 物资管理系统

posted @ 2025-03-05 21:20  Haivsisndh  阅读(51)  评论(0)    收藏  举报