|
@@ -0,0 +1,140 @@
|
|
|
+package cn.cslg.permission.service;
|
|
|
+
|
|
|
+import cn.cslg.permission.common.model.dto.ClientDTO;
|
|
|
+import cn.cslg.permission.common.utils.*;
|
|
|
+import cn.cslg.permission.domain.Client;
|
|
|
+import cn.cslg.permission.domain.Personnel;
|
|
|
+import cn.cslg.permission.mapper.ClientMapper;
|
|
|
+import cn.cslg.permission.service.associate.AssoTenantClientService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 委托方表 服务类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author 王岩
|
|
|
+ * @since 2022-02-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
+public class ClientService extends ServiceImpl<ClientMapper, Client> {
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final PersonnelService personnelService;
|
|
|
+ private final AssoTenantClientService assoTenantClientService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author lrj
|
|
|
+ * @param params
|
|
|
+ * @description 分页获得客户列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<Client> getPageList(ClientDTO params) {
|
|
|
+ LambdaQueryWrapper<Client> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (StringUtils.isNotEmpty(params.getName())) {
|
|
|
+ queryWrapper.like(Client::getName, params.getName());
|
|
|
+ }
|
|
|
+ if(params.getTenantId()!=null){
|
|
|
+
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ queryWrapper.isNotNull(Client::getTenantId);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc(Client::getCreateTime);
|
|
|
+ IPage<Client> lst = this.page(new Page<>(params.getCurrent(), params.getSize()), queryWrapper);
|
|
|
+ List<Client> list = this.page(new Page<>(params.getCurrent(), params.getSize()), queryWrapper).getRecords();
|
|
|
+ this.loadClient(list);
|
|
|
+ lst.setRecords(list);
|
|
|
+ return lst;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Client getClientByName(String name) {
|
|
|
+ LambdaQueryWrapper<Client> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Client::getName, name);
|
|
|
+ return this.getOne(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Client> getClientByTenant(Integer tenantId) {
|
|
|
+ LambdaQueryWrapper<Client> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Client::getTenantId, tenantId);
|
|
|
+ return this.list(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @autor lrj
|
|
|
+ * @param client
|
|
|
+ * @return
|
|
|
+ * @descrption 添加客户
|
|
|
+ */
|
|
|
+ public String add(Client client) {
|
|
|
+ client.setCreateBy(loginUtils.getId());
|
|
|
+ client.setStatus(1);
|
|
|
+ client.insert();
|
|
|
+ return Response.success(client.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @autor lrj
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ * @description 删除客户
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String delete(Integer id) {
|
|
|
+ //删除客户的关联信息
|
|
|
+ assoTenantClientService.deleteApplicationTenant(id,null);
|
|
|
+ this.removeById(id);
|
|
|
+ return Response.success(true);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * @autor lrj
|
|
|
+ * @param client
|
|
|
+ * @return
|
|
|
+ * @description 修改客户
|
|
|
+ */
|
|
|
+ public String edit(Client client) {
|
|
|
+ Client temp = this.getClientByName(client.getName());
|
|
|
+ if (temp != null && !temp.getId().equals(client.getId())) {
|
|
|
+ return Response.error("客户名称已存在");
|
|
|
+ }
|
|
|
+ client.updateById();
|
|
|
+ return Response.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @author 李仁杰
|
|
|
+ * @description 装载客户
|
|
|
+ */
|
|
|
+ public void loadClient(List<Client> clients){
|
|
|
+ List<Integer> personIds =clients.stream().map(Client::getPersonnelId).collect(Collectors.toList());
|
|
|
+ LambdaQueryWrapper<Personnel> queryWrapper =new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.select(Personnel::getPersonnelName)
|
|
|
+ .select(Personnel::getId);
|
|
|
+ queryWrapper.in(Personnel::getId,personIds);
|
|
|
+ List<Personnel> personnels = personnelService.list(queryWrapper);
|
|
|
+ for (Client client : clients) {
|
|
|
+ for (Personnel personnel : personnels) {
|
|
|
+ if (client.getPersonnelId() != null) {
|
|
|
+ if (client.getPersonnelId().equals(personnel.getId())) {
|
|
|
+ client.setPersonnelName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|