package com.rzyc.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.common.utils.DateUtils; import com.common.utils.StringUtils; import com.common.utils.model.Code; import com.common.utils.model.SingleResult; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.rzyc.bean.pojo.dto.AddEducationStudyDto; import com.rzyc.bean.pojo.vo.EducationResourceVo; import com.rzyc.bean.pojo.vo.EducationStudyListVo; import com.rzyc.bean.pojo.vo.EducationStudyVo; import com.rzyc.bean.pojo.vo.ListPageVo; import com.rzyc.bean.task.dto.PageDto; import com.rzyc.model.EducationResource; import com.rzyc.model.EducationStudy; import com.rzyc.model.ent.SysEnterprise; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotBlank; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; /** * @BelongsProject: inventory-api * @BelongsPackage: com.rzyc.controller * @Author: SYZ * @CreateTime: 2023-03-27 10:39 * @Version: 1.0 */ @Api(tags = "教育培训接口") @CrossOrigin("*") @RequestMapping("education") @Controller @Validated public class EducationStudyController extends BaseController { protected final static Logger logger = LoggerFactory.getLogger(EducationStudyController.class); /** * @description:获取培训学习列表 * @author: SYZ * @date: 2023/3/29 20:09 * @param: [dto, year, enterpriseId] * @return: com.common.utils.model.SingleResult> **/ @ApiOperation(value = "获取培训学习列表") @ApiImplicitParams({ @ApiImplicitParam(name = "year", value = "年份", dataType = "int", paramType = "query"), @ApiImplicitParam(name = "enterpriseId", value = "企业id", dataType = "string", paramType = "query", required = true), @ApiImplicitParam(name = "memberId", value = "成员id", dataType = "string", paramType = "query") }) @GetMapping("/getList") @ResponseBody public SingleResult> getList(@Valid PageDto dto, Integer year, String enterpriseId,String memberId) { SingleResult> result = new SingleResult<>(); String startDate = ""; String endDate = ""; if (null != year) { startDate = DateUtils.parseDate2String(DateUtils.getFirstDayOfMonth(year, 1), "yyyy-MM-dd HH:mm:ss"); endDate = DateUtils.parseDate2String(DateUtils.getLastDayOfMonth(year, 12), "yyyy-MM-dd HH:mm:ss"); } PageHelper.startPage(dto.getPage(), dto.getPageSize()); Page list = (Page) educationStudyMapper.selectEducationStudyList(startDate, endDate, enterpriseId,memberId, dto.getCondition());; ListPageVo pageVo = new ListPageVo<>(); pageVo.setRows(list); pageVo.setTotal(list.getTotal()); pageVo.setPage(list.getPageNum()); pageVo.setPageSize(list.getPageSize()); result.setData(pageVo); return result; } /** * @description:添加培训学习 * @author: SYZ * @date: 2023/3/29 20:09 * @param: [dto] * @return: com.common.utils.model.SingleResult **/ @ApiOperation(value = "添加培训学习") @PostMapping("/addOne") @ResponseBody public SingleResult addOne(@RequestBody @Valid AddEducationStudyDto dto) { SingleResult result = new SingleResult<>(); Integer count = educationStudyMapper.selectCount( new QueryWrapper().select("1").eq("id", dto.getId()) ); EducationStudy educationStudy = new EducationStudy(); educationStudy.setId(dto.getId()); educationStudy.setEnterpriseId(dto.getEnterpriseId()); educationStudy.setTitle(StringUtils.isBlank(dto.getTitle()) ? "" : dto.getTitle()); educationStudy.setContent(StringUtils.isBlank(dto.getContent()) ? "" : dto.getContent()); educationStudy.setUserId(StringUtils.isBlank(dto.getUserId()) ? "" : dto.getUserId()); educationStudy.setMemberId(StringUtils.isBlank(dto.getMemberId()) ? "" : dto.getMemberId()); educationStudy.setStudyDate(DateUtils.parseString2Date(dto.getStudyDate(), "yyyy-MM-dd")); educationStudy.setStudyUnit(StringUtils.isBlank(dto.getStudyUnit()) ? "" : dto.getStudyUnit()); educationStudy.setCreateTime(new Date()); if (0 == count){ int insertRow = educationStudyMapper.insert(educationStudy); return (0 == insertRow) ? result.setCodeMessageChain(Code.ERROR.getCode(), "失败") : result.setCodeMessageChain(Code.SUCCESS.getCode(), "成功"); }else{ int updateRow = educationStudyMapper.updateById(educationStudy); return (0 == updateRow) ? result.setCodeMessageChain(Code.ERROR.getCode(), "失败") : result.setCodeMessageChain(Code.SUCCESS.getCode(), "成功"); } } /** * @description:删除培训学习 * @author: SYZ * @date: 2023/3/29 20:09 * @param: [id] * @return: com.common.utils.model.SingleResult **/ @ApiOperation(value = "删除培训学习") @GetMapping("/delOne") @ApiImplicitParam(name = "id", value = "主键id", dataType = "string", paramType = "query", required = true) @ResponseBody public SingleResult delOne(@NotBlank(message = "id不能为空") String id) { SingleResult result = new SingleResult<>(); int delRow = educationStudyMapper.deleteById(id); return (0 == delRow) ? result.setCodeMessageChain(Code.ERROR.getCode(), "失败") : result.setCodeMessageChain(Code.SUCCESS.getCode(), "成功"); } /** * @description:获取培训学习详情 * @author: SYZ * @date: 2023/3/30 14:36 * @param: [id] * @return: com.common.utils.model.SingleResult **/ @ApiOperation(value = "获取培训学习详情") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", dataType = "string", paramType = "query", required = true) }) @GetMapping("/getDetails") @ResponseBody public SingleResult getDetails(@NotBlank(message = "id不能为空") String id){ SingleResult result = new SingleResult<>(); EducationStudy educationStudy = educationStudyMapper.selectById(id); List memberIds = Arrays.asList(educationStudy.getMemberId().split(",")); logger.info("memberIds: => {}",memberIds); List strings = entUserMapper.selectUsernamesByIds(memberIds); logger.info("memberNames: => {}",strings); StringBuilder strb = new StringBuilder(); for (int i=0;i> **/ @ApiOperation(value = "获取培训资料列表") @ApiImplicitParams({ @ApiImplicitParam(name = "entId",value = "企业id",dataType = "string",paramType = "query",required = true) }) @GetMapping("/getEducationResourceList") @ResponseBody public SingleResult> getEducationResourceList(@Valid PageDto dto,String entId){ SingleResult> result = new SingleResult<>(); SysEnterprise sysEnterprise = sysEnterpriseMapper.selectOne( new QueryWrapper().select("*").eq("SysEnterpriseId",entId) ); if (null == sysEnterprise){ return result.setCodeMessageChain(Code.ERROR.getCode(), "企业id错误"); } PageHelper.startPage(dto.getPage(), dto.getPageSize()); Page page = (Page) educationResourceMapper.selectEducationResourceList(dto.getCondition(),sysEnterprise.getWorkClassId()); ListPageVo pageVo = new ListPageVo<>(); pageVo.setRows(page); pageVo.setTotal(page.getTotal()); pageVo.setPage(page.getPageNum()); pageVo.setPageSize(page.getPageSize()); result.setData(pageVo); return result; } /** * @description:获取培训资料详情 * @author: SYZ * @date: 2023/3/30 14:37 * @param: [id] * @return: com.common.utils.model.SingleResult **/ @ApiOperation(value = "获取培训资料详情") @ApiImplicitParams({ @ApiImplicitParam(name = "id",value = "主键",dataType = "string",paramType = "query",required = true) }) @GetMapping("/getEducationResourceDetails") @ResponseBody public SingleResult getEducationResourceDetails(@NotBlank(message = "id不能为空") String id){ SingleResult result = new SingleResult<>(); EducationResource educationResource = educationResourceMapper.selectById(id); result.setData(educationResource); return result; } }