Helius
2021-06-23 4536a68f86f50e09032066e00e9e3cacf366cbd4
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
package com.matrix.system.app.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.app.dto.*;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.tools.DataAuthUtil;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author jyy
 * @date 2020-12-21
 **/
@Api(value = "ApiFollowupAction", tags = "跟进记录接口类")
@RestController
@RequestMapping(value = "/api/followup")
public class ApiFollowupAction {
 
    @Autowired
    private SysFollowupDao followupDao;
 
    @Autowired
    private SysVipAlbumDao vipAlbumDao;
 
    @Autowired
    private SysVipInfoDao vipInfoDao;
 
    @Autowired
    private SysFollowupCommentDao followupCommentDao;
 
 
 
    @Autowired
    private SysOrderItemDao orderItemDao;
 
    @Autowired
    private SysBeauticianStateDao beauticianStateDao;
 
 
    @ApiOperation(value = "新增跟进记录", notes = "新增跟进记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = SysFollowup.class)
    })
    @PostMapping(value = "/addFollowup")
    public AjaxResult addFollowup(@RequestBody @Validated SysFollowup followup) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        followup.setCreateBy(user.getSuName());
        followup.setUpdateBy(user.getSuName());
        followup.setStaffId(user.getSuId());
        followup.setCompanyId(user.getCompanyId());
        followup.setShopId(user.getShopId());
        //处理订单摘要
        if(followup.getOrderId()!=null){
            List<SysOrderItem> sysOrderItems = orderItemDao.selectByOrderId(followup.getOrderId());
            String abs="";
            if(sysOrderItems.size()>1){
                abs= sysOrderItems.get(0).getShoppingGoods().getName()+"等"+sysOrderItems.size()+"件商品";
            }else{
                abs= sysOrderItems.get(0).getShoppingGoods().getName();
            }
           followup.setOrderAbstract(abs);
        }
        //服务单摘要
        if(followup.getServiceId()!=null){
            List<SysBeauticianState> sysBeauticianStates = beauticianStateDao.selectBySerIds(followup.getServiceId());
            String abs="";
            if(sysBeauticianStates.size()>1){
                abs= sysBeauticianStates.get(0).getProjInfo().getName()+"等"+sysBeauticianStates.size()+"项服务";
            }else{
                abs= sysBeauticianStates.get(0).getProjInfo().getName();
            }
            followup.setOrderAbstract(abs);
        }
 
        followupDao.insert(followup);
        //插入图片
        List<SysVipAlbum> albums=followup.getAlbums();
        if(CollectionUtils.isNotEmpty(albums)){
            for (SysVipAlbum vipAlbum:albums){
                if(StringUtils.isNotBlank(vipAlbum.getImg())){
                    vipAlbum.setCreateBy(user.getSuName());
                    vipAlbum.setUpdateBy(user.getSuName());
                    vipAlbum.setSource(SysVipAlbum.SOURCE_FOLLOW);
                    vipAlbum.setVipId(followup.getVipId());
                    vipAlbum.setSourceId(followup.getId());
                    vipAlbumDao.insert(vipAlbum);
                }
            }
        }
 
        return AjaxResult.buildSuccessInstance("保存成功");
    }
 
    @ApiOperation(value = "跟进记录点赞或者取消点赞", notes = "跟进记录点赞或者取消点赞")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = AjaxResult.class)
    })
    @GetMapping(value = "/zanFollowup/{id}")
    public AjaxResult zanFollowup(@PathVariable("id")Long id) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        SysFollowup followup = followupDao.selectById(id);
        String zans=followup.getZans();
        if(StringUtils.isNotBlank(zans)){
            List<Long> zanIds = StringUtils.strToCollToLong(zans, ",");
            List<Long> zaned = zanIds.stream().filter(zanid -> zanid.equals(user.getSuId())).collect(Collectors.toList());
            if(CollectionUtils.isNotEmpty(zaned)){
                //取消赞
                List<Long> newZaned = zanIds.stream().filter(zanid -> !zanid.equals(user.getSuId())).collect(Collectors.toList());
                zans=StringUtils.collToStr(newZaned,",");
 
            }else{
                //点赞
                zanIds.add(user.getSuId());
                zans=StringUtils.collToStr(zanIds,",");
            }
        }else{
            //直接点赞
            zans=user.getSuId()+"";
        }
        followupDao.updateZan(id,zans);
        return AjaxResult.buildSuccessInstance("修改成功");
    }
 
 
    @ApiOperation(value = "评论跟进", notes = "评论跟进")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = AjaxResult.class)
    })
    @PostMapping(value = "/addFollowupComment")
    public AjaxResult addFollowupComment(@RequestBody @Validated SysFollowupComment followupComment) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        followupComment.setCreateBy(user.getSuName());
        followupComment.setUpdateBy(user.getSuName());
        followupComment.setStaffId(user.getSuId());
        followupCommentDao.insert(followupComment);
        return AjaxResult.buildSuccessInstance("评论成功");
    }
 
 
    @ApiOperation(value = "查询跟进记录", notes = "查询跟进记录")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = SysFollowup.class)
    })
    @PostMapping(value = "/findFollowup")
    public AjaxResult findFollowup(@RequestBody @Validated FollowupListDto followupListDto) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        if(!DataAuthUtil.hasAllShopAuth()){
            followupListDto.setShopId(user.getShopId());
        }
        followupListDto.setCompanyId(user.getCompanyId());
        followupListDto.setSelfStaff(user.getSuId());
        //TODO 需要设置跨店数据权限
        List<SysFollowup> rows= followupDao.selectByAppDto(followupListDto);
        return AjaxResult.buildSuccessInstance(rows,"查询成功");
    }
 
 
 
 
 
 
 
 
 
 
    
    
 
}