Skip to content

Instantly share code, notes, and snippets.

@youzipi
Created July 23, 2016 05:53
Show Gist options
  • Save youzipi/6c5aa531fd373bce1470b09cb1df08b6 to your computer and use it in GitHub Desktop.
Save youzipi/6c5aa531fd373bce1470b09cb1df08b6 to your computer and use it in GitHub Desktop.
service findPageBeanByForm
/**
* 按经销商id+[分页]查询
*
* @return
*/
@Override
public Pageable<LicenseVo> findByForm(LicenseForm form) {
BrandLicenseCustomerExample example = form2example(form);
Pageable<LicenseVo> pb = new Pageable<>(form.getPage(), form.getSize());
pb.setTotal(licenseCustomerMapper.countByExample(example));
/**
* 构造example,通过 前台传回的 PageRequestParam
* KKK findByForm demo
* @return
*/
private BrandLicenseCustomerExample form2example(LicenseForm form) {
BrandLicenseCustomerExample example = new BrandLicenseCustomerExample();
BrandLicenseCustomerExample.Criteria criteria = example.createCriteria();
//area
if (form.getProvinceId() != null) {
criteria.andCustomerProvinceIdEqualTo(form.getProvinceId());
if (form.getCityId() != null) {
criteria.andCustomerCityIdEqualTo(form.getCityId());
}
}
// brandId
if (form.getBrandId() != null) {
criteria.andBrandIdEqualTo(form.getBrandId());
}
// brandName %str%
if (StringUtils.isNotBlank(form.getCustomerName())) {
String customerName = form.getCustomerName();
CustomerExample customerExample = new CustomerExample();
customerExample.createCriteria().andCustomerUsernameLike("%" + customerName + "%");
List<Customer> customers = basicCustomerMapper.selectByExample(customerExample);
List<Long> customerIds = customers.parallelStream()
.map(Customer::getCustomerId)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(customerIds)) {
example.getOredCriteria().get(0).andCustomerIdIn(customerIds);
} else {
example.getOredCriteria().get(0).andCustomerIdEqualTo(-1L); //没有匹配customerName的经销商
}
} else {
if (form.getCustomerId() != null) {
criteria.andCustomerIdEqualTo(form.getCustomerId());
}
}
//undeleted
criteria.andDelFlagEqualTo("0");
//pagination
String limits = "license_id limit " + ((form.getPage() - 1) * form.getSize()) + "," + form.getSize();//todo
example.setOrderByClause(limits);
return example;
}
List<LicenseVo> list = licenseCustomerMapper.selectByExample(example)
.parallelStream()
.map(this::bean2Vo)
.map(this::withBrandInfo)
.map(this::withCustomerInfo)
.collect(Collectors.toList());
pb.setList(list);
return pb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment