张天森
2022-10-12 3c884ccd7b51edf3b36840bf99de5edaa41a38a7
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSanShuoExpertServiceImpl.java
@@ -2,6 +2,7 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.MD5;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -27,6 +28,7 @@
import com.panzhihua.service_community.service.ComStreetService;
import com.panzhihua.service_community.util.MyAESUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -34,6 +36,7 @@
import java.util.Date;
import java.util.List;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
@Service
@@ -59,45 +62,78 @@
     * @return 处理结果
     * */
    @Override
    public R addExpert(ComSanshuoExpertDTO comSanshuoExpertDTO) {
        ComSanshuoExpert expert=new ComSanshuoExpert();
        BeanUtil.copyProperties(comSanshuoExpertDTO,expert);
        //处理id
        if (nonNull(comSanshuoExpertDTO.getUnit())){
            String id = comSanshuoExpertDTO.getUnit();
            String[] split = id.split(",");
            comSanshuoExpertDTO.setUnitId(split[split.length-1]);
        }
        expert.setId(Snowflake.getId());
        expert.setCreateTime(new Date());
        if (expert.getLevel()==2){
            expert.setIndustryCenterId(Long.parseLong(comSanshuoExpertDTO.getUnitId()));
        }else if(expert.getLevel()==3){
            expert.setStreetId(Long.parseLong(comSanshuoExpertDTO.getUnitId()));
        }else if(expert.getLevel()==4){
            expert.setCommunityId(Long.parseLong(comSanshuoExpertDTO.getUnitId()));
        }
        expert.setStatus(1);
        expert.setDelFlag(1);
        int insert = comSanshuoExpertDao.insert(expert);
        if (insert>0){
            try {
                comSanshuoExpertDTO.setPassword(MyAESUtil.Encrypt(comSanshuoExpertDTO.getPassword(),"Ryo7M3n8loC5Abcd"));
            } catch (Exception e) {
                e.printStackTrace();
    @Transactional(rollbackFor = Exception.class)
    public R addOrUpdateExpert(ComSanshuoExpertDTO comSanshuoExpertDTO) {
        if (isNull(comSanshuoExpertDTO.getId())){
            //是否重名
            List<ComSanshuoExpert> checkExpert=comSanshuoExpertDao.selectExpertByNameOrPhoneOrAccount(comSanshuoExpertDTO);
            if (checkExpert.size() != 0){
                return R.fail("账号信息有重复");
            }
            //生成后台账号
            AdministratorsUserVO user=new AdministratorsUserVO();
            user.setUserId(Snowflake.getId());
            user.setAccount(comSanshuoExpertDTO.getAccount());
            user.setPassword(comSanshuoExpertDTO.getPassword());
            user.setName(comSanshuoExpertDTO.getName());
            user.setType(11);
            user.setImageUrl(comSanshuoExpertDTO.getAvatar());
            return userService.sanShuoAddUser(user);
            ComSanshuoExpert expert=new ComSanshuoExpert();
            BeanUtil.copyProperties(comSanshuoExpertDTO,expert);
            if (nonNull(comSanshuoExpertDTO.getUnit())){
                String id = comSanshuoExpertDTO.getUnit();
                String[] split = id.split(",");
                expert.setUnitId(split[split.length-1]);
            }
            expert.setId(Snowflake.getId());
            expert.setCreateTime(new Date());
            if (expert.getLevel()==2){
                expert.setIndustryCenterId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comSanshuoIndustryCenterDao.selectById(expert.getUnitId()).getName()+"调解站");
            }else if(expert.getLevel()==3){
                expert.setStreetId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comStreetDAO.selectById(expert.getUnitId()).getName()+"调解站");
            }else if(expert.getLevel()==4){
                expert.setCommunityId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comActDAO.selectById(expert.getUnitId()).getName()+"调解站");
            }
            expert.setStatus(1);
            expert.setDelFlag(1);
            int insert = comSanshuoExpertDao.insert(expert);
            if (insert>0){
                try {
                    comSanshuoExpertDTO.setPassword(comSanshuoExpertDTO.getPassword());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //生成后台账号
                AdministratorsUserVO user=new AdministratorsUserVO();
                user.setUserId(Snowflake.getId());
                user.setAccount(comSanshuoExpertDTO.getAccount());
                user.setPassword(comSanshuoExpertDTO.getPassword());
                user.setName(comSanshuoExpertDTO.getName());
                user.setType(11);
                user.setImageUrl(comSanshuoExpertDTO.getAvatar());
                user.setPhone(comSanshuoExpertDTO.getPhone());
                return R.ok(userService.sanShuoAddUser(user));
            }
        }else {
            ComSanshuoExpert expert=new ComSanshuoExpert();
            BeanUtil.copyProperties(comSanshuoExpertDTO,expert);
            if (nonNull(comSanshuoExpertDTO.getUnit())){
                String id = comSanshuoExpertDTO.getUnit();
                String[] split = id.split(",");
                expert.setUnitId(split[split.length-1]);
            }
            expert.setUpdateTime(new Date());
            if (expert.getLevel()==2){
                expert.setIndustryCenterId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comSanshuoIndustryCenterDao.selectById(expert.getUnitId()).getName()+"调解站");
            }else if(expert.getLevel()==3){
                expert.setStreetId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comStreetDAO.selectById(expert.getUnitId()).getName()+"调解站");
            }else if(expert.getLevel()==4){
                expert.setCommunityId(Long.parseLong(expert.getUnitId()));
                expert.setUnit(comActDAO.selectById(expert.getUnitId()).getName()+"调解站");
            }
            return R.ok(comSanshuoExpertDao.updateById(expert));
        }
        return R.fail("添加失败");
        return R.fail("操作失败");
    }
    /**
     * 后台获取专家列表
@@ -130,6 +166,10 @@
                }
            }
        }
        if (loginUserInfo.getAccount().equals("admin") || loginUserInfo.getAccount().equals("xiqu")){
            id=null;
            range=null;
        }
        return R.ok(comSanshuoExpertDao.expertPage(new Page(page,size),keyWord,range,id));
    }
@@ -161,6 +201,7 @@
        return R.ok(expertShowVOS);
    }
    /**
     * 专家级别与单位范围
     * */
