Browse Source

学校接口

xiatian 2 years ago
parent
commit
3c04a3d98c

+ 189 - 179
pom.xml

@@ -1,193 +1,203 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <groupId>cn.com.qmth</groupId>
-    <artifactId>marking-paper-struct</artifactId>
-    <version>1.0.0</version>
-    <packaging>jar</packaging>
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>cn.com.qmth</groupId>
+	<artifactId>marking-paper-struct</artifactId>
+	<version>1.0.0</version>
+	<packaging>jar</packaging>
 
 	<parent>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.3.12.RELEASE</version>
-        <relativePath/>
-    </parent>
+		<groupId>org.springframework.boot</groupId>
+		<artifactId>spring-boot-starter-parent</artifactId>
+		<version>2.3.12.RELEASE</version>
+		<relativePath />
+	</parent>
 
-    <properties>
-        <spring-boot.version>2.3.12.RELEASE</spring-boot.version>
-        <mybatis-plus.version>3.4.3.3</mybatis-plus.version>
-        <maven-compiler-version>3.8.1</maven-compiler-version>
-        <maven-surefire-version>2.22.2</maven-surefire-version>
-        <maven.compiler.source>1.8</maven.compiler.source>
-        <maven.compiler.target>1.8</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-        <qmth-boot-version>1.0.3</qmth-boot-version>
-    </properties>
+	<properties>
+		<spring-boot.version>2.3.12.RELEASE</spring-boot.version>
+		<mybatis-plus.version>3.4.3.3</mybatis-plus.version>
+		<maven-compiler-version>3.8.1</maven-compiler-version>
+		<maven-surefire-version>2.22.2</maven-surefire-version>
+		<maven.compiler.source>1.8</maven.compiler.source>
+		<maven.compiler.target>1.8</maven.compiler.target>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+		<qmth-boot-version>1.0.3</qmth-boot-version>
+	</properties>
 
-    <repositories>
-        <repository>
-            <id>nexus</id>
-            <name>nexus</name>
-            <url>http://192.168.10.201:8081/repository/maven-public/</url>
-        </repository>
-    </repositories>
-    <pluginRepositories>
-        <pluginRepository>
-            <id>nexus</id>
-            <name>nexus</name>
-            <url>http://192.168.10.201:8081/repository/maven-public/</url>
-        </pluginRepository>
-    </pluginRepositories>
+	<repositories>
+		<repository>
+			<id>nexus</id>
+			<name>nexus</name>
+			<url>http://192.168.10.201:8081/repository/maven-public/</url>
+		</repository>
+	</repositories>
+	<pluginRepositories>
+		<pluginRepository>
+			<id>nexus</id>
+			<name>nexus</name>
+			<url>http://192.168.10.201:8081/repository/maven-public/</url>
+		</pluginRepository>
+	</pluginRepositories>
 
