package com.dk.mdm.service.core;

import com.dk.common.infrastructure.annotaiton.Pagination;
import com.dk.common.mapper.BaseMapper;
import com.dk.common.model.pojo.PageList;
import com.dk.common.response.ResponseResultVO;
import com.dk.common.service.BaseService;
import com.dk.mdm.infrastructure.convert.core.JobConvert;
import com.dk.mdm.mapper.core.JobMapper;
import com.dk.mdm.model.pojo.core.Job;
import com.dk.mdm.model.query.core.JobQuery;
import com.dk.mdm.model.response.core.JobResponse;
import com.dk.mdm.model.vo.core.JobVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class JobService extends BaseService<Job> {

	@Override
	public BaseMapper<Job> getRepository() {
		return jobMapper;
	}

	@Autowired
	private JobMapper jobMapper;

	@Autowired
	private JobConvert jobConvert;

	/**
	 * @desc   : 重写主键
	 * @author : 姜宁
	 * @date   : 2023/1/5 9:45
	 */
	@Override
	public String getPrimaryKey() {
		return "job_id";
	}

	/**
	 * @desc   : 条件查询
	 * @author : 姜宁
	 * @date   : 2023/1/4 14:35
	 */
	@Pagination
	public ResponseResultVO<PageList<JobResponse>> selectByCond(JobQuery jobQuery)  {
//		ResponseResultVO<PageList<Object>> pageListResponseResultVO = super.mergeListWithCount(jobQuery, jobMapper.selectByCond(jobQuery),
//				jobMapper.countByCond(jobQuery));
//		String str = JSON.toJSONString(pageListResponseResultVO);
//		return ResponseResultUtil.success(AESUtil.aesEncrypt(str)) ;
		return super.mergeListWithCount(jobQuery, jobMapper.selectByCond(jobQuery),
				jobMapper.countByCond(jobQuery));
	}

	/**
	 * @desc   : 保存方法
	 * @author : 姜宁
	 * @date   : 2023/1/4 14:36
	 */
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public ResponseResultVO<?> insert(JobVO jobVO) {
		// 转化实体
		Job job = jobConvert.convertToPo(jobVO);
		return super.insert(job);
	}

	/**
	 * @desc   : 编辑方法
	 * @author : 姜宁
	 * @date   : 2023/1/4 14:37
	 */
	@Transactional(
			rollbackFor = {Exception.class}
	)
	public ResponseResultVO<Boolean> update(JobVO jobVO) {
		// 转化实体
		Job job = jobConvert.convertToPo(jobVO);
		return super.update(job);
	}

}
