-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
583 additions
and
1 deletion.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
src/main/java/com/kaishengit/controller/CustomerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.kaishengit.controller; | ||
|
||
import com.google.common.collect.Maps; | ||
import com.kaishengit.pojo.Customer; | ||
import com.kaishengit.service.CustomerService; | ||
import com.kaishengit.util.Strings; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import javax.inject.Inject; | ||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Controller | ||
@RequestMapping("/customer") | ||
public class CustomerController { | ||
|
||
@Inject | ||
private CustomerService customerService; | ||
|
||
@RequestMapping(method = RequestMethod.GET) | ||
public String list() { | ||
return "customer/list"; | ||
} | ||
|
||
|
||
/** | ||
* DataTables加载数据 | ||
* @return | ||
*/ | ||
@RequestMapping(value = "/customers.json",method = RequestMethod.GET) | ||
@ResponseBody | ||
public Map<String,Object> load(HttpServletRequest request) { | ||
Map<String,Object> resultMap = Maps.newHashMap(); | ||
|
||
String draw = request.getParameter("draw"); | ||
Integer start = Integer.valueOf(request.getParameter("start")); | ||
Integer length = Integer.valueOf(request.getParameter("length")); | ||
String searchValue = request.getParameter("search[value]"); | ||
String orderColumnIndex = request.getParameter("order[0][column]"); | ||
String orderType = request.getParameter("order[0][dir]"); | ||
String orderColumnName = request.getParameter("columns["+orderColumnIndex+"][name]"); | ||
|
||
Map<String,Object> param = Maps.newHashMap(); | ||
param.put("start",start); | ||
param.put("length",length); | ||
if(StringUtils.isNotEmpty(searchValue)) { | ||
param.put("keyword", "%" + Strings.toUTF8(searchValue) + "%"); | ||
} | ||
if(orderColumnName == null || orderType == null) { | ||
param.put("orderColumn","id"); | ||
param.put("orderType","desc"); | ||
} else { | ||
param.put("orderColumn", orderColumnName); | ||
param.put("orderType", orderType); | ||
} | ||
|
||
List<Customer> userList = customerService.findUserByParam(param); //.findAllUser(); | ||
Integer count = customerService.findCustomerCount(); | ||
Integer filteredCount = customerService.findUserCountByParam(param); | ||
|
||
resultMap.put("draw",draw); | ||
resultMap.put("recordsTotal",count); //总记录数 | ||
resultMap.put("recordsFiltered",filteredCount); //过滤出来的数量 | ||
resultMap.put("data",userList); | ||
|
||
return resultMap; | ||
} | ||
|
||
|
||
/** | ||
* 添加新客户 | ||
* @return | ||
*/ | ||
@RequestMapping(value = "/new",method = RequestMethod.POST) | ||
@ResponseBody | ||
public String newCust(Customer customer) { | ||
customerService.saveNewCustomer(customer); | ||
return "success"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.kaishengit.mapper; | ||
|
||
import com.kaishengit.pojo.Customer; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface CustomerMapper { | ||
|
||
/** | ||
* 添加新客户 | ||
* @param customer | ||
*/ | ||
void save(Customer customer); | ||
|
||
/** | ||
* 根据DataTables的查询方式获取 客户列表 | ||
* @param param | ||
* @return | ||
*/ | ||
List<Customer> findByParam(Map<String, Object> param); | ||
|
||
/** | ||
* 获取客户的总数量 | ||
* @return | ||
*/ | ||
Long count(); | ||
|
||
/** | ||
* 根据DataTables的查询方式获取客户总数量 | ||
* @param param | ||
* @return | ||
*/ | ||
Long countByParam(Map<String, Object> param); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.kaishengit.pojo; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Customer implements Serializable { | ||
|
||
private Integer id; | ||
private String custname; | ||
private String contact; | ||
private String tel; | ||
private String address; | ||
private String email; | ||
private String wechar; | ||
private String qq; | ||
private String mark; | ||
private Integer userid; | ||
private String progress; | ||
private String progresstime; | ||
private String createtime; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getCustname() { | ||
return custname; | ||
} | ||
|
||
public void setCustname(String custname) { | ||
this.custname = custname; | ||
} | ||
|
||
public String getContact() { | ||
return contact; | ||
} | ||
|
||
public void setContact(String contact) { | ||
this.contact = contact; | ||
} | ||
|
||
public String getTel() { | ||
return tel; | ||
} | ||
|
||
public void setTel(String tel) { | ||
this.tel = tel; | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
public void setEmail(String email) { | ||
this.email = email; | ||
} | ||
|
||
public String getWechar() { | ||
return wechar; | ||
} | ||
|
||
public void setWechar(String wechar) { | ||
this.wechar = wechar; | ||
} | ||
|
||
public String getQq() { | ||
return qq; | ||
} | ||
|
||
public void setQq(String qq) { | ||
this.qq = qq; | ||
} | ||
|
||
public String getMark() { | ||
return mark; | ||
} | ||
|
||
public void setMark(String mark) { | ||
this.mark = mark; | ||
} | ||
|
||
public Integer getUserid() { | ||
return userid; | ||
} | ||
|
||
public void setUserid(Integer userid) { | ||
this.userid = userid; | ||
} | ||
|
||
public String getProgress() { | ||
return progress; | ||
} | ||
|
||
public void setProgress(String progress) { | ||
this.progress = progress; | ||
} | ||
|
||
public String getProgresstime() { | ||
return progresstime; | ||
} | ||
|
||
public void setProgresstime(String progresstime) { | ||
this.progresstime = progresstime; | ||
} | ||
|
||
public String getCreatetime() { | ||
return createtime; | ||
} | ||
|
||
public void setCreatetime(String createtime) { | ||
this.createtime = createtime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.kaishengit.service; | ||
|
||
import com.kaishengit.mapper.CustomerMapper; | ||
import com.kaishengit.pojo.Customer; | ||
import com.kaishengit.util.ShiroUtil; | ||
import org.joda.time.DateTime; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Named | ||
@Transactional | ||
public class CustomerService { | ||
|
||
private Logger logger = LoggerFactory.getLogger(CustomerService.class); | ||
|
||
@Inject | ||
private CustomerMapper customerMapper; | ||
|
||
/** | ||
* 保存新客户 | ||
* @param customer | ||
*/ | ||
public void saveNewCustomer(Customer customer) { | ||
customer.setUserid(ShiroUtil.getCurrentUserId()); | ||
customer.setCreatetime(DateTime.now().toString("yyyy-MM-dd HH:mm")); | ||
|
||
customerMapper.save(customer); | ||
|
||
logger.info("{}-添加了新客户-{}",ShiroUtil.getCurrentUserName(),customer.getCustname()); | ||
} | ||
|
||
/** | ||
* 根据DataTables的查询方式获取 客户列表 | ||
* @param param | ||
* @return | ||
*/ | ||
public List<Customer> findUserByParam(Map<String, Object> param) { | ||
return customerMapper.findByParam(param); | ||
} | ||
|
||
/** | ||
* 获取客户的总数量 | ||
* @return | ||
*/ | ||
public Integer findCustomerCount() { | ||
return customerMapper.count().intValue(); | ||
} | ||
|
||
/** | ||
* 根据DataTables的查询方式获取客户总数量 | ||
* @param param | ||
* @return | ||
*/ | ||
public Integer findUserCountByParam(Map<String, Object> param) { | ||
return customerMapper.countByParam(param).intValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
<mapper namespace="com.kaishengit.mapper.CustomerMapper"> | ||
|
||
<cache/> | ||
|
||
<insert id="save"> | ||
INSERT into t_customer(custname,contact,tel,email,address,wechar,qq,createtime,mark,userid) | ||
VALUES (#{custname},#{contact},#{tel},#{email},#{address},#{wechar},#{qq},#{createtime},#{mark},#{userid}) | ||
</insert> | ||
|
||
<select id="findByParam" parameterType="map" resultType="Customer"> | ||
SELECT * FROM t_customer | ||
<where> | ||
<if test="keyword != null and keyword != ''"> | ||
(custname LIKE #{keyword} or contact like #{keyword}) | ||
</if> | ||
</where> | ||
order by ${orderColumn} ${orderType} | ||
limit ${start},${length} | ||
</select> | ||
|
||
<select id="count" resultType="java.lang.Long"> | ||
SELECT COUNT(*) FROM t_customer | ||
</select> | ||
<select id="countByParam" resultType="java.lang.Long"> | ||
SELECT COUNT(*) FROM t_customer | ||
<where> | ||
<if test="keyword != null and keyword != ''"> | ||
(custname LIKE #{keyword} or contact like #{keyword}) | ||
</if> | ||
</where> | ||
</select> | ||
|
||
|
||
</mapper> |
Oops, something went wrong.