|
@@ -1,8 +1,12 @@
|
|
|
package com.jpsoft.campus.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.campus.modules.base.entity.ApplicationPrimary;
|
|
|
import com.jpsoft.campus.modules.base.entity.Apportion;
|
|
|
+import com.jpsoft.campus.modules.base.entity.ApportionDetail;
|
|
|
import com.jpsoft.campus.modules.base.entity.SchoolInfo;
|
|
|
+import com.jpsoft.campus.modules.base.service.ApplicationPrimaryService;
|
|
|
+import com.jpsoft.campus.modules.base.service.ApportionDetailService;
|
|
|
import com.jpsoft.campus.modules.base.service.ApportionService;
|
|
|
import com.jpsoft.campus.modules.base.service.SchoolInfoService;
|
|
|
import com.jpsoft.campus.modules.common.dto.Sort;
|
|
@@ -34,11 +38,15 @@ public class ApportionController {
|
|
|
@Autowired
|
|
|
private ApportionService apportionService;
|
|
|
@Autowired
|
|
|
+ private ApportionDetailService apportionDetailService;
|
|
|
+ @Autowired
|
|
|
private SchoolInfoService schoolInfoService;
|
|
|
@Autowired
|
|
|
private DataDictionaryService dataDictionaryService;
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ApplicationPrimaryService applicationPrimaryService;
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@GetMapping("create")
|
|
@@ -263,4 +271,131 @@ public class ApportionController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="开始派位-小学")
|
|
|
+ @PostMapping("startApportionPrimary")
|
|
|
+ public MessageResult<Map> startApportionPrimary(String schoolId,String type,Integer amount,@RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ //读取等待派位人员信息列表
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("status","60");
|
|
|
+ if (StringUtils.isNotEmpty(schoolId)) {
|
|
|
+ searchParams.put("schoolId",schoolId);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(type)) {
|
|
|
+ searchParams.put("categoryId",type);
|
|
|
+ }
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+ Page<ApplicationPrimary> applicationPrimaryPage = applicationPrimaryService.pageSearch(searchParams,1,100000,false,sortList);
|
|
|
+
|
|
|
+ //随机抽取
|
|
|
+ if(amount > applicationPrimaryPage.size()){
|
|
|
+ amount = applicationPrimaryPage.size();
|
|
|
+ }
|
|
|
+ List<Integer> integerList = new ArrayList<>();
|
|
|
+ Random random = new Random();
|
|
|
+ for(int i=0;i<amount;i++){
|
|
|
+ for(int j=0;j>-1;j++) {
|
|
|
+ Integer ran = random.nextInt(applicationPrimaryPage.size());
|
|
|
+ if (!integerList.contains(ran)) {
|
|
|
+ integerList.add(ran);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入派位信息
|
|
|
+ Apportion apportion = new Apportion();
|
|
|
+ apportion.setId(UUID.randomUUID().toString());
|
|
|
+ apportion.setSchoolId(schoolId);
|
|
|
+ apportion.setType(type);
|
|
|
+ apportion.setDelFlag(false);
|
|
|
+ apportion.setCreateBy(subject);
|
|
|
+ apportion.setCreateTime(new Date());
|
|
|
+ apportion.setUpdateBy(subject);
|
|
|
+ apportion.setUpdateTime(new Date());
|
|
|
+ apportionService.insert(apportion);
|
|
|
+
|
|
|
+ //写入派位列表
|
|
|
+ for(int i=0;i<applicationPrimaryPage.size();i++){
|
|
|
+ ApplicationPrimary applicationPrimary = applicationPrimaryPage.get(i);
|
|
|
+ ApportionDetail apportionDetail = new ApportionDetail();
|
|
|
+ apportionDetail.setId(UUID.randomUUID().toString());
|
|
|
+ apportionDetail.setApportionId(apportion.getId());
|
|
|
+ apportionDetail.setApplicationId(applicationPrimary.getId());
|
|
|
+ apportionDetail.setStudentId(applicationPrimary.getStudentId());
|
|
|
+ apportionDetail.setPersonId(applicationPrimary.getPersonId());
|
|
|
+ apportionDetail.setSchoolId(schoolId);
|
|
|
+ Boolean bl = integerList.contains(i) == true ? true : false;
|
|
|
+ apportionDetail.setWinner(bl);
|
|
|
+ apportionDetail.setDelFlag(false);
|
|
|
+ apportionDetail.setCreateBy(subject);
|
|
|
+ apportionDetail.setCreateTime(new Date());
|
|
|
+ apportionDetail.setUpdateBy(subject);
|
|
|
+ apportionDetail.setUpdateTime(new Date());
|
|
|
+ apportionDetailService.insert(apportionDetail);
|
|
|
+
|
|
|
+ if(bl){
|
|
|
+ applicationPrimary.setStatus(String.valueOf(Integer.parseInt(applicationPrimary.getStatus()) + 10));
|
|
|
+ applicationPrimary.setOfferId(schoolId);
|
|
|
+ applicationPrimary.setUpdateBy(subject);
|
|
|
+ applicationPrimary.setUpdateTime(new Date());
|
|
|
+ applicationPrimaryService.update(applicationPrimary);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("apportionId",apportion.getId());
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(map);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="统计:开始派位-小学")
|
|
|
+ @PostMapping("startApportionPrimary")
|
|
|
+ public MessageResult<Map> startApportionPrimary(String apportionId,@RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ if (StringUtils.isNotEmpty(apportionId)) {
|
|
|
+ searchParams.put("apportionId",apportionId);
|
|
|
+ }
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
+ Page<ApplicationPrimary> applicationPrimaryPage = applicationPrimaryService.pageSearch(searchParams,1,100000,false,sortList);
|
|
|
+ map.put("all",applicationPrimaryPage.size());
|
|
|
+
|
|
|
+ searchParams.put("winner",true);
|
|
|
+ applicationPrimaryPage = applicationPrimaryService.pageSearch(searchParams,1,100000,false,sortList);
|
|
|
+ map.put("winner",applicationPrimaryPage.size());
|
|
|
+
|
|
|
+ searchParams.put("winner",false);
|
|
|
+ applicationPrimaryPage = applicationPrimaryService.pageSearch(searchParams,1,100000,false,sortList);
|
|
|
+ map.put("loser",applicationPrimaryPage.size());
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(map);
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|