@@ -174,16 +215,20 @@
                    vo.setLevel(i);
                    if (i==2){
                        //设置行业分中心为childList
                        vo.setId(2L);
                        vo.setChildList(comSanshuoIndustryCenterDao.indstryList());
                        vo.setName("行业分中心");
                    }else if (i==3){
                        vo.setId(3L);
                        vo.setChildList(comSanshuoIndustryCenterDao.streetList());
                        vo.setName("街道调解站");
                    }else if (i==4){
                        vo.setId(4L);
                        vo.setChildList(comSanshuoIndustryCenterDao.communityList());
                        vo.setName("社区调解站");
                    }else if(i==1){
                        vo.setName("三说话会堂");
                        vo.setId(1L);
                        vo.setName("三说会堂");
                    }
                    list.add(vo);
                }
@@ -238,28 +283,28 @@
     * 小程序获取专家列表
     * */
    @Override
    public R selectExpertList() {
        List<ComSanshuoExpert> comSanshuoExperts = comSanshuoExpertDao.selectList(new QueryWrapper<ComSanshuoExpert>().lambda().eq(ComSanshuoExpert::getStatus, 1).eq(ComSanshuoExpert::getDelFlag, 1));
        //设置成功率
        for (ComSanshuoExpert comSanshuoExpert : comSanshuoExperts) {
            //查询成功率
            Integer count = comEventMapper.selectCount(new QueryWrapper<ComEvent>().lambda().eq(ComEvent::getSpecialistId, comSanshuoExpert.getId()).eq(ComEvent::getEventProcessStatus, 6));
            Integer successCount = comEventMapper.selectCount(new QueryWrapper<ComEvent>().lambda().eq(ComEvent::getSpecialistId, comSanshuoExpert.getId()).eq(ComEvent::getEventProcessStatus, 6).eq(ComEvent::getEventResult, 2));
            comSanshuoExpert.setCount(count);
            if (nonNull(count) && !count.equals(0)){
                comSanshuoExpert.setCount(count);
                if (nonNull(successCount) && !count.equals(successCount)){
                    //计算成功率
                    comSanshuoExpert.setRate(NumberUtil.div(successCount, count,2));
                }else {
                    comSanshuoExpert.setRate(new BigDecimal(0));
                }
    public R selectExpertList(Integer type,Long id,Long cid) {
        List<ComSanshuoExpert> list=new ArrayList<>();
        if (type.equals(1)){
            //行业分中心下属专家
            list=comSanshuoExpertDao.selectList(new QueryWrapper<ComSanshuoExpert>().lambda().
                    eq(ComSanshuoExpert::getStatus, 1).
                    eq(ComSanshuoExpert::getDelFlag,1 ).
                    eq(ComSanshuoExpert::getIndustryCenterId, id));
        }else {
            if (nonNull(id)){
                list=comSanshuoExpertDao.selectList(new QueryWrapper<ComSanshuoExpert>().lambda().
                        eq(ComSanshuoExpert::getStatus, 1).
                        eq(ComSanshuoExpert::getDelFlag,1 ).
                        eq(ComSanshuoExpert::getCommunityId, id));
            }else {
                comSanshuoExpert.setCount(0);
                list=comSanshuoExpertDao.selectList(new QueryWrapper<ComSanshuoExpert>().lambda().
                        eq(ComSanshuoExpert::getStatus, 1).
                        eq(ComSanshuoExpert::getDelFlag,1 ).
                        eq(ComSanshuoExpert::getCommunityId,cid ));
            }
        }
        return R.ok(comSanshuoExperts);
        return R.ok(list);
    }