package com.glxp.mipsdl.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.glxp.mipsdl.annotation.AuthRuleAnnotation; import com.glxp.mipsdl.entity.drugcabinet.A001; import com.glxp.mipsdl.entity.drugcabinet.A002; import com.glxp.mipsdl.entity.drugcabinet.A002Mx; import com.glxp.mipsdl.entity.drugcabinet.B003; import com.glxp.mipsdl.req.drugCabinet.*; import com.glxp.mipsdl.res.BaseResponse; import com.glxp.mipsdl.res.drugCabinet.A002Response; import com.glxp.mipsdl.thirddao.drugcabinet.A001Mapper; import com.glxp.mipsdl.thirddao.drugcabinet.A002Mapper; import com.glxp.mipsdl.thirddao.drugcabinet.A002MxMapper; import com.glxp.mipsdl.thirddao.drugcabinet.B003Mapper; import com.glxp.mipsdl.util.ResultVOUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.*; /** * 药柜控制层 */ @RestController @Slf4j public class DrugCabinetController { @Resource private A001Mapper a001Mapper; @Resource private A002Mapper a002Mapper; @Resource private B003Mapper b003Mapper; @Resource private A002MxMapper a002MxMapper; @Value("${DRUG_MACHINE_URL:http://127.0.0.1:9997}") private String drugMachineUrl; @PostMapping("/udiwms/drug/filter/view") @AuthRuleAnnotation("") public BaseResponse drugFilterView(@RequestBody DrugMachineA001Request drugMachineA001Request) { if (StrUtil.isEmpty(drugMachineA001Request.getCode()) && StrUtil.isEmpty(drugMachineA001Request.getName()) && StrUtil.isEmpty(drugMachineA001Request.getNameCode())&& StrUtil.isEmpty(drugMachineA001Request.getYbbm())&& StrUtil.isEmpty(drugMachineA001Request.getManufactory()) ) { return ResultVOUtils.error(500,"查询参数不能为空"); } List list = a001Mapper.selectList( new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(drugMachineA001Request.getCode()),A001::getCode, drugMachineA001Request.getCode()) .like(StringUtils.isNotEmpty(drugMachineA001Request.getName()),A001::getName, drugMachineA001Request.getName()) .eq(StringUtils.isNotEmpty(drugMachineA001Request.getNameCode()),A001::getNameCode, drugMachineA001Request.getNameCode()) .eq(StringUtils.isNotEmpty(drugMachineA001Request.getYbbm()),A001::getYbbm, drugMachineA001Request.getYbbm()) .like(StringUtils.isNotEmpty(drugMachineA001Request.getManufactory()),A001::getManufactory, drugMachineA001Request.getManufactory() )); return ResultVOUtils.success(list); } @PostMapping("/udiwms/drug/filter/interface") @AuthRuleAnnotation("") public BaseResponse drugFilterInterface(@RequestBody DrugMachineA001Request drugMachineA001Request) { if (StrUtil.isEmpty(drugMachineA001Request.getCode()) && StrUtil.isEmpty(drugMachineA001Request.getName()) && StrUtil.isEmpty(drugMachineA001Request.getNameCode())&& StrUtil.isEmpty(drugMachineA001Request.getYbbm())&& StrUtil.isEmpty(drugMachineA001Request.getManufactory()) ) { return ResultVOUtils.error(500,"查询参数不能为空"); } Map headersMap = new HashMap(); headersMap.put("api_key","1101"); headersMap.put("secret_key","zBITspLNvuoEd4FaamlSoqxRHmNsmQ6L"); HttpRequest request = HttpRequest.post(drugMachineUrl+"/udiwms/drug/filter/view") .addHeaders(headersMap) .body(JSONUtil.toJsonStr(drugMachineA001Request)); String body = request.execute().body(); BaseResponse> listBaseResponse = JSONObject.parseObject(body, new TypeReference>>() { }); return listBaseResponse; } @PostMapping("/udiwms/order/filter/view") @AuthRuleAnnotation("") public BaseResponse orderFilterView(@RequestBody OrderMachineA002Request orderMachineA002Request) { if (StrUtil.isEmpty(orderMachineA002Request.getCode()) && StrUtil.isEmpty(orderMachineA002Request.getSickName()) && StrUtil.isEmpty(orderMachineA002Request.getSickCode()) && StrUtil.isEmpty(orderMachineA002Request.getPrescribeStartDate())&& StrUtil.isEmpty(orderMachineA002Request.getPrescribeEndDate()) ) { return ResultVOUtils.error(500,"查询参数不能为空"); } List list = a002Mapper.selectList( new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(orderMachineA002Request.getCode()),A002::getCode, orderMachineA002Request.getCode()) .eq(StringUtils.isNotEmpty(orderMachineA002Request.getSickCode()),A002::getCode, orderMachineA002Request.getSickCode()) .like(StringUtils.isNotEmpty(orderMachineA002Request.getSickName()),A002::getSickname, orderMachineA002Request.getSickName()) .between((StringUtils.isNotEmpty(orderMachineA002Request.getPrescribeStartDate()) && StringUtils.isNotEmpty(orderMachineA002Request.getPrescribeStartDate())), A002::getPrescribedate, orderMachineA002Request.getPrescribeStartDate(),orderMachineA002Request.getPrescribeEndDate()) ); List a002ResponseList = new ArrayList<>(); if(CollUtil.isNotEmpty(list)){ for (A002 a002 : list) { A002Response a002Response = new A002Response(); BeanUtils.copyProperties(a002,a002Response); List a002MxList = a002MxMapper.selectList( new LambdaQueryWrapper() .eq(StringUtils.isNotEmpty(orderMachineA002Request.getCode()),A002Mx::getCodefk, a002.getCode()) ); a002Response.setList(a002MxList); a002ResponseList.add(a002Response); } } return ResultVOUtils.success(a002ResponseList); } @PostMapping("/udiwms/order/filter/interface") @AuthRuleAnnotation("") public BaseResponse orderFilterInterface(@RequestBody OrderMachineA002Request orderMachineA002Request) { if (StrUtil.isEmpty(orderMachineA002Request.getCode()) && StrUtil.isEmpty(orderMachineA002Request.getSickName()) && StrUtil.isEmpty(orderMachineA002Request.getPrescribeStartDate())&& StrUtil.isEmpty(orderMachineA002Request.getPrescribeEndDate()) ) { return ResultVOUtils.error(500,"查询参数不能为空"); } Map headersMap = new HashMap(); headersMap.put("api_key","1101"); headersMap.put("secret_key","zBITspLNvuoEd4FaamlSoqxRHmNsmQ6L"); HttpRequest request = HttpRequest.post(drugMachineUrl+"/udiwms/order/filter/view") .addHeaders(headersMap) .body(JSONUtil.toJsonStr(orderMachineA002Request)); String body = request.execute().body(); BaseResponse> listBaseResponse = JSONObject.parseObject(body, new TypeReference>>() { }); return listBaseResponse; } @PostMapping("/udiwms/order/tagging") @AuthRuleAnnotation("") public BaseResponse orderCode(@RequestBody OrderMachineB003Request orderMachineB003Request) { if(StringUtils.isEmpty(orderMachineB003Request.getBillNo())){ return ResultVOUtils.error(500,"处方单号不能为空"); } if(StringUtils.isEmpty(orderMachineB003Request.getBillDate())){ return ResultVOUtils.error(500,"赋码日期不能为空"); } if(Objects.isNull(orderMachineB003Request.getProductsList())){ return ResultVOUtils.error(500,"处方产品明细不能为空"); } Map headersMap = new HashMap(); headersMap.put("api_key","1101"); headersMap.put("secret_key","zBITspLNvuoEd4FaamlSoqxRHmNsmQ6L"); HttpRequest request = HttpRequest.post(drugMachineUrl+"/udiwms/order/code/add") .addHeaders(headersMap) .body(JSONUtil.toJsonStr(orderMachineB003Request)); String body = request.execute().body(); BaseResponse listBaseResponse = JSONObject.parseObject(body, new TypeReference>() { }); return listBaseResponse; } @PostMapping("/udiwms/order/code/add") @AuthRuleAnnotation("") public BaseResponse orderCodeAdd(@RequestBody OrderMachineB003Request orderMachineB003Request) { for (OrderMachineB003ProductsRequest orderMachineB003ProductsRequest : orderMachineB003Request.getProductsList()) { if(CollUtil.isNotEmpty(orderMachineB003ProductsRequest.getCodeList())){ for (OrderMachineB003CodeRequest orderMachineB003CodeRequest : orderMachineB003ProductsRequest.getCodeList()) { B003 b003 = new B003(); BeanUtils.copyProperties(orderMachineB003CodeRequest,b003); b003.setBillno(orderMachineB003Request.getBillNo()); b003.setBilldate(orderMachineB003Request.getBillDate()); b003.setRemark(orderMachineB003Request.getRemark()); b003.setItemcode(orderMachineB003ProductsRequest.getItemCode()); b003Mapper.insert(b003); } } } return ResultVOUtils.success("新增成功"); } }