feat: 药品关联信息上下传输功能

dev_unify
chenhc 6 months ago
parent 96c9a354ce
commit 4f1258572d

@ -1,5 +1,6 @@
package com.glxp.api.controller.collect;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageInfo;
import com.glxp.api.annotation.CusRedissonAnnotation;
import com.glxp.api.annotation.RepeatSubmit;
@ -12,6 +13,7 @@ import com.glxp.api.req.collect.RelCodeBatchRequest;
import com.glxp.api.req.collect.RelCodeDetailRequest;
import com.glxp.api.res.PageSimpleResponse;
import com.glxp.api.res.collect.RelCodeBatchResponse;
import com.glxp.api.res.collect.RelCodeDetailByParentCodeResponse;
import com.glxp.api.service.collect.RelCodeBatchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
@ -111,4 +113,26 @@ public class RelCodeBatchController extends BaseController {
return ResultVOUtils.success("清空成功");
}
/**
*
* @param parentCode
* @return
*/
@GetMapping("/udiwms/relCode/batch/exist")
public BaseResponse batchExist(@RequestParam("parentCode") String parentCode) {
if (StrUtil.isBlank(parentCode)) return ResultVOUtils.error(500,"层级编码格式错误!");
return ResultVOUtils.success(relCodeBatchService.batchExist(parentCode));
}
@GetMapping("/udiwms/relCode/detailByParentCode")
public BaseResponse detailByParentCode(@RequestParam("parentCode") String parentCode) {
if (StrUtil.isBlank(parentCode)) return ResultVOUtils.error(500,"层级编码格式错误!");
List<RelCodeDetailByParentCodeResponse> list = relCodeBatchService.detailByParentCodeSpms(parentCode,1);
return ResultVOUtils.success(list);
}
}

@ -444,6 +444,8 @@ public class SpsSyncDownloadController {
if (CollectionUtil.isNotEmpty(bean.getRelCodeBatches())) {
for (RelCodeBatch entity : bean.getRelCodeBatches()) {
entity.setUpdateTime(null);
entity.setUploadFlagDown(1);
entity.setUploadFlagUp(0);
}
boolean b = relCodeBatchMapper.replaceBatchs(bean.getRelCodeBatches());
}

@ -112,7 +112,19 @@ public class RelCodeBatch implements Serializable {
@ApiModelProperty(value = "")
private String updateUser;
@TableField(value = "uploadFlag")
@TableField(value = "uploadFlagUp")
@ApiModelProperty(value = "")
private Integer uploadFlag;
private Integer uploadFlagUp;
@TableField(value = "uploadFlagDown")
@ApiModelProperty(value = "")
private Integer uploadFlagDown;
/**
*
*/
@TableField(value = "parentCode")
@ApiModelProperty(value = "")
private String parentCode;
}

@ -1,6 +1,8 @@
package com.glxp.api.req.collect;
import com.baomidou.mybatisplus.annotation.TableField;
import com.glxp.api.util.page.ListPageRequest;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ -81,4 +83,13 @@ public class RelCodeBatchRequest extends ListPageRequest {
private String code;
private String startDate;
private String endDate;
/**
*
*/
@TableField(value = "parentCode")
@ApiModelProperty(value = "")
private String parentCode;
}

@ -0,0 +1,125 @@
package com.glxp.api.res.collect;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.glxp.api.entity.collect.RelCodeDetail;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class RelCodeDetailByParentCodeResponse {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value="")
private Integer id;
/**
*
*/
@TableField(value = "productCode")
@ApiModelProperty(value="产品编码")
private String productCode;
/**
*
*/
@TableField(value = "subTypeNo")
@ApiModelProperty(value="类型编码")
private String subTypeNo;
/**
*
*/
@TableField(value = "cascadeRatio")
@ApiModelProperty(value="包装比例")
private String cascadeRatio;
/**
*
*/
@TableField(value = "packageSpec")
@ApiModelProperty(value="包装规格")
private String packageSpec;
/**
*
*/
@TableField(value = "comment")
@ApiModelProperty(value="备注")
private String comment;
/**
*
*/
@TableField(value = "batchNo")
@ApiModelProperty(value="批次号")
private String batchNo;
/**
*
*/
@TableField(value = "madeDate")
@ApiModelProperty(value="生产日期")
private String madeDate;
/**
*
*/
@TableField(value = "validateDate")
@ApiModelProperty(value="有效期至")
private String validateDate;
/**
*
*/
@TableField(value = "workShop")
@ApiModelProperty(value="生产车间")
private String workShop;
/**
* 线
*/
@TableField(value = "lineName")
@ApiModelProperty(value="生产线")
private String lineName;
/**
*
*/
@TableField(value = "lineManager")
@ApiModelProperty(value="负责人")
private String lineManager;
@TableField(value = "createTime")
@ApiModelProperty(value = "")
private Date createTime;
@TableField(value = "`createUser`")
@ApiModelProperty(value = "")
private String createUser;
@TableField(value = "updateTime")
@ApiModelProperty(value = "")
private Date updateTime;
@TableField(value = "updateUser")
@ApiModelProperty(value = "")
private String updateUser;
/**
*
*/
@TableField(value = "parentCode")
@ApiModelProperty(value = "")
private String parentCode;
private List<RelCodeDetail> relCodeDetail;
private List<RelCodeDetailByParentCodeResponse> RelCodeDetailSons;
}

