DataAssessmentSocreMasterController.java 10.5 KB
package com.skua.modules.assessment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.assessment.entity.DataAssessmentSocreMaster;
import com.skua.modules.assessment.service.IDataAssessmentSocreMasterService;
import com.skua.modules.assessment.vo.DataAssessmentSocreMasterVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 绩效考核评分基础信息
 */
@Slf4j
@Api(tags="绩效考核评分基础信息")
@RestController
@RequestMapping("/v1/product/assessmentnew/dataAssessmentSocreMaster")
public class DataAssessmentSocreMasterController {
	@Autowired
	private IDataAssessmentSocreMasterService dataAssessmentSocreMasterService;
	@Autowired
	private ISequenceService sequenceService;
	/**
	  * 分页列表查询
	 * @param dataAssessmentSocreMasterVO
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-分页列表查询")
	@ApiOperation(value="绩效考核评分基础信息-分页列表查询", notes="绩效考核评分基础信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<DataAssessmentSocreMasterVO>> queryPageList(DataAssessmentSocreMasterVO dataAssessmentSocreMasterVO,
																	@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																	@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																	HttpServletRequest req) {
		Result<IPage<DataAssessmentSocreMasterVO>> result = new Result<IPage<DataAssessmentSocreMasterVO>>();
		Page<DataAssessmentSocreMasterVO> pageList = new Page<DataAssessmentSocreMasterVO>(pageNo, pageSize);
		//自定义查询
		pageList = dataAssessmentSocreMasterService.queryCustomPageList(pageList,dataAssessmentSocreMasterVO);
		result.setSuccess(true);
		result.setResult(pageList);
		return result;
	}

	/**
	  *   添加
	 * @param dataAssessmentSocreMaster
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-添加")
	@ApiOperation(value="绩效考核评分基础信息-添加", notes="绩效考核评分基础信息-添加")
	@PostMapping(value = "/add")
	public Result<DataAssessmentSocreMaster> add(@RequestBody DataAssessmentSocreMaster dataAssessmentSocreMaster) {
		Result<DataAssessmentSocreMaster> result = new Result<DataAssessmentSocreMaster>();
		try {
			dataAssessmentSocreMaster.setId(String.valueOf(sequenceService.nextId()));
			dataAssessmentSocreMasterService.save(dataAssessmentSocreMaster);
			result.setResult(dataAssessmentSocreMaster);
			result.success("添加成功!");
		} catch (Exception e) {
			log.error(e.getMessage(),e);
			result.error500("操作失败");
		}
		return result;
	}

	/**
	  *   添加
	 * @param dataAssessmentSocreMaster
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-校验")
	@ApiOperation(value="绩效考核评分基础信息-校验", notes="绩效考核评分基础信息-校验")
	@PostMapping(value = "/check")
	public Result<String> check(@RequestBody DataAssessmentSocreMaster dataAssessmentSocreMaster) {
		Result<String> result = new Result<String>();
		try {
			QueryWrapper<DataAssessmentSocreMaster> query = new QueryWrapper<DataAssessmentSocreMaster>();
			query.eq("report_id",dataAssessmentSocreMaster.getReportId());
			query.eq("assessment_date",dataAssessmentSocreMaster.getAssessmentDate());
			query.eq("assessment_user",dataAssessmentSocreMaster.getAssessmentUser());
            List<DataAssessmentSocreMaster> list = dataAssessmentSocreMasterService.list(query);
            if(list!=null&&list.size()>0) {
            	result.setResult("yes");
            	result.success("已考核");
            }else {
            	result.setResult("no");
            	result.success("未考核");
            }
		} catch (Exception e) {
			log.error(e.getMessage(),e);
			result.error500("操作失败");
		}
		return result;
	}

	/**
	  *  编辑
	 * @param dataAssessmentSocreMaster
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-编辑")
	@ApiOperation(value="绩效考核评分基础信息-编辑", notes="绩效考核评分基础信息-编辑")
	@PutMapping(value = "/edit")
	public Result<DataAssessmentSocreMaster> edit(@RequestBody DataAssessmentSocreMaster dataAssessmentSocreMaster) {
		Result<DataAssessmentSocreMaster> result = new Result<DataAssessmentSocreMaster>();
		DataAssessmentSocreMaster dataAssessmentSocreMasterEntity = dataAssessmentSocreMasterService.getById(dataAssessmentSocreMaster.getId());
		if(dataAssessmentSocreMasterEntity==null) {
			result.error500("未找到对应实体");
		}else {
			boolean ok = dataAssessmentSocreMasterService.updateById(dataAssessmentSocreMaster);
			//TODO 返回false说明什么?
			if(ok) {
				result.success("修改成功!");
			}
		}
		return result;
	}

	/**
	  *   通过id删除
	 * @param id
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-通过id删除")
	@ApiOperation(value="绩效考核评分基础信息-通过id删除", notes="绩效考核评分基础信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		try {
			dataAssessmentSocreMasterService.removeById(id);
		} catch (Exception e) {
			log.error("删除失败",e.getMessage());
			return Result.error("删除失败!");
		}
		return Result.ok("删除成功!");
	}

	/**
	  *  批量删除
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "绩效考核评分基础信息-批量删除")
	@ApiOperation(value="绩效考核评分基础信息-批量删除", notes="绩效考核评分基础信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<DataAssessmentSocreMaster> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		Result<DataAssessmentSocreMaster> result = new Result<DataAssessmentSocreMaster>();
		if(ids==null || "".equals(ids.trim())) {
			result.error500("参数不识别!");
		}else {
			this.dataAssessmentSocreMasterService.removeByIds(Arrays.asList(ids.split(",")));
			result.success("删除成功!");
		}
		return result;
	}


  @AutoLog(value = "绩效考核基础信息-流程发起")
	@ApiOperation(value="绩效考核基础信息-流程发起", notes="绩效考核基础信息-流程发起")
	@PostMapping(value = "/start-process")
	public Result<DataAssessmentSocreMaster> startProcess(@RequestBody DataAssessmentSocreMaster purchaseInfo) {
		Result<DataAssessmentSocreMaster> result = new Result<DataAssessmentSocreMaster>();
		try {
			dataAssessmentSocreMasterService.startProcess(purchaseInfo);
			result.success("操作成功!");
		} catch (Exception e) {
			log.error(e.getMessage(),e);
			result.error500("操作失败");
		}
		return result;
	}

	@AutoLog(value = "绩效考核基础信息-修改业务数据及流程数据")
	@ApiOperation(value="绩效考核基础信息-修改业务数据及流程数据", notes="绩效考核基础信息-修改业务数据及流程数据")
	@PostMapping(value = "/editAndModifyProcess")
	public Result<DataAssessmentSocreMaster> editAndModifyProcess(@RequestBody DataAssessmentSocreMaster purchaseInfo) {
		Result<DataAssessmentSocreMaster> result = new Result<DataAssessmentSocreMaster>();
		try {
			dataAssessmentSocreMasterService.editAndModifyProcess(purchaseInfo);
			result.success("操作成功!");
		} catch (Exception e) {
			log.error(e.getMessage(),e);
			result.error500("操作失败");
		}
		return result;
	}

	/**
	  * 通过id查询
	 * @param id
	 * @return
	 */
	@AutoLog(value = "绩效考核基础信息-通过id查询")
	@ApiOperation(value="绩效考核基础信息-通过id查询", notes="绩效考核基础信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<DataAssessmentSocreMasterVO> queryById(@RequestParam(name="businessId",required=true) String businessId) {
		Result<DataAssessmentSocreMasterVO> result = new Result<DataAssessmentSocreMasterVO>();
		DataAssessmentSocreMasterVO dataAssessmentSocreMasterVO = dataAssessmentSocreMasterService.getAllDataById(businessId);
		if(dataAssessmentSocreMasterVO==null) {
			result.error500("未找到对应实体");
		}else {
			result.setResult(dataAssessmentSocreMasterVO);
			result.setSuccess(true);
		}
		return result;
	}

