fix:阿里药品关系维护

dev_unify
chenhc 8 months ago
parent 952171b068
commit cbcc5cd994

@ -40,4 +40,5 @@ public interface RedissonCacheKey {
String WEB_ADD_CODE = "web_add_code";
String XML_UPLOAD="xml_upload";
String XML_UPLOAD_ALI="xml_upload_ali";
}

@ -0,0 +1,38 @@
package com.glxp.api.controller.thrsys;
import com.glxp.api.annotation.CusRedissonAnnotation;
import com.glxp.api.annotation.RepeatSubmit;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.RedissonCacheKey;
import com.glxp.api.controller.BaseController;
import com.glxp.api.service.thrsys.ThirdAliDrugService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@RestController
public class ThirdAliDrugController extends BaseController {
@Resource
private ThirdAliDrugService thirdAliDrugService;
/**
*
*
* @param uuid
* @param file
* @return
*/
@RepeatSubmit()
@CusRedissonAnnotation(cacheName = RedissonCacheKey.XML_UPLOAD_ALI, key = {"#uuid"}, timeOutMsg = "系统正在处理,请勿重复上传")
@PostMapping("/udiwms/aliDrug/txtUpload")
public BaseResponse txtUpload(@RequestParam("uuid") String uuid, @RequestParam("file") MultipartFile file) {
thirdAliDrugService.txtUpload(file);
return ResultVOUtils.successMsg("上传成功!");
}
}

@ -2,8 +2,15 @@ package com.glxp.api.dao.thrsys;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.thrsys.ThirdAliDrug;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
@Mapper
public interface ThirdAliDrugMapper extends BaseMapper<ThirdAliDrug> {
int selectDrugsByNameCodes(@Param("nameCode") String nameCode);
int saveOrUpdateBatch(@Param("list") List<ThirdAliDrug> list);
}

