lishuai
2023-12-26 1293d3dba10c4e291dfbce4c936f952875557edb
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
@@ -15,12 +15,14 @@
import com.doumee.dao.business.DeviceRoleMapper;
import com.doumee.dao.business.model.Device;
import com.doumee.dao.business.model.DeviceRole;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.web.response.DeviceRoleVO;
import com.doumee.service.business.DeviceRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.MemberService;
import io.swagger.models.auth.In;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -45,6 +47,8 @@
    @Autowired
    private DeviceRoleMapper deviceRoleMapper;
    @Autowired
    private MemberService memberService;
    @Override
@@ -52,8 +56,8 @@
        // 获取之前是否存在默认门禁组
        DeviceRole newDeviceRole = null;
        if(Constants.ONE == deviceRole.getStatus() && null != deviceRole.getType()) {
            newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType());
        if(null != deviceRole.getType()) {
            newDeviceRole = getDeviceRole(deviceRole.getType());
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        if(null != newDeviceRole) {
@@ -62,8 +66,7 @@
            updateDeviceRole.setId(newDeviceRole.getId());
            updateDeviceRole.setEdirot(loginUserInfo.getId().toString());
            updateDeviceRole.setEditDate(new Date());
            updateDeviceRole.setIsdeleted(Constants.ONE);
            updateDeviceRole.setStatus(Constants.ZERO);
            updateDeviceRole.setIsDefault(Constants.ONE);
            deviceRoleMapper.updateById(updateDeviceRole);
        }
        DeviceRole insert = new DeviceRole();
@@ -74,7 +77,7 @@
        insert.setIsdeleted(Constants.ZERO);
        insert.setRemark(deviceRole.getRemark());
        insert.setName(deviceRole.getName());
        insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
        insert.setIsDefault(deviceRole.getIsDefault());
        insert.setType(deviceRole.getType());
        insert.setDoorIds(deviceRole.getDoorIds());
        insert.setDoorNames(deviceRole.getDoorNames());
@@ -110,7 +113,19 @@
    @Override
    public void updateById(DeviceRole deviceRole) {
        deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
        DeviceRole newDeviceRole = null;
        if(null != deviceRole.getType()) {
            newDeviceRole = getDeviceRole(deviceRole.getType());
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        if(null != newDeviceRole) {
            DeviceRole update = new DeviceRole();
            update.setEdirot(loginUserInfo.getId().toString());
            update.setEditDate(new Date());
            update.setId(newDeviceRole.getId());
            update.setIsDefault(Constants.ONE);
            deviceRoleMapper.updateById(update);
        }
        deviceRoleMapper.updateById(deviceRole);
    }
@@ -118,8 +133,8 @@
    public void updateStatusById(DeviceRole deviceRole) {
        // 获取之前是否存在默认门禁组
        DeviceRole newDeviceRole = null;
        if(Constants.ONE == deviceRole.getStatus() && null != deviceRole.getType()) {
            newDeviceRole = getDeviceRole(deviceRole.getStatus(), deviceRole.getType());
        if(null != deviceRole.getType()) {
            newDeviceRole = getDeviceRole(deviceRole.getType());
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        List<DeviceRole> deviceRoleList = new ArrayList<>();
@@ -145,12 +160,11 @@
        }
    }
    private DeviceRole getDeviceRole(Integer status, Integer type) {
    private DeviceRole getDeviceRole(String type) {
        LambdaQueryWrapper<DeviceRole> query = new LambdaQueryWrapper<>();
        query.eq(DeviceRole::getIsdeleted,Constants.ZERO)
                .eq(DeviceRole::getIsDefault,Constants.ZERO)
                .eq(DeviceRole::getType,type)
                .eq(DeviceRole::getStatus,status);
                .eq(DeviceRole::getType,type);
        // 查询是否有默认门禁组,只能有一组默认门禁组
        DeviceRole getDeviceRole = deviceRoleMapper.selectOne(query);
        return getDeviceRole;
@@ -217,8 +231,16 @@
        if (pageWrap.getModel().getIsDefault() != null) {
            queryWrapper.lambda().eq(DeviceRole::getIsDefault, pageWrap.getModel().getIsDefault());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.lambda().eq(DeviceRole::getType, pageWrap.getModel().getType());
        if (StringUtils.isNotBlank(pageWrap.getModel().getType())) {
            if(pageWrap.getModel().getType().length() > 1) {
                String[] types = pageWrap.getModel().getType().split(",");
                queryWrapper.lambda()
                        .eq(DeviceRole::getType, types[0])
                        .or()
                        .eq(DeviceRole::getType, types[1]);
            }else {
                queryWrapper.lambda().eq(DeviceRole::getType, pageWrap.getModel().getType());
            }
        }
        if (pageWrap.getModel().getDoorIds() != null) {
            queryWrapper.lambda().eq(DeviceRole::getDoorIds, pageWrap.getModel().getDoorIds());
@@ -235,9 +257,6 @@
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(DeviceRole::getStatus, pageWrap.getModel().getStatus());
        }
        queryWrapper.select("t_aa.*," +
                "(SELECT count(DISTINCT `KEY`) FROM `test` WHERE `test`.`key` = `t_aa`.id ) ");
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
@@ -245,7 +264,18 @@
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(deviceRoleMapper.selectPage(page, queryWrapper));
        IPage<DeviceRole> newPage = deviceRoleMapper.selectPage(page, queryWrapper);
        if(null != newPage && newPage.getRecords().size() > 0) {
            List<DeviceRole> deviceRoleList = newPage.getRecords();
            for (DeviceRole dto:deviceRoleList) {
                Member member = new Member();
                member.setIsdeleted(Constants.ZERO);
                member.setRoleIdParam("["+dto.getId()+"]");
                dto.setMemberNum((int) memberService.count(member));
            }
            newPage.setRecords(deviceRoleList);
        }
        return PageData.from(newPage);
    }
    @Override
@@ -259,7 +289,7 @@
        List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                .eq(DeviceRole::getType,type)
                .eq(DeviceRole::getIsdeleted, Constants.ZERO)
                .eq(DeviceRole::getStatus, Constants.ZERO)
                .eq(DeviceRole::getStatus, Constants.ONE)
        );
        List<DeviceRoleVO> deviceRoleVOList = new ArrayList<>();
        for (DeviceRole deviceRole:deviceRoleList) {