欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Day03

程序员文章站 2022-06-10 15:06:59
...

机构管理

统一启动就有一个超级租户(系统运营方),有个超级管理员。拥有所有权限。
机构入驻进来需要一个超级管理员,拥有租户所有套餐的所有权限。
创建部门
创建员工:分配权限 (这个租户拥有的权限)

代码生成

表设计

Day03
Day03

代码生成

strategy.setInclude(new String[]{"t_department", "t_employee","t_meal","t_menu",
        "t_permission","t_role","t_tenant","t_tenant_type"}); // 需要生成的表

分页+高级查询+关联查询

后台:
Domain
Day03
Mapper.xml

<sql id="whereSql">
    <where>
        <if test="keyword!=null and keyword!=''">

             and t.companyName like concat('%',#{keyword},"%")
        </if>
    </where>
</sql>
<!--List<Tenant> loadPageList(Page<Tenant> page, TenantQuery query);-->
<select id="loadPageList" resultMap="TenantMap">
    SELECT
        t.*, type.id tid,
        type. NAME tname,
      e.id eid,e.realName
    FROM
        t_tenant t
    LEFT JOIN t_tenant_type type ON t.tenant_type = type.id
    LEFT JOIN t_employee e on t.admin_id = e.id
    <include refid="whereSql"></include>
</select>

<resultMap id="TenantMap" type="Tenant">
    <id column="id" property="id" />
    <result column="tenant_type" property="tenantType" />
    <result column="companyName" property="companyName" />
    <result column="companyNum" property="companyNum" />
    <result column="registerTime" property="registerTime" />
    <result column="state" property="state" />
    <result column="address" property="address" />
    <result column="logo" property="logo" />
    <result column="admin_id" property="adminId" />

    <!-- 机构类型多对一关联-->
    <association property="type" javaType="TenantType">
        <id column="tid" property="id" />
        <result column="tname" property="name" />
    </association>

    <!--管理员的关联查询-->
    <association property="admin" javaType="Employee">
        <id column="eid" property="id" />
        <result column="realName" property="realName" />
    </association>
</resultMap>

删除

service
Day03
Mapper.xml
Day03

机构入驻

前台传递参数

Day03

后台实现

package org.hhw.hrm.service.impl;

import org.hhw.hrm.domain.Employee;
import org.hhw.hrm.domain.Tenant;
import org.hhw.hrm.mapper.EmployeeMapper;
import org.hhw.hrm.mapper.TenantMapper;
import org.hhw.hrm.service.ITenantService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;

@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements ITenantService {

    @Autowired
    private TenantMapper tenantMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public boolean insert(Tenant tenant) {
        //保存公司管理员信息-没有租户id
        Employee admin = entity.getAdmin();
        admin.setInputTime(new Date()); //输入时间
        admin.setState(0); // 正常
        admin.setType(1); //是否是租户管理员
        employeeMapper.insert(admin);
        System.out.println(admin.getId()+"iiii");

        //保存公司信息-要返回自增id
        entity.setAdminId(admin.getId());
        tenantMapper.insert(entity);

        System.out.println(entity.getId()+"jjjj");
        //修改管理员的租户id
        admin.setTenantId(entity.getId());
        employeeMapper.updateById(admin);        //添加套餐中间表
        tenantMapper.saveTenantMeals(tenant.getMealsMap());
        return true;
    }

    @Override
    public boolean deleteById(Serializable id) {

        //删除机构
        tenantMapper.deleteById(id);
        //删除管理员
        Wrapper<Employee> wapper = new EntityWrapper<>();
        wapper.eq("tenant_id",id);
        employeeMapper.delete(wapper);
        //删除中间表
        tenantMapper.removeTenantMeal(id);
        return true;
    }

    @Override
    public boolean updateById(Tenant tenant) {
        // 修改机构
        tenantMapper.updateById(tenant);
        //修改管理员
        employeeMapper.updateById(tenant.getAdminUser());
        //修改中间表-先删除后添加
        tenantMapper.removeTenantMeal(tenant.getId());
        tenantMapper.saveTenantMeals(tenant.getMealsMap());
        return true;
    }
}
package org.hhw.hrm.mapper;

import org.hhw.hrm.domain.Tenant;
import com.baomidou.mybatisplus.mapper.BaseMapper;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yhptest
 * @since 2019-09-02
 */
public interface TenantMapper extends BaseMapper<Tenant> {

    /**
     * 保存机构所对应的套餐的中间表信息
     * @param mealsMap
     */
    void saveTenantMeals(List<Map<String, Long>> mealsMap);

    /**
     * 删除中间表
     * @param id
     */
    void removeTenantMeal(Serializable id);
}
<!--void saveTenantMeals(List<Map<String, Long>> mealsMap);-->
<insert id="saveTenantMeals" parameterType="arrayList">
    insert into t_tenant_meal(tenant_id,meal_id) VALUES
    <foreach collection="list" separator="," item="item">
        (#{item.tenantId},#{item.mealId})
    </foreach>
</insert>

<!--void removeTenantMeal(Serializable id);-->
<delete id="removeTenantMeal" parameterType="long">
    DELETE  from t_tenant_meal where tenant_id =#{id}
</delete>