package com.nuvole.four.service.impl; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.nuvole.base.domain.SysUser; import com.nuvole.four.contants.Contants; import com.nuvole.four.domain.SpecialFeeRate; import com.nuvole.four.domain.dto.SpecialFeeRateDto; import com.nuvole.four.domain.dto.StoreIndustryManageDto; import com.nuvole.four.domain.query.SpecialFeeRateQuery; import com.nuvole.four.mapper.SpecialFeeRateMapper; import com.nuvole.four.service.SpecialFeeRateService; import com.nuvole.four.util.SystemUtil; import com.nuvole.util.IdGenerator; import com.walker.infrastructure.utils.CollectionUtils; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * @Description 行业管理-特殊行业费率Service实现类 * @Author dqh * @Date 2024-04-12 19:57:28 */ @Service @RequiredArgsConstructor public class SpecialFeeRateServiceImpl implements SpecialFeeRateService { private final SpecialFeeRateMapper specialFeeRateMapper; /** * 方法描述:批处理特殊费率 * id为空则新增;有值则修改 **/ @Override @Transactional(rollbackFor = Exception.class) public int addSelective(SpecialFeeRateDto entity){ entity.setDeleted((short) 0); entity.setStatus((short) 1); SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC); List rateList =new ArrayList<>(); //组装行业集合的数据;进行批量插入 或 更新 if(StrUtil.isNotBlank(entity.getIndustryManages())){ Object object = JSON.parse(entity.getIndustryManages()); if(object instanceof JSONArray){ List manageList = JSONArray.parseArray(entity.getIndustryManages(), StoreIndustryManageDto.class); for (StoreIndustryManageDto i : manageList) { SpecialFeeRate rate = new SpecialFeeRate(); BeanUtils.copyProperties(entity, rate); rate.setIndustryCode(i.getIndustryCode()); rate.setIndustryName(i.getIndustryName()); if (i.getId() == null) { //新增自动生成id rate.setId(IdGenerator.getId()); rate.setCreateBy(user.getId()); rate.setCreateTime(new Date()); }else{ //修改直接取传过来的id rate.setId(i.getId()); rate.setUpdateBy(user.getId()); rate.setUpdateTime(new Date()); } rateList.add(rate); } } } return specialFeeRateMapper.batchInsert(rateList); } @Override public int editSelective(SpecialFeeRate entity){ return specialFeeRateMapper.updateByPrimaryKeySelective(entity); } @Override public SpecialFeeRate get(Long id){ return specialFeeRateMapper.selectByPrimaryKey(id); } @Override public int del(Long id){ return specialFeeRateMapper.deleteByPrimaryKey(id); } @Override public List getList(SpecialFeeRateQuery query) { return specialFeeRateMapper.selectList(query); } /** * 方法描述:特殊费率配置查询 **/ @Override public SpecialFeeRateDto getConfig(Long industryId,Long channelId) { //根据行业id,查询所属通道的所有特殊费率配置 List specialFeeRateList = specialFeeRateMapper.selectByIndustryId(industryId,channelId); SpecialFeeRateDto dto = new SpecialFeeRateDto(); if(!CollectionUtils.isEmpty(specialFeeRateList)){ JSONArray jsonArray = new JSONArray(); specialFeeRateList.forEach( s -> { BeanUtils.copyProperties(s,dto); JSONObject jsonObject = new JSONObject(); jsonObject.put("id",String.valueOf(s.getId())); jsonObject.put("industryCode",s.getIndustryCode()); jsonObject.put("industryName",s.getIndustryName()); jsonArray.add(jsonObject); }); dto.setIndustryManages(jsonArray.toJSONString()); } return dto; } }