|
|
@@ -0,0 +1,90 @@
|
|
|
+package io.renren.modules.qmgj.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.renren.common.utils.Constant;
|
|
|
+import io.renren.common.utils.DateUtils;
|
|
|
+import io.renren.common.utils.PageUtils;
|
|
|
+import io.renren.common.utils.Query;
|
|
|
+import io.renren.common.xss.SQLFilter;
|
|
|
+import io.renren.modules.qmgj.dao.SchoolInfoDao;
|
|
|
+import io.renren.modules.qmgj.entity.SchoolInfoEntity;
|
|
|
+import io.renren.modules.qmgj.service.SchoolInfoService;
|
|
|
+import io.renren.modules.qmjz.entity.Region;
|
|
|
+import io.renren.modules.qmjz.service.RegionService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+@Service("schoolInfoService")
|
|
|
+public class SchoolInfoServiceImpl extends ServiceImpl<SchoolInfoDao, SchoolInfoEntity> implements SchoolInfoService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SchoolInfoDao schoolInfoDao;
|
|
|
+ @Autowired
|
|
|
+ private RegionService regionService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageUtils queryPage(Map<String, Object> params) {
|
|
|
+ QueryWrapper<SchoolInfoEntity> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.like(StrUtil.isNotBlank((String) params.get("SCHOOLNAME")), "SCHOOLNAME", (String) params.get("SCHOOLNAME"));
|
|
|
+ wrapper.eq(StrUtil.isNotBlank((String) params.get("PROVINCE")), "PROVINCE", ((String) params.get("PROVINCE")));
|
|
|
+ wrapper.eq(StrUtil.isNotBlank((String) params.get("REGION")), "REGION", ((String) params.get("REGION")));
|
|
|
+
|
|
|
+ //排序
|
|
|
+ String orderField = SQLFilter.sqlInject((String) params.get(Constant.ORDER_FIELD));
|
|
|
+ String order = (String) params.get(Constant.ORDER);
|
|
|
+ if (StringUtils.isNotEmpty(orderField) && StringUtils.isNotEmpty(order)) {
|
|
|
+ if (Constant.ASC.equalsIgnoreCase(order)) {
|
|
|
+ wrapper.orderByAsc(orderField);
|
|
|
+ } else {
|
|
|
+ wrapper.orderByDesc(orderField);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(!"INPUTTIME".equals(orderField), "INPUTTIME");
|
|
|
+ IPage<SchoolInfoEntity> page = this.page(new Query<SchoolInfoEntity>().getPage(params), wrapper);
|
|
|
+ page.setRecords(convertList(page.getRecords()));
|
|
|
+ return new PageUtils(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SchoolInfoEntity queryById(Long id) {
|
|
|
+ return convert(schoolInfoDao.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveEntity(SchoolInfoEntity schoolInfo) {
|
|
|
+ schoolInfo.setINPUTTIME(DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ schoolInfoDao.insert(schoolInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateEntityById(SchoolInfoEntity schoolInfo) {
|
|
|
+ schoolInfoDao.updateById(schoolInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SchoolInfoEntity> convertList(List<SchoolInfoEntity> list) {
|
|
|
+ return list.stream().map(s -> convert(s)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private SchoolInfoEntity convert(SchoolInfoEntity entity) {
|
|
|
+ entity.setPROVINCENAME(getName(entity.getPROVINCE()));
|
|
|
+ entity.setREGIONNAME(getName(entity.getREGION()));
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getName(String code) {
|
|
|
+ Region region = regionService.loadById(Long.valueOf(code), false);
|
|
|
+ return ObjectUtil.isNull(region) ? null : region.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|