You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
7.8 KiB
Java

package com.sztzjy.linkCommerce.controller.stu;
import cn.hutool.core.convert.Convert;
import com.sztzjy.linkCommerce.annotation.AnonymousAccess;
import com.sztzjy.linkCommerce.config.Constant;
import com.sztzjy.linkCommerce.entity.*;
import com.sztzjy.linkCommerce.entity.scoreDTO.StuModuleDTO;
import com.sztzjy.linkCommerce.mapper.StuCountMapper;
import com.sztzjy.linkCommerce.mapper.StuStudyTimeMapper;
import com.sztzjy.linkCommerce.mapper.UserinfoMapper;
import com.sztzjy.linkCommerce.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.UUID;
@Api(tags = "学习时间、访问次数相关")
@RequestMapping("api/studyTime")
@RestController
public class StudyTimeAndCountController {
@Autowired
StuStudyTimeMapper stuStudyTimeMapper;
@Autowired
UserinfoMapper userinfoMapper;
@Autowired
StuCountMapper stuCountMapper;
@PostMapping("/updateStudyTime")
@ApiOperation("更新学习时间")
@AnonymousAccess
public ResultEntity<StuModuleDTO> updateStudyTime(@RequestParam String userId, @RequestParam @ApiParam("项目名称 市场需求挖掘、产品规划") String projectName, @RequestParam String time) {
//先查询有无这个对象 没有则新增对象
StuStudyTimeExample stuStudyTimeExample = new StuStudyTimeExample();
stuStudyTimeExample.createCriteria().andUserIdEqualTo(userId);
List<StuStudyTime> stuStudyTimes = stuStudyTimeMapper.selectByExample(stuStudyTimeExample);
int insert = 0;
if (stuStudyTimes.isEmpty() || stuStudyTimes == null) {
Userinfo userinfo = userinfoMapper.selectByPrimaryKey(userId);
StuStudyTime stuStudyTime = new StuStudyTime();
stuStudyTime.setId(UUID.randomUUID().toString());
stuStudyTime.setSchoolId(userinfo.getSchoolId());
stuStudyTime.setUserId(userId);
stuStudyTime.setName(userinfo.getName());
stuStudyTime.setSchoolClassId(userinfo.getSchoolClassId());
stuStudyTime.setClassName(userinfo.getClassName());
stuStudyTime.setMarketResearchTime(0);
stuStudyTime.setProductEvaluationTime(0);
stuStudyTime.setProductLaunchTestTime(0);
stuStudyTime.setProductPlanningTime(0);
stuStudyTime.setSupplyChannelTime(0);
if (Constant.PRO_SCXQWJ.equals(projectName)) {
stuStudyTime.setMarketResearchTime(Convert.toInt(time));
} else if (Constant.PRO_CPGH.equals(projectName)) {
stuStudyTime.setProductPlanningTime(Convert.toInt(time));
} else if (Constant.PRO_CPTFCS.equals(projectName)) {
stuStudyTime.setProductLaunchTestTime(Convert.toInt(time));
} else if (Constant.PRO_GYQDGL.equals(projectName)) {
stuStudyTime.setSupplyChannelTime(Convert.toInt(time));
} else if (Constant.PRO_CPPGYKH.equals(projectName)) {
stuStudyTime.setProductEvaluationTime(Convert.toInt(time));
}
insert = stuStudyTimeMapper.insert(stuStudyTime);
} else {
StuStudyTime stuStudyTime = stuStudyTimes.get(0);
if (Constant.PRO_SCXQWJ.equals(projectName)) {
stuStudyTime.setMarketResearchTime(stuStudyTime.getMarketResearchTime() + Convert.toInt(time));
} else if (Constant.PRO_CPGH.equals(projectName)) {
stuStudyTime.setProductPlanningTime(stuStudyTime.getProductPlanningTime() + Convert.toInt(time));
} else if (Constant.PRO_CPTFCS.equals(projectName)) {
stuStudyTime.setProductLaunchTestTime(stuStudyTime.getProductLaunchTestTime() + Convert.toInt(time));
} else if (Constant.PRO_GYQDGL.equals(projectName)) {
stuStudyTime.setSupplyChannelTime(stuStudyTime.getSupplyChannelTime() + Convert.toInt(time));
} else if (Constant.PRO_CPPGYKH.equals(projectName)) {
stuStudyTime.setProductEvaluationTime(stuStudyTime.getProductEvaluationTime() + Convert.toInt(time));
}
insert = stuStudyTimeMapper.updateByPrimaryKey(stuStudyTime);
}
if (insert == 1) {
return new ResultEntity<>(HttpStatus.OK, "更新学习时间成功");
} else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "更新学习时间失败");
}
}
@PostMapping("/selectStudyTime")
@ApiOperation("查看学习时间")
@AnonymousAccess
public ResultEntity<StuStudyTime> selectStudyTime(@RequestParam String userId) {
StuStudyTimeExample stuStudyTimeExample = new StuStudyTimeExample();
stuStudyTimeExample.createCriteria().andUserIdEqualTo(userId);
List<StuStudyTime> stuStudyTimes = stuStudyTimeMapper.selectByExample(stuStudyTimeExample);
if (stuStudyTimes.isEmpty() || stuStudyTimes == null) {
return new ResultEntity<>(HttpStatus.OK, "暂无学习时间");
} else {
StuStudyTime stuStudyTime = stuStudyTimes.get(0);
return new ResultEntity<>(HttpStatus.OK, "查看学习时间成功", stuStudyTime);
}
}
@PostMapping("/updateStudyCount")
@ApiOperation("更新访问次数")
@AnonymousAccess
public ResultEntity updateStudyCount(@RequestParam String userId,@RequestParam String classId,@RequestParam String schoolId, @RequestParam @ApiParam("项目名称 市场需求挖掘、产品规划") String projectName) {
//先查询stucount表是否存在
StuCountExample stuCountExample = new StuCountExample();
stuCountExample.createCriteria().andUserIdEqualTo(userId).andProjectEqualTo(projectName);
List<StuCount> stuCounts = stuCountMapper.selectByExample(stuCountExample);
if(stuCounts.isEmpty() || stuCounts==null){
StuCount stuCount = new StuCount();
stuCount.setId(UUID.randomUUID().toString());
stuCount.setUserId(userId);
stuCount.setVisitCount(1);
stuCount.setClassId(classId);
stuCount.setProject(projectName);
stuCount.setSchoolId(schoolId);
int insert = stuCountMapper.insert(stuCount);
if(insert==1){
return new ResultEntity<>(HttpStatus.OK, "更新成功");
}else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "更新失败");
}
}
StuCount stuCount = stuCounts.get(0);
stuCount.setVisitCount(stuCount.getVisitCount()+1);
int insert = stuCountMapper.updateByPrimaryKey(stuCount);
if(insert==1){
return new ResultEntity<>(HttpStatus.OK, "更新成功");
}else {
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "更新失败");
}
}
@PostMapping("/selectStuCount")
@ApiOperation("查询学生项目访问次数")
@AnonymousAccess
public ResultEntity<List<StuCount>> selectStuCount(@RequestParam String userId, @RequestParam String schoolId) {
StuCountExample stuCountExample = new StuCountExample();
stuCountExample.createCriteria().andUserIdEqualTo(userId);
List<StuCount> stuCounts = stuCountMapper.selectByExample(stuCountExample);
if(stuCounts.isEmpty() || stuCounts==null){
return new ResultEntity<>(HttpStatus.OK, "暂无数据");
}else {
return new ResultEntity<>(HttpStatus.OK, "查询成功",stuCounts);
}
}
}