feat(sip): 根据项目ID生成订单编号

- 新增根据项目ID获取代理省份的方法- 修改订单编号生成逻辑,使用代理省份而非直接使用省份参数- 增加异常处理,当代理省份为空时抛出服务异常
- 优化数据库查询,减少冗余的省份参数传递
master
chenhao 2025-06-06 14:33:33 +08:00
parent 7d23b0ade8
commit 1a66bb45b1
7 changed files with 34 additions and 3 deletions

View File

@ -59,4 +59,6 @@ public interface AgentInfoMapper
*/ */
public int deleteAgentInfoByIds(String[] ids); public int deleteAgentInfoByIds(String[] ids);
public int selectCountByCode(AgentInfo agentInfo); public int selectCountByCode(AgentInfo agentInfo);
AgentInfo selectAgentInfoByCode(String agentCode);
} }

View File

@ -62,4 +62,6 @@ public interface ProjectOrderInfoMapper
List<ProjectOrderInfo> selectProjectOrderInfoByProjectId(List<Long> projectId); List<ProjectOrderInfo> selectProjectOrderInfoByProjectId(List<Long> projectId);
int selectMaxOrderCode(String province); int selectMaxOrderCode(String province);
String selectAgentProvinceByProjectId(Long projectId);
} }

View File

@ -58,4 +58,6 @@ public interface IAgentInfoService
* @return * @return
*/ */
public int deleteAgentInfoById(Long id); public int deleteAgentInfoById(Long id);
AgentInfo selectAgentInfoByCode(String agentCode);
} }

View File

@ -105,4 +105,10 @@ public class AgentInfoServiceImpl implements IAgentInfoService
{ {
return agentInfoMapper.deleteAgentInfoById(id); return agentInfoMapper.deleteAgentInfoById(id);
} }
@Override
public AgentInfo selectAgentInfoByCode(String agentCode) {
return agentInfoMapper.selectAgentInfoByCode(agentCode);
}
} }

View File

@ -10,6 +10,7 @@ import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.sip.domain.*; import com.ruoyi.sip.domain.*;
import com.ruoyi.sip.service.*; import com.ruoyi.sip.service.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -34,6 +35,7 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
private IProjectProductInfoService productInfoService; private IProjectProductInfoService productInfoService;
@Autowired @Autowired
private ICnareaService cnareaService; private ICnareaService cnareaService;
/** /**
* *
* *
@ -80,8 +82,9 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
*/ */
@Override @Override
public int insertProjectOrderInfo(ProjectOrderInfo projectOrderInfo) { public int insertProjectOrderInfo(ProjectOrderInfo projectOrderInfo) {
// 生成订单编号 // 生成订单编号
String orderNumber = generateOrderNumber(projectOrderInfo.getProvince()); String orderNumber = generateOrderNumber(projectOrderInfo.getProjectId());
projectOrderInfo.setOrderCode(orderNumber); projectOrderInfo.setOrderCode(orderNumber);
projectOrderInfo.setCreateTime(DateUtils.getNowDate()); projectOrderInfo.setCreateTime(DateUtils.getNowDate());
projectOrderInfo.setCreateBy(ShiroUtils.getUserId().toString()); projectOrderInfo.setCreateBy(ShiroUtils.getUserId().toString());
@ -111,7 +114,11 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
* @param province * @param province
* @return * @return
*/ */
private String generateOrderNumber(String province) { private String generateOrderNumber(Long projectId) {
String province = projectOrderInfoMapper.selectAgentProvinceByProjectId(projectId);
if (StringUtils.isEmpty(province)) {
throw new ServiceException("代表处所属省为空,无法生成订单编号");
}
// 获取当前时间格式为yyyyMMdd // 获取当前时间格式为yyyyMMdd
String currentDate = DateUtils.dateTimeNow("yyyyMMdd"); String currentDate = DateUtils.dateTimeNow("yyyyMMdd");
Cnarea cnarea = new Cnarea(); Cnarea cnarea = new Cnarea();
@ -143,7 +150,7 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
public int updateProjectOrderInfo(ProjectOrderInfo projectOrderInfo) { public int updateProjectOrderInfo(ProjectOrderInfo projectOrderInfo) {
ProjectOrderInfo existProjectOrderInfo = projectOrderInfoMapper.selectProjectOrderInfoById(projectOrderInfo.getId()); ProjectOrderInfo existProjectOrderInfo = projectOrderInfoMapper.selectProjectOrderInfoById(projectOrderInfo.getId());
if (!existProjectOrderInfo.getProvince().equals(projectOrderInfo.getProvince())) { if (!existProjectOrderInfo.getProvince().equals(projectOrderInfo.getProvince())) {
String orderNumber = generateOrderNumber(projectOrderInfo.getProvince()); String orderNumber = generateOrderNumber(projectOrderInfo.getProjectId());
projectOrderInfo.setOrderCode(orderNumber); projectOrderInfo.setOrderCode(orderNumber);
} }
projectOrderInfo.setUpdateBy(ShiroUtils.getUserId().toString()); projectOrderInfo.setUpdateBy(ShiroUtils.getUserId().toString());

View File

@ -101,6 +101,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAgentProvinceByProjectId" resultType="java.lang.String">
select t2.province
from project_info t1
inner join agent_info t2 on t1.agent_code = t2.agent_code
where t1.id = #{projectId}
limit 1
</select> </select>
<insert id="insertProjectOrderInfo" parameterType="ProjectOrderInfo" useGeneratedKeys="true" keyProperty="id"> <insert id="insertProjectOrderInfo" parameterType="ProjectOrderInfo" useGeneratedKeys="true" keyProperty="id">

View File

@ -49,6 +49,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where agent_code=#{agentCode} and status=0 where agent_code=#{agentCode} and status=0
<if test="id != null">and id!=#{id}</if> <if test="id != null">and id!=#{id}</if>
</select> </select>
<select id="selectAgentInfoByCode" resultType="com.ruoyi.sip.domain.AgentInfo">
<include refid="selectAgentInfoVo"/>
where agent_code=#{agentCode}
limit 1
</select>
<insert id="insertAgentInfo" parameterType="AgentInfo" useGeneratedKeys="true" keyProperty="id"> <insert id="insertAgentInfo" parameterType="AgentInfo" useGeneratedKeys="true" keyProperty="id">
insert into agent_info insert into agent_info