zouxuan 5 năm trước cách đây
mục cha
commit
7fe7ab9b0a

+ 10 - 0
pom.xml

@@ -171,6 +171,16 @@
 			<artifactId>lombok</artifactId>
 			<optional>true</optional>
 		</dependency>
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger2</artifactId>
+			<version>2.2.2</version>
+		</dependency>
+		<dependency>
+			<groupId>io.springfox</groupId>
+			<artifactId>springfox-swagger-ui</artifactId>
+			<version>2.2.2</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 2 - 0
src/main/java/com/ym/mec/collectfee/CollectFeeServerApplication.java

@@ -7,6 +7,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 @SpringBootApplication
 @MapperScan("com.ym.mec.collectfee.dao")
@@ -14,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
 @ServletComponentScan//filter才能生效
 @Configuration
 @EnableFeignClients
+@EnableSwagger2
 public class CollectFeeServerApplication {
 
 	public static void main(String[] args) {

+ 0 - 18
src/main/java/com/ym/mec/collectfee/controller/DemoController.java

@@ -1,18 +0,0 @@
-package com.ym.mec.collectfee.controller;
-
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.ym.mec.collectfee.common.web.BaseController;
-
-@RestController
-@RequestMapping("")
-public class DemoController extends BaseController {
-
-	@GetMapping("/info")
-	public Object getInfo() {
-		System.out.println("************* Demo Controller *************");
-		return succeed();
-	}
-}

+ 0 - 33
src/main/java/com/ym/mec/collectfee/controller/OrchestraController.java

@@ -1,33 +0,0 @@
-//package com.ym.mec.collectfee.controller;
-//
-//import com.ym.mec.collectfee.common.web.BaseController;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.validation.annotation.Validated;
-//import org.springframework.web.bind.annotation.*;
-//
-///**
-// * 乐团
-// */
-//@RestController
-//@RequestMapping("orchestra")
-//public class OrchestraController extends BaseController {
-//
-//    @Autowired
-//    ApplyInfoService applyInfoService;
-//
-//    /**
-//     * 乐团报名
-//     */
-//    @PostMapping("/apply")
-//    public void apply(@ModelAttribute @Validated ApplyInfo applyInfo) throws Exception {
-//        long id = applyInfoService.insert(applyInfo);
-//    }
-//
-//
-//    @GetMapping("/applyinfo")
-//    public void applyInfo(int id){
-//        applyInfoService
-//    }
-//
-//
-//}

+ 13 - 3
src/main/java/com/ym/mec/collectfee/controller/OrderController.java

@@ -2,13 +2,19 @@ package com.ym.mec.collectfee.controller;
 
 import com.ym.mec.collectfee.common.web.BaseController;
 import com.ym.mec.collectfee.service.OrderService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController()
 @RequestMapping("order")
+@Api("订单服务")
 public class OrderController extends BaseController {
 
     @Autowired
@@ -19,7 +25,9 @@ public class OrderController extends BaseController {
      * @param userId
      * @return
      */
-    @PostMapping("/get")
+    @PostMapping("/getOrderList")
+    @ApiOperation(value = "根据学生编号,获取订单列表")
+    @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "学生编号", required = true, dataType = "Integer")})
     public Object getOrders(Integer userId){
         return succeed(orderService.getOrderByUserId(userId));
     }
@@ -31,6 +39,9 @@ public class OrderController extends BaseController {
      * @return
      */
     @PostMapping("/applyNum")
+    @ApiOperation(value = "根据乐团名称、声部名称,查询报名人数")
+    @ApiImplicitParams({ @ApiImplicitParam(name = "poName", value = "乐团名称", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "voicePart", value = "声部名称", required = true, dataType = "String")})
     public Object queryNum(String poName,String voicePart){
         return orderService.countOrder(poName, voicePart);
     }
@@ -50,9 +61,8 @@ public class OrderController extends BaseController {
      * @param schoolId
      * @return
      */
-    @RequestMapping("/getSchoolDetail")
+    @GetMapping("/getSchoolDetail")
     public Object getSchoolDetail(Integer schoolId,Integer clazzId){
         return orderService.getSchoolDetail(schoolId,clazzId);
     }
-
 }

+ 60 - 0
src/main/java/com/ym/mec/collectfee/controller/UserController.java

@@ -0,0 +1,60 @@
+package com.ym.mec.collectfee.controller;
+
+
+import com.ym.mec.collectfee.common.web.BaseController;
+import com.ym.mec.collectfee.entity.ApplyInfo;
+import com.ym.mec.collectfee.service.ApplyInfoService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController()
+@RequestMapping("user")
+@Api("用户服务")
+public class UserController extends BaseController {
+
+    @Autowired
+    private ApplyInfoService applyInfoService;
+
+
+    /**
+     * 查询用户详情
+     * @param phone
+     * @param clazzId
+     * @return
+     */
+    @GetMapping("/getUserDetailByPhone")
+    @ApiOperation(value = "根据乐团编号、用户手机,查询用户详情")
+    @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "用户手机", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "clazzId", value = "乐团编号", required = true, dataType = "Integer")})
+    public Object getUserDetailByPhone(String phone,Integer clazzId){
+        if(StringUtils.isEmpty(phone) || clazzId == null){
+            return failed("参数校验异常");
+        }
+        ApplyInfo userByPhone = applyInfoService.findUserByPhone(phone, clazzId);
+        return succeed(userByPhone);
+    }
+
+    /**
+     * 用户报名
+     * @param applyInfo
+     * @return
+     */
+    @ApiOperation(value = "学生报名乐团")
+    @PostMapping("/userApply")
+    public Object userApply(ApplyInfo applyInfo){
+        if(applyInfo != null){
+            applyInfoService.insert(applyInfo);
+            return succeed();
+        }
+        return failed();
+    }
+
+}

