package com.hzya.frame.grpU8.acctVouchInfo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzya.frame.sysnew.application.database.dao.ISysApplicationDatabaseDao;
import com.hzya.frame.sysnew.application.database.entity.SysApplicationDatabaseEntity;
import com.hzya.frame.sysnew.application.entity.SysApplicationEntity;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.sysnew.user.entity.SysUserEntity;
import com.hzya.frame.util.bipV3.SHA256Util;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import com.hzya.frame.grpU8.acctVouchInfo.entity.AcctVouchInfoEntity;
import com.hzya.frame.grpU8.acctVouchInfo.dao.IAcctVouchInfoDao;
import com.hzya.frame.grpU8.acctVouchInfo.entity.AcctVouchInfoEntityVo;
import com.hzya.frame.grpU8.acctVouchInfo.service.IAcctVouchInfoService;
import org.apache.commons.lang3.StringUtils;
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;
import java.util.Map;

/**
 * 子表(AcctVouchInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-07-09 11:25:15
 */
@Service(value = "acctVouchInfoService")
public class AcctVouchInfoServiceImpl extends BaseService<AcctVouchInfoEntity, String> implements IAcctVouchInfoService {
     
    private IAcctVouchInfoDao acctVouchInfoDao;

    @Resource
    private ISysApplicationDatabaseDao sysApplicationDatabaseDao;
    
    @Autowired
	public void setAcctVouchInfoDao(IAcctVouchInfoDao dao) {
		this.acctVouchInfoDao = dao;
		this.dao = dao;
	}

	/**
	 * @param jsonObject
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 数据表
	 * @Date 11:52 上午 2024/3/27
	 **/
	@Override
	public Object queryData(JSONObject jsonObject) {
		AcctVouchInfoEntity entity = getData("jsonStr", jsonObject, AcctVouchInfoEntity.class);
		if(entity == null ){
			entity = new AcctVouchInfoEntity();
		}
		//判断分页
		if (entity.getPageNum() != null && entity.getPageSize() != null) {
			PageHelper.startPage(entity.getPageNum(), entity.getPageSize());
			List<AcctVouchInfoEntityVo> list = acctVouchInfoDao.queryData(entity);
			PageInfo pageInfo = new PageInfo(list);
			JSONObject object = new JSONObject();
			object.put("status","success");
			object.put("data",pageInfo);
			return object;
		}else {
			List<AcctVouchInfoEntityVo> list = acctVouchInfoDao.queryData(entity);
			JSONObject object = new JSONObject();
			object.put("status","success");
			object.put("data",list);
			return object;		}
	}

	/**
	 * @param entity
	 * @return com.hzya.frame.web.entity.JsonResultEntity
	 * @Author lvleigang
	 * @Description 数据表
	 * @Date 11:52 上午 2024/3/27
	 **/
	@Override
	public SysExtensionApiEntity addDataSourceCode(SysExtensionApiEntity entity) {
		try {
			SysApplicationEntity applicationEntity = entity.getReceiveApp();
			SysApplicationDatabaseEntity sysApplicationDatabaseEntity = new SysApplicationDatabaseEntity();
			sysApplicationDatabaseEntity.setSts("Y");
			sysApplicationDatabaseEntity.setDbStatus("1");
			sysApplicationDatabaseEntity.setAppId(applicationEntity.getId());
			sysApplicationDatabaseEntity.setDataSourceCode("master");
			List<SysApplicationDatabaseEntity> sysDataSourceEntities = sysApplicationDatabaseDao.queryDSBase(sysApplicationDatabaseEntity);
			if(sysDataSourceEntities != null && sysDataSourceEntities.size() > 0){
				String parm = entity.getBodys();
				JSONObject jsonObject = JSONObject.parseObject(parm);
				jsonObject.put("dataSourceCode",sysDataSourceEntities.get(0).getSourceCode());
				entity.setBodys(jsonObject.toJSONString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return entity;
	}
}
