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.AddEducationResourceDto; 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.ListPageVo; import com.rzyc.bean.task.dto.PageDto; import com.rzyc.model.EducationResource; import com.rzyc.model.EducationStudy; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; 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.lang.reflect.InvocationTargetException; 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 { /** * @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) }) @GetMapping("/getList") @ResponseBody public SingleResult> getList(@Valid PageDto dto, Integer year, String enterpriseId) throws Exception { 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, 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(@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.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(), "成功"); } }