|
@@ -0,0 +1,65 @@
|
|
|
+package com.qmth.distributed.print.business.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qmth.distributed.print.business.entity.BasicSchool;
|
|
|
+import com.qmth.distributed.print.business.enums.OrgCenterTypeEnum;
|
|
|
+import com.qmth.distributed.print.business.service.BasicSchoolService;
|
|
|
+import com.qmth.distributed.print.business.service.CallApiOrgCenterService;
|
|
|
+import com.qmth.distributed.print.business.service.OrgCenterDataDisposeService;
|
|
|
+import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 机构数据中心数据处理服务实现类
|
|
|
+ * @Author: CaoZixuan
|
|
|
+ * @Date: 2021-04-02
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeService {
|
|
|
+ @Resource
|
|
|
+ private CallApiOrgCenterService callApiOrgCenterService;
|
|
|
+ @Resource
|
|
|
+ private BasicSchoolService basicSchoolService;
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void updateSchoolInfo() throws IOException {
|
|
|
+ // 删除原有学校
|
|
|
+ basicSchoolService.remove(new QueryWrapper<BasicSchool>().lambda().gt(BasicSchool::getId,0));
|
|
|
+
|
|
|
+ List<Map> result = callApiOrgCenterService.callOrgInfo();
|
|
|
+ for (Map map : result) {
|
|
|
+ Long id = SystemConstant.convertIdToLong(String.valueOf(map.get("id")));
|
|
|
+ String code = String.valueOf(map.get("code"));
|
|
|
+ String name = String.valueOf(map.get("name"));
|
|
|
+ String accessKey = String.valueOf(map.get("accessKey"));
|
|
|
+ String accessSecret = String.valueOf(map.get("accessSecret"));
|
|
|
+ Map typeMap = JSONObject.parseObject(String.valueOf(map.get("type")));
|
|
|
+ String typeCode = String.valueOf(typeMap.get("code"));
|
|
|
+ String typeName = String.valueOf(typeMap.get("name"));
|
|
|
+ if (!Arrays.stream(OrgCenterTypeEnum.values()).map(OrgCenterTypeEnum::getTypeCode).collect(Collectors.toList()).contains(typeCode)){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("机构类型在枚举中不存在 + typeCode = " + typeCode);
|
|
|
+ }
|
|
|
+ if (!OrgCenterTypeEnum.PARTNER.getTypeCode().equals(typeCode)){
|
|
|
+ BasicSchool school = new BasicSchool();
|
|
|
+ school.setId(id);
|
|
|
+ school.setCode(code);
|
|
|
+ school.setName(name);
|
|
|
+ school.setEnable(true);
|
|
|
+ school.setAccessKey(accessKey);
|
|
|
+ school.setAccessSecret(accessSecret);
|
|
|
+ basicSchoolService.save(school);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|