| | |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ClientService extends BaseServiceImpl<ClientMapper, Client> { |
| | | |
| | | private final ClientMapper clientMapper; |
| | | |
| | | public boolean addClient(ClientPrarm clientPrarm) { |
| | | Client client=new Client(); |
| | | Client client = new Client(); |
| | | if (clientPrarm.getClientSuperior() != null) { |
| | | Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, clientPrarm.getClientSuperior())); |
| | | if (one != null) { |
| | | client.setSuperiorId(one.getId()); |
| | | } else { |
| | | throw new BusinessException("上级客户不存在"); |
| | | } |
| | | } |
| | | client.setClientName(clientPrarm.getClientName()); |
| | | client.setLinkMan(clientPrarm.getLinkMan()); |
| | | client.setMobile(clientPrarm.getMobile()); |
| | | client.setClientSuperior(clientPrarm.getClientSuperior()); |
| | | |
| | | |
| | | return save(client); |
| | | } |
| | | |
| | | |
| | | public boolean updateClient(Long id,ClientPrarm clientPrarm){ |
| | | public boolean updateClient(Long id, ClientPrarm clientPrarm) { |
| | | //Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, id)); |
| | | Client one=getById(id); |
| | | if(one==null){ |
| | | Client one = getById(id); |
| | | if (one == null) { |
| | | throw new BusinessException("该客户不存在"); |
| | | } |
| | | Client client=new Client(); |
| | | Client client = new Client(); |
| | | if (clientPrarm.getClientSuperior() != null) { |
| | | Client superior = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, clientPrarm.getClientSuperior())); |
| | | if (one != null) { |
| | | client.setSuperiorId(superior.getId()); |
| | | } else { |
| | | throw new BusinessException("上级客户不存在"); |
| | | } |
| | | } |
| | | client.setId(id); |
| | | client.setClientName(clientPrarm.getClientName()); |
| | | client.setLinkMan(clientPrarm.getLinkMan()); |
| | | client.setMobile(clientPrarm.getMobile()); |
| | | client.setClientSuperior(clientPrarm.getClientSuperior()); |
| | | |
| | | // update(client); |
| | | return updateById(client); |
| | | // update(client); |
| | | return updateById(client); |
| | | } |
| | | |
| | | public boolean deleteClient(Long id){ |
| | | Client one=getById(id); |
| | | public boolean deleteClient(Long id) { |
| | | Client one = getById(id); |
| | | if (one == null) { |
| | | throw new BusinessException("该客户不存在"); |
| | | } |
| | | return removeById(id); |
| | | } |
| | | |
| | | public List<Client> clientList(Long userId) { |
| | | return clientMapper.clientList(userId); |
| | | } |
| | | |
| | | public Client findByPhone(String phone) { |
| | | return getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getMobile, phone).last("limit 1")); |
| | | } |
| | | } |