嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-cweb/src/main/java/com/cweb/controller/Etc/EtcCustomerController.java

374 lines
15 KiB

package com.cweb.controller.Etc;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.EtcService;
import com.hai.entity.EtcCarMsg;
import com.hai.entity.EtcContractOrder;
import com.hai.entity.EtcCustMsg;
import com.hai.entity.SecDictionary;
import com.hai.etc.EtcCarMsgService;
import com.hai.etc.EtcCustMsgService;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@RestController
@RequestMapping(value="/etcCustomer")
@Api(value="etc客户信息")
public class EtcCustomerController {
Logger log = LoggerFactory.getLogger(EtcCustomerController.class);
@Resource
private UserCenter userCenter;
@Resource
private EtcCustMsgService etcCustMsgService;
@Resource
private EtcCarMsgService etcCarMsgService;
@RequestMapping(value = "/getEtcCarMsgList", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询车辆列表")
public ResponseData getEtcCarList(
HttpServletRequest request
) {
try {
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
Map<String, Object> mapUser = new HashMap<>();
mapUser.put("phone" , userInfoModel.getHighUser().getPhone());
mapUser.put("status" , 2);
EtcCustMsg etcCustMsg = etcCustMsgService.findEtcCustByMap(mapUser);
if (etcCustMsg == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到任何车辆!");
}
Map<String, Object> map = new HashMap<>();
map.put("custId" , etcCustMsg.getCustId());
return ResponseMsgUtil.success(etcCarMsgService.getEtcCarList(map));
} catch (Exception e) {
log.error("BsMsgController --> getMsgByList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getEtcContractOrderList", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询合同订单列表")
public ResponseData getEtcContractOrderList(
@RequestParam(value = "signStatus", required = false) String signStatus, HttpServletRequest request
) {
try {
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
Map<String, Object> mapUser = new HashMap<>();
mapUser.put("phone" , userInfoModel.getHighUser().getPhone());
mapUser.put("status" , 2);
EtcCustMsg etcCustMsg = etcCustMsgService.findEtcCustByMap(mapUser);
if (etcCustMsg == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到合同!");
}
Map<String, Object> map = new HashMap<>();
map.put("custId" , etcCustMsg.getCustId());
map.put("signStatus" , signStatus);
map.put("status" , 1);
return ResponseMsgUtil.success(etcCarMsgService.getEtcContractOrderList(map));
} catch (Exception e) {
log.error("BsMsgController --> getMsgByList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/findContractOrderById", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询合同订单详情")
public ResponseData findContractOrderById(
@RequestParam(value = "id", required = false) Long id
) {
try {
EtcContractOrder contractOrder = etcCarMsgService.findContractOrderById(id);
if (contractOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到合同!");
}
// 查询车辆信息
Map<String , Object> mapCar = new HashMap<>();
mapCar.put("vehId" , contractOrder.getVehId());
mapCar.put("custId" , contractOrder.getCustId());
EtcCarMsg carMsg = etcCarMsgService.findEtcCarByMap(mapCar);
if (carMsg == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到信息!");
}
// 查询车辆状态
JSONObject car = EtcService.getVehStatus(carMsg);
if (car.getString("errCode").equals("0")) {
carMsg.setVehStatus(car.getJSONObject("result").getInteger("vehStatus"));
carMsg.setPayStatus(car.getJSONObject("result").getInteger("payStatus"));
carMsg.setSignStatus(car.getJSONObject("result").getInteger("signStatus"));
contractOrder.setVehStatus(carMsg.getVehStatus());
etcCarMsgService.updateEtcCar(carMsg);
}
// 查询微信签约代扣信息
return ResponseMsgUtil.success(etcCarMsgService.findContractOrderById(id));
} catch (Exception e) {
log.error("BsMsgController --> getMsgByList() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/sendSignVerifyCode", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "签约验证码发送接口")
public ResponseData sendSignVerifyCode(@RequestParam(value = "id", required = true) Long id) {
try {
EtcContractOrder contractOrder = etcCarMsgService.findContractOrderById(id);
if (contractOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误!");
}
JSONObject object = EtcService.sendSignVerifyCode(contractOrder.getCustId());
if (object.getString("errCode").equals("0")) {
return ResponseMsgUtil.success("请求成功!");
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("errMsg"));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/checkSignVerifyCode", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "签约验证码核验接口")
public ResponseData checkSignVerifyCode(@RequestParam(value = "id", required = true) Long id ,
@RequestParam(value = "signImg", required = true) String signImg ,
@RequestParam(value = "verifyCode", required = true) String verifyCode ) {
try {
EtcContractOrder contractOrder = etcCarMsgService.findContractOrderById(id);
if (contractOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误!");
}
contractOrder.setSignImg(signImg);
contractOrder.setUpdateTime(new Date());
etcCarMsgService.updateContractOrder(contractOrder);
JSONObject object = EtcService.checkSignVerifyCode(contractOrder.getCustId() , verifyCode);
if (object.getString("errCode").equals("0")) {
Map<String , Object> mapCar = new HashMap<>();
mapCar.put("vehId" , contractOrder.getVehId());
mapCar.put("custId" , contractOrder.getCustId());
EtcCarMsg carMsg = etcCarMsgService.findEtcCarByMap(mapCar);
carMsg.setSignStatus(1);
carMsg.setUpdateTime(new Date());
etcCarMsgService.updateEtcCar(carMsg);
contractOrder.setSignStatus(1);
contractOrder.setExt3(object.toJSONString());
etcCarMsgService.updateContractOrder(contractOrder);
return ResponseMsgUtil.success("请求成功!");
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("errMsg"));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/getSignContractTemplate", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取签约合同模板")
public ResponseData getSignContractTemplate(@RequestParam(value = "contractId", required = true) Long contractId ) {
try {
EtcContractOrder contractOrder = etcCarMsgService.findContractOrderById(contractId);
if (contractOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "状态错误!");
}
JSONObject object = EtcService.getSignContractTemplate(contractOrder.getCustId() , contractOrder.getProductId() , contractOrder.getCardVarietyId());
if (object.getString("errCode").equals("0")) {
JSONObject jsonObject = (JSONObject) object.getJSONArray("result").get(0);
return ResponseMsgUtil.success(jsonObject.getString("url"));
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("errMsg"));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/checkNeedSign", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查看是否需要签约代扣")
public ResponseData checkNeedSign(@RequestParam(value = "contractId", required = true) Long contractId,
@RequestParam(value = "type", required = true) Integer type) {
try {
EtcContractOrder contractOrder = etcCarMsgService.findContractOrderById(contractId);
if (type == 1) {
JSONObject object = EtcService.checkNeedSignWechatWithhold( contractOrder.getProductId() , contractOrder.getCardVarietyId());
if (object.getString("errCode").equals("0")) {
return ResponseMsgUtil.success(object.getJSONObject("result"));
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("errMsg"));
}
} else {
JSONObject object = EtcService.checkSignWithhold( contractOrder.getCustId());
if (object.getString("errCode").equals("0")) {
if (object.getJSONObject("result").getBoolean("isSign")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已签约");
}
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, object.getString("errMsg"));
}
}
return ResponseMsgUtil.success(true);
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/sendSignWithholdCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "签约银行卡代扣发送验证码")
public ResponseData sendSignWithholdCode(@RequestBody JSONObject object, HttpServletRequest request) {
try {
if (object.getString("custId") == null ||
object.getString("cardNo") == null ||
object.getInteger("bankCardType") == null ||
object.getString("mobileNo") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "信息不全!");
}
if (object.getInteger("bankCardType") == 2 ) {
if (object.getString("cardExpired") == null ||
object.getString("cardCvv2") == null ) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "信用卡信息不全!");
}
}
JSONObject jsonObject = EtcService.sendSignWithholdCode(object);
if (jsonObject.getString("errCode").equals("0")) {
return ResponseMsgUtil.success(jsonObject.getJSONObject("result").getString("verifyCodeNo"));
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errMsg"));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/signWithhold", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "签约银行卡代扣")
public ResponseData signWithhold(@RequestBody JSONObject object, HttpServletRequest request) {
try {
if (object.getString("custId") == null ||
object.getString("cardNo") == null ||
object.getInteger("bankCardType") == null ||
object.getString("bankName") == null ||
object.getString("verifyCodeNo") == null ||
object.getString("verifyCode") == null ||
object.getString("mobileNo") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "信息不全!");
}
if (object.getInteger("bankCardType") == 2 ) {
if (object.getString("cardExpired") == null ||
object.getString("cardCvv2") == null ) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "信用卡信息不全!");
}
}
JSONObject jsonObject = EtcService.signWithhold(object);
if (jsonObject.getString("errCode").equals("0")) {
return ResponseMsgUtil.success("请求成功");
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("errMsg"));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}