|
@@ -1,9 +1,11 @@
|
|
|
package com.github.zuihou.authority.controller.core;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import com.github.zuihou.authority.dao.core.OrgRegionMapper;
|
|
|
import com.github.zuihou.authority.dto.core.OrgSaveDTO;
|
|
|
import com.github.zuihou.authority.dto.core.OrgUpdateDTO;
|
|
|
import com.github.zuihou.authority.entity.core.Org;
|
|
|
+import com.github.zuihou.authority.entity.core.OrgRegion;
|
|
|
import com.github.zuihou.authority.service.core.OrgService;
|
|
|
import com.github.zuihou.base.R;
|
|
|
import com.github.zuihou.base.controller.SuperCacheController;
|
|
@@ -20,18 +22,15 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.github.zuihou.utils.StrPool.*;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * <p>
|
|
|
- * 前端控制器
|
|
|
- * 组织
|
|
|
- * </p>
|
|
|
+ * 组织Controller
|
|
|
*
|
|
|
* @author zuihou
|
|
|
* @date 2019-07-22
|
|
@@ -41,21 +40,51 @@ import static com.github.zuihou.utils.StrPool.*;
|
|
|
@RestController @RequestMapping("/org") @Slf4j
|
|
|
public class OrgController extends SuperCacheController<OrgService, Long, Org, Org, OrgSaveDTO, OrgUpdateDTO>
|
|
|
{
|
|
|
+ @Resource
|
|
|
+ private OrgRegionMapper orgRegionMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public R<Org> handlerSave(OrgSaveDTO model)
|
|
|
{
|
|
|
+ // 1 保存组织
|
|
|
Org org = BeanPlusUtil.toBean(model, Org.class);
|
|
|
fillOrg(org);
|
|
|
this.baseService.save(org);
|
|
|
+
|
|
|
+ // 2 保存所属区域
|
|
|
+ String[] regionIds = org.getRegionIds().split(",");
|
|
|
+ for (String rId : regionIds)
|
|
|
+ {
|
|
|
+ orgRegionMapper.insert(OrgRegion.builder()
|
|
|
+ .orgId(org.getId())
|
|
|
+ .regionId(Long.parseLong(rId))
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+
|
|
|
return success(org);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public R<Org> handlerUpdate(OrgUpdateDTO model)
|
|
|
{
|
|
|
+ // 1 修改组织
|
|
|
Org org = BeanPlusUtil.toBean(model, Org.class);
|
|
|
fillOrg(org);
|
|
|
this.baseService.updateAllById(org);
|
|
|
+
|
|
|
+ // 2 保存所属区域
|
|
|
+ // 2.1 删除老数据
|
|
|
+ orgRegionMapper.deleteByOrgId(org.getId());
|
|
|
+ // 2.2 插入新数据
|
|
|
+ String[] regionIds = model.getRegionIds().split(",");
|
|
|
+ for (String rId : regionIds)
|
|
|
+ {
|
|
|
+ orgRegionMapper.insert(OrgRegion.builder()
|
|
|
+ .orgId(org.getId())
|
|
|
+ .regionId(Long.parseLong(rId))
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+
|
|
|
return success(org);
|
|
|
}
|
|
|
|
|
@@ -87,7 +116,6 @@ public class OrgController extends SuperCacheController<OrgService, Long, Org, O
|
|
|
* 查询系统所有的组织树
|
|
|
*
|
|
|
* @param status 状态
|
|
|
- * @return
|
|
|
* @author zuihou
|
|
|
* @date 2019-07-29 11:59
|
|
|
*/
|