|
@@ -1,14 +1,105 @@
|
|
package cn.com.qmth.print.manage.service.impl;
|
|
package cn.com.qmth.print.manage.service.impl;
|
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
import cn.com.qmth.print.manage.dao.OrgDao;
|
|
import cn.com.qmth.print.manage.dao.OrgDao;
|
|
import cn.com.qmth.print.manage.entity.OrgEntity;
|
|
import cn.com.qmth.print.manage.entity.OrgEntity;
|
|
import cn.com.qmth.print.manage.service.OrgService;
|
|
import cn.com.qmth.print.manage.service.OrgService;
|
|
-
|
|
|
|
|
|
+import cn.com.qmth.print.manage.service.query.OrgQuery;
|
|
|
|
+import cn.com.qmth.print.manage.utils.SolarUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class OrgServiceImpl extends ServiceImpl<OrgDao, OrgEntity> implements OrgService {
|
|
public class OrgServiceImpl extends ServiceImpl<OrgDao, OrgEntity> implements OrgService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private OrgDao orgDao;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SolarUtils solarUtils;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public IPage<OrgEntity> pageQuery(OrgQuery query) {
|
|
|
|
+ QueryWrapper<OrgEntity> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ if (StringUtils.isNotEmpty(query.getCode())) {
|
|
|
|
+ queryWrapper.lambda().like(OrgEntity::getCode, query.getCode());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(query.getName())) {
|
|
|
|
+ queryWrapper.lambda().like(OrgEntity::getName, query.getName());
|
|
|
|
+ }
|
|
|
|
+ queryWrapper.lambda().orderByAsc(OrgEntity::getId);
|
|
|
|
+ Page<OrgEntity> page = new Page<>(query.getPageNumber(), query.getPageSize());
|
|
|
|
+ return orgDao.selectPage(page, queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<OrgEntity> listByEnable() {
|
|
|
|
+ QueryWrapper<OrgEntity> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(OrgEntity::getEnable, true).orderByAsc(OrgEntity::getId);
|
|
|
|
+ return orgDao.selectList(queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public void pull() {
|
|
|
|
+ List<Map> mapList = solarUtils.pullSchool();
|
|
|
|
+ List<OrgEntity> orgEntities = orgDao.selectList(null);
|
|
|
|
+ List<OrgEntity> notExist;
|
|
|
|
+ if (CollectionUtils.isEmpty(mapList)) {
|
|
|
|
+ notExist = orgEntities;
|
|
|
|
+ } else {
|
|
|
|
+ List<String> codeList = mapList.stream().map(m -> m.get("code").toString()).collect(Collectors.toList());
|
|
|
|
+ notExist = orgEntities.stream().map(m -> {
|
|
|
|
+ if (!codeList.contains(m.getCode())) {
|
|
|
|
+ return m;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ for (Map map : mapList) {
|
|
|
|
+ Long orgId = Long.valueOf(String.valueOf(map.get("id"))); // 机构中心的id
|
|
|
|
+ String code = String.valueOf(map.get("code"));
|
|
|
|
+ String name = String.valueOf(map.get("name"));
|
|
|
|
+ String logo = String.valueOf(map.get("logo"));
|
|
|
|
+ String accessKey = String.valueOf(map.get("accessKey"));
|
|
|
|
+ String accessSecret = String.valueOf(map.get("accessSecret"));
|
|
|
|
+
|
|
|
|
+ OrgEntity entity = orgEntities.stream().filter(m -> m.getCode().equals(code)).findFirst().get();
|
|
|
|
+ if (entity == null) {
|
|
|
|
+ entity = new OrgEntity();
|
|
|
|
+ // 中心的学校ID被占用,则使用自增ID
|
|
|
|
+ OrgEntity orgById = orgDao.selectById(orgId);
|
|
|
|
+ if (orgById == null) {
|
|
|
|
+ entity.setId(orgId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ entity.setCode(code);
|
|
|
|
+ entity.setName(name);
|
|
|
|
+ entity.setAccessKey(accessKey);
|
|
|
|
+ entity.setAccessSecret(accessSecret);
|
|
|
|
+ entity.setLogoUrl(logo);
|
|
|
|
+ entity.setEnable(true);
|
|
|
|
+ this.saveOrUpdate(entity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 不在中心的学校,本地全部禁用
|
|
|
|
+ if (!CollectionUtils.isEmpty(notExist)) {
|
|
|
|
+ for (OrgEntity orgEntity : notExist) {
|
|
|
|
+ orgEntity.setEnable(false);
|
|
|
|
+ orgDao.updateById(orgEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|