@ -13,17 +13,23 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.dao.basic.BasicProductsDao;
import com.glxp.api.dao.collect.RelCodeBatchMapper;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.BasicProductsEntity;
import com.glxp.api.entity.basic.ProductInfoEntity;
import com.glxp.api.entity.basic.UdiEntity;
import com.glxp.api.entity.collect.RelCodeBatch;
import com.glxp.api.entity.collect.RelCodeDetail;
import com.glxp.api.exception.JsonException;
import com.glxp.api.req.collect.RelCodeBatchRequest;
import com.glxp.api.req.collect.RelCodeDetailRequest;
import com.glxp.api.res.collect.RelCodeBatchResponse;
import com.glxp.api.res.collect.RelCodeDetailByParentCodeResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.service.basic.ProductInfoService;
import com.glxp.api.util.HttpClient;
import com.glxp.api.util.udi.FilterUdiUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
@ -48,6 +54,8 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
private RelCodeDetailService relCodeDetailService;
@Resource
private CustomerService customerService;
@Resource
private ProductInfoService productInfoService;
/**
*
@ -154,12 +162,14 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
throw new JsonException("关联明细不能为空!");
}
AuthAdmin user = customerService.getUserBean();
RelCodeDetailRequest relCodeDetailRequest = detailList.get(0);
RelCodeBatch relCodeBatch = new RelCodeBatch();
BeanUtils.copyProperties(relCodeBatchRequest,relCodeBatch);
relCodeBatch.setCreateTime(new Date());
relCodeBatch.setCreateUser(user.getUserName());
relCodeBatch.setUpdateTime(new Date());
relCodeBatch.setUpdateUser(user.getUserName());
relCodeBatch.setParentCode(relCodeDetailRequest.getParentCode());
this.save(relCodeBatch);
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
for(RelCodeDetailRequest request : detailList){
@ -240,10 +250,10 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
});
if (baseResponse.getCode() == 20000){
Integer id = relCodeBatchRequest.getId();
return this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlag,1).eq(RelCodeBatch::getId,id));
return this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlagUp,1).eq(RelCodeBatch::getId,id));
}else {
Integer id = relCodeBatchRequest.getId();
this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlag,3).eq(RelCodeBatch::getId,id));
this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlagUp,2).eq(RelCodeBatch::getId,id));
return false;
}
} catch (Exception e) {
@ -251,4 +261,155 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
return false;
}
}
/**
*
*/
public List<RelCodeDetailByParentCodeResponse> detailByParentCode(String parentCode) {
Map<String, Object> paramMap = new HashMap<>(2);
paramMap.put("parentCode", parentCode);
String response = HttpClient.mipsGet(udiUrl + "/udiwms/relCode/detailByParentCode", paramMap);
try {
BaseResponse<List<RelCodeDetailByParentCodeResponse>> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<List<RelCodeDetailByParentCodeResponse>>>() {
});
if (baseResponse.getCode() == 20000) {
List<RelCodeDetailByParentCodeResponse> list = baseResponse.getData();
return list;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* parentCode
*/
public boolean UpdateDetailByParentCode(String parentCode,Integer uploadFlagDown) {
List<RelCodeDetailByParentCodeResponse> list = this.detailByParentCode(parentCode);
if (CollUtil.isNotEmpty(list)) {
for (int i = 0; i < list.size(); i++) {
try {
RelCodeDetailByParentCodeResponse relCodeDetailByParentCodeResponse = list.get(i);
this.saveDetailByParentCode(relCodeDetailByParentCodeResponse,uploadFlagDown);
List<RelCodeDetailByParentCodeResponse> relCodeDetailSons = relCodeDetailByParentCodeResponse.getRelCodeDetailSons();
if (CollUtil.isNotEmpty(relCodeDetailSons)) {
this.saveDetailByParentCode(relCodeDetailByParentCodeResponse,uploadFlagDown);
}
}catch (Exception e){
log.error("拉取国家同步库进行更新失败:[" + parentCode + "]" );
log.error(e.getMessage(), e);
}
}
return true;
}else
return false;
}
public void saveDetailByParentCode( RelCodeDetailByParentCodeResponse relCodeDetailByParentCodeResponse,Integer uploadFlagDown) {
String productCode = relCodeDetailByParentCodeResponse.getProductCode();
String subTypeNo = relCodeDetailByParentCodeResponse.getSubTypeNo();
String batchNo = relCodeDetailByParentCodeResponse.getBatchNo();
String parentCode1 = relCodeDetailByParentCodeResponse.getParentCode();
//如果不存在就添加
List<RelCodeBatch> navList = this.list(new LambdaQueryWrapper<RelCodeBatch>()
.eq(RelCodeBatch::getProductCode, productCode)
.eq(StrUtil.isNotBlank(subTypeNo), RelCodeBatch::getSubTypeNo, subTypeNo)
.eq(RelCodeBatch::getBatchNo, batchNo)
.eq(RelCodeBatch::getParentCode, parentCode1));
if (CollUtil.isEmpty(navList)) {
RelCodeBatch relCodeBatch = new RelCodeBatch();
BeanUtils.copyProperties(relCodeDetailByParentCodeResponse, relCodeBatch);
relCodeBatch.setCreateTime(new Date());
relCodeBatch.setUpdateTime(new Date());
relCodeBatch.setUploadFlagUp(1);
relCodeBatch.setUploadFlagDown(uploadFlagDown);
this.save(relCodeBatch);
List<RelCodeDetail> detailList = relCodeDetailByParentCodeResponse.getRelCodeDetail();
List<RelCodeDetail> relCodeDetails = new ArrayList<>();
for (RelCodeDetail relCodeDetail : detailList) {
relCodeDetail.setBatchIdFk(relCodeBatch.getId());
relCodeDetails.add(relCodeDetail);
}
relCodeDetailService.saveBatch(relCodeDetails);
}
}
public boolean batchExist(String parentCode) {
//1、排除掉层级是1的
UdiEntity udi = FilterUdiUtils.getUdi(parentCode);
String udi1 = udi.getUdi();
ProductInfoEntity byNameCode = productInfoService.findByNameCode(udi1);
if (byNameCode != null && "1".equals(byNameCode.getPackLevel())) return true;
//2、本地查询
List<RelCodeBatch> navList = this.list(new LambdaQueryWrapper<RelCodeBatch>()
.eq(RelCodeBatch::getParentCode, parentCode));
if (CollUtil.isNotEmpty(navList)) return true;
//3、查不到进行远程拉取更新
return this.UpdateDetailByParentCode(parentCode,0);
}
public List<RelCodeDetailByParentCodeResponse> detailByParentCodeSpms(String parentCode,Integer uploadFlagDown) {
List<RelCodeDetailByParentCodeResponse> respList = new ArrayList<>();
List<RelCodeBatch> list = this.list(new LambdaQueryWrapper<RelCodeBatch>().eq(RelCodeBatch::getParentCode, parentCode));
if (CollUtil.isEmpty(list)){
respList = this.detailByParentCode(parentCode);
for (int i = 0; i < respList.size(); i++) {
try {
RelCodeDetailByParentCodeResponse relCodeDetailByParentCodeResponse = respList.get(i);
this.saveDetailByParentCode(relCodeDetailByParentCodeResponse,uploadFlagDown);
List<RelCodeDetailByParentCodeResponse> relCodeDetailSons = relCodeDetailByParentCodeResponse.getRelCodeDetailSons();
if (CollUtil.isNotEmpty(relCodeDetailSons)) {
relCodeDetailSons.forEach( item -> {
this.saveDetailByParentCode(item,uploadFlagDown);
});
}
}catch (Exception e){
log.error("拉取国家同步库进行更新失败:[" + parentCode + "]" );
log.error(e.getMessage(), e);
}
}
return respList;
}else {
for (int i = 0; i < list.size(); i++) {
RelCodeBatch relCodeBatch = list.get(i);
RelCodeDetailByParentCodeResponse relCodeDetailByParentCodeResponse = new RelCodeDetailByParentCodeResponse();
List<RelCodeDetail> relCodeDetails = relCodeDetailService.list(new LambdaQueryWrapper<RelCodeDetail>().eq(RelCodeDetail::getParentCode, parentCode));
BeanUtils.copyProperties(relCodeBatch,relCodeDetailByParentCodeResponse);
relCodeDetailByParentCodeResponse.setRelCodeDetail(relCodeDetails);
if (CollUtil.isNotEmpty(relCodeDetails)){
RelCodeDetail relCodeDetail = relCodeDetails.get(0);
if (relCodeDetail.getPackLayer() > 1){//说明有下级
List<RelCodeDetailByParentCodeResponse> sons = new ArrayList<>();
for (int i1 = 0; i1 < relCodeDetails.size(); i1++) {
RelCodeDetail relCodeDetail1 = relCodeDetails.get(i1);
List<RelCodeDetailByParentCodeResponse> relCodeDetailByParentCodeResponses = this.detailByParentCodeSpms(relCodeDetail1.getCurCode(),uploadFlagDown);
if (CollUtil.isNotEmpty(relCodeDetailByParentCodeResponses)){
sons.addAll(relCodeDetailByParentCodeResponses);
}
}
relCodeDetailByParentCodeResponse.setRelCodeDetailSons(sons);
}
}
respList.add(relCodeDetailByParentCodeResponse);
}
return respList;
}
}
}

@ -6,6 +6,7 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
@ -1339,11 +1340,9 @@ public class SpsSyncDownloadService {
SpsSyncDrugDataTaskResponse dataResponse = null;
List<RelCodeBatch> relCodeBatches = relCodeBatchService.list(Wrappers.lambdaQuery(RelCodeBatch.class)
.le(!ge && (boolean) map.get("isNew"), RelCodeBatch::getUpdateTime, now)
.between(ge, RelCodeBatch::getUpdateTime, syncTime, now)
.between(!ge && !(boolean) map.get("isNew"), RelCodeBatch::getUpdateTime
, map.get("oldDate"), now)
.in(RelCodeBatch::getUploadFlagDown,0,2)
);
if (CollectionUtil.isNotEmpty(relCodeBatches)) {
dataResponse = new SpsSyncDrugDataTaskResponse();
dataResponse.setRelCodeBatches(relCodeBatches);
@ -1356,6 +1355,7 @@ public class SpsSyncDownloadService {
jsonMap.put(SpsSyncDrugDataTaskResponse.class.getSimpleName(), dataResponse);
remark.append("药品关联信息任务:").append(relCodeBatches.size()).append("条\n");
boolean update = relCodeBatchService.update(new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlagDown, 1).in(RelCodeBatch::getId, batchIds));
}
}

@ -59,7 +59,7 @@ public class UploadDrugDataTask implements SchedulingConfigurer {
private void process() {
logger.info("uploadDrugData----process------------");
//查找扫描
List<RelCodeBatch> list = relCodeBatchService.list(new LambdaUpdateWrapper<RelCodeBatch>().in(RelCodeBatch::getUploadFlag, 0, 2));
List<RelCodeBatch> list = relCodeBatchService.list(new LambdaUpdateWrapper<RelCodeBatch>().in(RelCodeBatch::getUploadFlagUp, 0, 2));
if (CollUtil.isNotEmpty(list)){
for (int i = 0; i < list.size(); i++) {
RelCodeBatch relCodeBatch = list.get(i);

Loading…
Cancel
Save