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

import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.setting.UnifiedService;
import cn.superdesk.uniorder.dto.param.setting.*;
import cn.superdesk.uniorder.dto.vo._function.select.SelectOptionUnifiedService;
import cn.superdesk.uniorder.dubbo.facade.setting.DubboUnifiedServiceService;
import cn.superdesk.uniorder.service.setting.UnifiedServiceService;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import com.alibaba.dubbo.config.annotation.Service;
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;

@Slf4j
@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboUnifiedServiceServiceImpl implements DubboUnifiedServiceService {

	@Autowired
	private UnifiedServiceService unifiedServiceService;

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

	@Override
	public void addObj(UnifiedServiceParam param) {

		UnifiedService unifiedService = AnBeanUtils.copy(param, UnifiedService.class);
		unifiedServiceService.insertSelective(unifiedService);

	}

	@Override
	public void updateObj(UnifiedServiceParam param) {

		UnifiedService unifiedService = AnBeanUtils.copy(param, UnifiedService.class);
		unifiedServiceService.updateByPrimaryKeySelective(unifiedService);
	}

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

	@Override
	public UnifiedService findById(Long id) {
		return unifiedServiceService.findById(id);
	}

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

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

		return unifiedServiceService.findAll(queryMap);
	}

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


	@Override
	public void addUnifiedService(UnifiedServiceParam param) {

		UnifiedService unifiedService = AnBeanUtils.copy(param, UnifiedService.class);
		unifiedServiceService.addUnifiedService(unifiedService);
	}

	@Override
	public void updateUnifiedService(UnifiedServiceParam param) {

		UnifiedService unifiedService = AnBeanUtils.copy(param, UnifiedService.class);
		unifiedServiceService.updateUnifiedService(unifiedService);
	}

	@Override
	public void deleteUnifiedService(Long id) {
		unifiedServiceService.deleteUnifiedService(id);
	}

	@Override
	public UnifiedService findUnifiedServiceById(Long id) {
		return unifiedServiceService.findUnifiedServiceById(id);
	}

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

	}


	/****************************************** 原先的 start ******************************************/


	@Override
	public R<List<UnifiedService>> getPage(Map<String, Object> params, int pageNum, int pageSize) {

		return unifiedServiceService.getPage(params, pageNum, pageSize);
	}

	@Override
	public List<UnifiedService> getAsService() {
		return unifiedServiceService.getAsService();
	}

	@Override
	public List<UnifiedService> getAsOrderType() {
		return unifiedServiceService.getAsOrderType();
	}

	@Override
	public List<SelectOptionUnifiedService> getSelectByVirt(Map<String, Object> params) {

		return unifiedServiceService.getSelectByVirt(params);
	}

	@Override
	public UnifiedService findByCode(String code) {
		return unifiedServiceService.findByCode(code);
	}

	@Override
	public UnifiedService addObj(UnifiedService model) {

		unifiedServiceService.insertSelective(model);
		return model;
	}

	@Override
	public UnifiedService updateObj(UnifiedService model) {

		unifiedServiceService.updateByPrimaryKeySelective(model);
		return model;
	}

	@Override
	public UnifiedService updateUnifiedServicePartGoodsTransport(UnifiedServicePartGoodsTransportParam partGoodsTransportParam) {

		UnifiedService entity = new UnifiedService();

		entity = AnBeanUtils.copy(partGoodsTransportParam, UnifiedService.class);

		log.info("\nentity = AnBeanUtils.copy(partGoodsTransportParam,UnifiedService.class)\n{}\n{}", AnJsonUtils.toJson(partGoodsTransportParam), AnJsonUtils.toJson(entity));

		unifiedServiceService.updateByPrimaryKeySelective(entity);

		return entity;

	}

	@Override
	public UnifiedService updateUnifiedServicePartOrderState(UnifiedServicePartOrderStateParam params) {

		UnifiedService entity = new UnifiedService();

//		entity = AnBeanUtils.copy(params, UnifiedService.class);
		entity.setId(params.getId());
		entity.setOrderStateJson(AnJsonUtils.toJson(params.getOrderStateJson()));

		log.info("\nentity = AnBeanUtils.copy(partOrderParam,UnifiedService.class)\n{}\n{}", AnJsonUtils.toJson(params), AnJsonUtils.toJson(entity));

		unifiedServiceService.updateByPrimaryKeySelective(entity);

		return entity;
	}

	@Override
	public UnifiedService updateUnifiedServicePartPayType(UnifiedServicePartPayTypeParam params) {

		UnifiedService entity = new UnifiedService();

//		entity = AnBeanUtils.copy(params, UnifiedService.class);
		entity.setId(params.getId());
		entity.setPayTypeJson(AnJsonUtils.toJson(params.getPayTypeJson()));
		log.info("\nentity = AnBeanUtils.copy(partOrderParam,UnifiedService.class)\n{}\n{}", AnJsonUtils.toJson(params), AnJsonUtils.toJson(entity));

		unifiedServiceService.updateByPrimaryKeySelective(entity);

		return entity;
	}

	@Override
	public UnifiedService updateUnifiedServicePartService(UnifiedServicePartServiceParam partServiceParam) {

		UnifiedService entity = new UnifiedService();

		entity = AnBeanUtils.copy(partServiceParam, UnifiedService.class);

		log.info("\nentity = AnBeanUtils.copy(partServiceParam,UnifiedService.class)\n{}\n{}", AnJsonUtils.toJson(partServiceParam), AnJsonUtils.toJson(entity));

		unifiedServiceService.updateByPrimaryKeySelective(entity);

		return entity;
	}

	@Override
	public void delObj(Long id) {

		unifiedServiceService.deleteObj(id);
	}


}
