|
@@ -0,0 +1,251 @@
|
|
|
+package com.xjrsoft.module.activity.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.db.Entity;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.gson.JsonArray;
|
|
|
+import com.google.gson.JsonElement;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import com.google.gson.JsonParser;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
+import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
|
|
|
+import com.xjrsoft.common.page.ConventPage;
|
|
|
+import com.xjrsoft.common.page.PageOutput;
|
|
|
+import com.xjrsoft.module.activity.dto.ActivityEnrollExportDto;
|
|
|
+import com.xjrsoft.module.activity.dto.ActivityEnrollPageDto;
|
|
|
+import com.xjrsoft.module.activity.dto.ActivityInfoPageDto;
|
|
|
+import com.xjrsoft.module.activity.dto.AddActivityInfoDto;
|
|
|
+import com.xjrsoft.module.activity.dto.ChangeStatusDto;
|
|
|
+import com.xjrsoft.module.activity.dto.UpdateActivityInfoDto;
|
|
|
+import com.xjrsoft.module.activity.entity.ActivityEnroll;
|
|
|
+import com.xjrsoft.module.activity.entity.ActivityInfo;
|
|
|
+import com.xjrsoft.module.activity.service.IActivityEnrollService;
|
|
|
+import com.xjrsoft.module.activity.service.IActivityInfoService;
|
|
|
+import com.xjrsoft.module.activity.vo.ActivityEnrollPageVo;
|
|
|
+import com.xjrsoft.module.activity.vo.ActivityEnrollRangeVo;
|
|
|
+import com.xjrsoft.module.activity.vo.ActivityInfoPageVo;
|
|
|
+import com.xjrsoft.module.activity.vo.ActivityInfoVo;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.concat.service.IXjrUserService;
|
|
|
+import com.xjrsoft.module.organization.entity.Department;
|
|
|
+import com.xjrsoft.module.organization.service.IDepartmentService;
|
|
|
+import com.xjrsoft.module.system.entity.File;
|
|
|
+import com.xjrsoft.module.system.service.IFileService;
|
|
|
+import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+* @title: 活动信息
|
|
|
+* @Author dzx
|
|
|
+* @Date: 2024-07-19
|
|
|
+* @Version 1.0
|
|
|
+*/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/activity" + "/activityInfo")
|
|
|
+@Api(value = "/activity" + "/activityInfo",tags = "活动信息代码")
|
|
|
+@AllArgsConstructor
|
|
|
+public class ActivityInfoController {
|
|
|
+
|
|
|
+
|
|
|
+ private final IActivityInfoService activityInfoService;
|
|
|
+ private final IBaseClassService classService;
|
|
|
+ private final IDepartmentService departmentService;
|
|
|
+ private final IXjrUserService xjrUserService;
|
|
|
+ private final IFileService fileService;
|
|
|
+ private final IActivityEnrollService enrollService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/page")
|
|
|
+ @ApiOperation(value="活动信息列表(分页)")
|
|
|
+ @SaCheckPermission("activityinfo:detail")
|
|
|
+ public RT<PageOutput<ActivityInfoPageVo>> page(@Valid ActivityInfoPageDto dto){
|
|
|
+
|
|
|
+ Page<ActivityInfoPageVo> page = activityInfoService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
|
|
|
+ PageOutput<ActivityInfoPageVo> pageOutput = ConventPage.getPageOutput(page, ActivityInfoPageVo.class);
|
|
|
+ return RT.ok(pageOutput);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/info")
|
|
|
+ @ApiOperation(value="根据id查询活动信息信息")
|
|
|
+ @SaCheckPermission("activityinfo:detail")
|
|
|
+ public RT<ActivityInfoVo> info(@RequestParam Long id){
|
|
|
+ ActivityInfo activityInfo = activityInfoService.getByIdDeep(id);
|
|
|
+ if (activityInfo == null) {
|
|
|
+ return RT.error("找不到此数据!");
|
|
|
+ }
|
|
|
+ ActivityInfoVo infoVo = BeanUtil.toBean(activityInfo, ActivityInfoVo.class);
|
|
|
+ if(infoVo.getOrgId() != null){
|
|
|
+ Department department = departmentService.getById(infoVo.getOrgId());
|
|
|
+ if(department != null){
|
|
|
+ infoVo.setOrgName(department.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(infoVo.getEnterpriseId() != null){
|
|
|
+ String tableName = "company_coop";
|
|
|
+ Entity where = Entity.create(tableName);
|
|
|
+ where.set("id", infoVo.getEnterpriseId());
|
|
|
+ Map<String, Object> objectMap = SqlRunnerAdapter.db().dynamicSelectOne(tableName, where);
|
|
|
+
|
|
|
+ if(objectMap != null && objectMap.containsKey("company_name")){
|
|
|
+ infoVo.setEnterpriseName(objectMap.get("company_name").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ActivityEnrollRangeVo> userRelationList = new ArrayList<>();
|
|
|
+ if(activityInfo.getEnrollRange() != null && !activityInfo.getEnrollRange().isEmpty()){
|
|
|
+ JSONArray asJsonArray = JSONUtil.parseArray(activityInfo.getEnrollRange());
|
|
|
+ for (Object jsonElement : asJsonArray) {
|
|
|
+ ActivityEnrollRangeVo relationDto = JSONUtil.toBean(JSONUtil.parseObj(jsonElement), ActivityEnrollRangeVo.class);
|
|
|
+ if(relationDto.getUserId() != null){
|
|
|
+ XjrUser xjrUser = xjrUserService.getById(relationDto.getUserId());
|
|
|
+ if(xjrUser != null){
|
|
|
+ relationDto.setName(xjrUser.getName());
|
|
|
+ }
|
|
|
+ }else if(relationDto.getDeptId() != null){
|
|
|
+ Department department = departmentService.getById(relationDto.getDeptId());
|
|
|
+ if(department != null){
|
|
|
+ relationDto.setName(department.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }else if(relationDto.getClassId() != null){
|
|
|
+ BaseClass aClass = classService.getById(relationDto.getClassId());
|
|
|
+ if(aClass != null){
|
|
|
+ relationDto.setName(aClass.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userRelationList.add(relationDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ infoVo.setActivityEnrollRangeList(userRelationList);
|
|
|
+
|
|
|
+ ActivityEnrollExportDto dto = new ActivityEnrollExportDto();
|
|
|
+ dto.setActivityInfoId(id);
|
|
|
+ List<ActivityEnrollPageVo> enrollList = enrollService.getList(dto);
|
|
|
+ infoVo.setEnrollCount(enrollList.size());
|
|
|
+
|
|
|
+ Set<ActivityEnrollPageVo> teacherSet = enrollList.stream().filter(x -> x.getTeacherId() != null).collect(Collectors.toSet());
|
|
|
+ infoVo.setTeacherCount(teacherSet.size());
|
|
|
+
|
|
|
+ Set<ActivityEnrollPageVo> studentSet = enrollList.stream().filter(x -> x.getStudentId() != null).collect(Collectors.toSet());
|
|
|
+ infoVo.setStudentCount(studentSet.size());
|
|
|
+
|
|
|
+ Set<ActivityEnrollPageVo> suretSet = enrollList.stream().filter(x -> (x.getStatus() == 1 || x.getStatus() == 2)).collect(Collectors.toSet());
|
|
|
+ infoVo.setSureCount(suretSet.size());
|
|
|
+
|
|
|
+ Set<ActivityEnrollPageVo> notSuretSet = enrollList.stream().filter(x -> x.getStatus() == 0).collect(Collectors.toSet());
|
|
|
+ infoVo.setNotSureCount(notSuretSet.size());
|
|
|
+ return RT.ok(infoVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = "/change-status")
|
|
|
+ @ApiOperation(value="修改状态")
|
|
|
+ @SaCheckPermission("officebuild:detail")
|
|
|
+ public RT<Boolean> changeStatus(@Valid @RequestBody ChangeStatusDto dto) throws Exception {
|
|
|
+ ActivityInfo activityInfo = activityInfoService.getById(dto.getId());
|
|
|
+ if(activityInfo == null){
|
|
|
+ throw new MyException("未能找到活动信息");
|
|
|
+ }
|
|
|
+ activityInfo.setStatus(dto.getStatus());
|
|
|
+ activityInfoService.updateById(activityInfo);
|
|
|
+ return RT.ok(true);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping
|
|
|
+ @ApiOperation(value = "新增活动信息")
|
|
|
+ @SaCheckPermission("activityinfo:add")
|
|
|
+ public RT<Boolean> add(@Valid @RequestBody AddActivityInfoDto dto){
|
|
|
+
|
|
|
+ boolean isSuccess = activityInfoService.add(dto);
|
|
|
+ return RT.ok(isSuccess);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping
|
|
|
+ @ApiOperation(value = "修改活动信息")
|
|
|
+ @SaCheckPermission("activityinfo:edit")
|
|
|
+ public RT<Boolean> update(@Valid @RequestBody UpdateActivityInfoDto dto){
|
|
|
+ return RT.ok(activityInfoService.update(dto));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping
|
|
|
+ @ApiOperation(value = "删除活动信息")
|
|
|
+ @SaCheckPermission("activityinfo:delete")
|
|
|
+ public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
|
|
|
+ return RT.ok(activityInfoService.delete(ids));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping(value = "/effective-list")
|
|
|
+ @ApiOperation(value="移动端活动信息列表(分页)")
|
|
|
+ @SaCheckPermission("activityinfo:detail")
|
|
|
+ public RT<PageOutput<ActivityInfoPageVo>> mobilePage(@Valid ActivityInfoPageDto dto){
|
|
|
+ dto.setIsEffective(1);
|
|
|
+ Page<ActivityInfoPageVo> page = activityInfoService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
|
|
|
+
|
|
|
+ List<ActivityEnroll> enrollList = enrollService.list(
|
|
|
+ new QueryWrapper<ActivityEnroll>().lambda()
|
|
|
+ .eq(ActivityEnroll::getUserId, StpUtil.getLoginIdAsLong())
|
|
|
+ );
|
|
|
+ Set<Long> collect = enrollList.stream().map(ActivityEnroll::getActivityInfoId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ for (ActivityInfoPageVo record : page.getRecords()) {
|
|
|
+ record.setIsEnroll(0);
|
|
|
+ if(collect.contains(Long.parseLong(record.getId()))){
|
|
|
+ record.setIsEnroll(1);
|
|
|
+ }
|
|
|
+ if(record.getCoverFileId() != null){
|
|
|
+ File file = fileService.getOne(new QueryWrapper<File>().lambda().eq(File::getFolderId, record.getCoverFileId()));
|
|
|
+ if(file != null){
|
|
|
+ record.setCoverFileUrl(file.getFileUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageOutput<ActivityInfoPageVo> pageOutput = ConventPage.getPageOutput(page, ActivityInfoPageVo.class);
|
|
|
+ return RT.ok(pageOutput);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/my-enroll-list")
|
|
|
+ @ApiOperation(value="我的报名记录(分页)")
|
|
|
+ @SaCheckPermission("activityinfo:detail")
|
|
|
+ public RT<PageOutput<ActivityInfoPageVo>> myEnrollList(@Valid ActivityInfoPageDto dto){
|
|
|
+ dto.setLoginUserId(StpUtil.getLoginIdAsLong());
|
|
|
+ Page<ActivityInfoPageVo> page = activityInfoService.getMyPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
|
|
|
+ for (ActivityInfoPageVo record : page.getRecords()) {
|
|
|
+ if(record.getCoverFileId() != null){
|
|
|
+ File file = fileService.getOne(new QueryWrapper<File>().lambda().eq(File::getFolderId, record.getCoverFileId()));
|
|
|
+ if(file != null){
|
|
|
+ record.setCoverFileUrl(file.getFileUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageOutput<ActivityInfoPageVo> pageOutput = ConventPage.getPageOutput(page, ActivityInfoPageVo.class);
|
|
|
+ return RT.ok(pageOutput);
|
|
|
+ }
|
|
|
+}
|