UserServicefeeServiceImpl.java 3.98 KB
/*
 * Copyright (c) 2018, 2028, glsx and/or its affiliates. All rights reserved.
 * GLSX PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */
package com.glsx.usercenter.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.google.common.collect.Lists;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glsx.common.utils.bean.BeanUtils;
import com.glsx.usercenter.mapper.SysUserServiceFeeMapper;
import com.glsx.usercenter.pojo.user.SysUserServiceFee;
import com.glsx.usercenter.service.IUserServicefeeService;

/**  
* @ClassName: UserServicefeeServiceImpl  
* @Description: TODO(这里用一句话描述这个类的作用)  
* @author Zheng Xiajun  
* @date 2019年12月25日 
*  
*/
@Service
public class UserServicefeeServiceImpl implements IUserServicefeeService {

	public Logger logger = LoggerFactory.getLogger(UserServicefeeServiceImpl.class);
	@Autowired
	private SysUserServiceFeeMapper sysUserServiceFeeMapper;


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.glsx.usercenter.service.IUserServicefeeService#insertSelective(com.
	 * glsx.usercenter.pojo.user.SysUserServiceFee)
	 */
	@Override
	public void insertSelective(SysUserServiceFee sysUserServiceFee) {
		sysUserServiceFeeMapper.insertSelective(sysUserServiceFee);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.glsx.usercenter.service.IUserServicefeeService#insert(java.lang.
	 * String)
	 */
	@Override
	public void updateUserServiceFee(String str, int userId, int userType) {
		// String str= 908,100,100,100|45874,200,200,200
	if (StringUtils.isNotBlank(str)) {
			List<SysUserServiceFee> list = sysUserServiceFeeMapper.getUserServiceFeeList(userId, null);
			if (!list.isEmpty()) {
				sysUserServiceFeeMapper.batchInsertHistory(list);
				sysUserServiceFeeMapper.deleteByUserId(userId);
				list.clear();
			} else {
				list = Lists.newArrayList();
			}

			String[] array = str.split("\\|");
			Date now = new Date();

			for (int i = 0; i < array.length; i++) {
				String item = array[i];
				SysUserServiceFee sysUserServiceFee = new SysUserServiceFee();
				sysUserServiceFee.setUserId(userId);
				sysUserServiceFee.setCreateTime(now);
				sysUserServiceFee.setUserType(userType);
				sysUserServiceFee.setServiceCode(item.split(",")[0]);
				if (BigDecimal.ZERO.compareTo(new BigDecimal(item.split(",")[1])) < 0) {

					sysUserServiceFee.setServiceFee(new BigDecimal(item.split(",")[1]));
					sysUserServiceFee.setFeeType(com.glsx.usercenter.constants.Constants.FEE_TYPE_INSTALL);
					list.add(sysUserServiceFee);
				}

				if (BigDecimal.ZERO.compareTo(new BigDecimal(item.split(",")[2])) < 0) {

					SysUserServiceFee sysUserServiceFee2 = new SysUserServiceFee();
					BeanUtils.copyBeanProp(sysUserServiceFee2, sysUserServiceFee);
					sysUserServiceFee2.setServiceFee(new BigDecimal(item.split(",")[2]));
					sysUserServiceFee2.setFeeType(com.glsx.usercenter.constants.Constants.FEE_ORDER_DISMANTLE);
					list.add(sysUserServiceFee2);
				}

				if (BigDecimal.ZERO.compareTo(new BigDecimal(item.split(",")[3])) < 0) {
					SysUserServiceFee sysUserServiceFee3 = new SysUserServiceFee();
					BeanUtils.copyBeanProp(sysUserServiceFee3, sysUserServiceFee);
					sysUserServiceFee3.setServiceFee(new BigDecimal(item.split(",")[3]));
					sysUserServiceFee3.setFeeType(com.glsx.usercenter.constants.Constants.FEE_TYPE_REPAIR);
					list.add(sysUserServiceFee3);
				}

			}
			sysUserServiceFeeMapper.batchInsert(list);
		}

	}

	@Override
	public List<SysUserServiceFee> getUserServiceFeeList(Integer userId,
			String serviceCode) {
		// TODO Auto-generated method stub
		return sysUserServiceFeeMapper.getUserServiceFeeList(userId, serviceCode);
	}

}