package com.happy.dao.impl; import com.happy.Model.Data2; import com.happy.Model.Data3; import com.happy.Model.Message; import com.happy.Model.Visitor; import com.happy.dao.userDao; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; import java.util.List; @Repository("userDao") public class userDaoImpl implements userDao { @Autowired private NamedParameterJdbcTemplate namedParameterJdbcTemplate; public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { return namedParameterJdbcTemplate; } public void setNamedParameterJdbcTemplate( NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; } public int insertInfo(Visitor visitor){ String sql = "insert into info(visitor_name, visitor_phone, reason, status, status_with_time, card_number, visited_at, id_card_img, created_time, visit_start_time, visit_end_time, member_name, member_phone, member_org, car_number, time) values(:visitor_name, :visitor_phone, :reason, :status, :status_with_time, :card_number, :visited_at, :id_card_img, :created_time, :visit_start_time, :visit_end_time, :member_name, :member_phone, :member_org, :car_number, :time)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("visitor_name", visitor.getVisitor_name()); sps.addValue("visitor_phone", visitor.getVisitor_phone()); sps.addValue("reason", visitor.getReason()); sps.addValue("status", visitor.getStatus()); sps.addValue("status_with_time", visitor.getStatus_with_time()); sps.addValue("card_number", visitor.getCard_number()); sps.addValue("visited_at", visitor.getVisited_at()); sps.addValue("id_card_img", visitor.getId_card_img()); sps.addValue("created_time", visitor.getCreated_time()); sps.addValue("visit_start_time", visitor.getVisit_start_time()); sps.addValue("visit_end_time", visitor.getVisit_end_time()); sps.addValue("member_name", visitor.getMember_name()); sps.addValue("member_phone", visitor.getMember_phone()); sps.addValue("member_org", visitor.getMember_org()); sps.addValue("car_number", visitor.getCar_number()); sps.addValue("time", visitor.getTime()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public List queryByCard(String card_number, String created_time){ String sql="select * from info where card_number=:card_number and created_time=:created_time"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("card_number", card_number); sps.addValue("created_time", created_time); List list=namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper(Visitor.class)); if(list != null && list.size() >0){ return list; } return null; } public List queryByTime(String time){ String sql="select * from info where `state`=1 and `time` < '" + time + "' limit 0, 8 "; MapSqlParameterSource sps = new MapSqlParameterSource(); List list=namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper(Visitor.class)); if(list != null && list.size() >0){ return list; } return null; } public int insertSchool(Data2 data2){ String sql = "insert into inschool(car_number, in_time, car_type, c_type, uid, order_id, empty_plot, in_channel_id, worksite_id, remark, force_update) values(:car_number, :in_time, :car_type, :c_type, :uid, :order_id, :empty_plot, :in_channel_id, :worksite_id, :remark, :force_update)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("car_number", data2.getCar_number()); sps.addValue("in_time", data2.getIn_time()); sps.addValue("car_type", data2.getCar_type()); sps.addValue("c_type", data2.getC_type()); sps.addValue("uid", data2.getUid()); sps.addValue("order_id", data2.getOrder_id()); sps.addValue("empty_plot", data2.getEmpty_plot()); sps.addValue("in_channel_id", data2.getIn_channel_id()); sps.addValue("worksite_id", data2.getWorksite_id()); sps.addValue("remark", data2.getRemark()); sps.addValue("force_update", data2.getForce_update()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public List queryInByCar(String car_number, String in_time){ String sql="select * from inschool where car_number=:car_number and in_time=:in_time "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("car_number", car_number); sps.addValue("in_time", in_time); List list=namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper(Data2.class)); if(list != null && list.size() >0){ return list; } return null; } public List queryOutByCar(String car_number, String out_time){ String sql="select * from outschool where car_number=:car_number and out_time=:out_time "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("car_number", car_number); sps.addValue("out_time", out_time); List list=namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper(Data3.class)); if(list != null && list.size() >0){ return list; } return null; } public int insertOutSchool(Data3 data3){ String sql = "insert into outschool(out_uid,uid,cash_pay,pay_type,electronic_pay,in_time,empty_plot,in_channel_id,out_channel_id,order_id,car_number,auth_code,freereasons,c_type,duration,total,out_time,car_type,amount_receivable) values(:out_uid,:uid,:cash_pay,:pay_type,:electronic_pay,:in_time,:empty_plot,:in_channel_id,:out_channel_id,:order_id,:car_number,:auth_code,:freereasons,:c_type,:duration,:total,:out_time,:car_type,:amount_receivable)"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("out_uid", data3.getOut_uid()); sps.addValue("uid", data3.getUid()); sps.addValue("cash_pay", data3.getCash_pay()); sps.addValue("pay_type", data3.getPay_type()); sps.addValue("electronic_pay", data3.getElectronic_pay()); sps.addValue("in_time", data3.getIn_time()); sps.addValue("empty_plot", data3.getEmpty_plot()); sps.addValue("in_channel_id", data3.getIn_channel_id()); sps.addValue("out_channel_id", data3.getOut_channel_id()); sps.addValue("order_id", data3.getOrder_id()); sps.addValue("car_number", data3.getCar_number()); sps.addValue("auth_code", data3.getAuth_code()); sps.addValue("freereasons", data3.getFreereasons()); sps.addValue("c_type", data3.getC_type()); sps.addValue("duration", data3.getDuration()); sps.addValue("total", data3.getTotal()); sps.addValue("out_time", data3.getOut_time()); sps.addValue("car_type", data3.getCar_type()); sps.addValue("amount_receivable", data3.getAmount_receivable()); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateVisiState(String car_number, String visit_start_time, String visit_end_time){ String sql = "update info set `state`=2 where car_number=:car_number and visit_start_time=:visit_start_time and visit_end_time=:visit_end_time"; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("car_number", car_number); sps.addValue("visit_start_time", visit_start_time); sps.addValue("visit_end_time", visit_end_time); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateVisiStateById(Integer id){ String sql = "update info set `state`=2 where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } public int updateVisiStateNoById(Integer id){ String sql = "update info set `state`=3 where id=:id "; MapSqlParameterSource sps = new MapSqlParameterSource(); sps.addValue("id", id); int num = 0; try{ num = namedParameterJdbcTemplate.update(sql, sps); } catch(Exception e){ e.printStackTrace(); } return num; } }