1、分页列表
方案1:设置查询条件通过EntityWrapper-不能返回关联对象
@PostMapping("/list")
public PageList<TenantType> json(@RequestBody TenantTypeQuery query)
{
System.out.println(query.getKeyword());
//分页携带查询条件EntityWrapper keywords要作用于name或者descrition
EntityWrapper<TenantType> wrapper = new EntityWrapper<>();
//wrapper.eq() 相等
wrapper.like("name",query.getKeyword()) //模糊查询
.or()
.like("description",query.getKeyword());
Page<TenantType> page = new Page<TenantType>(query.getPage(),query.getRows());
page = tenantTypeService.selectPage(page, wrapper);
return new PageList<TenantType>(page.getTotal(),page.getRecords());
}
方案2:自己写sql,还能返回关联对象
controller:
@PostMapping("/list")
public PageList<TenantType> json(@RequestBody TenantTypeQuery query)
{
return tenantTypeService.selectPageLiset(query);
}
Service
Mapper
Mapper.xml
这两种方案高级查询方案,第一种比较简单,第二种比较复杂,如果返回值不需要关联对象,就用第一种,否则就用第二种
3.跨越配置-在zuul进行配置(所有前端统一入口)
package cn.itsource.aigou.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class GlobalCorsConfig {
@Bean
public CorsFilter corsFilter() {
//1.添加CORS配置信息
CorsConfiguration config = new CorsConfiguration();
//1) 允许的域,不要写*,否则cookie就无法使用了
config.addAllowedOrigin("http://127.0.0.1:6001");
config.addAllowedOrigin("http://localhost:6001");
//2) 是否发送Cookie信息
config.setAllowCredentials(true);
//3) 允许的请求方式
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
// 4)允许的头信息
config.addAllowedHeader("*");
//2.添加映射路径,我们拦截一切请求
UrlBasedCorsConfigurationSource configSource = new
UrlBasedCorsConfigurationSource();
configSource.registerCorsConfiguration("/**", config);
//3.返回新的CorsFilter.
return new CorsFilter(configSource);
}
}
2. 机构管理(tenant)
分页+高级查询+关联查询
后台:
Domain
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
Mapper.xml
3. 机构入驻
. 前台传递参数
后台实现
package cn.itsource.hrm.service.impl;
import cn.itsource.hrm.domain.Employee;
import cn.itsource.hrm.domain.Tenant;
import cn.itsource.hrm.mapper.EmployeeMapper;
import cn.itsource.hrm.mapper.TenantMapper;
import cn.itsource.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;
/**
* <p>
* 服务实现类
* </p>
*
* @author yhptest
* @since 2019-09-02
*/
@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 cn.itsource.hrm.mapper;
import cn.itsource.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>
简历书写
系统中心是我做的,数据字典,操作日志,员工,部门,角色,权限,菜单,机构类型,机构,套餐