-    <dependencies>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-security</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>starter-api</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>data-mybatis-plus</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-schedule</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.github.jeffreyning</groupId>
-            <artifactId>mybatisplus-plus</artifactId>
-            <version>1.5.1-RELEASE</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-fss</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-retrofit</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-concurrent</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>tools-poi</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
+	<dependencies>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-solar</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-security</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>starter-api</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>data-mybatis-plus</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-schedule</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.github.jeffreyning</groupId>
+			<artifactId>mybatisplus-plus</artifactId>
+			<version>1.5.1-RELEASE</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-fss</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-retrofit</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-concurrent</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>tools-poi</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
 
 
-        <!-- Swagger jars start -->
-        <dependency>
-            <groupId>com.github.xiaoymin</groupId>
-            <artifactId>knife4j-spring-boot-starter</artifactId>
-            <version>2.0.9</version>
-        </dependency>
-        <dependency>
-            <groupId>io.swagger</groupId>
-            <artifactId>swagger-annotations</artifactId>
-            <version>1.5.24</version>
-        </dependency>
-        <dependency>
-            <groupId>io.swagger</groupId>
-            <artifactId>swagger-models</artifactId>
-            <version>1.5.24</version>
-        </dependency>
-        <!-- Swagger jars end -->
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>30.1.1-jre</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-collections4</artifactId>
-            <version>4.4</version>
-        </dependency>
-        <dependency>
-            <groupId>com.thoughtworks.xstream</groupId>
-            <artifactId>xstream</artifactId>
-            <version>1.4.16</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>2.8.0</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-text</artifactId>
-            <version>1.9</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-fileupload</groupId>
-            <artifactId>commons-fileupload</artifactId>
-            <version>1.4</version>
-        </dependency>
-        <dependency>
-            <groupId>org.quartz-scheduler</groupId>
-            <artifactId>quartz</artifactId>
-            <exclusions>
-                <exclusion>
-                    <artifactId>c3p0</artifactId>
-                    <groupId>com.mchange</groupId>
-                </exclusion>
-                <exclusion>
-                    <artifactId>*</artifactId>
-                    <groupId>com.zaxxer</groupId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.quartz-scheduler</groupId>
-            <artifactId>quartz-jobs</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>net.sf.json-lib</groupId>
-            <artifactId>json-lib-ext-spring</artifactId>
-            <version>1.0.2</version>
-        </dependency>
-        <dependency>
-            <groupId>com.qmth.boot</groupId>
-            <artifactId>core-cache</artifactId>
-            <version>${qmth-boot-version}</version>
-        </dependency>
-    </dependencies>
+		<!-- Swagger jars start -->
+		<dependency>
+			<groupId>com.github.xiaoymin</groupId>
+			<artifactId>knife4j-spring-boot-starter</artifactId>
+			<version>2.0.9</version>
+		</dependency>
+		<dependency>
+			<groupId>io.swagger</groupId>
+			<artifactId>swagger-annotations</artifactId>
+			<version>1.5.24</version>
+		</dependency>
+		<dependency>
+			<groupId>io.swagger</groupId>
+			<artifactId>swagger-models</artifactId>
+			<version>1.5.24</version>
+		</dependency>
+		<!-- Swagger jars end -->
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.76</version>
+		</dependency>
+		<dependency>
+			<groupId>com.google.guava</groupId>
+			<artifactId>guava</artifactId>
+			<version>30.1.1-jre</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-collections4</artifactId>
+			<version>4.4</version>
+		</dependency>
+		<dependency>
+			<groupId>com.thoughtworks.xstream</groupId>
+			<artifactId>xstream</artifactId>
+			<version>1.4.16</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>2.8.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-text</artifactId>
+			<version>1.9</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-fileupload</groupId>
+			<artifactId>commons-fileupload</artifactId>
+			<version>1.4</version>
+		</dependency>
+		<dependency>
+			<groupId>org.quartz-scheduler</groupId>
+			<artifactId>quartz</artifactId>
+			<exclusions>
+				<exclusion>
+					<artifactId>c3p0</artifactId>
+					<groupId>com.mchange</groupId>
+				</exclusion>
+				<exclusion>
+					<artifactId>*</artifactId>
+					<groupId>com.zaxxer</groupId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+		<dependency>
+			<groupId>org.quartz-scheduler</groupId>
+			<artifactId>quartz-jobs</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>net.sf.json-lib</groupId>
+			<artifactId>json-lib-ext-spring</artifactId>
+			<version>1.0.2</version>
+		</dependency>
+		<dependency>
+			<groupId>com.qmth.boot</groupId>
+			<artifactId>core-cache</artifactId>
+			<version>${qmth-boot-version}</version>
+		</dependency>
+	</dependencies>
 
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>${spring-boot.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
+	<dependencyManagement>
+		<dependencies>
+			<dependency>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-dependencies</artifactId>
+				<version>${spring-boot.version}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+		</dependencies>
+	</dependencyManagement>
 
-    <build>
-        <finalName>${project.artifactId}</finalName>
+	<build>
+		<finalName>${project.artifactId}</finalName>
 
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
+		<plugins>
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
+		</plugins>
+	</build>
 </project>

+ 15 - 2
src/main/java/cn/com/qmth/mps/controller/SchoolController.java

@@ -2,6 +2,8 @@ package cn.com.qmth.mps.controller;
 
 import java.util.List;
 
+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.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -12,6 +14,7 @@ import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.core.collection.PageResult;
 
+import cn.com.qmth.mps.service.SchoolService;
 import cn.com.qmth.mps.vo.school.SchoolDomain;
 import cn.com.qmth.mps.vo.school.SchoolQuery;
 import cn.com.qmth.mps.vo.school.SchoolVo;
@@ -23,27 +26,37 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/school")
 @Aac(strict = BOOL.FALSE, auth = BOOL.TRUE)
 public class SchoolController extends BaseController {
+	@Autowired
+	private SchoolService schoolService;
 
     @ApiOperation(value = "新增/修改")
     @RequestMapping(value = "save", method = RequestMethod.POST)
     public void save(SchoolDomain domain) {
+    	schoolService.saveSchool(getAccessUser(),domain);
     }
 
     @ApiOperation(value = "获取分页")
     @RequestMapping(value = "page", method = RequestMethod.POST)
     public PageResult<SchoolVo> page(SchoolQuery query) {
-        return null;
+        return schoolService.page(query,getAccessUser());
     }
     
     @ApiOperation(value = "获取信息")
     @RequestMapping(value = "info", method = RequestMethod.POST)
     public SchoolVo info(@RequestParam Long id) {
-        return null;
+        return schoolService.info(id,getAccessUser());
     }
     
     @ApiOperation(value = "启用/禁用")
     @RequestMapping(value = "toggle", method = RequestMethod.POST)
     public void enable(@RequestParam List<Long> ids, @RequestParam Boolean enable) {
+    	schoolService.toggle(ids,enable,getAccessUser());
+    }
+    
+    @ApiOperation(value = "同步")
+    @PostMapping("sync")
+    public void sync() {
+    	schoolService.syncSchool(getAccessUser());
     }
 
 }

+ 1 - 1
src/main/java/cn/com/qmth/mps/controller/UserController.java

@@ -72,7 +72,7 @@ public class UserController extends BaseController {
 	@ApiOperation(value = "启用/禁用")
 	@RequestMapping(value = "toggle", method = RequestMethod.POST)
 	public void toggle(@RequestParam List<Long> ids, @RequestParam Boolean enable) {
-		userService.toggle(ids,enable);
+		userService.toggle(ids,enable,getAccessUser());
 	}
 	
 	@ApiOperation(value = "重置指定用户密码")

+ 8 - 0
src/main/java/cn/com/qmth/mps/dao/SchoolDao.java

@@ -1,9 +1,17 @@
 package cn.com.qmth.mps.dao;
 
+import org.apache.ibatis.annotations.Param;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
 import cn.com.qmth.mps.entity.SchoolEntity;
+import cn.com.qmth.mps.vo.school.SchoolQuery;
+import cn.com.qmth.mps.vo.school.SchoolVo;
 
 public interface SchoolDao extends BaseMapper<SchoolEntity> {
 
+	IPage<SchoolVo> page(Page<SchoolVo> page,@Param("req") SchoolQuery query,@Param("schoolId") Long schoolId);
+
 }

+ 17 - 0
src/main/java/cn/com/qmth/mps/service/SchoolService.java

@@ -1,9 +1,26 @@
 package cn.com.qmth.mps.service;
 
+import java.util.List;
+
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.boot.core.collection.PageResult;
 
+import cn.com.qmth.mps.bean.User;
 import cn.com.qmth.mps.entity.SchoolEntity;
+import cn.com.qmth.mps.vo.school.SchoolDomain;
+import cn.com.qmth.mps.vo.school.SchoolQuery;
+import cn.com.qmth.mps.vo.school.SchoolVo;
 
 public interface SchoolService  extends IService<SchoolEntity> {
 
+	void syncSchool(User accessUser);
+
+	void saveSchool(User accessUser, SchoolDomain domain);
+
+	PageResult<SchoolVo> page(SchoolQuery query, User accessUser);
+
+	SchoolVo info(Long id, User accessUser);
+
+	void toggle(List<Long> ids, Boolean enable, User accessUser);
+
 }

+ 1 - 1
src/main/java/cn/com/qmth/mps/service/UserService.java

@@ -25,7 +25,7 @@ public interface UserService  extends IService<UserEntity> {
 
 	UserVo info(Long id);
 
-	void toggle(List<Long> ids, Boolean enable);
+	void toggle(List<Long> ids, Boolean enable, User user);
 
 	void updatePass(String password, User accessUser);
 

+ 142 - 0
src/main/java/cn/com/qmth/mps/service/impl/SchoolServiceImpl.java

@@ -1,15 +1,157 @@
 package cn.com.qmth.mps.service.impl;
 
+import java.util.List;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+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.qmth.boot.core.collection.PageResult;
+import com.qmth.boot.core.exception.StatusException;
 
+import cn.com.qmth.mps.bean.User;
 import cn.com.qmth.mps.dao.SchoolDao;
 import cn.com.qmth.mps.entity.SchoolEntity;
+import cn.com.qmth.mps.enums.Role;
 import cn.com.qmth.mps.service.SchoolService;
+import cn.com.qmth.mps.util.PageUtil;
+import cn.com.qmth.mps.util.SolarHttpUtil;
+import cn.com.qmth.mps.vo.school.SchoolDomain;
+import cn.com.qmth.mps.vo.school.SchoolQuery;
+import cn.com.qmth.mps.vo.school.SchoolVo;
 
 @Service
 public class SchoolServiceImpl extends ServiceImpl<SchoolDao, SchoolEntity> implements SchoolService {
+	@Value("${qmth.solar.host}")
+	private String host;
+	@Value("${qmth.solar.org.uri}")
+	private String uri;
+	@Value("${access-key}")
+	private String accessKey;
+	@Value("${access-secret}")
+	private String accessSecret;
+	@Value("${wxapp-url}")
+	private String wxappUrl;
+	
+	@Transactional
+	@Override
+	public void syncSchool(User user) {
+		if (!user.getRole().equals(Role.SUPER_ADMIN)) {
+			throw new StatusException("非法操作");
+		}
+		SolarHttpUtil orgUtil = new SolarHttpUtil(accessKey, accessSecret, host, uri);
+		List<SchoolEntity> list = orgUtil.getOrgs();
+		if (CollectionUtils.isEmpty(list)) {
+			return;
+		}
+		for (SchoolEntity org : list) {
+			addSchoolForSync(user, org);
+		}
+	}
+
+	private void addSchoolForSync(User user, SchoolEntity org) {
+		if (this.findSchoolByCode(org.getCode()) != null) {
+			return;
+		}
+		org.setId(null);
+		org.setEnable(true);
+		this.save(org);
+	}
+
+	private SchoolEntity findSchoolByCode(String code) {
+		QueryWrapper<SchoolEntity> wrapper = new QueryWrapper<>();
+		LambdaQueryWrapper<SchoolEntity> lw = wrapper.lambda();
+		lw.eq(SchoolEntity::getCode, code);
+		return this.getOne(wrapper);
+	}
+
+	@Transactional
+	@Override
+	public void saveSchool(User user, SchoolDomain domain) {
+		if (!user.getRole().equals(Role.SUPER_ADMIN) && domain.getId() == null) {
+			throw new StatusException("非法操作");
+		}
+		if (!user.getRole().equals(Role.SUPER_ADMIN) && domain.getId() != null
+				&& !user.getSchoolId().equals(domain.getId())) {
+			throw new StatusException("非法操作");
+		}
+		if (domain.getId() == null && StringUtils.isBlank(domain.getCode())) {
+			throw new StatusException("学校编码不能为空");
+		}
+		if (StringUtils.isBlank(domain.getName())) {
+			throw new StatusException("学校名称不能为空");
+		}
+		SchoolEntity ue = null;
+		if (domain.getId() != null) {
+			ue = this.getById(domain.getId());
+			if (ue == null) {
+				throw new StatusException("未找到学校");
+			}
+		} else {
+			if (findSchoolByCode(domain.getCode()) != null) {
+				throw new StatusException("学校编码已存在");
+			}
+			ue = new SchoolEntity();
+			ue.setCode(domain.getCode());
+			ue.setEnable(true);
+		}
+		ue.setName(domain.getName());
+		ue.setContacts(domain.getContacts());
+		ue.setTelephone(domain.getTelephone());
+		ue.setRegion(domain.getRegion());
+		this.saveOrUpdate(ue);
+	}
+
+	@Override
+	public PageResult<SchoolVo> page(SchoolQuery query, User user) {
+		Long schoolId=null;
+		if (!user.getRole().equals(Role.SUPER_ADMIN)) {
+			schoolId=user.getSchoolId();
+		}
+		IPage<SchoolVo> iPage = this.baseMapper.page(new Page<SchoolVo>(query.getPageNumber(), query.getPageSize()), query,schoolId);
+		if(CollectionUtils.isNotEmpty(iPage.getRecords())) {
+			for(SchoolVo vo:iPage.getRecords()) {
+				vo.setQrCode(wxappUrl);
+			}
+		}
+		return PageUtil.of(iPage);
+	}
 
+	@Override
+	public SchoolVo info(Long id, User user) {
+		if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(id)) {
+			return null;
+		}
+		SchoolEntity ue = this.getById(id);
+		if (ue == null) {
+			throw new StatusException("未找到学校");
+		}
+		SchoolVo vo=new SchoolVo();
+		BeanUtils.copyProperties(ue, vo);
+		vo.setQrCode(wxappUrl);
+		return vo;
+	}
 
+	@Transactional
+	@Override
+	public void toggle(List<Long> ids, Boolean enable, User user) {
+		if (!user.getRole().equals(Role.SUPER_ADMIN)) {
+			throw new StatusException("非法操作");
+		}
+		UpdateWrapper<SchoolEntity> wrapper = new UpdateWrapper<>();
+		LambdaUpdateWrapper<SchoolEntity> lw = wrapper.lambda();
+		lw.set(SchoolEntity::getEnable, enable);
+		lw.in(SchoolEntity::getId, ids);
+		this.update(wrapper);
+	}
 }

+ 4 - 1
src/main/java/cn/com/qmth/mps/service/impl/UserServiceImpl.java

@@ -263,11 +263,14 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 
 	@Transactional
 	@Override
-	public void toggle(List<Long> ids, Boolean enable) {
+	public void toggle(List<Long> ids, Boolean enable, User user) {
 		UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
 		LambdaUpdateWrapper<UserEntity> lw = wrapper.lambda();
 		lw.set(UserEntity::getEnable, enable);
 		lw.in(UserEntity::getId, ids);
+		if (!user.getRole().equals(Role.SUPER_ADMIN)) {
+			lw.eq(UserEntity::getSchoolId, user.getSchoolId());
+		}
 		this.update(wrapper);
 	}
 

+ 252 - 0
src/main/java/cn/com/qmth/mps/util/SolarHttpUtil.java

@@ -0,0 +1,252 @@
+package cn.com.qmth.mps.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.core.exception.StatusException;
+import com.qmth.boot.core.solar.model.AppLicense;
+import com.qmth.boot.tools.signature.SignatureEntity;
+import com.qmth.boot.tools.signature.SignatureType;
+
+import cn.com.qmth.mps.entity.SchoolEntity;
+
+public class SolarHttpUtil {
+
+	/** 默认的编码格式 */
+	private static final String DEFAULT_CHARSET = "UTF-8";
+
+	private static final String CONTENT_TYPE = "Content-Type";
+
+	private static final String APPLICATION_JSON = "application/x-www-form-urlencoded;charset=utf-8";
+
+	private static final String METHOD_POST = "POST";
+
+	private static final String AUTH = "Authorization";
+
+	private String host = null;
+
+	private String uri = null;
+
+	private String accessKey = null;
+
+	private String accessSecret = null;
+
+	public SolarHttpUtil(String accessKey, String accessSecret, String host, String uri) {
+		this.accessKey = accessKey;
+		this.accessSecret = accessSecret;
+		this.uri = uri;
+		this.host = host;
+	}
+
+	/**
+	 * 
+	 * @param params headers参数
+	 * @param datas  requestParams参数
+	 * @return
+	 * @throws Exception
+	 */
+	public String httpAction(Map<String, String> params, Map<String, Object> datas) {
+		String result = null;
+		HttpsURLConnection conn = null;
+		OutputStream os = null;
+		InputStream is = null;
+
+		try {
+
+			// 获取链接
+			URL url = new URL(host + uri);
+			conn = (HttpsURLConnection) url.openConnection();
+
+			conn.setRequestMethod(METHOD_POST);
+			conn.setRequestProperty(CONTENT_TYPE, APPLICATION_JSON);
+			// 设置鉴权
+			long time = System.currentTimeMillis();
+			String signature = SignatureEntity.build(SignatureType.SECRET, METHOD_POST, uri, time, accessKey,
+					accessSecret);
+			conn.setRequestProperty(AUTH, signature);
+			conn.setRequestProperty("time", String.valueOf(time));
+			// ssl
+			SSLContext context = SSLContext.getInstance("SSL", "SunJSSE");
+			TrustManager[] tm = new TrustManager[] { new X509TrustManager() {
+
+				@Override
+				public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+				}
+
+				@Override
+				public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+				}
+
+				@Override
+				public X509Certificate[] getAcceptedIssuers() {
+					return null;
+				}
+			} };
+			// 初始化
+			context.init(null, tm, new java.security.SecureRandom());
+			// 获取SSLSocketFactory对象
+			SSLSocketFactory ssf = context.getSocketFactory();
+			conn.setSSLSocketFactory(ssf);
+
+			conn.setUseCaches(false);
+			conn.setDoOutput(true);
+
+			// 设置额外的参数
+			if (params != null && !params.isEmpty()) {
+
+				for (Map.Entry<String, String> param : params.entrySet()) {
+					conn.setRequestProperty(param.getKey(), param.getValue());
+				}
+			}
+			// 创建链接
+			conn.connect();
+			// 设置请求参数
+			if (datas != null) {
+				StringBuilder sb = new StringBuilder();
+				for (Map.Entry<String, Object> data : datas.entrySet()) {
+					sb.append(data.getKey()).append("=").append(data.getValue()).append("&");
+				}
+				os = conn.getOutputStream();
+				os.write(sb.toString().getBytes());
+				os.flush();
+			}
+
+			result = getResult(conn);
+		} catch (IOException e) {
+			try {
+				JSONObject js = JSONObject.parseObject(e.getMessage());
+				if (js.getString("code").startsWith("401")) {
+					throw new StatusException("无效的授权");
+				} else {
+					throw new StatusException("授权服务器访问失败", e);
+				}
+			} catch (StatusException e1) {
+				throw e1;
+			} catch (Exception e2) {
+				throw new StatusException("授权服务器访问失败", e);
+			}
+		} catch (Exception e) {
+			throw new StatusException("授权服务器访问失败", e);
+		} finally {
+			try {
+				if (os != null) {
+					os.close();
+					os = null;
+				}
+				if (is != null) {
+					is.close();
+					is = null;
+				}
+			} catch (IOException e) {
+			}
+
+			if (conn != null) {
+				conn.disconnect();
+				conn = null;
+			}
+		}
+
+		return result;
+	}
+
+	/**
+	 * 获得连接请求的返回数据
+	 * 
+	 * @param conn
+	 * 
+	 * @return 字符串
+	 */
+	private String getResult(HttpURLConnection conn) throws IOException {
+
+		StringBuilder text = new StringBuilder();
+
+		InputStream is = null;
+		InputStreamReader sr = null;
+		BufferedReader br = null;
+
+		int code = conn.getResponseCode();
+
+		try {
+			is = code >= 400 ? conn.getErrorStream() : conn.getInputStream();
+
+			sr = new InputStreamReader(is, DEFAULT_CHARSET);
+			br = new BufferedReader(sr);
+
+			char[] chars = new char[4096];
+			int length = 0;
+
+			while ((length = br.read(chars)) != -1) {
+				text.append(chars, 0, length);
+			}
+		} finally {
+			if (br != null) {
+				br.close();
+				br = null;
+			}
+			if (sr != null) {
+				sr.close();
+				sr = null;
+			}
+			if (is != null) {
+				is.close();
+				is = null;
+			}
+		}
+		if (code >= 400) {
+			throw new IOException(text.toString());
+		}
+		return text.toString();
+	}
+
+	public AppLicense getAppInfo() {
+		String str = this.httpAction(null, null);
+		AppLicense appInfo = JSONObject.parseObject(str, AppLicense.class);
+		return appInfo;
+	}
+
+	public List<SchoolEntity> getOrgs() {
+		List<SchoolEntity> orgs = new ArrayList<SchoolEntity>();
+		int pageNumber = 1;
+		int pageSize = 100;
+		for (;;) {
+			Map<String, Object> datas = new HashMap<String, Object>();
+			datas.put("pageNumber", pageNumber);
+			datas.put("pageSize", pageSize);
+			String str = this.httpAction(null, datas);
+			JSONArray orgArray = JSONArray.parseArray(str);
+			for (int i = 0; i < orgArray.size(); i++) {
+				JSONObject orgOb = orgArray.getJSONObject(i);
+				SchoolEntity org = new SchoolEntity();
+				org.setCode(orgOb.getString("code"));
+				org.setName(orgOb.getString("name"));
+				org.setEnable(true);
+				orgs.add(org);
+			}
+			if (orgArray.size() != pageSize) {
+				break;
+			}
+			pageNumber++;
+		}
+
+		return orgs;
+	}
+}

+ 18 - 0
src/main/resources/mapper/SchoolMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.qmth.mps.dao.SchoolDao">
+
+	<select id="page"
+		resultType="cn.com.qmth.mps.vo.school.SchoolVo">
+		select t.*,s.name schoolName from mps_school
+		t
+		where 1=1
+		<if test="schoolId != null">
+			and t.id=#{schoolId}
+		</if>
+		<if test="req.name != null and reqname !=''">
+			and t.name like concat('%', #{req.name}, '%')
+		</if>
+		order by t.update_time desc
+	</select>
+</mapper>