DemandInfoController.java 14.7 KB
Newer Older
liqin's avatar
liqin committed
1 2 3 4 5 6 7
package cn.wisenergy.chnmuseum.party.web.controller;

import cn.wisenergy.chnmuseum.party.model.DemandInfo;
import cn.wisenergy.chnmuseum.party.model.Employee;
import cn.wisenergy.chnmuseum.party.service.impl.DemandInfoServiceImpl;
import cn.wisenergy.chnmuseum.party.service.impl.EmployeeServiceImpl;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
8 9
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
liqin's avatar
liqin committed
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
import com.vdurmont.emoji.EmojiParser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 需求建议信息 前端控制器
 * </p>
 *
 * @author 杨智平
 * @since 2018-08-29
 */
@Api(tags = "呼叫服务或者吐槽建议")
@RestController
@RequestMapping("/demandInfo")
public class DemandInfoController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(EmployeeController.class);

    @Resource
    private DemandInfoServiceImpl demandInfoService;

    @Resource
    private EmployeeServiceImpl employeeService;

    /**
     * 获取单个呼叫服务或者吐槽建议
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "获取单个呼叫服务或者吐槽建议")
    @GetMapping(value = "/getById")
    @RequiresPermissions("/demandInfo/getById")
    public ResponseEntity<DemandInfo> getById(String id) {
        try {
            DemandInfo one = this.demandInfoService.selectOneById(id);
            if (null != one) {
                one.setContent(EmojiParser.parseToUnicode(one.getContent()));
                if (StringUtils.isNotBlank(one.getFeedbackInfo())) {
                    one.setFeedbackInfo(EmojiParser.parseToUnicode(one.getFeedbackInfo()));
                }
                return ResponseEntity.ok(one);
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        } catch (Exception e) {
            logger.error("获取单个呼叫服务或者吐槽建议出错!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    /**
     * 获取呼叫服务或者吐槽建议列表
     *
     * @param lineNumber
     * @param content
     * @param phoneNumber
     * @param type
     * @param time
     * @return
     */
    @ApiOperation(value = "获取呼叫服务或者吐槽建议列表")
    @GetMapping(value = "/getList")
    @RequiresPermissions("/demandInfo/getList")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "lineNumber", value = "叫号单号", required = false),
            @ApiImplicitParam(name = "content", value = "需求内容", required = false, dataType = "String"),
            @ApiImplicitParam(name = "phoneNumber", value = "手机号码", required = false, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "消息类型:1-吐槽建议2-呼叫记录", required = true),
            @ApiImplicitParam(name = "time", value = "反馈日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "callTime", value = "呼叫日期", required = false, dataType = "String"),
            @ApiImplicitParam(name = "bankBranchId", value = "归属网点ID", required = false, dataType = "String")})
    public ResponseEntity<Page<DemandInfo>> getList(String lineNumber, String content, String phoneNumber,
                                                    Integer type, String time, String callTime, String bankBranchId,
                                                    String roleId, String currentBankId) {
        try {
            if (!"3".equals(roleId)) {
                roleId = "0";
            }
            String startDate = null;
            String endDate = null;
            String callStartDate = null;
            String callEndDate = null;
            if (StringUtils.isNoneBlank(time)) {
                startDate = time + " 00:00:00";
                endDate = time + " 23:59:59";
            }
            if (StringUtils.isNoneBlank(callTime)) {
                callStartDate = callTime + " 00:00:00";
                callEndDate = callTime + " 23:59:59";
            }
            lineNumber = StringUtils.trimToNull(lineNumber); // 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
            content = StringUtils.trimToNull(content);
            phoneNumber = StringUtils.trimToNull(phoneNumber);
            Page<DemandInfo> page = this.getPage();
            Page<DemandInfo> demandInfoPage = this.demandInfoService.selectDemandInfoList(page, lineNumber, content, phoneNumber,
                    startDate, endDate, type, bankBranchId, callStartDate, callEndDate, roleId, currentBankId);
            for (DemandInfo demandInfo : demandInfoPage.getRecords()) {
                demandInfo.setContent(EmojiParser.parseToUnicode(demandInfo.getContent()));
                if (StringUtils.isNotBlank(demandInfo.getFeedbackInfo())) {
                    demandInfo.setFeedbackInfo(EmojiParser.parseToUnicode(demandInfo.getFeedbackInfo()));
                }
            }
            return ResponseEntity.ok(demandInfoPage);
        } catch (Exception e) {
            logger.error("服务器错误!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 添加
     */
    @Transactional
    @ApiOperation("APP端添加吐槽建议或者呼叫记录")
    @PostMapping(value = "/add")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "lineNumber", value = "叫号单号", required = true),
            @ApiImplicitParam(name = "content", value = "需求内容", required = true, dataType = "String"),
            @ApiImplicitParam(name = "phoneNumber", value = "手机号码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "type", value = "消息类型:1-吐槽建议2-呼叫记录", required = true)})
    public ResponseEntity<Map<String, Object>> add(DemandInfo demandInfo) {
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
        try {
            boolean ret = false;
            //接收人员工号,多人使用|分割,如"01014760|01158451"
            String recUsrNbr = "";
            //反馈人ID
            String personId = "";
            if (demandInfo.getBankBranchId() != null) {
                Employee emp = this.employeeService.getEmpCodeBybankId(demandInfo.getBankBranchId());
                if (emp != null) {
                    recUsrNbr = emp.getCode();
                    personId = emp.getId();
                    //现在改为反馈的时候再存入反馈人ID
//                    demandInfo.setFeedbackPersonId(emp.getId());
                }
            }
            demandInfo.setLineNumber(StringUtils.trimToNull(demandInfo.getLineNumber()));// 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
            demandInfo.setContent(EmojiParser.parseToHtmlHexadecimal(demandInfo.getContent().trim()));
            demandInfo.setPhoneNumber(StringUtils.trimToNull(demandInfo.getPhoneNumber()));
            demandInfo.setCreateTime(new Date(System.currentTimeMillis()));
liqin's avatar
liqin committed
169
            ret = this.demandInfoService.save(demandInfo);
liqin's avatar
liqin committed
170 171 172 173 174 175 176 177 178 179 180 181 182
            if (!ret) {
                resultMap.put("status", 400);
                resultMap.put("message", "提交失败");
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
            }

            if (!"".equals(recUsrNbr)) {
                //招乎正文,要求以[发送人姓名OR发送人部室]正文格式
                String zhCnt = "";
                if (demandInfo.getType() == 1) {
                    //吐槽建议
                    zhCnt = "客户" + demandInfo.getLineNumber() + "号("
                            + demandInfo.getPhoneNumber() + ")有吐槽建议,请及时反馈改进,"
liqin's avatar
liqin committed
183
                            + "并点击链接" + demandInfo.getId() + "&personId=" + personId + "及时回复客户。";
liqin's avatar
liqin committed
184 185 186 187 188 189 190 191 192 193
                } else if (demandInfo.getType() == 2) {
                    //呼叫大堂
                    zhCnt = "客户" + demandInfo.getLineNumber() + "号("
                            + demandInfo.getPhoneNumber() + ")呼叫大堂,内容为'"
                            + demandInfo.getContent() + "',请及时服务接待!";

                }
                logger.info(zhCnt);
            }
            // 201
liqin's avatar
liqin committed
194
            resultMap.put("status", 200);
liqin's avatar
liqin committed
195
            resultMap.put("message", "提交成功");
liqin's avatar
liqin committed
196
            return ResponseEntity.status(HttpStatus.OK).body(resultMap);
liqin's avatar
liqin committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
        } catch (Exception e) {
            logger.error("提交错误!", e);
        }
        resultMap.put("status", 500);
        resultMap.put("message", "操作失败");
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
    }

    @ApiOperation(value = "填写反馈内容")
    @PutMapping(value = "/edit")
    public ResponseEntity<Map<String, Object>> edit(String id, String feedbackInfo, String personId) {
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
        try {
            if (!StringUtils.isNoneBlank(id)) {
                resultMap.put("status", 400);
                resultMap.put("message", "页面信息失效,请重新点击链接进入");
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
            }
            //验证反馈人是否存在
liqin's avatar
liqin committed
216
            Employee employee = employeeService.getById(personId);
liqin's avatar
liqin committed
217 218 219 220 221 222 223 224 225 226 227 228 229
            if (employee == null) {
                resultMap.put("status", 400);
                resultMap.put("message", "反馈链接有误");
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
            }
            if (!StringUtils.isNoneBlank(feedbackInfo)) {
                resultMap.put("status", 400);
                resultMap.put("message", "请输入反馈内容");
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
            } else {
                feedbackInfo = StringUtils.trimToNull(feedbackInfo); // 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
            }

liqin's avatar
liqin committed
230
            DemandInfo entity = this.demandInfoService.getById(id);
liqin's avatar
liqin committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
            if (entity.getFeedbackInfo() != null) {
                resultMap.put("status", 400);
                resultMap.put("message", "您已反馈,请勿重复提交!");
                return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resultMap);
            }

            //保存反馈人ID
            entity.setFeedbackPersonId(personId);
            entity.setFeedbackTime(new Date(System.currentTimeMillis()));
            entity.setFeedbackInfo(EmojiParser.parseToHtmlHexadecimal(feedbackInfo.trim()));
            boolean ret = this.demandInfoService.updateById(entity);
            if (!ret) {
                resultMap.put("status", 500);
                resultMap.put("message", "反馈失败");
                return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
            } else {
liqin's avatar
liqin committed
247
                resultMap.put("status", 200);
liqin's avatar
liqin committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
                resultMap.put("message", "反馈成功");
                return ResponseEntity.ok(resultMap);
            }
        } catch (Exception e) {
            logger.error("反馈错误!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(resultMap);
    }

    /**
     * App获取呼叫服务或者吐槽建议列表
     *
     * @param type
     * @param advisorId
     * @param bankBranchId
     * @return
     */
    @ApiOperation(value = "App获取呼叫服务或者吐槽建议列表")
    @GetMapping(value = "/getListOnApp")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "type", value = "消息类型:1-吐槽建议2-呼叫记录", required = true),
            @ApiImplicitParam(name = "advisorId", value = "发送人ID(当前登陆用户Id)", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bankBranchId", value = "归属网点ID", required = true, dataType = "String")})
    public ResponseEntity<List<DemandInfo>> getListOnApp(Integer type, String advisorId, String bankBranchId) {
        try {

liqin's avatar
liqin committed
274
            QueryWrapper<DemandInfo> demandInfoWrapper = new QueryWrapper<>();
liqin's avatar
liqin committed
275 276 277
            demandInfoWrapper.eq("type", type)
                    .eq("advisor_id", advisorId)
                    .eq("bank_branch_id", bankBranchId)
liqin's avatar
liqin committed
278 279
                    .orderByDesc("create_time");
            List<DemandInfo> demandInfoList = this.demandInfoService.list(demandInfoWrapper);
liqin's avatar
liqin committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
            for (DemandInfo demandInfo : demandInfoList) {
                demandInfo.setContent(EmojiParser.parseToUnicode(demandInfo.getContent()));
                if (StringUtils.isNotBlank(demandInfo.getFeedbackInfo())) {
                    demandInfo.setFeedbackInfo(EmojiParser.parseToUnicode(demandInfo.getFeedbackInfo()));
                }
            }
            return ResponseEntity.ok(demandInfoList);
        } catch (Exception e) {
            logger.error("服务器错误!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * APP获取单个呼叫服务或者吐槽建议
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "App获取单个呼叫服务或者吐槽建议")
    @GetMapping(value = "/getByIdForApp")
    public ResponseEntity<DemandInfo> getByIdForApp(String id) {
        try {
liqin's avatar
liqin committed
303 304
            QueryWrapper<DemandInfo> ew = new QueryWrapper<>();
            ew.select("id,line_number AS lineNumber,create_time AS createTime,phone_number AS phoneNumber,content,feedback_info AS feedbackInfo");
liqin's avatar
liqin committed
305
            ew.eq("id", id);
liqin's avatar
liqin committed
306
            DemandInfo one = this.demandInfoService.getOne(ew);
liqin's avatar
liqin committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320
            if (null != one) {
                return ResponseEntity.ok(one);
            }
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
        } catch (Exception e) {
            logger.error("获取单个呼叫服务或者吐槽建议出错!", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }



}