Bläddra i källkod

上传文件至 'Shop/src/cn/dao/impl'

1801010538 5 år sedan
förälder
incheckning
f5238e03ed

+ 44 - 0
Shop/src/cn/dao/impl/AgentDaoImpl.java

@@ -0,0 +1,44 @@
+package cn.dao.impl;
+
+import cn.dao.AgentDao;
+import cn.domain.Agent;
+import cn.domain.Order;
+import cn.util.JDBCUtils;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+public class AgentDaoImpl implements AgentDao {
+    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
+
+    @Override
+    public void register(Agent agent) throws Exception {
+        String name = agent.getName();
+        int phone = agent.getPhone();
+        String img = agent.getImg();
+        String company = agent.getCompany();
+        String password = agent.getPassword();
+        String mid = agent.getMid();
+        String sql = "insert into agent(mid,name,phone,img,company,password) values(?,?,?,?,?,?)";
+        template.update(sql,mid,name,phone,img,company,password);
+    }
+
+    @Override
+    public Agent login(String name, String password)throws Exception {
+        try{
+            String sql = "SELECT * FROM agent WHERE NAME=? AND PASSWORD = ?";
+            Agent agent = template.queryForObject(sql,new BeanPropertyRowMapper< Agent >(Agent.class), name,password);
+            return agent;
+        }catch (Exception e){
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+    @Override
+    public Agent findByMid(String mid) throws Exception {
+        String sql = "select * from agent where mid = ?";
+        Agent agent = template.queryForObject(sql,new BeanPropertyRowMapper<Agent>(Agent.class),mid);
+        return agent;
+    }
+}

+ 44 - 0
Shop/src/cn/dao/impl/CompanyDaoImpl.java

@@ -0,0 +1,44 @@
+package cn.dao.impl;
+
+import cn.dao.CompanyDao;
+import cn.domain.Company;
+import cn.util.JDBCUtils;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+
+public class CompanyDaoImpl implements CompanyDao {
+    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
+    @Override
+    public void register(Company company) throws Exception {
+        String sql = "insert into company values(?,?,?,?)";
+        template.update(sql,company.getMid(),company.getName(),company.getImg(),company.getCode());
+    }
+
+    @Override
+    public List<Company> companyInfomation() throws Exception {
+        String sql = "select * from company where code = 1";
+        List<Company> companies =  template.query(sql,new BeanPropertyRowMapper<Company>(Company.class));
+        return companies;
+    }
+
+    @Override
+    public List<Company> pendingMatters() throws Exception {
+        String sql = "select * from company where code = 0";
+        List<Company> companies =  template.query(sql,new BeanPropertyRowMapper<Company>(Company.class));
+        return companies;
+    }
+
+    @Override
+    public void pass(String mid) throws Exception {
+        String sql = "update company set code=1 where mid=?";
+        template.update(sql,mid);
+    }
+
+    @Override
+    public List<Company> findCompany() throws Exception {
+        String sql = "select * from company where code=1";
+        return template.query(sql,new BeanPropertyRowMapper<Company>(Company.class));
+    }
+}

+ 32 - 0
Shop/src/cn/dao/impl/OrderDaoImpl.java

@@ -0,0 +1,32 @@
+package cn.dao.impl;
+
+import cn.dao.OrderDao;
+import cn.domain.Order;
+import cn.util.JDBCUtils;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+
+public class OrderDaoImpl implements OrderDao {
+    JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
+    @Override
+    public void saveOrder(Order order) throws Exception {
+        String sql = "insert into orders values(?,?,?,?,?,?,?,?,?)";
+        template.update(sql,order.getId(),order.getName(),order.getBuyer(),order.getSaler(),order.getProduct(),order.getAmount(),order.getPrice(),order.getTotalprice(),order.getTime());
+    }
+
+    @Override
+    public List<Order> findBySaler(String saler) throws Exception {
+        String sql = "select * from orders where saler = ?";
+        List<Order> orders = template.query(sql,new BeanPropertyRowMapper<Order>(Order.class),saler);
+        return orders;
+    }
+
+    @Override
+    public List<Order> findByBuyer(String buyer) throws Exception {
+        String sql = "select * from orders where buyer = ?";
+        List<Order> orders = template.query(sql,new BeanPropertyRowMapper<Order>(Order.class),buyer);
+        return orders;
+    }
+}

+ 74 - 0
Shop/src/cn/dao/impl/ProductDaoImpl.java

@@ -0,0 +1,74 @@
+package cn.dao.impl;
+
+import cn.dao.ProductDao;
+import cn.domain.Product;
+import cn.util.JDBCUtils;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+
+public class ProductDaoImpl implements ProductDao {
+    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
+    @Override
+    public List<Product> findProduct() throws Exception {
+        String sql = "select * from products";
+//        System.out.println(template.query(sql,new BeanPropertyRowMapper<Product>(Product.class)).toString());
+        return template.query(sql,new BeanPropertyRowMapper<Product>(Product.class));
+    }
+
+    @Override
+    public Product findProductById(String mid) throws Exception {
+        String sql = "select * from products where mid = ?";
+        Product product = template.queryForObject(sql,new BeanPropertyRowMapper<Product>(Product.class),mid);
+        return product;
+    }
+
+    @Override
+    public List<Product> findProductByScompany(String scompany) throws Exception {
+        try{
+            String sql = "select * from products where scompany = ?";
+            List<Product> products = template.query(sql,new BeanPropertyRowMapper<Product>(Product.class),scompany);
+            return products;
+        }catch (Exception e){
+            e.getMessage();
+            return null;
+        }
+
+    }
+
+    @Override
+    public void addProduct(Product product) throws Exception {
+        String mid = product.getMid();
+        int id = product.getId();
+        String name = product.getName();
+        double price = product.getPrice();
+        String detail = product.getDetail();
+        String scompany = product.getScompany();
+        String img = product.getImg();
+        String sql = "insert into products values(?,?,?,?,?,?,?)";
+        template.update(sql,mid,id,name,price,detail,scompany,img);
+        System.out.println(template.update(sql,mid,id,name,price,detail,scompany,img));
+    }
+
+    @Override
+    public void deleteProduct(String mid) throws Exception {
+        String sql = "delete from products where mid=?";
+        template.update(sql,mid);
+    }
+
+    @Override
+    public void updateProduct(Product product) throws Exception {
+        String sql = "update products set id=?,name=?,price=?,detail=?,scompany=?,img=? where mid=?";
+        int id = product.getId();
+        String name = product.getName();
+        double price = product.getPrice();
+        String detail = product.getDetail();
+        String scompany = product.getScompany();
+        String img = product.getImg();
+        String mid = product.getMid();
+        System.out.println(template.update(sql,id,name,price,detail,scompany,img,mid));
+        template.update(sql,id,name,price,detail,scompany,img,mid);
+
+    }
+}