2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-08 93d6fdb255ebd9d33adebc4e96ecc5f74b6281ea
Merge remote-tracking branch 'origin/master'
已修改5个文件
103 ■■■■ 文件已修改
dao/src/main/java/com/sandu/ximon/dao/domain/Client.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/resources/mapper/ClientMapper.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/ClientController.java 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/param/ClientPrarm.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
dao/src/main/java/com/sandu/ximon/dao/domain/Client.java
@@ -43,6 +43,11 @@
     */
    private String mobile;
    /**
     * 密码
     */
    private String password;
    /*灯杆数量*/
    private Integer countLight;
dao/src/main/resources/mapper/ClientMapper.xml
@@ -10,6 +10,7 @@
        <result property="clientSuperior" column="client_superior" jdbcType="VARCHAR"/>
        <result property="linkMan" column="linkman" jdbcType="VARCHAR"/>
        <result property="mobile" column="mobile" jdbcType="VARCHAR"/>
        <result property="password" column="password" jdbcType="VARCHAR"/>
        <result property="countLight" column="count_light" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>
ximon-admin/src/main/java/com/sandu/ximon/admin/controller/ClientController.java
@@ -13,10 +13,11 @@
import com.sandu.ximon.dao.domain.Client;
import com.sandu.ximon.dao.enums.AdministratorEnums;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 *客户模块
 * 客户模块
 */
@RestController
@AllArgsConstructor
@@ -26,32 +27,32 @@
    private final ClientService clientService;
    @PostMapping("/add")
    public ResponseVO<Object> addClient(@RequestBody ClientPrarm clientPrarm){
    public ResponseVO<Object> addClient(@RequestBody @Validated ClientPrarm clientPrarm) {
        boolean b = clientService.addClient(clientPrarm);
        if(b){
        if (b) {
            return ResponseUtil.success("添加成功");
        }else {
        } else {
            return ResponseUtil.fail("添加失败");
        }
    }
    @PostMapping ("/update/{id}")
    public ResponseVO<Object> updateClient(@PathVariable Long id,@RequestBody ClientPrarm clientPrarm){
        boolean b = clientService.updateClient(id,clientPrarm);
        if(b){
    @PostMapping("/update/{id}")
    public ResponseVO<Object> updateClient(@PathVariable Long id, @RequestBody @Validated ClientPrarm clientPrarm) {
        boolean b = clientService.updateClient(id, clientPrarm);
        if (b) {
            return ResponseUtil.success("更新成功");
        }else {
        } else {
            return ResponseUtil.fail("更新失败");
        }
    }
    @PostMapping("/delete/{id}")
    public ResponseVO<Object> deleteClient(@PathVariable Long id){
    public ResponseVO<Object> deleteClient(@PathVariable Long id) {
        boolean b = clientService.deleteClient(id);
        if(b){
        if (b) {
            return ResponseUtil.success("删除成功");
        }else {
        } else {
            return ResponseUtil.fail("删除失败");
        }
    }
@@ -72,13 +73,13 @@
    public ResponseVO<Object> listLikeClient(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) {
        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
        LambdaQueryWrapper<Client> wrapper = Wrappers.lambdaQuery(Client.class);
        if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())){
            wrapper.eq(Client::getSuperiorId,SecurityUtils.getUserId());
        if (AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) {
            wrapper.eq(Client::getSuperiorId, SecurityUtils.getUserId());
        }
        if(null!=keyword){
            wrapper.like(Client::getClientName,keyword)
                    .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getMobile,keyword))
                    .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getLinkMan,keyword));
        if (null != keyword) {
            wrapper.like(Client::getClientName, keyword)
                    .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getMobile, keyword))
                    .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getLinkMan, keyword));
        }
        return ResponseUtil.successPage(clientService.list(wrapper));
    }