+ 4 - 3
src/main/java/com/ym/mec/collectfee/controller/YqPayController.java

@@ -9,19 +9,18 @@ import com.ym.mec.collectfee.utils.GenerateNum;
 import com.ym.mec.collectfee.utils.yqpay.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
-import lombok.extern.log4j.Log4j;
+import springfox.documentation.annotations.ApiIgnore;
 
-import java.math.BigDecimal;
 import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.zip.Inflater;
 
 @Slf4j
 @RestController
@@ -29,8 +28,10 @@ import java.util.zip.Inflater;
 public class YqPayController {
 
     @Autowired
+    @Lazy
     private YqPayService yqPayService;
     @Autowired
+    @Lazy
     private YqQueryService yqQueryService;
     @Autowired
     private OrderService orderService;

+ 2 - 0
src/main/java/com/ym/mec/collectfee/controller/YqRegController.java

@@ -5,10 +5,12 @@ import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import springfox.documentation.annotations.ApiIgnore;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+@ApiIgnore
 @Controller
 @RequestMapping("yqreg")
 public class YqRegController {

+ 8 - 1
src/main/java/com/ym/mec/collectfee/dao/ApplyInfoDao.java

@@ -2,10 +2,17 @@ package com.ym.mec.collectfee.dao;
 
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.entity.ApplyInfo;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Component;
 
 @Component
 public interface ApplyInfoDao extends BaseDAO<Integer, ApplyInfo> {
 
-	
+    /**
+     * 根据用户输入的手机,乐团编号查询用户信息
+     * @param phone
+     * @param clazzId
+     * @return
+     */
+    ApplyInfo findUserByPhone(@Param("phone") String phone, @Param("clazzId") Integer clazzId);
 }

+ 6 - 0
src/main/java/com/ym/mec/collectfee/service/ApplyInfoService.java

@@ -5,4 +5,10 @@ import com.ym.mec.collectfee.entity.ApplyInfo;
 
 public interface ApplyInfoService extends BaseService<Integer, ApplyInfo> {
 
+    /**
+     * 根据用户输入的手机,乐团编号查询用户信息
+     * @return
+     */
+    ApplyInfo findUserByPhone(String phone,Integer clazzId);
+
 }

+ 1 - 0
src/main/java/com/ym/mec/collectfee/service/YqPayService.java

@@ -2,6 +2,7 @@ package com.ym.mec.collectfee.service;
 
 import com.ym.mec.collectfee.utils.yqpay.Msg;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;

+ 5 - 1
src/main/java/com/ym/mec/collectfee/service/impl/ApplyInfoServiceImpl.java

@@ -18,5 +18,9 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 	public BaseDAO<Integer, ApplyInfo> getDAO() {
 		return applyInfoDao;
 	}
-	
+
+	@Override
+	public ApplyInfo findUserByPhone(String phone, Integer clazzId) {
+		return applyInfoDao.findUserByPhone(phone,clazzId);
+	}
 }

+ 4 - 1
src/main/java/com/ym/mec/collectfee/service/impl/OrderServiceImpl.java

@@ -7,6 +7,7 @@ import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
 import com.ym.mec.collectfee.dao.OrderDao;
 import com.ym.mec.collectfee.entity.*;
 import com.ym.mec.collectfee.service.OrderService;
+import com.ym.mec.collectfee.service.SchoolService;
 import com.ym.mec.collectfee.utils.HttpUtil;
 import com.ym.mec.collectfee.utils.XStreamUtil;
 import org.apache.commons.lang3.RandomUtils;
@@ -26,6 +27,8 @@ public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements
 	
 	@Autowired
 	private OrderDao orderDao;
+	@Autowired
+	private SchoolService schoolService;
 
 	//公共密钥
 	private String publicKey = "e99a18c428cb38d5f260853678922e03";
@@ -115,7 +118,7 @@ public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements
 			xs.toXML(requestParamBean,writer);
 			String parseBody = parseBody(HttpUtil.postXmlData(writer.toString(), url));
 			ResponseCourseEntity xmlToObject = XStreamUtil.xmlToObject("body", ResponseCourseEntity.class, parseBody);
-			return xmlToObject;
+			return schoolService.upsetSchool(xmlToObject);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}

