营业执照文件上传逻辑优化

This commit is contained in:
sxu 2024-10-30 10:45:31 +08:00
parent be0f3ff1a5
commit 6dd54bddc3
5 changed files with 45 additions and 20 deletions

View File

@ -56,4 +56,13 @@ public interface BmFileInfoMapper {
* @return 结果
*/
int deleteBmFileInfoByIds(Long[] ids);
/**
* 删除附件
*
* @param bmFileInfo 附件信息
* @return 结果
*/
int deleteBmFileInfoByBizInfo(BmFileInfo bmFileInfo);
}

View File

@ -110,7 +110,7 @@ public class SupplierInfoController extends BaseController {
@PutMapping
public AjaxResult edit(@RequestBody SupplierInfo supplierInfo) {
try {
return toAjax(supplierInfoService.updateSupplierInfo(supplierInfo));
return supplierInfoService.updateSupplierInfo(supplierInfo);
} catch (Exception e) {
return error("系统错误, " + e.getMessage());
}

View File

@ -41,7 +41,7 @@ public interface ISupplierInfoService {
* @param supplierInfo 物资厂家管理
* @return 结果
*/
int updateSupplierInfo(SupplierInfo supplierInfo);
AjaxResult updateSupplierInfo(SupplierInfo supplierInfo);
/**
* 批量删除物资厂家管理

View File

@ -82,6 +82,7 @@ public class SupplierInfoServiceImpl implements ISupplierInfoService {
AtomicBoolean addFileInfoResult = new AtomicBoolean(false);
supplierInfo.getBmFileInfos().forEach(bmFileInfo -> {
bmFileInfo.setModelId(supplierInfo.getSupplierId());
bmFileInfo.setCreateTime(DateUtils.getNowDate());
addFileInfoResult.set(bmFileInfoMapper.insertBmFileInfo(bmFileInfo) > 0);
});
return addFileInfoResult.get() ? AjaxResult.success("新增任务成功") : AjaxResult.error("新增任务失败,附件表插入0条");
@ -91,20 +92,6 @@ public class SupplierInfoServiceImpl implements ISupplierInfoService {
} catch (Exception e) {
throw new ServiceException("数据库错误或供应商名称重复");
}
// if (insertedSupplierInfoResult > 0 && ArrayUtil.isNotEmpty(supplierInfo.getFiles())) {
// AjaxResult uploadedFilesResult = remoteFileService.uploadFile(supplierInfo.getFiles());
// if (uploadedFilesResult.isSuccess()) {
// Object uploadFilesResultData = uploadedFilesResult.get("data");
// if (uploadFilesResultData != null) {
// if (uploadFilesResultData instanceof List) {
//
// }
// }
// } else {
// return AjaxResult.error("新增任务失败,文件上传失败:" + uploadedFilesResult.get("msg"));
// }
// }
}
/**
@ -114,10 +101,25 @@ public class SupplierInfoServiceImpl implements ISupplierInfoService {
* @return 结果
*/
@Override
public int updateSupplierInfo(SupplierInfo supplierInfo) {
public AjaxResult updateSupplierInfo(SupplierInfo supplierInfo) {
supplierInfo.setUpdateTime(DateUtils.getNowDate());
try {
return supplierInfoMapper.updateSupplierInfo(supplierInfo);
int updatedSupplierInfoResult = supplierInfoMapper.updateSupplierInfo(supplierInfo);
if (updatedSupplierInfoResult > 0) {
if (CollectionUtils.isEmpty(supplierInfo.getBmFileInfos())) {
return AjaxResult.success("修改任务成功,无营业执照附件");
}
bmFileInfoMapper.deleteBmFileInfoByBizInfo(supplierInfo.getBmFileInfos().get(0));
AtomicBoolean addFileInfoResult = new AtomicBoolean(false);
supplierInfo.getBmFileInfos().forEach(bmFileInfo -> {
bmFileInfo.setModelId(supplierInfo.getSupplierId());
bmFileInfo.setCreateTime(DateUtils.getNowDate());
addFileInfoResult.set(bmFileInfoMapper.insertBmFileInfo(bmFileInfo) > 0);
});
return addFileInfoResult.get() ? AjaxResult.success("修改任务成功") : AjaxResult.error("修改任务失败,附件表插入0条");
} else {
return AjaxResult.error("修改任务失败,info表插入0条");
}
} catch (Exception e) {
throw new ServiceException("数据库错误或供应商名称重复");
}

View File

@ -5,6 +5,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<mapper namespace="com.bonus.material.basic.mapper.BmFileInfoMapper">
<resultMap type="com.bonus.material.basic.domain.BmFileInfo" id="BmFileInfoResult">
<result property="id" column="id" />
<result property="taskId" column="task_id" />
<result property="modelId" column="model_id" />
<result property="name" column="name" />
<result property="url" column="url" />
@ -14,12 +15,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectBmFileInfoVo">
select id, model_id, name, url, dic_id, create_by, create_time from bm_file_info
select id, task_id, model_id, name, url, dic_id, create_by, create_time from bm_file_info
</sql>
<select id="selectBmFileInfoList" parameterType="com.bonus.material.basic.domain.BmFileInfo" resultMap="BmFileInfoResult">
<include refid="selectBmFileInfoVo"/>
<where>
<where>
<if test="taskId != null "> and task_id = #{taskId}</if>
<if test="modelId != null "> and model_id = #{modelId}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="url != null and url != ''"> and url = #{url}</if>
@ -35,6 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertBmFileInfo" parameterType="com.bonus.material.basic.domain.BmFileInfo" useGeneratedKeys="true" keyProperty="id">
insert into bm_file_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null">task_id,</if>
<if test="modelId != null">model_id,</if>
<if test="name != null">name,</if>
<if test="url != null">url,</if>
@ -43,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="taskId != null">#{taskId},</if>
<if test="modelId != null">#{modelId},</if>
<if test="name != null">#{name},</if>
<if test="url != null">#{url},</if>
@ -55,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateBmFileInfo" parameterType="com.bonus.material.basic.domain.BmFileInfo">
update bm_file_info
<trim prefix="SET" suffixOverrides=",">
<if test="taskId != null">task_id = #{taskId},</if>
<if test="modelId != null">model_id = #{modelId},</if>
<if test="name != null">name = #{name},</if>
<if test="url != null">url = #{url},</if>
@ -75,4 +80,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<delete id="deleteBmFileInfoByBizInfo" parameterType="com.bonus.material.basic.domain.BmFileInfo">
delete from bm_file_info
<where>
<if test="taskId != null "> and task_id = #{taskId}</if>
<if test="modelId != null "> and model_id = #{modelId}</if>
<if test="dicId != null "> and dic_id = #{dicId}</if>
</where>
</delete>
</mapper>