package com.rzyc.controller; 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.educationStudy.dto.AddEducationStudyDto; import com.rzyc.bean.educationStudy.vo.EducationStudyListVo; import com.rzyc.bean.educationStudy.vo.ListPageVo; import com.rzyc.bean.task.dto.PageDto; 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.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.Date; /** * @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 { /** * 检查记录详细 */ @ApiOperation(value = "获取列表") @ApiImplicitParams({ @ApiImplicitParam(name = "year",value = "年份",dataType = "int",paramType = "query",required = true) }) @GetMapping("/getList") @ResponseBody public SingleResult> getList(@Valid PageDto dto, int year) throws Exception{ SingleResult> result = new SingleResult<>(); String startDate = DateUtils.parseDate2String(DateUtils.getFirstDayOfMonth(year,1), "yyyy-MM-dd HH:mm:ss"); String 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, 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; } @ApiOperation(value = "添加") @PostMapping("/addOne") @ResponseBody public SingleResult addOne(@Valid AddEducationStudyDto dto) { SingleResult result = new SingleResult<>(); 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()); int insertRow = educationStudyMapper.insert(educationStudy); return (0 == insertRow) ? result.setCodeMessageChain(Code.ERROR.getCode(), "失败") : result.setCodeMessageChain(Code.ERROR.getCode(), "成功"); } @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.ERROR.getCode(), "成功"); } }