|
|
|
|
package com.glxp.api.service.collect;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.glxp.api.dao.collect.IoCollectOrderMapper;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicCollectBustypeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicSkPrescribeEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.BasicSkPrescribeItemEntity;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrder;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderBiz;
|
|
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderCodeMan;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderDetailBizEntity;
|
|
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
|
|
import com.glxp.api.req.collect.CollectOrderRequest;
|
|
|
|
|
import com.glxp.api.req.inout.DeleteTageCodeRequest;
|
|
|
|
|
import com.glxp.api.req.inout.FilterOrderRequest;
|
|
|
|
|
import com.glxp.api.res.basic.UdiRelevanceResponse;
|
|
|
|
|
import com.glxp.api.res.collect.IoCollectOrderResponse;
|
|
|
|
|
import com.glxp.api.res.inout.IoOrderResponse;
|
|
|
|
|
import com.glxp.api.service.basic.BasicCollectBustypeService;
|
|
|
|
|
import com.glxp.api.service.basic.BasicSkPrescirbeDetailService;
|
|
|
|
|
import com.glxp.api.service.basic.BasicSkPrescribeService;
|
|
|
|
|
import com.glxp.api.service.basic.UdiRelevanceService;
|
|
|
|
|
import com.glxp.api.service.inout.IoOrderDetailBizService;
|
|
|
|
|
import com.glxp.api.service.inout.IoOrderService;
|
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
|
import com.glxp.api.util.MsDateUtil;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class IoCollectOrderService extends ServiceImpl<IoCollectOrderMapper, IoCollectOrder> {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderMapper collectOrderMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderCodeManService ioCollectOrderCodeManService;
|
|
|
|
|
|
|
|
|
|
public IoCollectOrder getByBillNo(String billNo) {
|
|
|
|
|
return collectOrderMapper.selectOne(new LambdaQueryWrapper<IoCollectOrder>().eq(IoCollectOrder::getBillNo, billNo).last("limit 1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<IoCollectOrderResponse> filterList(CollectOrderRequest collectOrderRequest) {
|
|
|
|
|
if (collectOrderRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
if (collectOrderRequest.getPage() != null) {
|
|
|
|
|
int offset = (collectOrderRequest.getPage() - 1) * collectOrderRequest.getLimit();
|
|
|
|
|
PageHelper.offsetPage(offset, collectOrderRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
List<IoCollectOrderResponse> data = collectOrderMapper.filterList(collectOrderRequest);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderService orderService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderDetailBizService orderDetailBizService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicCollectBustypeService collectBustypeService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCollectOrderBizService collectOrderBizService;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiRelevanceService udiRelevanceService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicSkPrescribeService basicSkPrescribeService;
|
|
|
|
|
@Resource
|
|
|
|
|
BasicSkPrescirbeDetailService basicSkPrescirbeDetailService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入内部数据
|
|
|
|
|
*/
|
|
|
|
|
public void importOrder() {
|
|
|
|
|
importUdi();
|
|
|
|
|
importPrescribe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clearOrder() {
|
|
|
|
|
collectOrderMapper.clearOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void importUdi() {
|
|
|
|
|
//下载UDI内部单据
|
|
|
|
|
FilterOrderRequest filterOrderRequest = new FilterOrderRequest();
|
|
|
|
|
filterOrderRequest.setPage(1);
|
|
|
|
|
filterOrderRequest.setLimit(1000);
|
|
|
|
|
filterOrderRequest.setStatus(7);
|
|
|
|
|
filterOrderRequest.setProductType(null);
|
|
|
|
|
List<IoOrderResponse> list = orderService.filterList(filterOrderRequest);
|
|
|
|
|
List<IoCollectOrder> collectOrderList = new ArrayList<>();
|
|
|
|
|
for (IoOrderResponse ioOrderEntity : list) {
|
|
|
|
|
BasicCollectBustypeEntity collectBustypeEntity = collectBustypeService.findByAddr(ioOrderEntity.getAction());
|
|
|
|
|
if (collectBustypeEntity == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (collectOrderMapper.exists(new LambdaQueryWrapper<IoCollectOrder>().eq(IoCollectOrder::getBillNo, ioOrderEntity.getBillNo()))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
IoCollectOrder collectOrder = IoCollectOrder.builder()
|
|
|
|
|
.billNo(ioOrderEntity.getBillNo())
|
|
|
|
|
.busType(collectBustypeEntity.getCode())
|
|
|
|
|
.fromType(collectBustypeEntity.getFromType())
|
|
|
|
|
.fromCorp(ioOrderEntity.getFromName())
|
|
|
|
|
.billTime(ioOrderEntity.getCreateTime())
|
|
|
|
|
.createTime(ioOrderEntity.getCreateTime())
|
|
|
|
|
.createUser(ioOrderEntity.getCreateUser())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.splitStatus(0)
|
|
|
|
|
.tagStatus(0)
|
|
|
|
|
.build();
|
|
|
|
|
collectOrderList.add(collectOrder);
|
|
|
|
|
List<IoOrderDetailBizEntity> orderDetailBizEntities = orderDetailBizService.findByOrderId(ioOrderEntity.getBillNo());
|
|
|
|
|
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = new ArrayList<>();
|
|
|
|
|
for (IoOrderDetailBizEntity bizEntity : orderDetailBizEntities) {
|
|
|
|
|
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByRelId(bizEntity.getBindRlFk() + "");
|
|
|
|
|
IoCollectOrderBiz collectOrderBiz = IoCollectOrderBiz.builder().orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.relId(bizEntity.getBindRlFk())
|
|
|
|
|
.thrCode(udiRelevanceResponse.getMainId())
|
|
|
|
|
.ybbm(udiRelevanceResponse.getYbbm())
|
|
|
|
|
.payFeeCode(udiRelevanceResponse.getPayFeeCode())
|
|
|
|
|
.cpmctymc(bizEntity.getCoName())
|
|
|
|
|
.nameCode(bizEntity.getNameCode())
|
|
|
|
|
.ggxh(bizEntity.getSpec())
|
|
|
|
|
.batchNo(bizEntity.getBatchNo())
|
|
|
|
|
.productDate(bizEntity.getProductDate())
|
|
|
|
|
.expireDate(bizEntity.getExpireDate())
|
|
|
|
|
.count(bizEntity.getCount())
|
|
|
|
|
.measureUnit(bizEntity.getMeasname())
|
|
|
|
|
.tagStatus(1)
|
|
|
|
|
.unTagCount(bizEntity.getCount()).build();
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(udiRelevanceResponse.getProductsType()) == 2) {
|
|
|
|
|
collectOrderBiz.setGgxh(udiRelevanceResponse.getBzgg());
|
|
|
|
|
collectOrderBiz.setMeasureUnit(udiRelevanceResponse.getPrepnUnit());
|
|
|
|
|
}
|
|
|
|
|
collectOrderBizs.add(collectOrderBiz);
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(collectOrderBizs))
|
|
|
|
|
collectOrderBizService.saveBatch(collectOrderBizs);
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(collectOrderList)) {
|
|
|
|
|
saveBatch(collectOrderList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void importPrescribe() {
|
|
|
|
|
//下载处方
|
|
|
|
|
List<BasicSkPrescribeEntity> basicSkPrescribeEntities = basicSkPrescribeService.list();
|
|
|
|
|
|
|
|
|
|
List<IoCollectOrder> collectOrderList = new ArrayList<>();
|
|
|
|
|
for (BasicSkPrescribeEntity basicSkPrescribeEntity : basicSkPrescribeEntities) {
|
|
|
|
|
BasicCollectBustypeEntity collectBustypeEntity = collectBustypeService.findByAddr(String.valueOf(basicSkPrescribeEntity.getAddr()));
|
|
|
|
|
if (collectBustypeEntity == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (collectOrderMapper.exists(new LambdaQueryWrapper<IoCollectOrder>().eq(IoCollectOrder::getBillNo, basicSkPrescribeEntity.getCode()))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
IoCollectOrder collectOrder = IoCollectOrder.builder()
|
|
|
|
|
.billNo(basicSkPrescribeEntity.getCode())
|
|
|
|
|
.busType(collectBustypeEntity.getCode())
|
|
|
|
|
.fromType(collectBustypeEntity.getFromType())
|
|
|
|
|
.fromCorp(basicSkPrescribeEntity.getSickerCode())
|
|
|
|
|
.billTime(MsDateUtil.localToDate(basicSkPrescribeEntity.getCreateTime()))
|
|
|
|
|
.createTime(new Date())
|
|
|
|
|
.createUser(basicSkPrescribeEntity.getCreateUser())
|
|
|
|
|
.updateTime(new Date())
|
|
|
|
|
.splitStatus(0)
|
|
|
|
|
.tagStatus(0)
|
|
|
|
|
.build();
|
|
|
|
|
collectOrderList.add(collectOrder);
|
|
|
|
|
List<BasicSkPrescribeItemEntity> basicSkPrescribeItemEntities = basicSkPrescirbeDetailService.findByPrescribeNum(basicSkPrescribeEntity.getCode());
|
|
|
|
|
|
|
|
|
|
List<IoCollectOrderBiz> collectOrderBizs = new ArrayList<>();
|
|
|
|
|
for (BasicSkPrescribeItemEntity bizEntity : basicSkPrescribeItemEntities) {
|
|
|
|
|
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByRelId(bizEntity.getRelId() + "");
|
|
|
|
|
IoCollectOrderBiz collectOrderBiz = IoCollectOrderBiz.builder().orderIdFk(collectOrder.getBillNo())
|
|
|
|
|
.relId(bizEntity.getRelId())
|
|
|
|
|
.thrCode(bizEntity.getItemCode())
|
|
|
|
|
.ybbm(udiRelevanceResponse.getYbbm())
|
|
|
|
|
.payFeeCode(udiRelevanceResponse.getPayFeeCode())
|
|
|
|
|
.cpmctymc(bizEntity.getItemName())
|
|
|
|
|
.nameCode(udiRelevanceResponse.getNameCode())
|
|
|
|
|
.ggxh(bizEntity.getGgxh())
|
|
|
|
|
.batchNo(bizEntity.getBatchNo())
|
|
|
|
|
.count(IntUtil.value(bizEntity.getMeasureCount()))
|
|
|
|
|
.measureUnit(bizEntity.getMeasureUnit())
|
|
|
|
|
.tagStatus(1)
|
|
|
|
|
.unTagCount(bizEntity.getCount()).build();
|
|
|
|
|
|
|
|
|
|
// if (IntUtil.value(udiRelevanceResponse.getProductsType()) == 2) {
|
|
|
|
|
// collectOrderBiz.setGgxh(udiRelevanceResponse.getBzgg());
|
|
|
|
|
// collectOrderBiz.setMeasureUnit(udiRelevanceResponse.getPrepnUnit());
|
|
|
|
|
// }
|
|
|
|
|
collectOrderBizs.add(collectOrderBiz);
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(collectOrderBizs))
|
|
|
|
|
collectOrderBizService.saveBatch(collectOrderBizs);
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isNotEmpty(collectOrderList)) {
|
|
|
|
|
saveBatch(collectOrderList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void removeCode(DeleteTageCodeRequest deleteTageCodeRequest) {
|
|
|
|
|
Integer delType = deleteTageCodeRequest.getDelType();
|
|
|
|
|
Long codeManId = deleteTageCodeRequest.getCodeManId();
|
|
|
|
|
IoCollectOrderCodeMan ioCollectOrderCodeMan = ioCollectOrderCodeManService.getById(codeManId);
|
|
|
|
|
if (ioCollectOrderCodeMan == null) throw new JsonException("码明细id有误");
|
|
|
|
|
String bizIdFk = ioCollectOrderCodeMan.getBizIdFk();
|
|
|
|
|
Integer scanCount = ioCollectOrderCodeMan.getScanCount();
|
|
|
|
|
Integer delCount = 0;
|
|
|
|
|
if (delType == 1){//1.减一,,,IoCollectOrderCodeMan-1 IoCollectOrderBiz-1
|
|
|
|
|
Integer newCount = scanCount - 1;
|
|
|
|
|
delCount = 1;
|
|
|
|
|
if (newCount == 0){
|
|
|
|
|
ioCollectOrderCodeManService.removeById(codeManId);
|
|
|
|
|
}else {
|
|
|
|
|
ioCollectOrderCodeMan.setScanCount(newCount);
|
|
|
|
|
ioCollectOrderCodeManService.updateById(ioCollectOrderCodeMan);
|
|
|
|
|
}
|
|
|
|
|
}else if (delType == 2){//2.删除 IoCollectOrderCodeMan-删除 IoCollectOrderBiz-数量
|
|
|
|
|
delCount = scanCount;
|
|
|
|
|
ioCollectOrderCodeManService.removeById(codeManId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (delCount >0){
|
|
|
|
|
IoCollectOrderBiz bizServiceOne = collectOrderBizService.getOne(new LambdaQueryWrapper<IoCollectOrderBiz>()
|
|
|
|
|
.eq(IoCollectOrderBiz::getId, bizIdFk));
|
|
|
|
|
if (bizServiceOne == null) throw new JsonException("扫码详情未查找到");
|
|
|
|
|
Integer count = bizServiceOne.getCount();
|
|
|
|
|
Integer newCount = count - delCount;
|
|
|
|
|
if (newCount > 0){
|
|
|
|
|
bizServiceOne.setCount(newCount);
|
|
|
|
|
collectOrderBizService.updateById(bizServiceOne);
|
|
|
|
|
}else {
|
|
|
|
|
collectOrderBizService.removeById(bizServiceOne.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|