|
@@ -1,9 +1,18 @@
|
|
|
package com.dayou.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.dayou.dto.CustomerDTO;
|
|
|
import com.dayou.entity.Customer;
|
|
|
+import com.dayou.entity.Districts;
|
|
|
import com.dayou.mapper.CustomerMapper;
|
|
|
import com.dayou.service.ICustomerService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayou.service.IDistrictsService;
|
|
|
+import com.fasterxml.jackson.databind.util.BeanUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -19,6 +28,9 @@ import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.ArrayList;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -36,25 +48,49 @@ import com.dayou.enums.BatchTaskTypeEnum;
|
|
|
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IDistrictsService districtsService;
|
|
|
+
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public Page<Customer> selectPage(Page page,Customer customer){
|
|
|
- return this.page(page, new QueryWrapper<Customer>(customer));
|
|
|
+ public Page<CustomerDTO> selectPage(Page page,Customer customer){
|
|
|
+ Page result = this.page(page, new QueryWrapper<Customer>(customer));
|
|
|
+ List<CustomerDTO> xRecords = new ArrayList<>();
|
|
|
+ List<Customer> records = result.getRecords();
|
|
|
+ records.stream().forEach(x->{
|
|
|
+ CustomerDTO dto = new CustomerDTO();
|
|
|
+ BeanUtils.copyProperties(x,dto);
|
|
|
+ if (StrUtil.isNotEmpty(x.getCity())){
|
|
|
+ List<Long> citys = JSON.parseArray(x.getCity(), Long.class);
|
|
|
+ List<Districts> list = districtsService.list(new LambdaQueryWrapper<Districts>().select(Districts::getExtName).in(Districts::getId, citys));
|
|
|
+ dto.setFirstCity(list.get(1).getExtName());
|
|
|
+ dto.setSecCity(list.get(2).getExtName());
|
|
|
+ }
|
|
|
+ xRecords.add(dto);
|
|
|
+ });
|
|
|
+ result.setRecords(xRecords);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Customer detail(Long id){
|
|
|
- return this.getById(id);
|
|
|
+ public CustomerDTO detail(Long id){
|
|
|
+ Customer byId = this.getById(id);
|
|
|
+ CustomerDTO dto = new CustomerDTO();
|
|
|
+ BeanUtils.copyProperties(byId,dto);
|
|
|
+ dto.setCitys(JSON.parseArray(byId.getCity(),Long.class));
|
|
|
+ return dto;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean add(Customer customer){
|
|
|
+ public Boolean add(CustomerDTO customer){
|
|
|
+ customer.setCity(JSON.toJSONString(customer.getCitys()));
|
|
|
return this.save(customer);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean update(Customer customer){
|
|
|
+ public Boolean update(CustomerDTO customer){
|
|
|
+ customer.setCity(JSON.toJSONString(customer.getCitys()));
|
|
|
return this.updateById(customer);
|
|
|
}
|
|
|
|