ConsumMfcubestService.java 3.88 KB
package cn.csbr.app.service;

import cn.csbr.app.exception.ApiException;
import cn.csbr.springboot.dao.mapper.MfcubestockdetailMapper;
import cn.csbr.springboot.dao.mapper.MfcubestockdetailOldMapper;
import cn.csbr.springboot.dao.mapper.TrchargingMapper;
import cn.csbr.springboot.dao.mapper.TrchargingdetailMapper;
import cn.csbr.springboot.dao.model.Mfcubestockdetail;
import cn.csbr.springboot.dao.model.MfcubestockdetailOld;
import cn.csbr.springboot.dao.model.Trcharging;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Log4j2
public class ConsumMfcubestService {
    @Autowired
    private TrchargingMapper trchargingMapper;
    @Autowired
    private TrchargingdetailMapper trchargingdetailMapper;
    @Autowired
    private MfcubestockdetailMapper mfcubestockdetailMapper;
    @Autowired
    private MfcubestockdetailOldMapper mfcubestockdetailOldMapper;
    public String show(Map map){

        System.out.println(map.get("barcode"));
        return "aaa";
    }
    //反消耗
    @Transactional(rollbackFor = {ApiException.class, Exception.class})
    public String getConSum(Map map) throws Exception {
//        if (map=) {
//            throw new ApiException("消耗单传入数据为空");
//        }
//
//        log.info("===>拉取解析后的反消耗数据");
        // List<ConsumMfcubest> conSum = ConsumXmlToList.getConSum(xml);
        //for (int i = 0; i < conSum.size(); i++) {
        //ConsumMfcubest mfcubest = conSum.get(i);
        Trcharging trcharging = trchargingMapper.getTrcharging(map.get("operationNo").toString());//根据手术单号查询手术单是否存在
        if (trcharging == null) {
            log.info("没有该手术单" + map.get("operationNo").toString() + ",无法进行反消耗");
            throw new ApiException("没有该手术单" + map.get("operationNo").toString() + ",无法进行反消耗");
        }
        //进行手术单删除
        int count = trchargingdetailMapper.delTrchargingDetail(trcharging.getGuid());
        if (count > 0) {
            //删除手术单头表
            trchargingMapper.delTrcharging(map.get("operationNo").toString());
            log.info("手术单清除成功=>" + map.get("operationNo").toString());
        }
        //List<ConsumDetail> consumDetailList = mfcubest.getConsumDetailList();
        // for (int j = 0; j < consumDetailList.size(); j++) {
        // ConsumDetail consumDetail = consumDetailList.get(j);
        MfcubestockdetailOld mfcubestockdetailOld = mfcubestockdetailOldMapper.searchDetailByBarcode(map.get("barcode").toString());
        if (mfcubestockdetailOld == null) {
            log.info("该耗材" + map.get("barcode").toString() + "没有消耗记录");
            throw new ApiException("该耗材" + map.get("barcode").toString() + "没有消耗记录");
        }
        Mfcubestockdetail mfcubestockdetail = mfcubestockdetailMapper.searchDetailByBarcode(map.get("barcode").toString());
        if (mfcubestockdetail != null) {
            log.info("该耗材" + map.get("barcode").toString() + "还在柜中没有被消耗");
            throw new ApiException("该耗材" + map.get("barcode").toString() + "还在柜中没有被消耗");
        }
        Mfcubestockdetail mfcubestockdetail1 = new Mfcubestockdetail();
        BeanUtils.copyProperties(mfcubestockdetailOld, mfcubestockdetail1);
        System.out.println(mfcubestockdetail1.toString());
        int insert = mfcubestockdetailMapper.insert(mfcubestockdetail1);
        if (insert > 0) {
            //开始删除库存历史
            mfcubestockdetailOldMapper.mfcubestockdetaildel(map.get("barcode").toString());
            log.info("反消耗成功");
        }

        return "ok";
    }
}