三、部分代码
CategoryServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.services.CategoryService; public class CategoryServiceImpl implements CategoryService { // 查询所有分类 @Override public List selectAll() throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); List list = dao.select("select id,name from category where 1=1 and del_flag='0' ", 2, null); if (!list.isEmpty()) { return list; } return null; } }
GoodsServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import java.util.Vector; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.services.GoodsService; public class GoodsServiceImpl implements GoodsService { // 条件查询商品 @Override public Vector<Vector> selectByCondition(Object[] paraArray) throws Exception { Vector<Vector> rows = new Vector<Vector>(); BaseDaoImpl dao = new BaseDaoImpl(); StringBuilder sqlBuilder = new StringBuilder( "select g.id,g.name,g.price,g.origin,c.name as categoryName,w.name as warehouseName, g.stock,w.id as warehouseId,c.id as categoryId " + "from goods g,warehouse w,category c " + "where 1=1 and g.del_flag='0' and w.del_flag='0' and c.del_flag='0' and g.warehouse_id=w.id and g.category_id=c.id "); if (!"全部".equals(paraArray[0])) { sqlBuilder.append(" and g.category_id='" + paraArray[0] + "'"); } if (!"全部".equals(paraArray[1])) { sqlBuilder.append(" and g.warehouse_id='" + paraArray[1] + "'"); } String sql = sqlBuilder.toString(); List<Object[]> list = dao.select(sql, 9, null); if (!list.isEmpty()) { for (Object[] object : list) { Vector temp = new Vector<String>(); for (int i = 0; i < object.length; i++) { temp.add(object[i]); } rows.add(temp); } } return rows; } // 逻辑删除商品 @Override public int deleteById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update goods set del_flag='1' where id=?", paraArray); return result; } // 通过id修改销售单 @Override public int updateById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update goods set name=?,price=?,origin=?,stock=?,warehouse_id=?,category_id=? where id=?", paraArray); return result; } // 插入销售单 @Override public int insertById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.insert( "insert into goods(id,name,price,origin,stock,warehouse_id,category_id,del_flag) values(?,?,?,?,?,?,?,'0')", paraArray); return result; } // 查询所有销售单 @Override public List selectAll() throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); String sql = "select id,name from goods where 1=1 and del_flag='0' "; List<Object[]> list = dao.select(sql, 2, null); return list; } // 通过id查询销售单 @Override public List selectById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); String sql = "select c.id,c.name,w.id,w.name,g.stock " + "from goods g,category c,warehouse w " + "where g.category_id=c.id and g.warehouse_id=w.id and g.del_flag='0' and c.del_flag='0' and w.del_flag='0' and g.id=?"; List<Object[]> list = dao.select(sql, 5, paraArray); return list; } // 通过id修改库存 @Override public int updateStockById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update goods set stock=stock+? where id=?", paraArray); return result; } }
SaleOrderServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import java.util.Vector; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.services.SaleOrderService; public class SaleOrderServiceImpl implements SaleOrderService { // 条件查询销售单 @Override public Vector<Vector> selectByCondition(Object[] paraArray) throws Exception { Vector<Vector> rows = new Vector<Vector>(); BaseDaoImpl dao = new BaseDaoImpl(); StringBuilder sqlBuilder = new StringBuilder( "select s.id,s.bill_no,g.name,s.amount,c.name,w.name,u.name,c.id,w.id " + " from sale_order s,user u,goods g,category c,warehouse w " + " where s.handler_id=u.id and s.category_id=c.id and s.warehouse_id=w.id and s.goods_id=g.id and s.del_flag='0' and g.del_flag='0' and c.del_flag='0' and w.del_flag='0'"); String name = paraArray[0].toString().trim(); if (!name.isEmpty()) { sqlBuilder.append(" and g.name like '%" + paraArray[0] + "%' "); } if (!"全部".equals(paraArray[1])) { sqlBuilder.append(" and s.category_id='" + paraArray[1] + "' "); } if (!"全部".equals(paraArray[2])) { sqlBuilder.append(" and s.warehouse_id='" + paraArray[2] + "' "); } String sql = sqlBuilder.toString(); List<Object[]> list = dao.select(sql, 9, null); if (!list.isEmpty()) { for (Object[] object : list) { Vector temp = new Vector<String>(); for (int i = 0; i < object.length; i++) { temp.add(object[i]); } rows.add(temp); } } return rows; } // 插入销售单 @Override public int insert(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.insert( "insert into sale_order(id,bill_no,handler_id,category_id,warehouse_id,amount,goods_id) values(?,?,?,?,?,?,?)", paraArray); return result; } }
StockOrderServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import java.util.Vector; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.services.StockOrderService; public class StockOrderServiceImpl implements StockOrderService { // 条件查询入库单 @Override public Vector<Vector> selectStockInputByCondition(Object[] paraArray) throws Exception { Vector<Vector> rows = new Vector<Vector>(); BaseDaoImpl dao = new BaseDaoImpl(); StringBuilder sqlBuilder = new StringBuilder( "select s.id,s.bill_no,g.name,s.amount,c.name,w.name,u.name,c.id,w.id " + " from stock_order s,goods g,user u,category c,warehouse w " + " where s.handler_id=u.id and s.goods_id=g.id and s.category_id=c.id and s.warehouse_id=w.id and s.sign='0' and s.del_flag='0' and g.del_flag='0' and c.del_flag=0 and w.del_flag='0' "); String name = paraArray[0].toString().trim(); if (!name.isEmpty()) { sqlBuilder.append(" and g.name like '%" + paraArray[0] + "%' "); } if (!"全部".equals(paraArray[1])) { sqlBuilder.append(" and s.category_id='" + paraArray[1] + "' "); } if (!"全部".equals(paraArray[2])) { sqlBuilder.append(" and s.warehouse_id='" + paraArray[2] + "' "); } if (!"全部".equals(paraArray[3])) { sqlBuilder.append(" and s.handler_id='" + paraArray[3] + "' "); } String sql = sqlBuilder.toString(); List<Object[]> list = dao.select(sql, 9, null); if (!list.isEmpty()) { for (Object[] object : list) { Vector temp = new Vector<String>(); for (int i = 0; i < object.length; i++) { temp.add(object[i]); } rows.add(temp); } } return rows; } // 通过id逻辑删除入库单 @Override public int deleteStockInputById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update stock_order set del_flag='1' where id=?", paraArray); return result; } // 通过id修改入库单 @Override public int updateStockInputById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update stock_order set amount=? where id=?", paraArray); return result; } // 插入入库单 @Override public int insertStockInput(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.insert( "insert into stock_order(id,bill_no,handler_id,warehouse_id,category_id,amount,goods_id,sign) values(?,?,?,?,?,?,?,'0')", paraArray); return result; } // 条件查询出库单 @Override public Vector<Vector> selectStockOutputByCondition(Object[] paraArray) throws Exception { Vector<Vector> rows = new Vector<Vector>(); BaseDaoImpl dao = new BaseDaoImpl(); StringBuilder sqlBuilder = new StringBuilder( "select s.id,s.bill_no,g.name,s.amount,c.name,w.name,u.name,c.id,w.id " + " from stock_order s,goods g,user u,category c,warehouse w " + " where s.handler_id=u.id and s.goods_id=g.id and s.category_id=c.id and s.warehouse_id=w.id and s.sign='1' and s.del_flag='0' and g.del_flag='0' and c.del_flag=0 and w.del_flag='0' "); String name = paraArray[0].toString().trim(); if (!name.isEmpty()) { sqlBuilder.append(" and g.name like '%" + paraArray[0] + "%' "); } if (!"全部".equals(paraArray[1])) { sqlBuilder.append(" and s.category_id='" + paraArray[1] + "' "); } if (!"全部".equals(paraArray[2])) { sqlBuilder.append(" and s.warehouse_id='" + paraArray[2] + "' "); } if (!"全部".equals(paraArray[3])) { sqlBuilder.append(" and s.handler_id='" + paraArray[3] + "' "); } String sql = sqlBuilder.toString(); List<Object[]> list = dao.select(sql, 9, null); if (!list.isEmpty()) { for (Object[] object : list) { Vector temp = new Vector<String>(); for (int i = 0; i < object.length; i++) { temp.add(object[i]); } rows.add(temp); } } return rows; } // 通过id逻辑删除出库单 @Override public int deleteStockOutputById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update stock_order set del_flag='1' where id=?", paraArray); return result; } // 通过id修改出库单 @Override public int updateStockOutputById(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update stock_order set amount=? where id=?", paraArray); return result; } // 插入出库单 @Override public int insertStockOutput(Object[] paraArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.insert( "insert into stock_order(id,bill_no,handler_id,warehouse_id,category_id,amount,goods_id,sign) values(?,?,?,?,?,?,?,'1')", paraArray); return result; } }
UserServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import org.omg.PortableServer.SERVANT_RETENTION_POLICY_ID; import org.rancode.module.dao.BaseDao; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.entity.User; import org.rancode.module.services.UserService; public class UserServiceImpl implements UserService { // 查询一条记录 @Override public User selectOne(Object[] paraArray) throws Exception { User user = new User(); BaseDaoImpl dao = new BaseDaoImpl(); String sql = "select id,name,password,identity from user where name=? and password=?"; List list = dao.select(sql, 4, paraArray); if (!list.isEmpty()) { user.setId((String) ((Object[]) list.get(0))[0]); user.setName((String) ((Object[]) list.get(0))[1]); user.setPassword((String) ((Object[]) list.get(0))[2]); user.setIdentity((String) ((Object[]) list.get(0))[3]); return user; } return null; } // 通过Id修改用户 @Override public int updateUserById(Object[] paraArray) throws Exception { int result = 0; BaseDaoImpl dao = new BaseDaoImpl(); String sql = "update user set name = ?,password=? where id=?"; result = dao.update(sql, paraArray); return result; } }
WarehouseServiceImpl
package org.rancode.module.services.Impl; import java.util.List; import java.util.Vector; import org.rancode.module.dao.Impl.BaseDaoImpl; import org.rancode.module.services.WarehouseService; public class WarehouseServiceImpl implements WarehouseService { // 遍历所有仓库 @Override public List selectAll() throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); List list = dao.select("select id,name from warehouse where 1=1 and del_flag='0' ", 2, null); if (!list.isEmpty()) { return list; } return null; } // 遍历所有仓库返回Vector @Override public Vector<Vector> selectAllVexctor() throws Exception { Vector<Vector> rows = new Vector<Vector>(); BaseDaoImpl dao = new BaseDaoImpl(); List<Object[]> list = dao.select("select id,sort,name from warehouse where 1=1 and del_flag='0' order by sort", 3, null); if (!list.isEmpty()) { int number = 1; for (Object[] object : list) { Vector temp = new Vector<String>(); for (int i = 0; i < object.length; i++) { if (i == 1) { temp.add(number); } else { temp.add(object[i]); } } rows.add(temp); number++; } } return rows; } // 通过Id修改仓库 @Override public int updateById(Object[] paramArray) throws Exception { int result = 0; BaseDaoImpl dao = new BaseDaoImpl(); result = dao.update("update warehouse set name=? where id=?", paramArray); return result; } // 通过Id逻辑删除仓库 @Override public int deleteById(Object[] paramArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.update("update warehouse set del_flag='1' where id=?", paramArray); return result; } // 插入仓库 @Override public int insertById(Object[] paramArray) throws Exception { BaseDaoImpl dao = new BaseDaoImpl(); int result = 0; result = dao.insert("insert into warehouse(id,name) values(?,?) ", paramArray); return result; } }
四、其他
1.更多系统
更多JavaSwing系统请关注专栏。
https://blog.csdn.net/helongqiang/category_6229101.html
https://blog.csdn.net/helongqiang/category_6229101.html
2.源码下载
Java+Swing+Mysql实现进销存管理系统
3.运行项目
请点击以下链接,部署你的项目。
Eclipse如何导入JavaSwing项目超详细图文教程
Eclipse如何导入JavaSwing项目超详细视频教程
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!