package cn.superdesk.uniorder.dubbo.provider.accounting;

import cn.hutool.core.date.DateUtil;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.accounting.AccountingAppeal;
import cn.superdesk.uniorder.dto.param.accounting.AccountingAppealParam;
import cn.superdesk.uniorder.dubbo.facade.accounting.DubboAccountingAppealService;
import cn.superdesk.uniorder.service.accounting.AccountingAppealService;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @Description: 对账单-申诉
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-10-23 17:19:13
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-10-23 17:19:13
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboAccountingAppealServiceImpl implements DubboAccountingAppealService {

	@Autowired
	private AccountingAppealService accountingAppealService;


	/****************************************** extends BaseService 部分 start ******************************************/

	@Override
	public void addObj(AccountingAppealParam param) {

		AccountingAppeal accountingAppeal = AnBeanUtils.copy(param, AccountingAppeal.class);
		accountingAppealService.insertSelective(accountingAppeal);

	}

	@Override
	public void updateObj(AccountingAppealParam param) {

		AccountingAppeal accountingAppeal = AnBeanUtils.copy(param, AccountingAppeal.class);
		accountingAppealService.updateByPrimaryKeySelective(accountingAppeal);
	}

	@Override
	public void deleteObj(Long id) {
		accountingAppealService.deleteObj(id);
	}

	@Override
	public AccountingAppeal findById(Long id) {
		return accountingAppealService.findById(id);
	}

	@Override
	public PageInfo<AccountingAppeal> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
		return accountingAppealService.findByPaging(conditions, pageNun, pageSize);
	}

	@Override
	public List<AccountingAppeal> findAll(Map<String, Object> queryMap) {

		return accountingAppealService.findAll(queryMap);
	}



	/****************************************** extends BaseService 部分   end ******************************************/


	@Override
	public void addAccountingAppeal(AccountingAppealParam param) {

		log.info("\n\n\n\n{}\n\n\n\n", AnJsonUtils.toPrettyJson(param));

//        AccountingAppeal accountingAppeal = AnBeanUtils.copy(param, AccountingAppeal.class);

		AccountingAppeal accountingAppeal = new AccountingAppeal();
		accountingAppeal.setId(param.getId());
		accountingAppeal.setAccountingOrderId(param.getAccountingOrderId());
		accountingAppeal.setAccountingOrderSn(param.getAccountingOrderSn());
		accountingAppeal.setAccountingType(param.getAccountingType());
		accountingAppeal.setAccountingSubType(param.getAccountingSubType());
		accountingAppeal.setRemark(param.getRemark());
//        accountingAppeal.setImg(JsonUtils.toJson(param.getImg()));
//        accountingAppeal.setImg(param.getImg());

		accountingAppeal.setImg(JSONObject.parse(AnJsonUtils.toJson(param.getImg())));

		accountingAppeal.setCreateTime(DateUtil.date());
		accountingAppeal.setCreateUserId(param.getCreateUserId());

		accountingAppeal.setUpdateTime(DateUtil.date());
		accountingAppeal.setUpdateUserId(param.getCreateUserId());

		accountingAppealService.addAccountingAppeal(accountingAppeal);
	}

	@Override
	public void updateAccountingAppeal(AccountingAppealParam param) {

//        AccountingAppeal accountingAppeal = AnBeanUtils.copy(param, AccountingAppeal.class);


		AccountingAppeal accountingAppeal = new AccountingAppeal();
		accountingAppeal.setId(param.getId());
		accountingAppeal.setAccountingOrderId(param.getAccountingOrderId());
		accountingAppeal.setAccountingOrderSn(param.getAccountingOrderSn());
		accountingAppeal.setAccountingType(param.getAccountingType());
		accountingAppeal.setAccountingSubType(param.getAccountingSubType());
		accountingAppeal.setRemark(param.getRemark());

//        accountingAppeal.setImg(JsonUtils.toJson(param.getImg()));
//        accountingAppeal.setImg(param.getImg());

		accountingAppeal.setImg(JSONObject.parse(AnJsonUtils.toJson(param.getImg())));

		accountingAppeal.setUpdateTime(DateUtil.date());
		accountingAppeal.setUpdateUserId(param.getUpdateUserId());

		accountingAppealService.updateAccountingAppeal(accountingAppeal);
	}

	@Override
	public void deleteAccountingAppeal(Long id) {
		accountingAppealService.deleteAccountingAppeal(id);
	}

	@Override
	public AccountingAppeal findAccountingAppealById(Long id) {
		return accountingAppealService.findAccountingAppealById(id);
	}

	@Override
	public AccountingAppeal findAccountingAppealByAccountingOrderId(Long accountingOrderId) {
		return accountingAppealService.findAccountingAppealByAccountingOrderId(accountingOrderId);
	}

	@Override
	public R<List<AccountingAppeal>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {
		return accountingAppealService.pageQuery(conditions, pageNun, pageSize);

	}
}