+ 27 - 0
src/main/java/com/ym/mec/collectfee/service/impl/SchoolServiceImpl.java

@@ -3,11 +3,16 @@ package com.ym.mec.collectfee.service.impl;
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
 import com.ym.mec.collectfee.dao.SchoolDao;
+import com.ym.mec.collectfee.entity.Course;
 import com.ym.mec.collectfee.entity.ResponseCourseEntity;
 import com.ym.mec.collectfee.entity.School;
 import com.ym.mec.collectfee.service.SchoolService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
 
 @Service
 public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implements SchoolService {
@@ -21,7 +26,29 @@ public class SchoolServiceImpl extends BaseServiceImpl<Integer, School> implemen
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public School upsetSchool(ResponseCourseEntity courseEntity) {
+		List<Course> courses = courseEntity.getCourses();
+		if(courses != null && courses.size() > 0){
+			Course course = courses.get(0);
+			School school = schoolDao.get(course.getClassId());
+			Date date = new Date();
+			if(school == null){
+				school = new School();
+				school.setBranchId(course.getBranchId());
+				school.setName(course.getClassName());
+				school.setSchoolId(course.getClassId());
+				school.setStatus(course.getStatus());
+				school.setCreateTime(date);
+				school.setUpdateTime(date);
+				schoolDao.insert(school);
+			}else {
+				school.setStatus(course.getStatus());
+				school.setUpdateTime(date);
+				schoolDao.update(school);
+			}
+			return school;
+		}
 		return null;
 	}
 }

+ 3 - 0
src/main/resources/config/mybatis/ApplyInfoMapper.xml

@@ -64,4 +64,7 @@
 	<select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM apply_info
 	</select>
+    <select id="findUserByPhone" resultMap="ApplyInfo">
+		SELECT * FROM apply_info WHERE patriarch_phone_ = #{phone} AND school_ = #{clazzId}
+	</select>
 </mapper>