package com.hzya.frame.sysnew.archivesContrast.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.sysnew.archivesContrast.entity.SysArchivesContrastEntity;
import com.hzya.frame.sysnew.archivesContrast.dao.ISysArchivesContrastDao;
import com.hzya.frame.sysnew.archivesContrast.service.ISysArchivesContrastService;
import com.hzya.frame.sysnew.user.entity.SysUserEntity;
import com.hzya.frame.sysnew.userCompany.entity.SysUserCompanyEntity;
import com.hzya.frame.sysnew.userRoles.entity.SysUserRolesEntity;
import com.hzya.frame.util.AESUtil;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import com.hzya.frame.basedao.service.impl.BaseService;

import java.util.List;

/**
 * 档案对照表服务实现类
 *
 * @author makejava
 * @since 2024-05-27 16:21:36
 */
@Service(value = "sysArchivesContrastService")
public class SysArchivesContrastServiceImpl extends BaseService<SysArchivesContrastEntity, String> implements ISysArchivesContrastService {
     
    private ISysArchivesContrastDao sysArchivesContrastDao;
    
    @Autowired
	public void setSysArchivesContrastDao(ISysArchivesContrastDao dao) {
		this.sysArchivesContrastDao = dao;
		this.dao = dao;
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 查询档案列表分页
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity queryEntityPage(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		//判断分页
		if (entity == null || entity.getPageNum() == null || entity.getPageSize() == null) {
			return BaseResult.getFailureMessageEntity("分页查询参数不存在");
		}
		if(entity.getType() == null || "".equals(entity.getType()) ){
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
		List<SysArchivesContrastEntity> list = sysArchivesContrastDao.queryByLike(entity);
		PageInfo pageInfo = new PageInfo(list);
		return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 查询档案列表
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity queryEntity(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		if (entity == null || entity.getType() == null || "".equals(entity.getType())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		List<SysArchivesContrastEntity> list = sysArchivesContrastDao.queryByLike(entity);
		return BaseResult.getSuccessMessageEntity("查询数据成功", list);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 保存档案
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity saveEntity(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("参数不允许为空");
		}
		if (entity.getType() == null || "".equals(entity.getType())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		if (entity.getLeftCode() == null || "".equals(entity.getLeftCode())) {
			return BaseResult.getFailureMessageEntity("请先输入左编码");
		}
		if (entity.getRightCode() == null || "".equals(entity.getRightCode())) {
			return BaseResult.getFailureMessageEntity("请先输入右编码");
		}
		entity.setCreate();
		entity.setSts("Y");
		//保存
		sysArchivesContrastDao.save(entity);
		return BaseResult.getSuccessMessageEntity("保存档案成功", entity);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 获取档案
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity getEntity(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("参数不允许为空");
		}
		if (entity.getType() == null || "".equals(entity.getType())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		if (entity.getId() == null || "".equals(entity.getId())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		entity = sysArchivesContrastDao.getEntity(entity);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("获取档案失败");
		}
		return BaseResult.getSuccessMessageEntity("获取档案成功", entity);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 修改档案
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity updateEntity(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("参数不允许为空");
		}
		if (entity.getId() == null || "".equals(entity.getId())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		if (entity.getType() == null || "".equals(entity.getType())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		if (entity.getLeftCode() == null || "".equals(entity.getLeftCode())) {
			return BaseResult.getFailureMessageEntity("请先输入左编码");
		}
		if (entity.getRightCode() == null || "".equals(entity.getRightCode())) {
			return BaseResult.getFailureMessageEntity("请先输入右编码");
		}
		entity.setUpdate();
		//保存
		sysArchivesContrastDao.update(entity);
		return BaseResult.getSuccessMessageEntity("修改档案成功", entity);
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 删除档案
	 * @Date 4:25 下午 2024/5/27
	 **/
	@Override
	public JsonResultEntity deleteEntity(JSONObject jsonObject) {
		SysArchivesContrastEntity entity = getData("jsonStr", jsonObject, SysArchivesContrastEntity.class);
		if (entity == null) {
			return BaseResult.getFailureMessageEntity("参数不允许为空");
		}
		if (entity.getId() == null || "".equals(entity.getId())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		if (entity.getType() == null || "".equals(entity.getType())) {
			return BaseResult.getFailureMessageEntity("系统错误");
		}
		entity.setUpdate();
		//删除
		sysArchivesContrastDao.logicRemove(entity);
		return BaseResult.getSuccessMessageEntity(" 删除档案成功", entity);
	}
}
