|
@@ -1,44 +1,86 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.api.provider;
|
|
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
+import java.util.List;
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.common.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgListByNameLikeReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.OrgReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgListByNameLikeResp;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.OrgResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.OrgService;
|
|
|
-
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("${url.prefix}/org")
|
|
|
-public class OrgCloudServiceProvider extends ControllerSupport implements OrgCloudService{
|
|
|
+public class OrgCloudServiceProvider extends ControllerSupport implements OrgCloudService {
|
|
|
|
|
|
@Autowired
|
|
|
private OrgService orgService;
|
|
|
-
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrgRepo orgRepo;
|
|
|
+
|
|
|
@ApiOperation(value = "保存机构", notes = "保存机构")
|
|
|
- @PostMapping
|
|
|
+ @PostMapping("saveOrg")
|
|
|
@Override
|
|
|
public OrgResp saveOrg(OrgReq orgReq) throws Exception {
|
|
|
OrgResp orgResp = new OrgResp();
|
|
|
- Org org = orgService.findFirstByParentIdAndCode(orgReq.getRootOrgId(),orgReq.getOrgCode());
|
|
|
- if(org == null){
|
|
|
+ Org org = orgService.findFirstByParentIdAndCode(orgReq.getRootOrgId(), orgReq.getOrgCode());
|
|
|
+ if (org == null) {
|
|
|
org = new Org();
|
|
|
org.setName(orgReq.getOrgName());
|
|
|
- org.setCode(orgReq.getOrgCode());
|
|
|
- org.setParentId(orgReq.getRootOrgId());
|
|
|
- org.setRootId(orgReq.getRootOrgId());
|
|
|
- org.setEnable(true);
|
|
|
- org = orgService.save(org);
|
|
|
+ org.setCode(orgReq.getOrgCode());
|
|
|
+ org.setParentId(orgReq.getRootOrgId());
|
|
|
+ org.setRootId(orgReq.getRootOrgId());
|
|
|
+ org.setEnable(true);
|
|
|
+ org = orgService.save(org);
|
|
|
}
|
|
|
orgResp.setId(org.getId());
|
|
|
orgResp.setName(org.getName());
|
|
|
return orgResp;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "按机构名称模糊查询机构列表", notes = "按机构名称模糊查询机构列表")
|
|
|
+ @PostMapping("getOrgListByNameLike")
|
|
|
+ @Override
|
|
|
+ public GetOrgListByNameLikeResp getOrgListByNameLike(GetOrgListByNameLikeReq req) {
|
|
|
+ String orgName = req.getOrgName();
|
|
|
+ String rootOrgId = req.getRootOrgId();
|
|
|
+
|
|
|
+ List<Org> list = Lists.newArrayList();
|
|
|
+ if (StringUtils.isNotBlank(orgName)) {
|
|
|
+ list = orgRepo.findByRootIdAndNameLike(Long.parseLong(rootOrgId), orgName);
|
|
|
+ }
|
|
|
+
|
|
|
+ GetOrgListByNameLikeResp resp = new GetOrgListByNameLikeResp();
|
|
|
+ List<OrgBean> orgList = Lists.newArrayList();
|
|
|
+ resp.setOrgList(orgList);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ for (Org curOrg : list) {
|
|
|
+ OrgBean orgBean = new OrgBean();
|
|
|
+ orgBean.setId(curOrg.getId());
|
|
|
+ orgBean.setLevel(curOrg.getLevel());
|
|
|
+ orgBean.setName(curOrg.getName());
|
|
|
+ orgBean.setParentId(curOrg.getParentId());
|
|
|
+ orgBean.setRootId(curOrg.getRootId());
|
|
|
+ orgList.add(orgBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
}
|