@ -95,6 +95,12 @@ public class ThirdAliDrug implements Serializable {
@TableField(value = "packLevel")
@ApiModelProperty(value = "包装级别")
private String packLevel;
/**
*
*/
@TableField(value = "erpId")
@ApiModelProperty(value = "包装级别")
private String erpId;
/**
*
@ -111,4 +117,19 @@ public class ThirdAliDrug implements Serializable {
private Date updateTime;
private static final long serialVersionUID = 1L;
public ThirdAliDrug(String type, String manufacturer, String cpmctymc, String form, String formSpec, String bzgg, String spmc, String nameCode, String packRatio, String packLevel, Date createTime, Date updateTime) {
this.type = type;
this.manufacturer = manufacturer;
this.cpmctymc = cpmctymc;
this.form = form;
this.formSpec = formSpec;
this.bzgg = bzgg;
this.spmc = spmc;
this.nameCode = nameCode;
this.packRatio = packRatio;
this.packLevel = packLevel;
this.createTime = createTime;
this.updateTime = updateTime;
}
}

@ -1,14 +1,227 @@
package com.glxp.api.service.thrsys;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.glxp.api.exception.JsonException;
import com.glxp.api.service.auth.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.thrsys.ThirdAliDrugMapper;
import com.glxp.api.entity.thrsys.ThirdAliDrug;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@Service
@Slf4j
public class ThirdAliDrugService extends ServiceImpl<ThirdAliDrugMapper, ThirdAliDrug> {
@Resource
private CustomerService customerService;
//解析TXT获取对应的对象列表
@Transactional(rollbackFor = Exception.class)
public void txtUpload(MultipartFile file) {
try {
String fileName = file.getOriginalFilename();
String suffix = FileUtil.getSuffix(fileName);
if (!"txt".equals(suffix)) {
throw new JsonException("仅支持TXT文件类型错误" + suffix);
}
log.info(file.getSize() + "文件长度");
if (file.getSize() > 10 * 1024 * 1024) {
throw new JsonException("上传文件超过10M");
}
List<ThirdAliDrug> thirdAliDrugs = new ArrayList<>();
String customerId = customerService.getCustomerId();
try (BufferedReader br = new BufferedReader(new InputStreamReader(file.getInputStream()))) {
String line;
while ((line = br.readLine()) != null) {
String[] fields = fillEmptyParts(line);
Date createTime = new Date();
if (fields.length == 9) {
ThirdAliDrug medicine = new ThirdAliDrug(
fields[0].trim(),
fields[1].trim(),
fields[2].trim(),
fields[3].trim(),
fields[4].trim(),
fields[5].trim(),
fields[6].trim(),
fields[6].trim(),
fields[7].trim(),
fields[8].trim(),
createTime,
createTime
);
if (StrUtil.isNotEmpty(medicine.getNameCode())) {
int i = this.baseMapper.selectDrugsByNameCodes(medicine.getNameCode());
if (i == 0) {
medicine.setErpId(customerId);
thirdAliDrugs.add(medicine);
if (CollUtil.isNotEmpty(thirdAliDrugs) && thirdAliDrugs.size() >= 500) {
this.baseMapper.saveOrUpdateBatch(thirdAliDrugs);
thirdAliDrugs.clear();
}
}
}
}else
if (fields.length == 10) {
ThirdAliDrug medicine = new ThirdAliDrug(
fields[0].trim(),
fields[1].trim(),
fields[2].trim(),
fields[3].trim(),
fields[4].trim(),
fields[5].trim(),
fields[6].trim(),
fields[7].trim(),
fields[8].trim(),
fields[9].trim(),
createTime,
createTime
);
if (StrUtil.isNotEmpty(medicine.getNameCode())) {
int i = this.baseMapper.selectDrugsByNameCodes(medicine.getNameCode());
if (i == 0) {
medicine.setErpId(customerId);
thirdAliDrugs.add(medicine);
if (CollUtil.isNotEmpty(thirdAliDrugs) && thirdAliDrugs.size() >= 500) {
this.baseMapper.saveOrUpdateBatch(thirdAliDrugs);
thirdAliDrugs.clear();
}
}
}
}else
if (fields.length == 11) {
ThirdAliDrug medicine = new ThirdAliDrug(
fields[0].trim(),
fields[1].trim(),
fields[2].trim(),
fields[3].trim(),
fields[4].trim(),
fields[5].trim(),
fields[7].trim(),
fields[8].trim(),
fields[9].trim(),
fields[10].trim(),
createTime,
createTime
);
if (StrUtil.isNotEmpty(medicine.getNameCode())) {
int i = this.baseMapper.selectDrugsByNameCodes(medicine.getNameCode());
if (i == 0) {
medicine.setErpId(customerId);
thirdAliDrugs.add(medicine);
if (CollUtil.isNotEmpty(thirdAliDrugs) && thirdAliDrugs.size() >= 500) {
this.baseMapper.saveOrUpdateBatch(thirdAliDrugs);
thirdAliDrugs.clear();
}
}
}
}else if (fields.length > 11) {
ThirdAliDrug medicine = new ThirdAliDrug(
fields[0].trim(),
fields[1].trim(),
fields[2].trim(),
fields[3].trim(),
fields[4].trim(),
fields[5].trim(),
fields[7].trim(),
fields[9].trim(),
fields[10].trim(),
fields[11].trim(),
createTime,
createTime
);
if (StrUtil.isNotEmpty(medicine.getNameCode())) {
int i = this.baseMapper.selectDrugsByNameCodes(medicine.getNameCode());
if (i == 0) {
thirdAliDrugs.add(medicine);
if (CollUtil.isNotEmpty(thirdAliDrugs) && thirdAliDrugs.size() >= 500) {
this.baseMapper.saveOrUpdateBatch(thirdAliDrugs);
thirdAliDrugs.clear();
}
}
}
}
}
} catch (IOException e) {
throw new JsonException("上传失败:" + "标识重复");
}
if (CollUtil.isNotEmpty(thirdAliDrugs)) {
this.baseMapper.saveOrUpdateBatch(thirdAliDrugs);
}
} catch (Exception e) {
throw new JsonException("上传失败:" + e.getMessage());
}
}
public static String[] fillEmptyParts(String input) {
// Step 1: Split the input string by commas
String[] parts = input.split(",");
// Step 2: Count the number of commas (which will be one less than the number of parts we want)
// But we need to account for leading/trailing commas as well, so we use a different approach
int commaCount = 0;
boolean inEmptyPart = true; // To handle leading commas
for (char c : input.toCharArray()) {
if (c == ',') {
commaCount++;
inEmptyPart = true; // Next part will be empty until we find non-comma characters
} else if (inEmptyPart && c != ' ') {
inEmptyPart = false; // We found the start of a non-empty part
}
}
// If the input ends with a comma, we need an extra empty part
// But we also need to handle the case where the input is just commas (e.g., ",,,")
// So we use Math.max to ensure we at least have one part if the input is non-empty
int desiredArraySize = Math.max(commaCount + 1, parts.length);
// Step 3: Create a new array with the desired size and fill it with empty strings
String[] filledParts = new String[desiredArraySize];
Arrays.fill(filledParts, "");
// Step 4: Copy non-empty parts from the original array to the new array
int index = 0;
for (String part : parts) {
if (!part.trim().isEmpty()) {
filledParts[index++] = part.trim(); // Trim any surrounding spaces for cleanliness
}
// Note: We don't increment index for empty parts because those are already represented by empty strings in filledParts
}
// Note: At this point, if there were more commas than non-empty parts, the remaining elements in filledParts will be empty strings.
// If there were leading/trailing commas or multiple consecutive commas, those will also be represented by empty strings.
return filledParts;
}
}

@ -15,6 +15,7 @@
<result column="nameCode" jdbcType="VARCHAR" property="nameCode"/>
<result column="packRatio" jdbcType="VARCHAR" property="packRatio"/>
<result column="packLevel" jdbcType="VARCHAR" property="packLevel"/>
<result column="erpId" jdbcType="VARCHAR" property="packLevel"/>
<result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
<result column="updateTime" jdbcType="TIMESTAMP" property="updateTime"/>
</resultMap>
@ -32,6 +33,23 @@
packRatio,
packLevel,
createTime,
erpId,
updateTime
</sql>
<select id="selectDrugsByNameCodes" resultType="int">
SELECT count(1) FROM third_ali_drug WHERE nameCode = #{nameCode}
</select>
<!-- 自定义saveOrUpdateBatch方法 -->
<insert id="saveOrUpdateBatch" parameterType="com.glxp.api.entity.thrsys.ThirdAliDrug" >
INSERT INTO third_ali_drug (`type`, manufacturer, cpmctymc, form, formSpec, bzgg, spmc, nameCode, packRatio,
packLevel, createTime, updateTime,erpId)
VALUES
<foreach collection="list" item="item" separator="," index="index">
(#{item.type}, #{item.manufacturer}, #{item.cpmctymc}, #{item.form}, #{item.formSpec}, #{item.bzgg}, #{item.spmc}, #{item.nameCode},
#{item.packRatio}, #{item.packLevel}, #{item.createTime}, #{item.updateTime}, #{item.erpId})
</foreach>
</insert>
</mapper>
Loading…
Cancel
Save