package me.zhengjie.application.bank.controller; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.rest.AnonymousPostMapping; import me.zhengjie.application.bank.BaseController; import me.zhengjie.application.bank.controller.vo.BankOrderVO; import me.zhengjie.application.bank.service.BankOrderService; import me.zhengjie.base.ResponseDTO; import me.zhengjie.base.ResultCode; import me.zhengjie.base.util.DateUtils; import me.zhengjie.base.util.StatusEnum; import me.zhengjie.domain.order.OrderConstant; import org.apache.commons.lang3.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.validation.Valid; import java.util.List; @Validated @RestController @RequestMapping("${fqgz.bank.app.url-prefix}/order") @Slf4j @RequiredArgsConstructor @Api(tags = "客户经理APP: 订单管理") public class BankOrderController extends BaseController { private final BankOrderService bankOrderService; /** * 得到业务编号 * * @return */ @RequestMapping("/business-no") public ResponseDTO businessNo() { String no = "100" + DateUtils.getNo(); return ResponseDTO.success(no); } /** * 创建/修改订单 * * @return */ @AnonymousPostMapping("/save") public ResponseDTO saveOrder(@RequestBody @Valid BankOrderVO vo) { if (vo.getJointFlag() != null && vo.getJointFlag() == OrderConstant.JOINT_FLAG_TRUE) { if (StringUtils.isEmpty(vo.getJointName()) || StringUtils.isEmpty(vo.getJointIdCard()) || StringUtils.isEmpty(vo.getJointPhone()) || StringUtils.isEmpty(vo.getJointSex()) || StringUtils.isEmpty(vo.getJointIdcardFrontPic()) || StringUtils.isEmpty(vo.getJointIdcardBackPic())) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } } bankOrderService.saveContractOrder(vo, getCurrentUser()); return ResponseDTO.success(); } /** * 订单列表 * * @param json * @return */ @PostMapping("/list") public ResponseDTO> orderList(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String phone = jsonObj.getString("phone"); String status = jsonObj.getString("status"); String contractNo = jsonObj.getString("contractNo"); Long index = jsonObj.getLong("index"); Long size = jsonObj.getLong("size"); List list = bankOrderService.getContractOrderList(contractNo, phone, status, index, size); return ResponseDTO.success(list); } /** * 查询主订单详情 * * @param json * @return */ @RequestMapping("/info") public ResponseDTO orderInfo(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); if (StringUtils.isEmpty(businessNo)) { return ResponseDTO.error(ResultCode.PARAM_IS_BLANK); } BankOrderVO order = bankOrderService.getContractOrderWithBizNo(businessNo); if (order == null) { return ResponseDTO.error(ResultCode.ORDER_DATA_NOT_EXIST); } return ResponseDTO.success(order); } /** * 提交订单 * * @param json * @return */ @ApiOperation("提交订单") @PostMapping(value = "/submit") public ResponseDTO submitOrder(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); return bankOrderService.submitContractOrder(businessNo, getCurrentUser()); } /** * 删除订单 * * @param json * @return */ @RequestMapping("/delete") public ResponseDTO delete(@RequestBody String json) { JSONObject jsonObj = JSONObject.parseObject(json); String businessNo = jsonObj.getString("businessNo"); String status= StatusEnum.NotaryStatusEnum.DELETE.getStatus().toString(); bankOrderService.updateStatus(businessNo,status,null); return ResponseDTO.success(); } /** * 银行合同OCR解析输入 * * @param file * @param orderType * @return */ @RequestMapping("/ocr-parser") public ResponseDTO orderOCRParser(MultipartFile file, Integer orderType) { Object object = bankOrderService.parseContractOrder(orderType, file, getCurrentUser()); if (object == null) { return ResponseDTO.error(ResultCode.ORDER_OCR_SERVICE_UNAVAILABLE); } return ResponseDTO.success(object); } }