	 /**
	  * 通过id查询
	  * @param dataAssessmentSocreMasterVO
	  * @return
	  */
	 @AutoLog(value = "绩效考核基础信息-通过id查询")
	 @ApiOperation(value="绩效考核基础信息-通过id查询", notes="绩效考核基础信息-通过id查询")
	 @GetMapping(value = "/scoreRat")
	 public Result  socreRat(DataAssessmentSocreMasterVO dataAssessmentSocreMasterVO) {
		 Result  result = new Result ();
		 List<DataAssessmentSocreMasterVO> list = dataAssessmentSocreMasterService.getAllData(dataAssessmentSocreMasterVO);
		 int totalScores = list.size();
		 Map<String, Object> resMap = Maps.newHashMap();
		Integer excellent =0;
		Integer pass =0;
		Integer fail =0;

		 for (DataAssessmentSocreMasterVO item : list) {
			 Double score = ConvertUtils.getDouble( item.getAssessmentScore(),0);
			 if (score != null) {
				 if (score >= 85) {
					 excellent++;
				 } else if (score >= 60) {
					 pass++;
				 } else {
					 fail++;
				 }
			 }
		 }
		 resMap.put("excellent",excellent);
		 resMap.put("pass",pass);
		 resMap.put("fail",fail);
		 resMap.put("totalScores",totalScores);
		 result.setResult(resMap);
		 return result;
	 }

	/**
	 * 通过id查询
	 * @param dataAssessmentSocreMasterVO
	 * @return
	 */
	@AutoLog(value = "绩效考核基础信息-通过id查询")
	@ApiOperation(value="绩效考核基础信息-通过id查询", notes="绩效考核基础信息-通过id查询")
	@GetMapping(value = "/scoreSort")
	public Result  scoreSort(DataAssessmentSocreMasterVO dataAssessmentSocreMasterVO) {
		Result  result = new Result ();
		List<DataAssessmentSocreMasterVO> list = dataAssessmentSocreMasterService.getAllData(dataAssessmentSocreMasterVO);
		list=list.stream().sorted(Comparator.comparing(s->ConvertUtils.getDouble(((DataAssessmentSocreMasterVO)s).getAssessmentScore(),0)).reversed()).collect(Collectors.toList());
		result.setResult(list);
		return result;
	}


}