package com.xzx.gc.user.service;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.util.StrUtil;
|
import com.xzx.gc.entity.ConfigInfo;
|
import com.xzx.gc.entity.CoreSetMoney;
|
import com.xzx.gc.entity.PartnerConfig;
|
import com.xzx.gc.user.mapper.PartnerConfigMapper;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import tk.mybatis.mapper.entity.Example;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
@Service
|
@Transactional
|
public class PartnerConfigService {
|
|
@Autowired
|
private PartnerConfigMapper partnerConfigMapper;
|
|
@Autowired
|
private ConfigService configService;
|
@Autowired
|
private CityPartnerService cityPartnerService;
|
|
private String checkConfigValue(String type,String partnerId){
|
PartnerConfig config = new PartnerConfig();
|
config.setConfigCode(type);
|
config.setPartnerId(Long.parseLong(partnerId));
|
String num = partnerConfigMapper.selectConfigByCode(config);
|
return num;
|
}
|
private int updateConfigValue(Long id,String code, String value, String partnerId, String groupType){
|
PartnerConfig config = new PartnerConfig();
|
config.setId(id);
|
config.setConfigCode(code);
|
config.setConfigValue(value);
|
config.setConfigGroup(groupType);
|
config.setPartnerId(Long.parseLong(partnerId));
|
config.setUpdateTime(new Date());
|
int num = partnerConfigMapper.updateByPrimaryKeySelective(config);
|
return num;
|
}
|
private int insertConfigValue(String code, String value, String partnerId, String groupType){
|
PartnerConfig config = new PartnerConfig();
|
config.setConfigCode(code);
|
config.setConfigValue(value);
|
config.setConfigGroup(groupType);
|
config.setPartnerId(Long.parseLong(partnerId));
|
config.setDelFlag((byte)0);
|
config.setCreateTime(new Date());
|
int num = partnerConfigMapper.insertUseGeneratedKeys(config);
|
return num;
|
}
|
public void updateMoneyPartnerSetting(CoreSetMoney money,String partnerId) {
|
if (!StringUtils.isEmpty(money.getTimeInterval())) {
|
String psId = checkConfigValue("INTERVAL_TIME",partnerId);
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"INTERVAL_TIME",money.getTimeInterval(),partnerId,"orderTime");
|
}else{
|
insertConfigValue("INTERVAL_TIME",money.getTimeInterval(),partnerId,"orderTime");
|
}
|
}
|
if (!StringUtils.isEmpty(money.getStartTime())) {
|
String psId = checkConfigValue("START_TIME",partnerId);
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"START_TIME",money.getStartTime(),partnerId,"orderTime");
|
}else{
|
insertConfigValue("START_TIME",money.getStartTime(),partnerId,"orderTime");
|
}
|
}
|
if (!StringUtils.isEmpty(money.getEndTime())) {
|
String psId = checkConfigValue("END_TIME",partnerId);
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"END_TIME",money.getEndTime(),partnerId,"orderTime");
|
}else{
|
insertConfigValue("END_TIME",money.getEndTime(),partnerId,"orderTime");
|
}
|
}
|
if (!StringUtils.isEmpty(money.getOrderTimeout())) {
|
String psId = checkConfigValue("ORDERTIMEOUT",partnerId);
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"ORDERTIMEOUT",money.getOrderTimeout(),partnerId,"");
|
}else{
|
insertConfigValue("ORDERTIMEOUT",money.getOrderTimeout(),partnerId,"");
|
}
|
}
|
if (!StringUtils.isEmpty(money.getOrderTotal())) {
|
String psId = checkConfigValue("ORDERTOTAL",partnerId);
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"ORDERTOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
|
}else{
|
insertConfigValue("ORDERTOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
|
}
|
}
|
|
if (!StringUtils.isEmpty(money.getOrderViewNum())) {
|
// BigDecimal ovnum = new BigDecimal(money.getOrderViewNum());
|
String psId = checkConfigValue("ORDER_VIEW_TOTAL",partnerId);
|
BigDecimal ovN = new BigDecimal(money.getOrderViewNum());
|
if(ovN.compareTo(BigDecimal.ZERO)==0){
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"ORDER_VIEW_TOTAL",money.getOrderViewNum(),partnerId,"ORDER_NUM");
|
}else{
|
insertConfigValue("ORDER_VIEW_TOTAL",money.getOrderViewNum(),partnerId,"ORDER_NUM");
|
}
|
}else if(ovN.compareTo(BigDecimal.ZERO)==1){
|
if (!StringUtils.isEmpty(money.getOrderTotal())) {
|
if(null!=psId&&!"".equals(psId)){
|
updateConfigValue(Long.parseLong(psId),"ORDER_VIEW_TOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
|
}else{
|
insertConfigValue("ORDER_VIEW_TOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
|
}
|
}
|
|
}
|
|
|
}
|
}
|
|
public List<PartnerConfig> queryPartnerConfigByPid(String s) {
|
Example example = new Example(PartnerConfig.class);
|
Example.Criteria criteria = example.createCriteria();
|
criteria.andEqualTo("partnerId", s);
|
return partnerConfigMapper.selectByExample(example);
|
}
|
|
public void updateMoney(CoreSetMoney coreSetMoney){
|
List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
|
if(null!=partnerIds&&partnerIds.size()>0){
|
updateMoneyPartnerSetting(coreSetMoney,partnerIds.get(0));
|
}else{
|
configService.updateMoneySetting(coreSetMoney);
|
}
|
}
|
}
|