package cn.huge.module.mediate.controller.client; import cn.huge.base.common.constant.GzRegionBaseEnum; import cn.huge.base.common.utils.DateUtils; import cn.huge.base.common.utils.ReturnFailUtils; import cn.huge.base.common.utils.ReturnSucUtils; import cn.huge.module.mediate.service.CaseInfoService; import cn.huge.module.mediate.service.JudicInfoService; import cn.huge.module.mediate.utils.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.Date; /** * @title: 公共参数-id工具接口api-mediate服务专用 * @description: 公共参数-id工具接口api-mediate服务专用 * @company: hugeinfo * @author: liyj * @time: 2022-04-29 10:12:39 * @version: 1.0.0 */ @Slf4j @RestController @RequestMapping("/api/client/mediateUtils") public class MediateUtilsController { @Autowired(required = false) private HttpServletRequest request; @Autowired private CaseInfoService caseInfoService; @Autowired private JudicInfoService judicInfoService; /** * 公共id-获取时间Id,后四位常量 * @url {ctx}/api/client/mediateUtils/getNewTimeId * @return Object */ @GetMapping("/getNewTimeId") public Object getNewTimeId() { try { return ReturnSucUtils.getRepInfo(MediateIdUtils.getNewTimeId()); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 案件id-获取时间Id,后四位常量 * @url {ctx}/api/client/mediateUtils/getNewTimeCaseId * @return Object */ @GetMapping("/getNewTimeCaseId") public Object getNewTimeCaseId() { try { return ReturnSucUtils.getRepInfo(CaseIdUtils.getNewTimeId()); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 生成新的调解案号 * @url {ctx}/api/client/mediateUtils/createCaseNo * @param area 区 * @return Object */ @GetMapping("/createCaseNo") public Object createCaseNo(@RequestParam(value = "area") String area) { try { // 判断是否需要查询数据库获取初始化序号 if (CaseNoUtils.getFlag(area)){ // 查询数据库已存在多少,初始化序号 String caseNoPrefix = CaseNoUtils.getSign(area); String newCaseNo = caseInfoService.getNewCaseNo(caseNoPrefix); if(StringUtils.isBlank(newCaseNo)){ newCaseNo = "0"; } String numStr = newCaseNo.replace(caseNoPrefix, "").replace("号", ""); int noCount = Integer.parseInt(numStr); // 设置初始化序号 CaseNoUtils.setCount(area, noCount); // 设置不需要查询 CaseNoUtils.setFlag(area, false); } return ReturnSucUtils.getRepInfo(CaseNoUtils.getCaseNo(area)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 从startNo(包括startNo)开始生成新的调解案号 * @url {ctx}/api/client/mediateUtils/setCaseNoByStartNo * @return Object */ @GetMapping("/setCaseNoByStartNo") public Object setCaseNoByStartNo(@RequestParam(value = "area") String area, @RequestParam(value = "startNo") int startNo) { try { CaseNoUtils.setCount(area, startNo); CaseNoUtils.setFlag(area, false); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 生成新的事项编号 * @url {ctx}/api/client/mediateUtils/createCaseRef * @return Object */ @GetMapping("/createCaseRef") public Object createCaseRef(@RequestParam(value = "area") String area) { try { // 判断是否需要查询数据库获取初始化序号 if (CaseRefUtils.getFlag(area)){ // 查询数据库已存在多少,初始化序号 String caseRsfSign = CaseRefUtils.getSign(area); String newCaseRef = caseInfoService.getNewCaseRef(caseRsfSign); int refCount = 0; if(StringUtils.isBlank(newCaseRef)){ refCount = 0; }else { if (newCaseRef.indexOf("-") != -1) { String[] numStrs = newCaseRef.split("-"); refCount = Integer.parseInt(numStrs[2]) + 1; }else { refCount = 0; } } // 设置初始化序号 CaseRefUtils.setCount(area, refCount); // 设置不需要查询 CaseRefUtils.setFlag(area, false); } // 获取事项编号 return ReturnSucUtils.getRepInfo(CaseRefUtils.getCaseRsf(area)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 从startNo(包括startNo)开始生成新的事项编号 * @url {ctx}/api/client/mediateUtils/setCaseNoByStartRef * @return Object */ @GetMapping("/setCaseNoByStartRef") public Object setCaseNoByStartRef(@RequestParam(value = "area") String area, @RequestParam(value = "startRef") int startRef) { try { CaseRefUtils.setCount(area, startRef); CaseRefUtils.setFlag(area, false); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 司法确认id-获取时间Id,后四位常量 * @url {ctx}/api/client/mediateUtils/getNewTimeJudicId * @return Object */ @GetMapping("/getNewTimeJudicId") public Object getNewTimeJudicId() { try { return ReturnSucUtils.getRepInfo(JudicIdUtils.getNewTimeId()); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 生成新的调解案号 * @url {ctx}/api/client/mediateUtils/createJudicNo * @param custId 客户编号 * @return Object */ @GetMapping("/createJudicNo") public Object createJudicNo(@RequestParam(value = "custId") String custId) { try { if (JudicNoUtils.JUDIC_NO_FALG){ int year = DateUtils.getYear(new Date()); String judicNoPrefix = "(" + year + ")司法确认"; String newJudicNo = judicInfoService.getNewJudicNo(judicNoPrefix, custId); if(StringUtils.isBlank(newJudicNo)){ newJudicNo = "0"; } String numStr = newJudicNo.replace(judicNoPrefix, "").replace("号", ""); int num = Integer.parseInt(numStr); JudicNoUtils.JUDIC_NO_SIGN = num; JudicNoUtils.JUDIC_NO_FALG = false; } return ReturnSucUtils.getRepInfo(JudicNoUtils.getJudicNo()); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 从startNo(包括startNo)开始生成新的司法确认号 * @url {ctx}/api/client/mediateUtils/setJudicByStartNo * @return Object */ @GetMapping("/setJudicByStartNo") public Object setJudicByStartNo(@RequestParam(value = "startNo") int startNo) { try { JudicNoUtils.JUDIC_NO_SIGN = startNo-1; JudicNoUtils.JUDIC_NO_FALG = false; return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } }