wangzhinan 3 anni fa
parent
commit
602ee63e5a

+ 46 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineOrderService.java

@ -1168,6 +1168,52 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        return false;
    }
    /**
     * 根据处方号获取处方状态
     * @param realOrder
     * @return
     */
    public String getDataStatus(String realOrder){
        OauthWlyyConfigDO oauthWlyyConfigDO = oauthWlyyConfigDao.findOne("getDataStatus");
        //token获取accesstoken
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("appid", oauthWlyyConfigDO.getAppId()));
        params.add(new BasicNameValuePair("appSecret",oauthWlyyConfigDO.getAppSecret()));
        String res = httpClientUtil.post(oauthWlyyConfigDO.getTokenUrl(),params,"UTF-8");
        String token = null;
        JSONObject rsjson = JSONObject.parseObject(res);
        logger.info("checkWlyyDoctor token :"+rsjson.toString());
        Integer status = rsjson.getInteger("status");
        if(status==10000){
            //设置入参
            List<NameValuePair> p = new ArrayList<>();
            p.add(new BasicNameValuePair("jwCode", realOrder));
            //设置头部
            token = rsjson.getJSONObject("result").getString("accesstoken");
            Map<String,Object> headerMap = new HashedMap();
            headerMap.put("accesstoken",token);
            String rs = httpClientUtil.headerPost(oauthWlyyConfigDO.getUrl(),p,"UTF-8",headerMap);
            WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO();
            wlyyHttpLogDO.setCode("getDataStatus");
            wlyyHttpLogDO.setRequest(p.toString());
            wlyyHttpLogDO.setResponse(rs);
            wlyyHttpLogDO.setName("根据处方号获取i健康处方状态");
            wlyyHttpLogDO.setStatus("1");
            wlyyHttpLogDO.setCreateTime(new Date());
            httpLogDao.save(wlyyHttpLogDO);
            logger.info("getDataStatus:"+rs);
            return rs;
        }else {
            return null;
        }
    }
    /**
     *

+ 7 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockOutService.java

@ -138,6 +138,7 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
        mediicinestockout = outDao.save(mediicinestockout);
        List<Mediicinestockupdetail> mediicinestockupdetailList = mediicinestockupdetailDao.getoutdetail(obj.getUpId());
        Double price = 0.0;
        List<Mediicinestockoutdetail> mediicinestockoutdetails = new ArrayList<>();
        for (DrugDO drug : obj.getDrugs()) {
            Mediicinedrugs mediicinedrugs = drugsDao.findOne(drug.getDrugId());
            Mediicinestockoutdetail mediicinestockoutdetail = new Mediicinestockoutdetail();
@ -148,7 +149,8 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
            mediicinestockoutdetail.setOrgCode(mediicinedrugs.getOrgCode());
            mediicinestockoutdetail.setQuantity(drug.getQty().toString());
            mediicinestockoutdetail.setProductPic(mediicinedrugs.getPic());
            outdetailDao.save(mediicinestockoutdetail);
            mediicinestockoutdetail = outdetailDao.save(mediicinestockoutdetail);
            mediicinestockoutdetails.add(mediicinestockoutdetail);
            for (Mediicinestockupdetail mediicinestockupdetail:mediicinestockupdetailList){
                if (mediicinedrugs.getDrugCode().equalsIgnoreCase(mediicinestockupdetail.getDrugCode())){
                    mediicinestockupdetail.setWareHouses(drug.getQty().toString());
@ -160,7 +162,10 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
        DecimalFormat df = new DecimalFormat("#0.00");
        mediicinestockout.setPrice(df.format(price));
        outDao.save(mediicinestockout);
        result.put("response",ConstantUtils.SUCCESS);
        JSONObject object = new JSONObject();
        object.put("list",mediicinestockoutdetails);
        object.put("out",mediicinestockout);
        result.put("response",object);
        result.put("msg",ConstantUtils.SUCCESS);
        return result;
    }

+ 262 - 107
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -2533,6 +2533,20 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    stringObjectMap.put("cardStatusName", "未知");
                }
            }
            String daibuSql = "";
            int daibuNumber;
            //待补商品数量
            daibuSql = "SELECT\n" +
                    "\tsum(\n" +
                    "\t\tt.cargo_capacity - cast(t.qty AS UNSIGNED)\n" +
                    "\t)\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory t\n" +
                    "WHERE\n" +
                    "\tt.id_device = '"+stringObjectMap.get("id").toString()+"'\n" +
                    "AND (t.state = '1' OR t.state = '21')";
            daibuNumber = jdbcTemplate.queryForObject(daibuSql, Integer.class);
            stringObjectMap.put("daibushangpinshuliang", daibuNumber);
            String tempSql = "SELECT\n" +
                    "\tifnull(sum(t.qty), 0) AS qty\n" +
                    "FROM\n" +
@ -4315,49 +4329,152 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     */
    @Transactional(rollbackFor = Exception.class)
    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception {
        MediicinecabinetInventory inventory =  inventoryDao.findOne(id);
        //更新设备缺货状态的该药品的已变动数量
        InventoryDO inventoryDO = new InventoryDO();
        inventoryDO.setDrugCode(inventory.getDrugCode());
        inventoryDO.setOrgCode(inventory.getOrgCode());
        inventoryDO.setRatedInventory(inventory.getRatedInventory());
        boolean cargoCapacityChanged = false;
        //库存变动
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
            if (Integer.parseInt(qty) > 99) {
                throw new Exception("库存数量最多99个,请重新设置");
            }
            //有药品时的补货
            MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
            inventoryRecord.setDeviceId(inventory.getIdDevice());
            inventoryRecord.setEquNum(inventory.getEquNum());
            inventoryRecord.setOldDrugId(inventory.getDrugId());
            inventoryRecord.setDrugId(inventory.getDrugId());
            inventoryRecord.setLayerNo(inventory.getLayerNo());
            inventoryRecord.setWayerNo(inventory.getWayerNo());
            inventoryRecord.setMergeState(inventory.getState());
            inventoryRecord.setMergeCargo(inventory.getMerge());
            inventoryRecord.setOldQuantity(inventory.getQty());
            inventoryRecord.setQuantity(qty);
            inventoryRecord.setCreateUser(userId);
            inventoryRecord.setType("1");
            inventoryRecordDao.save(inventoryRecord);
            //提升容量至库存数(修改的库存数大于容量时)
            if (Integer.parseInt(qty) > Integer.parseInt(inventory.getCargoCapacity())) {
                cargoCapacityChanged = true;
                inventory.setCargoCapacity(qty);
            }
            inventory.setQty(qty);
            //库存变更已变更的数量
            inventoryDO.setQty(Integer.parseInt(qty));
            //设置额定库存
            inventory.setRatedInventory(Integer.parseInt(qty));
        }
        //更改货道容量-start
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){
            inventoryDO.setQty(Integer.parseInt(inventory.getQty()));
            //2022-01-05-bug:13617-start
            if (Integer.parseInt(inventory.getQty()) > Integer.parseInt(cargoCapacity)) {
        if (id.contains(",")){
            String str[] = id.split(",");
            MediicinecabinetInventory mediicinecabinetInventory = new MediicinecabinetInventory();
            for (int i=0;i<str.length;i++){
                MediicinecabinetInventory inventory =  inventoryDao.findOne(str[i]);
                //更新设备缺货状态的该药品的已变动数量
                InventoryDO inventoryDO = new InventoryDO();
                inventoryDO.setDrugCode(inventory.getDrugCode());
                inventoryDO.setOrgCode(inventory.getOrgCode());
                inventoryDO.setRatedInventory(inventory.getRatedInventory());
                boolean cargoCapacityChanged = false;
                //库存变动
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
                    if (Integer.parseInt(qty) > 99) {
                        throw new Exception("库存数量最多99个,请重新设置");
                    }
                    //有药品时的补货
                    MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                    inventoryRecord.setDeviceId(inventory.getIdDevice());
                    inventoryRecord.setEquNum(inventory.getEquNum());
                    inventoryRecord.setOldDrugId(inventory.getDrugId());
                    inventoryRecord.setDrugId(inventory.getDrugId());
                    inventoryRecord.setLayerNo(inventory.getLayerNo());
                    inventoryRecord.setWayerNo(inventory.getWayerNo());
                    inventoryRecord.setMergeState(inventory.getState());
                    inventoryRecord.setMergeCargo(inventory.getMerge());
                    inventoryRecord.setOldQuantity(inventory.getQty());
                    inventoryRecord.setQuantity(qty);
                    inventoryRecord.setCreateUser(userId);
                    inventoryRecord.setType("1");
                    inventoryRecordDao.save(inventoryRecord);
                    //提升容量至库存数(修改的库存数大于容量时)
                    if (Integer.parseInt(qty) > Integer.parseInt(inventory.getCargoCapacity())) {
                        cargoCapacityChanged = true;
                        inventory.setCargoCapacity(qty);
                    }
                    inventory.setQty(qty);
                    //库存变更已变更的数量
                    inventoryDO.setQty(Integer.parseInt(qty));
                    //设置额定库存
                    inventory.setRatedInventory(Integer.parseInt(qty));
                }
                //更改货道容量-start
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){
                    inventoryDO.setQty(Integer.parseInt(inventory.getQty()));
                    //2022-01-05-bug:13617-start
                    if (Integer.parseInt(inventory.getQty()) > Integer.parseInt(cargoCapacity)) {
                        //有药品时的补货
                        MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                        inventoryRecord.setDeviceId(inventory.getIdDevice());
                        inventoryRecord.setEquNum(inventory.getEquNum());
                        inventoryRecord.setOldDrugId(inventory.getDrugId());
                        inventoryRecord.setDrugId(inventory.getDrugId());
                        inventoryRecord.setLayerNo(inventory.getLayerNo());
                        inventoryRecord.setWayerNo(inventory.getWayerNo());
                        inventoryRecord.setMergeState(inventory.getState());
                        inventoryRecord.setMergeCargo(inventory.getMerge());
                        inventoryRecord.setOldQuantity(inventory.getQty());
                        inventoryRecord.setQuantity(cargoCapacity);
                        inventoryRecord.setCreateUser(userId);
                        inventoryRecord.setType("1");
                        inventoryRecordDao.save(inventoryRecord);
                        inventory.setQty(cargoCapacity);
                        inventoryDO.setQty(Integer.parseInt(cargoCapacity));
                        //设置额定库存
                        inventory.setRatedInventory(Integer.parseInt(cargoCapacity));
                    }
                    //2022-01-05-bug:13617-end
                    if (Integer.parseInt(cargoCapacity) > 99) {
                        throw new Exception("货道容量最多99个,如超过请放置另一格");
                    }
                    inventory.setCargoCapacity(cargoCapacity);
                    cargoCapacityChanged = true;
                }
                //更改货道容量-end
                //下架药品
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(status)){
                    //下架时,清空库存
                    if ("0".equals(status)) {
                        inventory.setQty("0");
                        inventoryDO.setQty(0);
                        inventory.setDrugCode(null);
                        inventory.setDrugId(null);
                        inventory.setDrugName(null);
                        inventory.setPrice(null);
                        //设置额定库存
                        inventory.setRatedInventory(0);
                    }
                    inventory.setShelfStatus(status);
                    MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                    inventoryRecord.setDeviceId(inventory.getIdDevice());
                    inventoryRecord.setEquNum(inventory.getEquNum());
                    inventoryRecord.setOldDrugId(inventory.getDrugId());
                    inventoryRecord.setDrugId(inventory.getDrugId());
                    inventoryRecord.setLayerNo(inventory.getLayerNo());
                    inventoryRecord.setWayerNo(inventory.getWayerNo());
                    inventoryRecord.setMergeState(inventory.getState());
                    inventoryRecord.setMergeCargo(inventory.getMerge());
                    inventoryRecord.setOldQuantity(inventory.getQty());
                    inventoryRecord.setQuantity("0");
                    inventoryRecord.setCreateUser(userId);
                    inventoryRecord.setType("4");
                    inventoryRecordDao.save(inventoryRecord);
                }
                inventory.setUpdateTime(new Date());
                //更改设备缺货状态
                updateDeviceState(inventory.getId(), inventoryDO);
                mediicinecabinetInventory = inventoryDao.save(inventory);
                //重算设备容量
                if (cargoCapacityChanged) {
                    Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
                    String tempSql = "SELECT\n" +
                            "\tifnull(sum(t.cargo_capacity), 0) as cargoCapacity\n" +
                            "FROM\n" +
                            "\tt_mediicinecabinet_inventory t\n" +
                            "WHERE\n" +
                            "\tt.id_device = '"+inventory.getIdDevice()+"'\n" +
                            "AND (t.state = '1' OR t.state = '21')";
                    Map<String,Object> totalMap = jdbcTemplate.queryForMap(tempSql);
                    Integer noOnlineTotal1 = 0;
                    if (totalMap!=null){
                        if (totalMap.get("cargoCapacity") != null) {
                            noOnlineTotal1 = (int) Double.parseDouble(totalMap.get("cargoCapacity").toString());
                        }
                    }
                    mediicinedevice.setCapacity(String.valueOf(noOnlineTotal1));
                    deviceDao.save(mediicinedevice);
                }
            }
            return mediicinecabinetInventory;
        }else {
            MediicinecabinetInventory inventory =  inventoryDao.findOne(id);
            //更新设备缺货状态的该药品的已变动数量
            InventoryDO inventoryDO = new InventoryDO();
            inventoryDO.setDrugCode(inventory.getDrugCode());
            inventoryDO.setOrgCode(inventory.getOrgCode());
            inventoryDO.setRatedInventory(inventory.getRatedInventory());
            boolean cargoCapacityChanged = false;
            //库存变动
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
                if (Integer.parseInt(qty) > 99) {
                    throw new Exception("库存数量最多99个,请重新设置");
                }
                //有药品时的补货
                MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                inventoryRecord.setDeviceId(inventory.getIdDevice());
@ -4369,80 +4486,113 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                inventoryRecord.setMergeState(inventory.getState());
                inventoryRecord.setMergeCargo(inventory.getMerge());
                inventoryRecord.setOldQuantity(inventory.getQty());
                inventoryRecord.setQuantity(cargoCapacity);
                inventoryRecord.setQuantity(qty);
                inventoryRecord.setCreateUser(userId);
                inventoryRecord.setType("1");
                inventoryRecordDao.save(inventoryRecord);
                inventory.setQty(cargoCapacity);
                inventoryDO.setQty(Integer.parseInt(cargoCapacity));
                //提升容量至库存数(修改的库存数大于容量时)
                if (Integer.parseInt(qty) > Integer.parseInt(inventory.getCargoCapacity())) {
                    cargoCapacityChanged = true;
                    inventory.setCargoCapacity(qty);
                }
                inventory.setQty(qty);
                //库存变更已变更的数量
                inventoryDO.setQty(Integer.parseInt(qty));
                //设置额定库存
                inventory.setRatedInventory(Integer.parseInt(cargoCapacity));
            }
            //2022-01-05-bug:13617-end
            if (Integer.parseInt(cargoCapacity) > 99) {
                throw new Exception("货道容量最多99个,如超过请放置另一格");
                inventory.setRatedInventory(Integer.parseInt(qty));
            }
            //更改货道容量-start
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){
                inventoryDO.setQty(Integer.parseInt(inventory.getQty()));
                //2022-01-05-bug:13617-start
                if (Integer.parseInt(inventory.getQty()) > Integer.parseInt(cargoCapacity)) {
                    //有药品时的补货
                    MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                    inventoryRecord.setDeviceId(inventory.getIdDevice());
                    inventoryRecord.setEquNum(inventory.getEquNum());
                    inventoryRecord.setOldDrugId(inventory.getDrugId());
                    inventoryRecord.setDrugId(inventory.getDrugId());
                    inventoryRecord.setLayerNo(inventory.getLayerNo());
                    inventoryRecord.setWayerNo(inventory.getWayerNo());
                    inventoryRecord.setMergeState(inventory.getState());
                    inventoryRecord.setMergeCargo(inventory.getMerge());
                    inventoryRecord.setOldQuantity(inventory.getQty());
                    inventoryRecord.setQuantity(cargoCapacity);
                    inventoryRecord.setCreateUser(userId);
                    inventoryRecord.setType("1");
                    inventoryRecordDao.save(inventoryRecord);
                    inventory.setQty(cargoCapacity);
                    inventoryDO.setQty(Integer.parseInt(cargoCapacity));
                    //设置额定库存
                    inventory.setRatedInventory(Integer.parseInt(cargoCapacity));
                }
                //2022-01-05-bug:13617-end
                if (Integer.parseInt(cargoCapacity) > 99) {
                    throw new Exception("货道容量最多99个,如超过请放置另一格");
                }
                inventory.setCargoCapacity(cargoCapacity);
                cargoCapacityChanged = true;
            }
            inventory.setCargoCapacity(cargoCapacity);
            cargoCapacityChanged = true;
        }
        //更改货道容量-end
        //下架药品
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(status)){
            //下架时,清空库存
            if ("0".equals(status)) {
                inventory.setQty("0");
                inventoryDO.setQty(0);
                inventory.setDrugCode(null);
                inventory.setDrugId(null);
                inventory.setDrugName(null);
                inventory.setPrice(null);
                //设置额定库存
                inventory.setRatedInventory(0);
            //更改货道容量-end
            //下架药品
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(status)){
                //下架时,清空库存
                if ("0".equals(status)) {
                    inventory.setQty("0");
                    inventoryDO.setQty(0);
                    inventory.setDrugCode(null);
                    inventory.setDrugId(null);
                    inventory.setDrugName(null);
                    inventory.setPrice(null);
                    //设置额定库存
                    inventory.setRatedInventory(0);
                }
                inventory.setShelfStatus(status);
                MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
                inventoryRecord.setDeviceId(inventory.getIdDevice());
                inventoryRecord.setEquNum(inventory.getEquNum());
                inventoryRecord.setOldDrugId(inventory.getDrugId());
                inventoryRecord.setDrugId(inventory.getDrugId());
                inventoryRecord.setLayerNo(inventory.getLayerNo());
                inventoryRecord.setWayerNo(inventory.getWayerNo());
                inventoryRecord.setMergeState(inventory.getState());
                inventoryRecord.setMergeCargo(inventory.getMerge());
                inventoryRecord.setOldQuantity(inventory.getQty());
                inventoryRecord.setQuantity("0");
                inventoryRecord.setCreateUser(userId);
                inventoryRecord.setType("4");
                inventoryRecordDao.save(inventoryRecord);
            }
            inventory.setShelfStatus(status);
            MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
            inventoryRecord.setDeviceId(inventory.getIdDevice());
            inventoryRecord.setEquNum(inventory.getEquNum());
            inventoryRecord.setOldDrugId(inventory.getDrugId());
            inventoryRecord.setDrugId(inventory.getDrugId());
            inventoryRecord.setLayerNo(inventory.getLayerNo());
            inventoryRecord.setWayerNo(inventory.getWayerNo());
            inventoryRecord.setMergeState(inventory.getState());
            inventoryRecord.setMergeCargo(inventory.getMerge());
            inventoryRecord.setOldQuantity(inventory.getQty());
            inventoryRecord.setQuantity("0");
            inventoryRecord.setCreateUser(userId);
            inventoryRecord.setType("4");
            inventoryRecordDao.save(inventoryRecord);
        }
        inventory.setUpdateTime(new Date());
            inventory.setUpdateTime(new Date());
        //更改设备缺货状态
        updateDeviceState(inventory.getId(), inventoryDO);
            //更改设备缺货状态
            updateDeviceState(inventory.getId(), inventoryDO);
        inventoryDao.save(inventory);
        //重算设备容量
        if (cargoCapacityChanged) {
            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
            String tempSql = "SELECT\n" +
                    "\tifnull(sum(t.cargo_capacity), 0) as cargoCapacity\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory t\n" +
                    "WHERE\n" +
                    "\tt.id_device = '"+inventory.getIdDevice()+"'\n" +
                    "AND (t.state = '1' OR t.state = '21')";
            Map<String,Object> totalMap = jdbcTemplate.queryForMap(tempSql);
            Integer noOnlineTotal1 = 0;
            if (totalMap!=null){
                if (totalMap.get("cargoCapacity") != null) {
                    noOnlineTotal1 = (int) Double.parseDouble(totalMap.get("cargoCapacity").toString());
            inventoryDao.save(inventory);
            //重算设备容量
            if (cargoCapacityChanged) {
                Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
                String tempSql = "SELECT\n" +
                        "\tifnull(sum(t.cargo_capacity), 0) as cargoCapacity\n" +
                        "FROM\n" +
                        "\tt_mediicinecabinet_inventory t\n" +
                        "WHERE\n" +
                        "\tt.id_device = '"+inventory.getIdDevice()+"'\n" +
                        "AND (t.state = '1' OR t.state = '21')";
                Map<String,Object> totalMap = jdbcTemplate.queryForMap(tempSql);
                Integer noOnlineTotal1 = 0;
                if (totalMap!=null){
                    if (totalMap.get("cargoCapacity") != null) {
                        noOnlineTotal1 = (int) Double.parseDouble(totalMap.get("cargoCapacity").toString());
                    }
                }
                mediicinedevice.setCapacity(String.valueOf(noOnlineTotal1));
                deviceDao.save(mediicinedevice);
            }
            mediicinedevice.setCapacity(String.valueOf(noOnlineTotal1));
            deviceDao.save(mediicinedevice);
            return inventory;
        }
        return inventory;
    }
@ -5282,7 +5432,12 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        }
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(outDetailId)){
            Mediicinestockoutdetail detail =mediicinestockoutdetailDao.findOne(outDetailId);
            detail.setBatchNum(total+"");
            if (org.apache.commons.lang.StringUtils.isNotBlank(detail.getBatchNum())){
                detail.setBatchNum((total+Integer.parseInt(detail.getBatchNum()))+"");
            }else {
                detail.setBatchNum(total+"");
            }
            mediicinestockoutdetailDao.save(detail);
        }

+ 34 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/job/MedicineDrugsJob.java

@ -0,0 +1,34 @@
package com.yihu.jw.job;
import com.yihu.jw.service.channel.MedicineService;
import com.yihu.jw.service.channel.PrescriptionStatusUpdateService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * Created by Trick on 2019/10/15.
 */
public class MedicineDrugsJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(MedicineDrugsJob.class);
    @Autowired
    private MedicineService medicineService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("START========MedicineDrugsJob========");
        try {
            Trigger trigger =jobExecutionContext.getTrigger();
            System.out.println("执行时间为"+trigger.getNextFireTime());
            medicineService.getOrgPhysicDict(null,null,null,null);
            logger.info("END========MedicineDrugsJob========");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("END===ERROE===MedicineDrugsJob,message:"+e.getMessage());
        }
    }
}

+ 33 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/job/MedicinePrescriptionStatusJob.java

@ -0,0 +1,33 @@
package com.yihu.jw.job;
import com.yihu.jw.service.channel.MedicineService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * Created by Trick on 2019/10/15.
 */
public class MedicinePrescriptionStatusJob implements Job {
    private static final Logger logger = LoggerFactory.getLogger(MedicinePrescriptionStatusJob.class);
    @Autowired
    private MedicineService medicineService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("START========MedicinePrescriptionStatusJob========");
        try {
            Trigger trigger =jobExecutionContext.getTrigger();
            System.out.println("执行时间为"+trigger.getNextFireTime());
            medicineService.syncPrescriptionStatus();
            logger.info("END========MedicinePrescriptionStatusJob========");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("END===ERROE===MedicinePrescriptionStatusJob,message:"+e.getMessage());
        }
    }
}

+ 23 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/repository/job/MediicinedrugsDao.java

@ -0,0 +1,23 @@
package com.yihu.jw.repository.job;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface MediicinedrugsDao extends PagingAndSortingRepository<Mediicinedrugs, String> {
    //返回订单明细
    @Query("select a from Mediicinedrugs a  ")
    List<Mediicinedrugs> getorderdetail();
    boolean existsByDrugCodeAndOrgCode(String drugCode, String orgCode);
    Mediicinedrugs findByDrugCodeAndOrgCode(String drugCode, String orgCode);
    List<Mediicinedrugs> findMediicinedrugsByOrgCode(String orgCode);
}

+ 64 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/repository/job/MediicineorderDao.java

@ -0,0 +1,64 @@
package com.yihu.jw.repository.job;
import com.yihu.jw.entity.a1entity.Mediicineorder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface MediicineorderDao extends PagingAndSortingRepository<Mediicineorder, String>, JpaSpecificationExecutor<Mediicineorder> {
    //统计时间段的销售额
    @Query("select sum(a.amount) from Mediicineorder a where a.prescribeTime >=?1 and a.prescribeTime<=?2")
    float getsumamount(Date beg, Date end);
    //统计时间段的天的订单数量
    @Query("select count(1) from Mediicineorder a where a.prescribeTime >= ?1 and a.prescribeTime<=?2")
    int getcount(Date beg, Date end);
    @Query("select a from Mediicineorder a where a.prescribeNum = ?1")
    Mediicineorder findMediicineorderByPrescribeNum(String prescribeNum);
    @Query("select a from Mediicineorder a where a.id=?1")
    Mediicineorder findById(String id);
    @Query("select a from Mediicineorder a where a.orderNum=?1")
    Mediicineorder findByOrderNum(String order);
    @Query("select a from Mediicineorder a where a.shippingEqu=?1 and a.sellState=1 order by a.shippingTime desc ")
    List<Mediicineorder> findByEquNum(String equNum);
    @Query("select a from Mediicineorder a where a.shippingEqu=?1 and a.shippingTime>=?2 and a.shippingTime<=?3 and a.sellState=1 order by a.shippingTime desc ")
    List<Mediicineorder> findByEquNumAndDate(String equNum, Date startTime, Date endTime);
    @Query("select a from Mediicineorder a where a.shippingEqu=?1  and a.sellState=1 order by a.shippingTime desc ")
    List<Mediicineorder> findByEquNumAndPage(String equNum, Pageable pageable);
    @Query("select a from Mediicineorder a where a.shippingEqu=?1 and a.shippingTime>=?2 and a.shippingTime<=?3 and a.sellState=1 ")
    List<Mediicineorder> findByEquNumAndDateAndPage(String equNum, Date startTime, Date endTime, Pageable pageable);
    @Query("select a from Mediicineorder a where a.shippingEqu=?1 and a.sellState=1 order by a.shippingTime desc ")
    List<Mediicineorder> findBy(String equNum);
    Mediicineorder findMediicineorderByPickUpNum(String pickUpNum);
    Mediicineorder findMediicineorderByPickUpNumAndSellStateAndBelongCommunity(String pickUpNum, String sellState, String belongCommunity);
    Mediicineorder findMediicineorderBySocialSecurityCardNum(String cardNum);
    List<Mediicineorder> findMediicineordersBySocialSecurityCardNum(String cardNum);
    List<Mediicineorder> findMediicineordersBySocialSecurityCardNumAndSellStateAndBelongCommunity(String cardNum, String sellState, String belongCommunity);
    List<Mediicineorder> findMediicineorderBySellState(String sellState);
}

+ 183 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/service/channel/MedicineService.java

@ -0,0 +1,183 @@
package com.yihu.jw.service.channel;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import com.yihu.jw.entity.a1entity.Mediicineorder;
import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO;
import com.yihu.jw.entity.wlyyinfo.OauthWlyyConfigDO;
import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao;
import com.yihu.jw.repository.job.MediicinedrugsDao;
import com.yihu.jw.repository.job.MediicineorderDao;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.wlyy.dao.OauthWlyyConfigDao;
import com.yihu.jw.wlyy.wlyyhttp.WlyyHttpService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class MedicineService {
    private static final Logger logger = LoggerFactory.getLogger(MedicineService.class);
    @Autowired
    private WlyyHttpService wlyyHttpService;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private MediicinedrugsDao mediicinedrugsDao;
    @Autowired
    private MediicineorderDao mediicineorderDao;
    @Autowired
    private OauthWlyyConfigDao oauthWlyyConfigDao;
    @Autowired
    private WlyyHttpLogDao wlyyHttpLogDao;
    public void getOrgPhysicDict(String orgCode, String name, String orgName, String physicCode) {
        String param = "";
        if (StringUtils.isNoneBlank(orgCode)) {
            param = "?orgCode=" + orgCode;
        }
        if (StringUtils.isNoneBlank(name)) {
            param += "?name=" + name;
        }
        if (StringUtils.isNoneBlank(orgName)) {
            param += "?orgName" + orgName;
        }
        if (StringUtils.isNoneBlank(physicCode)) {
            param += "?physicCode" + physicCode;
        }
        com.alibaba.fastjson.JSONObject re = wlyyHttpService.sendWlyyMesGet("getOrgPhysicDict", param);
        if (re != null) {
            JSONArray jsonArray = JSONArray.parseArray(re.getString("data"));
            logger.info("mediicinedrugs size:" + jsonArray.size());
            if (jsonArray != null && jsonArray.size() > 0) {
                Integer addCount = 0;
                Integer updateCount = 0;
                List<Mediicinedrugs> list = new ArrayList<>();
                for (int i = 0; i < jsonArray.size(); i++) {
                    com.alibaba.fastjson.JSONObject h = (com.alibaba.fastjson.JSONObject) jsonArray.get(i);
                    String drugCode = h.getString("physic_code");
                    if (!mediicinedrugsDao.existsByDrugCodeAndOrgCode(drugCode, h.getString("orgCode"))) {
                        Mediicinedrugs org = new Mediicinedrugs();
                        org.setDrugCode(drugCode);
                        org.setDosForm(h.getString("physic_form_name"));
                        org.setDrugName(h.getString("physic_name"));
                        org.setDrugNameAlies(h.getString("physic_name"));
                        org.setPrice(h.getFloat("retail_price"));
                        org.setSpecif(h.getString("physic_spec"));
                        org.setDrugClass(h.getString("subject_class_name"));
                        org.setUnit(h.getString("dose_unit_name"));
                        org.setUseDose(h.getString("min_dose"));
                        org.setOrgCode(h.getString("orgCode"));
                        org.setQuantityUnit(h.getString("quantity_unit_name"));
                        org.setPackUnit(h.getString("pack_unit_name"));
                        org.setSpellCode(h.getString("spellCode"));
                        list.add(org);
                        addCount++;
                    } else {
                        Mediicinedrugs org = mediicinedrugsDao.findByDrugCodeAndOrgCode(drugCode, h.getString("orgCode"));
                        org.setDrugCode(drugCode);
                        org.setDosForm(h.getString("physic_form_name"));
                        org.setDrugName(h.getString("physic_name"));
                        org.setDrugNameAlies(h.getString("physic_name"));
                        org.setPrice(h.getFloat("retail_price"));
                        org.setSpecif(h.getString("physic_spec"));
                        org.setDrugClass(h.getString("subject_class_name"));
                        org.setUnit(h.getString("dose_unit_name"));
                        org.setUseDose(h.getString("min_dose"));
                        org.setOrgCode(h.getString("orgCode"));
                        org.setQuantityUnit(h.getString("quantity_unit_name"));
                        org.setPackUnit(h.getString("pack_unit_name"));
                        org.setSpellCode(h.getString("spellCode"));
                        list.add(org);
                        updateCount++;
                    }
                }
                mediicinedrugsDao.save(list);
                logger.info("mediicinedrugs:addCount:" + addCount + " updateCount:" + updateCount);
            }
        }
    }
    public void syncPrescriptionStatus() {
        List<Mediicineorder> mediicineorderList = mediicineorderDao.findMediicineorderBySellState("0");
        for (Mediicineorder mediicineorder:mediicineorderList){
            String result = getDataStatus(mediicineorder.getPickUpNum());
            if (StringUtils.isNoneBlank(result)){
                JSONObject resObj = JSONObject.parseObject(result);
                if (resObj.getString("status").equalsIgnoreCase("200")){
                    String code = resObj.getString("RECIPE_STATUS_CODE");
                    if (code.equalsIgnoreCase("5")){
                        mediicineorder.setSellState("1");
                        mediicineorder.setShippingEqu("线下药房");
                        mediicineorder.setShippingTime(new Date());
                        mediicineorderDao.save(mediicineorder);
                    }else if (code.equalsIgnoreCase("9")){
                        mediicineorder.setSellState("-1");
                        mediicineorder.setShippingEqu("线下作废");
                        mediicineorder.setShippingTime(new Date());
                        mediicineorderDao.save(mediicineorder);
                    }
                }
            }
        }
    }
    /**
     * 获取处方状态
     * @param realOrder
     * @return
     */
    public String getDataStatus(String realOrder){
        OauthWlyyConfigDO oauthWlyyConfigDO = oauthWlyyConfigDao.findOne("getDataStatus");
        //token获取accesstoken
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("appid", oauthWlyyConfigDO.getAppId()));
        params.add(new BasicNameValuePair("appSecret",oauthWlyyConfigDO.getAppSecret()));
        String res = httpClientUtil.post(oauthWlyyConfigDO.getTokenUrl(),params,"UTF-8");
        String token = null;
        JSONObject rsjson = JSONObject.parseObject(res);
        logger.info("checkWlyyDoctor token :"+rsjson.toString());
        Integer status = rsjson.getInteger("status");
        if(status==10000){
            //设置入参
            List<NameValuePair> p = new ArrayList<>();
            p.add(new BasicNameValuePair("jwCode", realOrder));
            //设置头部
            token = rsjson.getJSONObject("result").getString("accesstoken");
            Map<String,Object> headerMap = new HashedMap();
            headerMap.put("accesstoken",token);
            String rs = httpClientUtil.headerPost(oauthWlyyConfigDO.getUrl(),p,"UTF-8",headerMap);
            WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO();
            wlyyHttpLogDO.setCode("getDataStatus");
            wlyyHttpLogDO.setRequest(p.toString());
            wlyyHttpLogDO.setResponse(rs);
            wlyyHttpLogDO.setName("根据处方号获取i健康处方状态");
            wlyyHttpLogDO.setStatus("1");
            wlyyHttpLogDO.setCreateTime(new Date());
            wlyyHttpLogDao.save(wlyyHttpLogDO);
            logger.info("getDataStatus:"+rs);
            return rs;
        }else {
            return null;
        }
    }
}

+ 18 - 0
svr/svr-internet-hospital-job/src/main/java/com/yihu/jw/web/quota/JobController.java

@ -165,6 +165,24 @@ public class JobController extends BaseController {
                        logger.info("prescription_overdue_job  job exist");
                    }
                    break;
                case "medicine_drugs_job":
                    if (!quartzHelper.isExistJob("medicine_drugs_job")) {
                        String trigger = SystemConf.getInstance().getSystemProperties().getProperty("medicine_drugs_job");
                        quartzHelper.addJob(MedicineDrugsJob.class, trigger, "medicine_drugs_job", new HashMap<String, Object>());
                        logger.info("medicine_drugs_job  job success");
                    } else {
                        logger.info("medicine_drugs_job  job exist");
                    }
                    break;
                case "medicine_order_status":
                    if (!quartzHelper.isExistJob("medicine_order_status")) {
                        String trigger = SystemConf.getInstance().getSystemProperties().getProperty("medicine_order_status");
                        quartzHelper.addJob(MedicinePrescriptionStatusJob.class, trigger, "medicine_order_status", new HashMap<String, Object>());
                        logger.info("medicine_order_status  job success");
                    } else {
                        logger.info("medicine_order_status  job exist");
                    }
                    break;
                case "data_ykupload_job" :
                    //互联网医院 监管平台上报
                    if (!quartzHelper.isExistJob("data_ykupload_job")) {

+ 41 - 0
svr/svr-internet-hospital-job/src/main/resources/application.yml

@ -429,3 +429,44 @@ express:
  sf_check_word: QkeIfIvQdheqIv2cVSgAUnBU29lfNbVk
jobs:
  schedule: 0 */30 * * * ?
---
spring:
  profiles: jwZnygProd
  datasource:
    url: jdbc:mysql://59.61.92.90:9409/medicine?useUnicode:true&characterEncoding=utf-8&autoReconnect=true&useSSL=false #jdbc:mysql://192.0.33.27:3306/base?useUnicode:true&characterEncoding=utf-8&autoReconnect=true
    username: wlyy
    password: qY#j2n5O
hlwyyEntrance:
  url: http://172.16.1.42:10023
# mq 是否获取his数据,flag代表获取演示数据,false代表获取his真实数据
demo:
  flag: false
#支付支付
pay:
  flag: true
hospital:
  url: https://wx.xmzsh.com #https://172.16.1.34
  mqUser: JKZL
  mqPwd: 123456
  SourceSysCode: S60
  TargetSysCode: S01
im:
  im_list_get: http://172.16.1.42:3000/
  data_base_name: im
fastDFS:
  fastdfs_file_url: http://192.168.120.103:6004/
wlyy:
  url: http://www.xmtyw.cn/wlyytest/
wechat:
  id: d24d1367-7f4f-43af-910e-a0a43799e040  # base库中,wx_wechat 的id字段
  flag: false #演示环境  true走Mysql数据库  false走Oracle
  ids: xm_hcyy_wx
express:
  sf_url: http://bsp-oisp.sf-express.com/bsp-oisp/sfexpressService
  sf_code: WH000091
  sf_check_word: QkeIfIvQdheqIv2cVSgAUnBU29lfNbVk
jobs:
  schedule: 0 */30 * * * ?

+ 8 - 0
svr/svr-internet-hospital-job/src/main/resources/bootstrap.yml

@ -68,3 +68,11 @@ spring:
    config:
      uri: ${wlyy.pring.config.uri:http://192.168.250.39:1221}
      label: ${wlyy.spring.config.label:master}
---
spring:
  profiles: jwZnygProd
  cloud:
    config:
      uri: ${wlyy.spring.config.uri:http://127.0.0.1:1221}
      label: ${wlyy.spring.config.label:master}

+ 4 - 0
svr/svr-internet-hospital-job/src/main/resources/system.properties

@ -27,3 +27,7 @@ data_ykupload_job_2=0 0 0 * * ?
uncheck_prescription_notice_job=0 */1 * * * ?
medicine_drugs_job = 0 0 5 * * ? *
medicine_order_status=0 * * * * ? *