嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-service/src/main/java/com/hai/service/impl/BsIntegralRebateServiceImpl...

112 lines
3.9 KiB

package com.hai.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.utils.DateUtil;
import com.hai.dao.BsIntegralRebateMapper;
import com.hai.entity.BsIntegralRebate;
import com.hai.entity.BsIntegralRebateExample;
import com.hai.service.BsIntegralRebateService;
import com.hai.service.HighUserService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("bsIntegralRebateService")
public class BsIntegralRebateServiceImpl implements BsIntegralRebateService {
@Resource
private BsIntegralRebateMapper bsIntegralRebateMapper;
@Resource
private HighUserService highUserService;
@Override
public BsIntegralRebate findIntegralRebateByMap(Map<String, Object> map) {
BsIntegralRebateExample example = new BsIntegralRebateExample();
BsIntegralRebateExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map , "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map , "type"));
}
if (MapUtils.getLong(map , "companyId") != null) {
criteria.andCompanyIdEqualTo(MapUtils.getLong(map , "companyId"));
}
if (MapUtils.getLong(map , "productId") != null) {
criteria.andProductIdEqualTo(MapUtils.getLong(map , "productId"));
}
List<BsIntegralRebate> list = bsIntegralRebateMapper.selectByExample(example);
if (list.size() > 0) {
return bsIntegralRebateMapper.selectByExample(example).get(0);
}
return null;
}
@Override
public BsIntegralRebate findIntegralRebateById(Long id) {
return bsIntegralRebateMapper.selectByPrimaryKey(id);
}
@Override
public List<BsIntegralRebate> getIntegralRebateByList(Map<String, Object> map) {
BsIntegralRebateExample example = new BsIntegralRebateExample();
BsIntegralRebateExample.Criteria criteria = example.createCriteria();
if (MapUtils.getInteger(map , "type") != null) {
criteria.andTypeEqualTo(MapUtils.getInteger(map , "type"));
}
if (MapUtils.getLong(map , "companyId") != null) {
criteria.andCompanyIdEqualTo(MapUtils.getLong(map , "companyId"));
}
if (MapUtils.getLong(map , "productId") != null) {
criteria.andProductIdEqualTo(MapUtils.getLong(map , "productId"));
}
return bsIntegralRebateMapper.selectByExample(example);
}
@Override
public void insertIntegralRebate(BsIntegralRebate bsIntegralRebate) {
bsIntegralRebateMapper.insert(bsIntegralRebate);
}
@Override
public void updateIntegralRebate(BsIntegralRebate bsIntegralRebate) {
bsIntegralRebateMapper.updateByPrimaryKeySelective(bsIntegralRebate);
}
@Override
public void deleteIntegralRebate(Long id) {
bsIntegralRebateMapper.deleteByPrimaryKey(id);
}
@Override
public void integralRebate(JSONObject object) {
Map<String, Object> map = new HashMap<>();
map.put("type" , object.getInteger("type"));
map.put("productId" , object.getLong("productId"));
map.put("companyId" , object.getLong("companyId"));
if (object.getLong("companyId") != null) {
BsIntegralRebate bsIntegralRebate = findIntegralRebateByMap(map);
if (DateUtil.isEffectiveDate(object.getDate("createTime"), bsIntegralRebate.getStartTime() , bsIntegralRebate.getEndTime())) {
BigDecimal integralNum = object.getBigDecimal("price").multiply(bsIntegralRebate.getPercentage()).setScale( 0, BigDecimal.ROUND_HALF_UP );
highUserService.goldHandle(object.getLong("userId"), integralNum.intValue(), 1, 4, object.getLong("orderId") , object.getString("remark") + integralNum);
}
}
}
}