ximon-admin/src/main/java/com/sandu/ximon/admin/param/ClientPrarm.java
@@ -15,5 +15,7 @@
    private String linkMan;
    @NotEmpty
    private String mobile;
    @NotEmpty
    private String password;
}
ximon-admin/src/main/java/com/sandu/ximon/admin/service/ClientService.java
@@ -1,5 +1,6 @@
package com.sandu.ximon.admin.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.object.BaseConditionVO;
@@ -9,6 +10,7 @@
import com.sandu.ximon.dao.domain.Client;
import com.sandu.ximon.dao.mapper.ClientMapper;
import lombok.AllArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -18,10 +20,17 @@
public class ClientService extends BaseServiceImpl<ClientMapper, Client> {
    private final ClientMapper clientMapper;
    private final PasswordEncoder passwordEncoder;
    public boolean addClient(ClientPrarm clientPrarm) {
        if (getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, clientPrarm.getClientName().trim())) != null) {
            throw new BusinessException("该用户名已存在!");
        }
        Client client = new Client();
        if (clientPrarm.getClientSuperior() != null&&!"".equals(clientPrarm.getClientSuperior())) {
        if (clientPrarm.getClientSuperior() != null && !"".equals(clientPrarm.getClientSuperior())) {
            Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, clientPrarm.getClientSuperior()));
            if (one != null) {
                client.setSuperiorId(one.getId());
@@ -33,6 +42,7 @@
        client.setLinkMan(clientPrarm.getLinkMan());
        client.setMobile(clientPrarm.getMobile());
        client.setClientSuperior(clientPrarm.getClientSuperior());
        client.setPassword(passwordEncoder.encode(clientPrarm.getPassword()));
        return save(client);
@@ -40,15 +50,26 @@
    public boolean updateClient(Long id, ClientPrarm clientPrarm) {
        //判断用户是否存在
        Client one = getById(id);
        if (one == null) {
            throw new BusinessException("该客户不存在");
        }
        //判断用户名是否重复
        if (getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getClientName, clientPrarm.getClientName().trim())) != null) {
            throw new BusinessException("该用户名已存在!");
        }
        //判断上级用户是否存在
        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());
            if (superior != null) {
                if (superior.getId().equals(one.getId())) {
                    throw new BusinessException("上级客户为本账户!");
                } else {
                    client.setSuperiorId(superior.getId());
                }
            } else {
                throw new BusinessException("上级客户不存在");
            }
@@ -58,38 +79,50 @@
        client.setLinkMan(clientPrarm.getLinkMan());
        client.setMobile(clientPrarm.getMobile());
        client.setClientSuperior(clientPrarm.getClientSuperior());
        client.setPassword(passwordEncoder.encode(clientPrarm.getPassword()));
        // update(client);
        return updateById(client);
    }
    public boolean deleteClient(Long id) {
        //判断删除用户是否存在
        Client one = getById(id);
        if (one == null) {
            throw new BusinessException("该客户不存在");
        }
        //判断删除的用户有无下级用户
        LambdaQueryWrapper<Client> lambdaQueryWrapper = Wrappers.lambdaQuery(Client.class).eq(Client::getSuperiorId, id);
        List<Client> list = list(lambdaQueryWrapper);
        if (list != null && list.size() != 0) {
            throw new BusinessException("删除的用户下有下级用户,不允许删除");
        }
        return removeById(id);
    }
    public List<Client>  clientList(Long userId, BaseConditionVO baseConditionVO) {
        return clientMapper.clientList(userId,baseConditionVO.getPageNo(),baseConditionVO.getPageSize());
    public List<Client> clientList(Long userId, BaseConditionVO baseConditionVO) {
        return clientMapper.clientList(userId, baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
    }
    public Client findByPhone(String phone) {
        return getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getMobile, phone).last("limit 1"));
    }
    /**\
    /**
     * \
     * 其他类用来查找客户id使用  如果没有上级客户 这返回用户ID
     *
     * @param
     * @return
     */
    public Long getClientId(){
    public Long getClientId() {
        Long userId = SecurityUtils.getUserId();
        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
        if(one!=null&&one.getSuperiorId()!=null){
        if (one != null && one.getSuperiorId() != null) {
            return one.getSuperiorId();
        }else {
        } else {
            return userId;
        }
@@ -97,14 +130,15 @@
    /**
     * 一级客户返回false  二级客户返回true
     *
     * @return
     */
    public boolean findClientId(){
    public boolean findClientId() {
        Long userId = SecurityUtils.getUserId();
        Client one = getOne(Wrappers.lambdaQuery(Client.class).eq(Client::getId, userId));
        if(one!=null&&one.getSuperiorId()!=null){
        if (one != null && one.getSuperiorId() != null) {
            return true;
        }else {
        } else {
            return false;
        }