提交 b82f4903 authored 作者: liupengfei's avatar liupengfei

开发版 v0.0.1已完成

上级 547107b4
......@@ -8,12 +8,14 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.excetion.BaseException;
import com.form.customer.QueryCustomerForm;
import com.model.customer.Customer;
import com.service.customer.CustomerService;
import com.util.CallBack;
import com.util.PageInfo;
import com.util.PageParam;
import com.vo.customer.CustomerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -30,13 +32,26 @@ public class CustomerController {
@PostMapping("/save")
public CallBack<?> save(Customer entity){
entity.setCreateTime(new Date());
service.insert(entity);
if (entity.getId() != null) {
service.updateByPrimaryKey(entity);
} else {
service.insert(entity);
}
return CallBack.success();
}
@ApiOperation(value = "查询客户信息", notes = "查询全部客户信息")
@GetMapping("/page")
public CallBack<PageInfo<Customer>> page(PageParam pageParam, QueryCustomerForm form) {
public CallBack<PageInfo<CustomerVo>> page(PageParam pageParam, QueryCustomerForm form) {
return CallBack.success(service.page(pageParam, form));
}
@ApiOperation(value = "根据客户id查询客户信息")
@GetMapping("/get")
public CallBack<Customer> get(Integer id) {
if (id == null) {
throw new BaseException("id不能为空");
}
return CallBack.success(service.selectByPrimaryKey(id));
}
}
......@@ -68,7 +68,7 @@ public class UserController {
if (response.isSuccess()) {
SimpleUserListVo vo = JSON.parseObject(response.getBody(), SimpleUserListVo.class);
return ServiceResult.success(vo.getUserlist());
}
}
return ServiceResult.failure("-3", response.getBody());
}
}
package com.enums.customer;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public enum CustomerHasBusinessEnum {
/** 未知 */
NONE("-1","未知"),
/** 是 */
YES("1","有"),
/** 否 */
NO("0","无");
private final String code;
private final String name;
private static final HashMap<String,String> MAP = new HashMap<String,String>();
static {
stream().forEach(e -> {
MAP.put(e.code, e.name);
});
}
private CustomerHasBusinessEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static Map<String, String> getMap(){
return CustomerHasBusinessEnum.MAP;
}
/**
* @return
* @author lpf
* @date: 2019年3月18日 下午5:05:16
*/
public static Stream<CustomerHasBusinessEnum> stream(){
return Stream.of(values());
}
/**
* 判断名称是否有效
* @param name
* @return
* @author lpf
* @date: 2018年6月11日 下午6:30:16
*/
public static boolean isExist(String code) {
return stream().anyMatch(e -> e.code.equals(code));
}
/**
* 根据code 获取名字
* @Title getName
* @param code
* @return String
* @author lpf
* @date 2019年3月18日17:14:18
*/
public static String getName(String code) {
return stream().filter(e -> e.code.equals(code)).findFirst().map(e -> e.name).orElse(NONE.name);
}
/**
* 根据名字 获取code
* @Title getCode
* @param name
* @return String
* @author lpf
* @date 2019年3月18日17:14:18
*/
public static String getCode(String name) {
return stream().filter(e -> e.name.equals(name)).findFirst().map(e -> e.code).orElse(NONE.code);
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
package com.enums.customer;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public enum CustomerSigningEnum {
/** 是 */
YES("1","已签约"),
/** 否 */
NO("0","未签约");
private final String code;
private final String name;
private static final HashMap<String,String> MAP = new HashMap<String,String>();
static {
stream().forEach(e -> {
MAP.put(e.code, e.name);
});
}
private CustomerSigningEnum(String code, String name) {
this.code = code;
this.name = name;
}
public static Map<String, String> getMap(){
return CustomerSigningEnum.MAP;
}
/**
* @return
* @author lpf
* @date: 2019年3月18日 下午5:05:16
*/
public static Stream<CustomerSigningEnum> stream(){
return Stream.of(values());
}
/**
* 判断名称是否有效
* @param name
* @return
* @author lpf
* @date: 2018年6月11日 下午6:30:16
*/
public static boolean isExist(String code) {
return stream().anyMatch(e -> e.code.equals(code));
}
/**
* 根据code 获取名字
* @Title getName
* @param code
* @return String
* @author lpf
* @date 2019年3月18日17:14:18
*/
public static String getName(String code) {
return stream().filter(e -> e.code.equals(code)).findFirst().map(e -> e.name).orElse(NO.name);
}
/**
* 根据名字 获取code
* @Title getCode
* @param name
* @return String
* @author lpf
* @date 2019年3月18日17:14:18
*/
public static String getCode(String name) {
return stream().filter(e -> e.name.equals(name)).findFirst().map(e -> e.code).orElse(NO.code);
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
......@@ -12,7 +12,7 @@ public class QueryCustomerForm {
private String text;
@ApiModelProperty("是否分配了负责人,0全部,1 未分配,2已分配")
private String hasUser;
@ApiModelProperty("商机,''全部 1 有, 0无")
@ApiModelProperty("商机,''全部 1 有, 0无,-1未知")
private String hasBusiness;
@ApiModelProperty("中央级, ''全部 1 是 0 否")
private String central;
......
......@@ -51,10 +51,13 @@ public class Customer {
private String updateName;
@ApiModelProperty("指派时间")
private Date allotTime;
@ApiModelProperty("商机,''全部 1 有, 0无")
/** @see com.enums.CustomerHasBusinessEnum */
@ApiModelProperty("商机,''全部 1 有, 0无,-1未知")
private String hasBusiness;
/** @see com.enums.BooleanStatusEnum */
@ApiModelProperty("中央级, ''全部 1 是 0 否")
private String central;
/** @see com.enums.CustomerSigningEnum */
@ApiModelProperty("签约 '' 全部 1 是 0 否")
private String signing;
}
......@@ -5,9 +5,10 @@ import com.model.customer.Customer;
import com.service.BaseService;
import com.util.PageInfo;
import com.util.PageParam;
import com.vo.customer.CustomerVo;
public interface CustomerService extends BaseService<Customer, Integer>{
PageInfo<Customer> page(PageParam pageParam, QueryCustomerForm form);
PageInfo<CustomerVo> page(PageParam pageParam, QueryCustomerForm form);
}
......@@ -6,13 +6,18 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.enums.BooleanStatusEnum;
import com.enums.customer.CustomerHasBusinessEnum;
import com.enums.customer.CustomerSigningEnum;
import com.form.customer.QueryCustomerForm;
import com.mapper.BaseMapper;
import com.mapper.customer.CustomerMapper;
import com.model.customer.Customer;
import com.service.BaseServiceImpl;
import com.util.BeanUtils;
import com.util.PageInfo;
import com.util.PageParam;
import com.vo.customer.CustomerVo;
@Service
public class CustomerServiceImpl extends BaseServiceImpl<Customer, Integer> implements CustomerService{
......@@ -24,13 +29,18 @@ public class CustomerServiceImpl extends BaseServiceImpl<Customer, Integer> impl
return this.mapper;
}
@Override
public PageInfo<Customer> page(PageParam pageParam, QueryCustomerForm form) {
if (StringUtils.isNotBlank(pageParam.getOrderBy())) {
public PageInfo<CustomerVo> page(PageParam pageParam, QueryCustomerForm form) {
if (StringUtils.isBlank(pageParam.getOrderBy())) {
pageParam.setOrderBy(" createTime desc ");
}
startPage(pageParam);
List<Customer> list = mapper.list(form);
return new PageInfo<>(list);
List<CustomerVo> result = BeanUtils.copyList(list, CustomerVo.class, (r, t) -> {
t.setHasBusinessZh(CustomerHasBusinessEnum.getName(r.getHasBusiness()));
t.setCentralZh(BooleanStatusEnum.getName(r.getCentral()));
t.setSigningZh(CustomerSigningEnum.getName(r.getSigning()));
});
return new PageInfo<>(list, result);
}
......
......@@ -3,6 +3,7 @@ package com.util;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import com.github.pagehelper.Page;
......@@ -60,6 +61,60 @@ public class PageInfo<T> implements Serializable {
this(list, 8);
}
public PageInfo(List<?> list, List<T> target) {
this(list, 8, (p) -> {
p.list = target;
});
}
/**
* 包装Page对象
*
* @param list page结果
* @param navigatePages 页码数量
* @param con 最后执行 消费PageInfo 对象程序
*/
public PageInfo(List<?> list, int navigatePages, Consumer<PageInfo<T>> con) {
if (list instanceof Page) {
Page page = (Page) list;
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.pages = page.getPages();
this.list = page;
this.size = page.size();
this.total = page.getTotal();
//由于结果是>startRow的,所以实际的需要+1
if (this.size == 0) {
this.startRow = 0;
this.endRow = 0;
} else {
this.startRow = page.getStartRow() + 1;
//计算实际的endRow(最后一页的时候特殊)
this.endRow = this.startRow - 1 + this.size;
}
} else if (list instanceof Collection) {
this.pageNum = 1;
this.pageSize = list.size();
this.pages = this.pageSize > 0 ? 1 : 0;
this.size = list.size();
this.total = list.size();
this.startRow = 0;
this.endRow = list.size() > 0 ? list.size() - 1 : 0;
}
if (list instanceof Collection) {
this.navigatePages = navigatePages;
//计算导航页
calcNavigatepageNums();
//计算前后页,第一页,最后一页
calcPage();
//判断页面边界
judgePageBoudary();
}
//
con.accept(this);
}
/**
* 包装Page对象
*
......
package com.vo.customer;
import com.model.customer.Customer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class CustomerVo extends Customer{
@ApiModelProperty("商机,''全部 1 有, 0无,-1未知")
private String hasBusinessZh;
@ApiModelProperty("中央级, ''全部 1 是 0 否")
private String centralZh;
@ApiModelProperty("签约 '' 全部 1 是 0 否")
private String signingZh;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论