|
@@ -1,17 +1,24 @@
|
|
|
package com.fjhx.service.customer.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fjhx.utils.WrapperUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.base.BaseEntity;
|
|
|
+import com.fjhx.base.Condition;
|
|
|
import com.fjhx.entity.customer.Customer;
|
|
|
-import com.fjhx.params.customer.CustomerVo;
|
|
|
+import com.fjhx.entity.customer.CustomerLink;
|
|
|
import com.fjhx.mapper.customer.CustomerMapper;
|
|
|
+import com.fjhx.params.customer.CustomerVo;
|
|
|
+import com.fjhx.service.customer.CustomerLinkService;
|
|
|
import com.fjhx.service.customer.CustomerService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
* <p>
|
|
@@ -24,31 +31,67 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CustomerLinkService customerLinkService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<Customer> getPage(Map<String, String> condition) {
|
|
|
+ public Page<Customer> getPage(Condition condition) {
|
|
|
+ String keyword = condition.getKeyword();
|
|
|
|
|
|
- QueryWrapper<Customer> wrapper = Wrappers.query();
|
|
|
+ LambdaQueryWrapper<Customer> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.and(ObjectUtil.isNotEmpty(keyword), q -> q
|
|
|
+ .like(Customer::getCode, keyword)
|
|
|
+ .like(Customer::getName, keyword)
|
|
|
+ );
|
|
|
|
|
|
- WrapperUtil.init(condition, wrapper)
|
|
|
- .createTimeDesc();
|
|
|
|
|
|
Page<Customer> page = page(condition, wrapper);
|
|
|
+ List<Customer> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void add(CustomerVo customerVo) {
|
|
|
save(customerVo);
|
|
|
+
|
|
|
+ List<CustomerLink> customerLinkList = customerVo.getCustomerLinkList();
|
|
|
+ customerLinkList.forEach(customerLink -> customerLink.setCustomerId(customerVo.getId()));
|
|
|
+
|
|
|
+ customerLinkService.saveBatch(customerLinkList);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void edit(CustomerVo customerVo) {
|
|
|
+
|
|
|
updateById(customerVo);
|
|
|
+
|
|
|
+
|
|
|
+ List<CustomerLink> customerLinkList = customerVo.getCustomerLinkList();
|
|
|
+ customerLinkList.forEach(customerLink -> customerLink.setCustomerId(customerVo.getId()));
|
|
|
+ customerLinkService.saveOrUpdateBatch(customerLinkList);
|
|
|
+
|
|
|
+
|
|
|
+ List<Long> customerLinkIdList = customerLinkList.stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
+ customerLinkService.remove(
|
|
|
+ Wrappers.<CustomerLink>lambdaQuery()
|
|
|
+ .eq(CustomerLink::getCustomerId, customerVo.getId())
|
|
|
+ .notIn(BaseEntity::getId, customerLinkIdList));
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void delete(CustomerVo customerVo) {
|
|
|
removeById(customerVo.getId());
|
|
|
+ customerLinkService.remove(CustomerLink::getCustomerId, customerVo.getId());
|
|
|
}
|
|
|
|
|
|
}
|