ZQN
2024-06-25 7987ac6bf58cd64f0ad2af915ed1a9749960f643
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.project.enforce.service.impl;
 
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.common.core.domain.entity.SysUser;
import com.project.common.exception.base.BaseException;
import com.project.common.utils.DateUtils;
import com.project.common.utils.SecurityUtils;
import com.project.common.utils.StringUtils;
import com.project.enforce.domain.EnforceComplaintLog;
import com.project.enforce.domain.bo.editBo.ComplaintResultBo;
import com.project.enforce.domain.bo.editBo.EnforceComplaintLogBo;
import com.project.enforce.domain.bo.queryBo.EnforceComplaintLogQueryBo;
import com.project.enforce.domain.vo.EnforceComplaintLogVo;
import com.project.enforce.domain.vo.OrderNodeVo;
import com.project.enforce.mapper.EnforceComplaintLogMapper;
import com.project.enforce.service.IEnforceComplaintLogService;
import com.project.system.service.ISysDeptService;
import com.project.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
 
/**
 * 投诉记录Service业务层处理
 *
 * @author manton
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class EnforceComplaintLogServiceImpl extends ServiceImpl<EnforceComplaintLogMapper, EnforceComplaintLog> implements IEnforceComplaintLogService {
 
    private final ISysDeptService deptService;
    private final ISysUserService userService;
 
 
    @Override//列表查询
    public List<EnforceComplaintLogVo> queryList(EnforceComplaintLogQueryBo bo)
    {
        QueryWrapper<EnforceComplaintLog> qw = getQw(bo);
        List<EnforceComplaintLog> list = this.list(qw);
        return Convert.toList(EnforceComplaintLogVo.class , list);
    }
 
    @Override//id查询
    public EnforceComplaintLogVo queryById(Long id)
    {
        EnforceComplaintLog db = this.baseMapper.selectById(id);
        return Convert.convert(EnforceComplaintLogVo.class , db);
    }
 
 
    @Override//添加
    @Transactional
    public Boolean insertByBo(EnforceComplaintLogBo bo)
    {
        EnforceComplaintLog add = Convert.convert(EnforceComplaintLog.class, bo);
        validEntityBeforeSave(add);
        return this.save(add);
    }
 
    @Override//修改
    @Transactional
    public Boolean updateByBo(EnforceComplaintLogBo bo)
    {
        EnforceComplaintLog update = Convert.convert(EnforceComplaintLog.class, bo);
        validEntityBeforeSave(update);
        return this.updateById(update);
    }
 
    @Override//删除
    @Transactional
    public Boolean deleteByIds(Collection<Long> ids)
    {
 
        //做一些业务上的校验,判断是否需要校验
 
        return this.removeByIds(ids);
    }
 
    @Override//投诉单节点
    public List<OrderNodeVo> orderNodeList(Long id)
    {
        List<OrderNodeVo> vos = new ArrayList<>();
        EnforceComplaintLog order = this.getById(id);
        if (order.getComplaintTime()!=null){
            vos.add(new OrderNodeVo("发起投诉",order.getCompanyUser(),order.getCompanyName(),order.getComplaintTime(), null));
        }
        if (order.getInTime()!=null && StringUtils.isNotEmpty(order.getInUser())){
 
            vos.add(new OrderNodeVo("处理中",order.getInUser(), userService.getDeptNameByUserId(order.getInId()), order.getInTime(), null));
        }
        if (order.getResultTime()!=null){
            if (order.getComplaintStatus()==-1){
                vos.add(new OrderNodeVo("已驳回",order.getResultUser(),userService.getDeptNameByUserId(order.getResultId()),order.getResultTime(), order.getComplaintResult()));
            } else {
                vos.add(new OrderNodeVo("已办结",order.getResultUser(),userService.getDeptNameByUserId(order.getResultId()),order.getResultTime(), order.getComplaintResult()));
            }
        }
        return vos;
    }
 
    @Override//响应投诉
    @Transactional
    public Boolean inComplaint(ComplaintResultBo bo)
    {
        SysUser loginUser = userService.selectUserById(SecurityUtils.getUserId());
        return this.update(lu()
                .set(EnforceComplaintLog::getInId,loginUser.getUserId())
                .set(EnforceComplaintLog::getInUser,loginUser.getNickName())
                .set(EnforceComplaintLog::getInTime, DateUtils.getNowDate())
                .set(EnforceComplaintLog::getComplaintStatus, 1)
                .eq(EnforceComplaintLog::getId, bo.getId())
        );
    }
 
    @Override//处理结果
    @Transactional
    public Boolean doComplaint(ComplaintResultBo bo)
    {
        if (StringUtils.isEmpty(bo.getResult())){
            throw new BaseException("请填写处理结果");
        }
        SysUser loginUser = userService.selectUserById(SecurityUtils.getUserId());
        return this.update(lu()
                .set(EnforceComplaintLog::getResultId,loginUser.getUserId())
                .set(EnforceComplaintLog::getResultUser,loginUser.getNickName())
                .set(EnforceComplaintLog::getResultTime, DateUtils.getNowDate())
                .set(EnforceComplaintLog::getComplaintStatus, bo.getComplaintStatus())
                .set(EnforceComplaintLog::getComplaintResult, bo.getResult())
                .eq(EnforceComplaintLog::getId, bo.getId())
        );
    }
 
 
//-------------------------------------------------------------------------------------
 
    //保存前校验
    private void validEntityBeforeSave(EnforceComplaintLog entity)
    {
        if (StringUtils.isEmpty(entity.getExecuteDeptName()) && entity.getExecuteDeptName()!=null){
            entity.setExecuteDeptName(deptService.getDeptAllName(entity.getExecuteDeptId()));
        }
        if (entity.getId()==null){
            if (entity.getCompanyId()==null
                    || StringUtils.isEmpty(entity.getCompanyName())
                    || StringUtils.isEmpty(entity.getCompanyUser())
                    || StringUtils.isEmpty(entity.getCompanyPhone())
            ){
                throw new BaseException("投诉企业不能为空!");
            }
            if (entity.getExecuteDeptId() == null
                    || StringUtils.isEmpty(entity.getExecuteDeptName())
            ){
                throw new BaseException("投诉单位不能为空!");
            }
            if (StringUtils.isEmpty(entity.getComplaintType())){
                throw new BaseException("请选择要投诉类型!");
            }
            if (StringUtils.isEmpty(entity.getComplaintReason())){
                throw new BaseException("请填写投诉内容!");
            }
 
            if (entity.getOrderId()!=null){ //执法单投诉
                int count = this.count(lq().eq(EnforceComplaintLog::getOrderId, entity.getOrderId()));
                if (count >0){
                    throw new BaseException("该执法单已投诉!");
                }
            }
            entity.setComplaintTime(DateUtils.getNowDate());
        }
    }
 
    //获取查询参数
    private QueryWrapper<EnforceComplaintLog> getQw(EnforceComplaintLogQueryBo bo)
    {
        QueryWrapper<EnforceComplaintLog> qw = Wrappers.query();
 
            qw.eq(StringUtils.isNotEmpty(bo.getOrderId()), "order_id", bo.getOrderId());
            qw.eq(StringUtils.isNotEmpty(bo.getOrderNo()), "order_no", bo.getOrderNo());
            qw.eq(StringUtils.isNotEmpty(bo.getEnforceReason()), "enforce_reason", bo.getEnforceReason());
            qw.eq(bo.getCompanyId() != null, "company_id", bo.getCompanyId());
            qw.like(StringUtils.isNotEmpty(bo.getCompanyName()), "company_name", bo.getCompanyName());
            qw.eq(StringUtils.isNotEmpty(bo.getCompanyUser()), "company_user", bo.getCompanyUser());
            qw.eq(StringUtils.isNotEmpty(bo.getCompanyPhone()), "company_phone", bo.getCompanyPhone());
            qw.eq(bo.getExecuteUser() != null, "execute_user", bo.getExecuteUser());
            qw.eq(bo.getExecutePhone() != null, "execute_phone", bo.getExecutePhone());
            qw.like(bo.getExecuteDeptName() != null, "execute_dept_name", bo.getExecuteDeptName());
            qw.eq(StringUtils.isNotEmpty(bo.getComplaintType()), "complaint_type", bo.getComplaintType());
            qw.eq(StringUtils.isNotEmpty(bo.getComplaintReason()), "complaint_reason", bo.getComplaintReason());
            qw.eq(bo.getComplaintStatus() != null, "complaint_status", bo.getComplaintStatus());
            qw.eq(StringUtils.isNotEmpty(bo.getReturnReason()), "return_reason", bo.getReturnReason());
            qw.eq(StringUtils.isNotEmpty(bo.getComplaintResult()), "complaint_result", bo.getComplaintResult());
        if (StringUtils.isNotEmpty(bo.getIsAsc()) && StringUtils.isNotEmpty(bo.getOrderByColumn())){
            if ("acs".equals(bo.getIsAsc())) {
                qw.orderByAsc(bo.getOrderByColumn());
            } else if ("desc".equals(bo.getIsAsc())) {
                qw.orderByDesc(bo.getOrderByColumn());
            }
        }
        return qw;
    }
}