新建协议接口

This commit is contained in:
sxu 2024-11-11 15:22:32 +08:00
parent 219fa82d64
commit 0992fa22d7
6 changed files with 59 additions and 5 deletions

View File

@ -547,4 +547,9 @@ public class GlobalConstants {
* Long 65535L * Long 65535L
*/ */
public static final Long LONG_65535 = 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;
} }

View File

@ -87,7 +87,11 @@ public class BmAgreementInfoController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody BmAgreementInfo bmAgreementInfo) public AjaxResult add(@RequestBody BmAgreementInfo bmAgreementInfo)
{ {
return toAjax(bmAgreementInfoService.insertBmAgreementInfo(bmAgreementInfo)); try {
return bmAgreementInfoService.insertBmAgreementInfo(bmAgreementInfo);
} catch (Exception e) {
return error("系统错误, " + e.getMessage());
}
} }
/** /**

View File

@ -1,5 +1,6 @@
package com.bonus.material.basic.mapper; package com.bonus.material.basic.mapper;
import java.util.Date;
import java.util.List; import java.util.List;
import com.bonus.material.basic.domain.BmAgreementInfo; import com.bonus.material.basic.domain.BmAgreementInfo;
@ -58,4 +59,6 @@ public interface BmAgreementInfoMapper
* @return 结果 * @return 结果
*/ */
public int deleteBmAgreementInfoByAgreementIds(Long[] agreementIds); public int deleteBmAgreementInfoByAgreementIds(Long[] agreementIds);
public int selectNumByMonth(Date nowDate);
} }

View File

@ -1,6 +1,8 @@
package com.bonus.material.basic.service; package com.bonus.material.basic.service;
import java.util.List; import java.util.List;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.basic.domain.BmAgreementInfo; import com.bonus.material.basic.domain.BmAgreementInfo;
/** /**
@ -33,7 +35,7 @@ public interface IBmAgreementInfoService
* @param bmAgreementInfo 协议管理 * @param bmAgreementInfo 协议管理
* @return 结果 * @return 结果
*/ */
public int insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo); public AjaxResult insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo);
/** /**
* 修改协议管理 * 修改协议管理

View File

@ -1,12 +1,20 @@
package com.bonus.material.basic.service.impl; package com.bonus.material.basic.service.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; 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.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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.bonus.material.basic.mapper.BmAgreementInfoMapper; import com.bonus.material.basic.mapper.BmAgreementInfoMapper;
import com.bonus.material.basic.domain.BmAgreementInfo; import com.bonus.material.basic.domain.BmAgreementInfo;
import com.bonus.material.basic.service.IBmAgreementInfoService; import com.bonus.material.basic.service.IBmAgreementInfoService;
import org.springframework.util.CollectionUtils;
/** /**
* 协议管理Service业务层处理 * 协议管理Service业务层处理
@ -51,10 +59,38 @@ public class BmAgreementInfoServiceImpl implements IBmAgreementInfoService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo) public AjaxResult insertBmAgreementInfo(BmAgreementInfo bmAgreementInfo)
{ {
List<BmAgreementInfo> list = bmAgreementInfoMapper.selectBmAgreementInfoList(bmAgreementInfo);
if (!CollectionUtils.isEmpty(list) && list.size() > 0) {
return AjaxResult.error("已存在重复数据");
}
try {
bmAgreementInfo.setCreateTime(DateUtils.getNowDate()); bmAgreementInfo.setCreateTime(DateUtils.getNowDate());
return bmAgreementInfoMapper.insertBmAgreementInfo(bmAgreementInfo); 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;
} }
/** /**

View File

@ -142,4 +142,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{agreementId} #{agreementId}
</foreach> </foreach>
</delete> </delete>
<select id="selectNumByMonth" resultType="java.lang.Integer">
select count(*) from bm_agreement_info where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m')
</select>
</mapper> </mapper>