diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/GlobalConstants.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/GlobalConstants.java index f9263509..810b4402 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/GlobalConstants.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/constant/GlobalConstants.java @@ -547,4 +547,9 @@ public class GlobalConstants { * Long 65535L */ public static final Long LONG_65535 = 65535L; + + public static final int NUM_9 = 9; + public static final int NUM_100 = 100; + public static final int NUM_99 = 99; + public static final int NUM_1000 = 1000; } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/controller/BmAgreementInfoController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/controller/BmAgreementInfoController.java index 63e0e3cf..377930fc 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/controller/BmAgreementInfoController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/controller/BmAgreementInfoController.java @@ -87,7 +87,11 @@ public class BmAgreementInfoController extends BaseController @PostMapping public AjaxResult add(@RequestBody BmAgreementInfo bmAgreementInfo) { - return toAjax(bmAgreementInfoService.insertBmAgreementInfo(bmAgreementInfo)); + try { + return bmAgreementInfoService.insertBmAgreementInfo(bmAgreementInfo); + } catch (Exception e) { + return error("系统错误, " + e.getMessage()); + } } /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/mapper/BmAgreementInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/mapper/BmAgreementInfoMapper.java index 04a47f72..1e8919d2 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/mapper/BmAgreementInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/mapper/BmAgreementInfoMapper.java @@ -1,5 +1,6 @@ package com.bonus.material.basic.mapper; +import java.util.Date; import java.util.List; import com.bonus.material.basic.domain.BmAgreementInfo; @@ -58,4 +59,6 @@ public interface BmAgreementInfoMapper * @return 结果 */ public int deleteBmAgreementInfoByAgreementIds(Long[] agreementIds); + + public int selectNumByMonth(Date nowDate); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/IBmAgreementInfoService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/IBmAgreementInfoService.java index 41579fb1..9c19749b 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/IBmAgreementInfoService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/IBmAgreementInfoService.java @@ -1,6 +1,8 @@ package com.bonus.material.basic.service; import java.util.List; + +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.basic.domain.BmAgreementInfo; /** @@ -33,7 +35,7 @@ public interface IBmAgreementInfoService * @param bmAgreementInfo 协议管理 * @return 结果 */ - public int insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo); + public AjaxResult insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo); /** * 修改协议管理 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmAgreementInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmAgreementInfoServiceImpl.java index ae9b2e95..45e61c7a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmAgreementInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmAgreementInfoServiceImpl.java @@ -1,12 +1,20 @@ package com.bonus.material.basic.service.impl; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; + +import com.bonus.common.biz.constant.GlobalConstants; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.bonus.material.basic.mapper.BmAgreementInfoMapper; import com.bonus.material.basic.domain.BmAgreementInfo; import com.bonus.material.basic.service.IBmAgreementInfoService; +import org.springframework.util.CollectionUtils; /** * 协议管理Service业务层处理 @@ -51,10 +59,38 @@ public class BmAgreementInfoServiceImpl implements IBmAgreementInfoService * @return 结果 */ @Override - public int insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo) + public AjaxResult insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo) { - bmAgreementInfo.setCreateTime(DateUtils.getNowDate()); - return bmAgreementInfoMapper.insertBmAgreementInfo(bmAgreementInfo); + List list = bmAgreementInfoMapper.selectBmAgreementInfoList(bmAgreementInfo); + if (!CollectionUtils.isEmpty(list) && list.size() > 0) { + return AjaxResult.error("已存在重复数据"); + } + try { + bmAgreementInfo.setCreateTime(DateUtils.getNowDate()); + bmAgreementInfo.setCreateBy(SecurityUtils.getUsername()); + bmAgreementInfo.setAgreementCode(getAgreementCode()); + return AjaxResult.success(bmAgreementInfoMapper.insertBmAgreementInfo(bmAgreementInfo)); + } catch (Exception e) { + throw new ServiceException("错误信息描述"); + } + } + + private String getAgreementCode() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + int num = bmAgreementInfoMapper.selectNumByMonth(nowDate); + num = num + 1; + String code = ""; + if (num > GlobalConstants.NUM_9 && num < GlobalConstants.NUM_100) { + code = "XY" + result + "-00" + num; + } else if (num > GlobalConstants.NUM_99 && num < GlobalConstants.NUM_1000) { + code = "XY" + result + "-0" + num; + } else { + code = "XY" + result + "-000" + num; + } + return code; } /** diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml index d05a1ae6..1141f8d9 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/BmAgreementInfoMapper.xml @@ -142,4 +142,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{agreementId} + + \ No newline at end of file