jiaosong
2023-12-06 d510d441a45178cc24bfaf516715ef082ab1507b
#门禁角色设置
已修改3个文件
101 ■■■■■ 文件已修改
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/DeviceRole.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceRoleService.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmvisit_service/src/main/java/com/doumee/dao/business/model/DeviceRole.java
@@ -1,5 +1,6 @@
package com.doumee.dao.business.model;
import com.baomidou.mybatisplus.annotation.TableField;
import com.doumee.core.annotation.excel.ExcelColumn;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -17,7 +18,7 @@
 */
@Data
@ApiModel("门禁角色信息表")
@TableName("`door_role`")
@TableName("`device_role`")
public class DeviceRole {
    @TableId(type = IdType.AUTO)
@@ -96,5 +97,9 @@
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date hkDate;
    @ApiModelProperty(value = "使用人数")
    @ExcelColumn(name="使用人数")
    @TableField(exist = false)
    private Integer memberNum;
}
server/dmvisit_service/src/main/java/com/doumee/service/business/DeviceRoleService.java
@@ -14,7 +14,7 @@
    /**
     * 创建
     *
     *
     * @param deviceRole 实体对象
     * @return Integer
     */
@@ -48,6 +48,14 @@
     */
    void updateById(DeviceRole deviceRole);
    /**
     * 主键更新
     *
     * @param deviceRole 实体对象
     */
    void updateStatusById(DeviceRole deviceRole);
    /**
     * 批量主键更新
     *
@@ -78,7 +86,7 @@
     * @return List<DeviceRole>
     */
    List<DeviceRole> findList(DeviceRole deviceRole);
    /**
     * 分页查询
     *
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java
@@ -1,7 +1,11 @@
package com.doumee.service.business.impl;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.DeviceRoleMapper;
import com.doumee.dao.business.model.DeviceRole;
@@ -10,10 +14,13 @@
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections.CollectionUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date;
import java.util.List;
/**
@@ -29,8 +36,40 @@
    @Override
    public Integer create(DeviceRole deviceRole) {
        deviceRoleMapper.insert(deviceRole);
        return deviceRole.getId();
        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
        query.lambda()
                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                .eq(DeviceRole::getType,deviceRole.getType())
                .eq(DeviceRole::getStatus,Constants.ONE);
        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"同一个用户类型,只能有一个默认角色");
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        DeviceRole insert = new DeviceRole();
        insert.setCreator(loginUserInfo.getId().toString());
        insert.setCreateDate(new Date());
        insert.setEdirot(loginUserInfo.getId().toString());
        insert.setEditDate(new Date());
        insert.setIsdeleted(Constants.ZERO);
        insert.setRemark(deviceRole.getRemark());
        insert.setName(deviceRole.getName());
        insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
        insert.setType(deviceRole.getType());
        insert.setDoorIds(deviceRole.getDoorIds());
        insert.setDoorNames(deviceRole.getDoorNames());
        insert.setParkIds(deviceRole.getParkIds());
        insert.setParkNames(deviceRole.getParkNames());
        insert.setStatus(deviceRole.getStatus());
        insert.setHkId(deviceRole.getHkId());
        insert.setHkStatus(deviceRole.getHkStatus());
        insert.setHkDate(deviceRole.getHkDate());
        deviceRoleMapper.insert(insert);
        return insert.getId();
    }
    @Override
@@ -54,7 +93,39 @@
    @Override
    public void updateById(DeviceRole deviceRole) {
        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
        query.lambda()
                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                .eq(DeviceRole::getType,deviceRole.getType())
                .eq(DeviceRole::getStatus,Constants.ONE);
        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"同一个用户类型,只能有一个默认角色");
        }
        deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
        deviceRoleMapper.updateById(deviceRole);
    }
    @Override
    public void updateStatusById(DeviceRole deviceRole) {
        QueryWrapper<DeviceRole> query = new QueryWrapper<>();
        query.lambda()
                .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                .eq(DeviceRole::getType,deviceRole.getType())
                .eq(DeviceRole::getStatus,Constants.ONE);
        List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query);
        if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"同一个用户类型,只能有一个默认角色");
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        DeviceRole update = new DeviceRole();
        update.setEdirot(loginUserInfo.getId().toString());
        update.setEditDate(new Date());
        update.setId(deviceRole.getId());
        update.setStatus(deviceRole.getStatus());
        update.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1);
        deviceRoleMapper.updateById(update);
    }
    @Override
@@ -83,7 +154,7 @@
        QueryWrapper<DeviceRole> wrapper = new QueryWrapper<>(deviceRole);
        return deviceRoleMapper.selectList(wrapper);
    }
    @Override
    public PageData<DeviceRole> findPage(PageWrap<DeviceRole> pageWrap) {
        IPage<DeviceRole> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
@@ -136,6 +207,9 @@
        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());