|
|
package com.example.client.service.impl;
|
|
|
|
|
|
import cn.bronet.admin.common.core.domain.AjaxResult;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.example.client.domain.CCertificateStudent;
|
|
|
import com.example.client.domain.CUser;
|
|
|
import com.example.client.domain.bo.CCertificateStudentBo;
|
|
|
import com.example.client.domain.vo.CCertificateStudentVo;
|
|
|
import com.example.client.domin.UserContext;
|
|
|
import com.example.client.enumeration.Identity;
|
|
|
import com.example.client.mapper.CCertificateStudentMapper;
|
|
|
import com.example.client.mapper.CUserMapper;
|
|
|
import com.example.client.service.FruitService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.ibatis.javassist.expr.NewArray;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.lang.reflect.Array;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created with IDEA
|
|
|
* author: MaDongXu
|
|
|
* Date:2021/9/17
|
|
|
* Time:15:42
|
|
|
* */
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class FruitServiceImpl implements FruitService {
|
|
|
|
|
|
@Autowired
|
|
|
private CUserMapper cUserMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private CCertificateStudentMapper cCertificateStudentMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查看所有的证书
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult selectAllFruits(Integer classify) {
|
|
|
|
|
|
|
|
|
Long uId = UserContext.currentUserId();
|
|
|
CUser cUser = cUserMapper.selectById(uId);
|
|
|
|
|
|
List<CCertificateStudentVo> vos = new ArrayList<>();
|
|
|
|
|
|
//没有分类
|
|
|
if (classify==null){
|
|
|
|
|
|
//家长
|
|
|
if (cUser.getIdentityType().equals(Identity.PATRIARCH)){
|
|
|
|
|
|
List<CCertificateStudent> allFruits = cCertificateStudentMapper.getAllFruits(cUser.getAtPresent());
|
|
|
|
|
|
for (CCertificateStudent allFruit : allFruits) {
|
|
|
|
|
|
CCertificateStudentVo vo = new CCertificateStudentVo();
|
|
|
BeanUtils.copyProperties(allFruit,vo);
|
|
|
|
|
|
vos.add(vo);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(vos);
|
|
|
|
|
|
//学生
|
|
|
}else {
|
|
|
|
|
|
List<CCertificateStudent> allFruits = cCertificateStudentMapper.getAllFruits(uId);
|
|
|
|
|
|
for (CCertificateStudent allFruit : allFruits) {
|
|
|
|
|
|
CCertificateStudentVo vo = new CCertificateStudentVo();
|
|
|
BeanUtils.copyProperties(allFruit,vo);
|
|
|
|
|
|
vos.add(vo);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(vos);
|
|
|
}
|
|
|
|
|
|
//有分类
|
|
|
}else {
|
|
|
|
|
|
//家长
|
|
|
if (cUser.getIdentityType().equals(Identity.PATRIARCH)){
|
|
|
|
|
|
LambdaQueryWrapper<CCertificateStudent> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(CCertificateStudent::getClassify,classify)
|
|
|
.eq(CCertificateStudent::getUserId,cUser.getAtPresent());
|
|
|
List<CCertificateStudent> allFruits = cCertificateStudentMapper.selectList(queryWrapper);
|
|
|
|
|
|
for (CCertificateStudent allFruit : allFruits) {
|
|
|
|
|
|
CCertificateStudentVo vo = new CCertificateStudentVo();
|
|
|
BeanUtils.copyProperties(allFruit,vo);
|
|
|
|
|
|
vos.add(vo);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(vos);
|
|
|
|
|
|
//学生
|
|
|
}else {
|
|
|
|
|
|
LambdaQueryWrapper<CCertificateStudent> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(CCertificateStudent::getClassify,classify)
|
|
|
.eq(CCertificateStudent::getUserId,uId);
|
|
|
|
|
|
List<CCertificateStudent> allFruits = cCertificateStudentMapper.selectList(queryWrapper);
|
|
|
|
|
|
for (CCertificateStudent allFruit : allFruits) {
|
|
|
|
|
|
CCertificateStudentVo vo = new CCertificateStudentVo();
|
|
|
BeanUtils.copyProperties(allFruit,vo);
|
|
|
|
|
|
vos.add(vo);
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success(vos);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 打开成果树
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult openFruit() {
|
|
|
|
|
|
Long uId = UserContext.currentUserId();
|
|
|
CUser cUser = cUserMapper.selectById(uId);
|
|
|
|
|
|
//家长
|
|
|
if (cUser.getIdentityType().equals(Identity.PATRIARCH)){
|
|
|
|
|
|
//苹果编号1~12
|
|
|
List<Integer> fruits = cCertificateStudentMapper.openFruit(cUser.getAtPresent());
|
|
|
|
|
|
return AjaxResult.success(fruits);
|
|
|
|
|
|
//学生
|
|
|
}else {
|
|
|
|
|
|
//苹果编号1~12
|
|
|
List<Integer> fruits = cCertificateStudentMapper.openFruit(uId);
|
|
|
|
|
|
return AjaxResult.success(fruits);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询单个成果
|
|
|
* @param certificateId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult selectFruit(Long certificateId) {
|
|
|
|
|
|
//根据证书Id查询证书表
|
|
|
CCertificateStudent cCertificateStudent = cCertificateStudentMapper.selectById(certificateId);
|
|
|
|
|
|
//创建返回值vo
|
|
|
CCertificateStudentVo vo = new CCertificateStudentVo();
|
|
|
BeanUtils.copyProperties(cCertificateStudent,vo);
|
|
|
|
|
|
return AjaxResult.success(vo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 上传证书
|
|
|
* @param bo
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public AjaxResult saveFruit(CCertificateStudentBo bo) {
|
|
|
|
|
|
Long uId = UserContext.currentUserId();
|
|
|
CUser cUser = cUserMapper.selectById(uId);
|
|
|
|
|
|
//家长 上传
|
|
|
if (cUser.getIdentityType().equals(Identity.PATRIARCH)){
|
|
|
|
|
|
Integer count = cCertificateStudentMapper.count(cUser.getAtPresent());
|
|
|
List<Integer> integers = cCertificateStudentMapper.openFruit(cUser.getAtPresent());
|
|
|
|
|
|
//等于 12 个
|
|
|
if (count.equals(12)){
|
|
|
|
|
|
int classify = (int) (Math.random() * 12 + 1);
|
|
|
|
|
|
CCertificateStudent cCertificateStudent = new CCertificateStudent();
|
|
|
BeanUtils.copyProperties(bo,cCertificateStudent);
|
|
|
cCertificateStudent.setCreateTime(LocalDateTime.now())
|
|
|
.setUpdateTime(LocalDateTime.now())
|
|
|
.setClassify(classify);
|
|
|
|
|
|
cCertificateStudentMapper.insert(cCertificateStudent);
|
|
|
|
|
|
//小于 12 个
|
|
|
}else {
|
|
|
|
|
|
ArrayList<Integer> classify = new ArrayList<>();
|
|
|
classify.add(1);
|
|
|
classify.add(2);
|
|
|
classify.add(3);
|
|
|
classify.add(4);
|
|
|
classify.add(5);
|
|
|
classify.add(6);
|
|
|
classify.add(7);
|
|
|
classify.add(8);
|
|
|
classify.add(9);
|
|
|
classify.add(10);
|
|
|
classify.add(11);
|
|
|
classify.add(12);
|
|
|
|
|
|
for (int i = 0; i < classify.size(); i++) {
|
|
|
|
|
|
for (Integer integer : integers) {
|
|
|
|
|
|
if (integer.equals(classify.get(i))){
|
|
|
|
|
|
classify.remove(i);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.info("<<<classify<<<::"+classify.toString());
|
|
|
|
|
|
int index =(int) Math.random() * classify.size();
|
|
|
|
|
|
CCertificateStudent cCertificateStudent = new CCertificateStudent();
|
|
|
BeanUtils.copyProperties(bo,cCertificateStudent);
|
|
|
cCertificateStudent.setCreateTime(LocalDateTime.now())
|
|
|
.setUpdateTime(LocalDateTime.now())
|
|
|
.setClassify(classify.get(index));
|
|
|
|
|
|
cCertificateStudentMapper.insert(cCertificateStudent);
|
|
|
|
|
|
}
|
|
|
|
|
|
return AjaxResult.success();
|
|
|
//学生上传
|
|
|
}else{
|
|
|
|
|
|
|
|
|
Integer count = cCertificateStudentMapper.count(uId);
|
|
|
List<Integer> integers = cCertificateStudentMapper.openFruit(uId);
|
|
|
|
|
|
//等于 12 个
|
|
|
if (count.equals(12)){
|
|
|
|
|
|
int classify = (int) (Math.random() * 12 + 1);
|
|
|
|
|
|
CCertificateStudent cCertificateStudent = new CCertificateStudent();
|
|
|
BeanUtils.copyProperties(bo,cCertificateStudent);
|
|
|
cCertificateStudent.setCreateTime(LocalDateTime.now())
|
|
|
.setUpdateTime(LocalDateTime.now())
|
|
|
.setClassify(classify);
|
|
|
|
|
|
cCertificateStudentMapper.insert(cCertificateStudent);
|
|
|
|
|
|
//小于 12 个
|
|
|
}else {
|
|
|
|
|
|
//int[] classify ={1,2,3,4,5,6,7,8,9,10,11,12};
|
|
|
ArrayList<Integer> classify = new ArrayList<>();
|
|
|
classify.add(1);
|
|
|
classify.add(2);
|
|
|
classify.add(3);
|
|
|
classify.add(4);
|
|
|
classify.add(5);
|
|
|
classify.add(6);
|
|
|
classify.add(7);
|
|
|
classify.add(8);
|
|
|
classify.add(9);
|
|
|
classify.add(10);
|
|
|
classify.add(11);
|
|
|
classify.add(12);
|
|
|
|
|
|
for (int i = 0; i < classify.size(); i++) {
|
|
|
|
|
|
for (Integer integer : integers) {
|
|
|
|
|
|
if (integer.equals(classify.get(i))){
|
|
|
|
|
|
classify.remove(i);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
log.info("<<<classify<<<::"+classify.toString());
|
|
|
|
|
|
int index =(int) Math.random() * classify.size();
|
|
|
|
|
|
CCertificateStudent cCertificateStudent = new CCertificateStudent();
|
|
|
BeanUtils.copyProperties(bo,cCertificateStudent);
|
|
|
cCertificateStudent.setCreateTime(LocalDateTime.now())
|
|
|
.setUpdateTime(LocalDateTime.now())
|
|
|
.setClassify(classify.get(index));
|
|
|
|
|
|
cCertificateStudentMapper.insert(cCertificateStudent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|