xuekang
2024-05-13 15a0280ae9e7db96fdf0744c722d214d2cb5a0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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<SpecialFeeRate> rateList =new ArrayList<>();
        //组装行业集合的数据;进行批量插入 或 更新
        if(StrUtil.isNotBlank(entity.getIndustryManages())){
            Object object = JSON.parse(entity.getIndustryManages());
            if(object instanceof JSONArray){
                List<StoreIndustryManageDto> 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<SpecialFeeRate> getList(SpecialFeeRateQuery query) {
        return specialFeeRateMapper.selectList(query);
    }
 
    /**
     * 方法描述:特殊费率配置查询
     **/
    @Override
    public SpecialFeeRateDto getConfig(Long industryId,Long channelId) {
        //根据行业id,查询所属通道的所有特殊费率配置
        List<SpecialFeeRate> 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;
    }
}