Prechádzať zdrojové kódy

Merge branch 'medicare' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into luofenqiang

luofenqiang 3 rokov pred
rodič
commit
d852bdaecc
15 zmenil súbory, kde vykonal 826 pridanie a 29 odobranie
  1. 94 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MedicineWarrayRule.java
  2. 16 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MediicinecabinetInventory.java
  3. 52 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/RuleDO.java
  4. 5 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java
  5. 13 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MedicineWarrayRuleDao.java
  6. 3 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicineDeviceDao.java
  7. 11 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinecabinetInventoryDao.java
  8. 4 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinestockupDao.java
  9. 3 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinestockupdetailDao.java
  10. 42 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java
  11. 15 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineUpEndpoint.java
  12. 52 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineOrderService.java
  13. 50 24
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineServive.java
  14. 22 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockUpService.java
  15. 444 5
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

+ 94 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MedicineWarrayRule.java

@ -0,0 +1,94 @@
package com.yihu.jw.entity.a1entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name="t_medicine_warray_rule")
public class MedicineWarrayRule extends UuidIdentityEntityWithOperator implements Serializable {
    /**
     * 设备编号
     */
    private String equNum;
    /**
     * 是否生效,1生效,0失效
     */
    private Integer del;
    /**
     * 上限
     */
    private Integer  upper;
    /**
     * 下限
     */
    private Integer  lower;
    /**
     * 匹配值
     */
    @Column
    private Integer matchValue;
    /**
     * 匹配单位
     */
    private String matchUnit;
    public MedicineWarrayRule() {
    }
    public String getEquNum() {
        return equNum;
    }
    public void setEquNum(String equNum) {
        this.equNum = equNum;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    public Integer getUpper() {
        return upper;
    }
    public void setUpper(Integer upper) {
        this.upper = upper;
    }
    public Integer getLower() {
        return lower;
    }
    public void setLower(Integer lower) {
        this.lower = lower;
    }
    public Integer getMatchValue() {
        return matchValue;
    }
    public void setMatchValue(Integer matchValue) {
        this.matchValue = matchValue;
    }
    public String getMatchUnit() {
        return matchUnit;
    }
    public void setMatchUnit(String matchUnit) {
        this.matchUnit = matchUnit;
    }
}

+ 16 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MediicinecabinetInventory.java

@ -124,6 +124,14 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
     */
    private String faultState;
    /**
     * 2021-12-29 额定库存,用于设备药品库存预警,单货道额定库存------->统计判断缺货在进行累加
     * 初始化为0,+
     * 重置设备(解绑设备)为0,+
     * 设定商品,更换商品,矫正库存--->qty,下架药品-->0 +
     */
    private Integer ratedInventory;
    public MediicinecabinetInventory() {
    }
@ -294,4 +302,12 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
    public void setFaultState(String faultState) {
        this.faultState = faultState;
    }
    public Integer getRatedInventory() {
        return ratedInventory;
    }
    public void setRatedInventory(Integer ratedInventory) {
        this.ratedInventory = ratedInventory;
    }
}

+ 52 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/RuleDO.java

@ -0,0 +1,52 @@
package com.yihu.jw.entity.a1entity;
import java.io.Serializable;
public class RuleDO implements Serializable {
    private Integer upper;
    private Integer lower;
    private Integer matchValue;
    private String matchUnit;
    public RuleDO() {
    }
    public Integer getUpper() {
        return upper;
    }
    public void setUpper(Integer upper) {
        this.upper = upper;
    }
    public Integer getLower() {
        return lower;
    }
    public void setLower(Integer lower) {
        this.lower = lower;
    }
    public Integer getMatchValue() {
        return matchValue;
    }
    public void setMatchValue(Integer matchValue) {
        this.matchValue = matchValue;
    }
    public String getMatchUnit() {
        return matchUnit;
    }
    public void setMatchUnit(String matchUnit) {
        this.matchUnit = matchUnit;
    }
}

+ 5 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -83,6 +83,7 @@ public class BaseRequestMapping {
        public static final String getUpDetailListById  = "/getUpDetailListById";
        public static final String getUpDetailById  = "/getUpDetailById";
        public static final String getRecordDetailListById  = "/getRecordDetailListById";
        public static final String getUpDetailByUserIdAndDeviceId  = "/getUpDetailByUserIdAndDeviceId";
        public static final String getOrgListByTown  = "/getOrgListByTown";
        public static final String enableOrDis  = "/enableOrDis";
        public static final String docFullInfo  = "/docFullInfo";
@ -176,6 +177,7 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/baseDevice";
        public static final String DOCINFO  = "/docInfo";
        public static final String CREATE  = "/create";
        public static final String setWarrayRule  = "/setWarrayRule";
        public static final String CREATEADDRESS  = "/createAddress";
        public static final String DELETEADDRESS  = "/deleteAddress";
        public static final String updateCommunity  = "/updateCommunity";
@ -200,6 +202,7 @@ public class BaseRequestMapping {
        public static final String getOutOfStockDeviceListByUserId  = "/getOutOfStockDeviceListByUserId";
        public static final String getDevicesDeliveryList  = "/getDevicesDeliveryList";
        public static final String getDetialOutOfStock  = "/getDetialOutOfStock";
        public static final String getOutOfStockInfoByDeviceWithPage  = "/getOutOfStockInfoByDeviceWithPage";
        public static final String getDevInventory  = "/getDevInventory";
        public static final String getDevInventoryByUserId  = "/getDevInventoryByUserId";
        public static final String countall  = "/countall";
@ -239,6 +242,8 @@ public class BaseRequestMapping {
        public static final String getDevicePriceStatistics = "/getDevicePriceStatistics";
        public static final String getShippingType = "/getShippingType";
        public static final String getPrescriptionStatics = "/getPrescriptionStatics";
        public static final String SYSTEMUPDATE  = "/systemUpdate";
    }
    /**

+ 13 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MedicineWarrayRuleDao.java

@ -0,0 +1,13 @@
package com.yihu.jw.base.dao.a2dao;
import com.yihu.jw.entity.a1entity.MedicineWarrayRule;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface MedicineWarrayRuleDao extends PagingAndSortingRepository<MedicineWarrayRule, String> {
    List<MedicineWarrayRule> findMedicineWarrayRulesByEquNumAndDel(String equNum, Integer del);
}

+ 3 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicineDeviceDao.java

@ -47,4 +47,7 @@ public interface MediicineDeviceDao extends PagingAndSortingRepository<Mediicine
    Mediicinedevice findByBelongCommunity(String belongCommunity);
    Mediicinedevice findByBelongCommunityAndEquNum(String belongCommunity,String equNum);
    List<Mediicinedevice> findMediicinedevicesByBelongCommunityInAndDel(String[] belongCommunitys, String del);
}

+ 11 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinecabinetInventoryDao.java

@ -26,4 +26,15 @@ public interface MediicinecabinetInventoryDao extends PagingAndSortingRepository
    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByLayerNoAndMerge(String layerNo, String merge);
    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(String deviceId, String[] states);
    @Query("select sum(qty) as qty, drugCode as drugCode, orgCode as orgCode, sum(ratedInventory) as ratedInventory from MediicinecabinetInventory where idDevice = ?1 and state in ?2 and drugCode is not null and orgCode is not null group by drugCode,orgCode")
    List<Map<String, Object>> selectsomethingBysomeCondition(String deviceId, String[] states);
    @Query("select sum(qty) as qty, drugCode as drugCode, orgCode as orgCode, sum(ratedInventory) as ratedInventory from MediicinecabinetInventory where equNum = ?1 and state in ?2 and drugCode is not null and orgCode is not null group by drugCode,orgCode")
    List<Map<String, Object>> selectsomethingBysomeConditionWithEquNum(String equNum, String[] states);
}

+ 4 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinestockupDao.java

@ -14,4 +14,8 @@ public interface MediicinestockupDao extends PagingAndSortingRepository<Mediicin
    @Query("select a from Mediicinestockup a  ")
    List<Mediicinestockup> getlist();
    @Query(" select id as id from Mediicinestockup where replenishEr = ?1 and replenishEqu = ?2 and state = ?3")
    List<String> selectUpIdsByReplenishErAndReplenishEquAndState(String userId, String deviceId, String state);
}

+ 3 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinestockupdetailDao.java

@ -13,4 +13,7 @@ public interface MediicinestockupdetailDao extends PagingAndSortingRepository<Me
    //按订单号出货明细
    @Query("select a from Mediicinestockupdetail a where a.idstockup =  ?1 ")
    List<Mediicinestockupdetail> getoutdetail(String idstockup);
    List<Mediicinestockupdetail> findMediicinestockupdetailsByIdstockupInOrderByIdstockupAscCreateTimeDesc(List<String> ids);
}

+ 42 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -3,6 +3,7 @@ package com.yihu.jw.base.endpoint.a4endpoint;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.service.a3service.MedicineServive;
import com.yihu.jw.base.service.a3service.MedicinedeviceService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.entity.a1entity.MedicineDeviceDelivery;
@ -19,6 +20,7 @@ import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@ -34,6 +36,8 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private  MedicinedeviceService deviceService;
    @Autowired
    private MedicineServive medicineServive;
    @Autowired
    private ObjectMapper objectMapper;
@ -603,6 +607,20 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getOutOfStockInfoByDeviceWithPage)
    @ApiOperation(value = "通过设备id获取设备的缺货信息")
    public PageEnvelop getOutOfStockInfoByDeviceWithPage(
            @ApiParam(name = "deviceId", value = "设备id")
            @RequestParam(value = "deviceId") String deviceId,
            @ApiParam(name = "page", value = "页码", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "分页大小", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        JSONObject result = deviceService.getOutOfStockInfoByDeviceWithPage(deviceId, page,size);
        return success(result.getJSONArray("msg"),result.getInteger("count"),page,size);
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDevInventory)
    @ApiOperation(value = "获取设备库存")
    public Envelop getDevInventory(
@ -748,4 +766,28 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.setWarrayRule)
    @ApiOperation(value = "设置设备药品库存报警规则")
    public Envelop setWarrayRule(
            @ApiParam(name = "isAll", value = "是否全部设备", required = true)
            @RequestParam(value = "isAll") Boolean isAll,
            @ApiParam(name = "equNums", value = "设备编号串,多个用英文逗号隔开")
            @RequestParam(value = "equNums", required = false) String equNums,
            @ApiParam(name = "rules", value = "规则json")
            @RequestParam(value = "rules", required = false ) String jsonRules,
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId) throws Exception {
        if (!isAll && StringUtils.isEmpty(equNums)) {
            return failed("未选择设备");
        }
        String str = deviceService.setMedicineWarrayRule(isAll, equNums, jsonRules, userId);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
}

+ 15 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineUpEndpoint.java

@ -213,4 +213,19 @@ public class MedicineUpEndpoint extends EnvelopRestEndpoint {
    }
    //补货记录-----------------------------
    @GetMapping(value = BaseRequestMapping.BaseUp.getUpDetailByUserIdAndDeviceId)
    @ApiOperation(value = "根据用户和设备获取备货单详情" , notes="根据用户和设备获取备货单详情")
    public ListEnvelop<Mediicinestockupdetail> getUpDetailByUserIdAndDeviceId  (
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "deviceId", value = "设备id", required = true)
            @RequestParam(value = "deviceId") String deviceId) throws Exception {
        JSONObject jsonObject = stockupService.getUpDetailByUserIdAndDeviceId(deviceId, userId);
        List<Mediicinestockupdetail> list = JSONObject.parseArray(jsonObject.getJSONArray("msg").toJSONString(), Mediicinestockupdetail.class);
        return success(list, Mediicinestockupdetail.class);
    }
}

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

@ -112,6 +112,9 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
    @Autowired
    private WlyyHospitalSysDictDao hospitalSysDictDao;
    @Autowired
    private MedicineWarrayRuleDao medicineWarrayRuleDao;
    /**
     * 新增药品信息
     *
@ -868,6 +871,8 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
            mediicineorder.setShippingTime(new Date());
            mediicineorder.setShippingType(shippingType);
            orderDao.save(mediicineorder);
            //更新设备缺货状态
            updateDeviceState(medicineShipmentLog);
        }
        //查询更新订单信息start
@ -893,6 +898,51 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        return result;
    }
    /**
     * 更新设备缺货信息
     * @param medicineShipmentLog
     */
    public void updateDeviceState(MedicineShipmentLog medicineShipmentLog) {
        //包含原来药品信息
//        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(medicineShipmentLog.getDeviceId(), new String[]{"1", "21"});
        Iterator<Map<String, Object>> it = collect.iterator();
        while (it.hasNext()) {
            Map<String, Object> stringObjectMap = it.next();
            if (String.valueOf(stringObjectMap.get("drugCode")).equals(medicineShipmentLog.getDrugCode()) &&
                        String.valueOf(stringObjectMap.get("orgCode")).equals(medicineShipmentLog.getOrgCode())) {
                stringObjectMap.put("qty", String.valueOf(Integer.parseInt(stringObjectMap.get("qty") + "") - 1));
            }
        }
        Mediicinedevice mediicinedevice = deviceDao.findMediicinedeviceByEquNum(medicineShipmentLog.getDeviceId());
        //该设备库存预警规则
        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(medicineShipmentLog.getDeviceId(), 1);
        //不缺货
        mediicinedevice.setStatus("1");
        quit:for (MedicineWarrayRule rule : rules) {
            for (Map<String, Object> stringObjectMap : collect) {
                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + "");
                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) {
                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + "");
                    if ("%".equals(rule.getMatchUnit())) {
                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
                        if (tempQty <= matchValue) {
                            mediicinedevice.setStatus("0");
                            break quit;
                        }
                    }
                    if ("件".equals(rule.getMatchUnit())) {
                        if (tempQty <= rule.getMatchValue()) {
                            mediicinedevice.setStatus("0");
                            break quit;
                        }
                    }
                }
            }
        }
        deviceDao.save(mediicinedevice);
    }
    public JSONObject checkOrderComplete(String orderId) {
@ -930,6 +980,8 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        result.put("msg", "订单未完成,请联系管理员!");
        return result;
    }
    //=================================调用i健康接口=================================//
    public String getEhcCardInfo(String ehealthCode) throws Exception {

+ 50 - 24
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineServive.java

@ -2,9 +2,10 @@ package com.yihu.jw.base.service.a3service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.dao.a2dao.MediicineDeviceDao;
import com.yihu.jw.base.dao.a2dao.MediicinedrugsDao;
import com.yihu.jw.entity.a1entity.Mediicinedevice;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import com.yihu.jw.hospital.HospitalDao;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.wlyy.wlyyhttp.WlyyHttpService;
import org.apache.commons.lang3.StringUtils;
@ -26,6 +27,9 @@ public class MedicineServive {
    private HttpClientUtil httpClientUtil;
    @Autowired
    private MediicinedrugsDao mediicinedrugsDao;
    @Autowired
    private MediicineDeviceDao deviceDao;
    @Value("${medicine.socketUrl}")
    private String socketUrl;
@ -101,20 +105,22 @@ public class MedicineServive {
            , Boolean humidityControl, Boolean heat) throws Exception {
        JSONObject object = new JSONObject();
        String param = "";
        if (StringUtils.isNoneBlank(devId)) {
            param = "?devId=" + devId;
            param += "?devId=" + devId;
        }
        if (StringUtils.isNoneBlank(temperature)) {
            param += "?temperature=" + temperature;
            object.put("temperature",temperature);
        }
        if (StringUtils.isNoneBlank(humidity)) {
            param += "?humidity=" + humidity;
            object.put("humidity",humidity);
        }
        param += "?temperatureControl=" + temperatureControl;
        param += "?humidityControl=" + humidityControl;
        param += "?heat=" + heat;
        object.put("temperatureControl",temperatureControl);
        object.put("humidityControl",humidityControl);
        object.put("heat",heat);
        param+="&type=SetTemperatureAndHumidity&mess="+object.toJSONString()+"";
        String res = httpClientUtil.get(socketUrl+param,"utf-8");
       System.out.println(res);
        System.out.println(res);
        /* if (StringUtils.isNoneBlank(res)){
            object =JSONObject.parseObject(res);
        }else{
@ -123,27 +129,47 @@ public class MedicineServive {
    }
    /*public void sendSocketMessage(String devId, String type,String message) throws Exception {
    /**
     * socket发送事件
     * @param devId
     * @param type
     * @param message
     * @throws Exception
     */
    public String sendSocketMessage(String devId, String type,String message) throws Exception {
        JSONObject object = new JSONObject();
        String param = "";
        if (StringUtils.isNoneBlank(devId)) {
            param = "?devId=" + devId;
        }
        if (StringUtils.isNoneBlank(temperature)) {
            param += "?temperature=" + temperature;
        }
        if (StringUtils.isNoneBlank(humidity)) {
            param += "?humidity=" + humidity;
        }
        param += "?temperatureControl=" + temperatureControl;
        param += "?humidityControl=" + humidityControl;
        param += "?heat=" + heat;
        param +="&type="+type+"&mess="+message+"";
        String res = httpClientUtil.get(socketUrl+param,"utf-8");
        System.out.println(res);
        *//* if (StringUtils.isNoneBlank(res)){
            object =JSONObject.parseObject(res);
        }else{
            throw new Exception("调用设备通信接口设置温湿度失败!");
        }*//*
    }*/
        return res;
    }
    /**
     * socket发送事件
     * @param equNum
     * @param type
     * @param message
     * @throws Exception
     */
    public String systemUpdate(String equNum, String type,String message) throws Exception {
        int i=0;
        if (StringUtils.isNoneBlank(equNum)){
            String res = sendSocketMessage(equNum+"_T",type,message);
            logger.info("更新设备"+res);
            i++;
        }else {
            List<Mediicinedevice> mediicinedeviceList =deviceDao.selectByBelongComminity();
            for (Mediicinedevice mediicinedevice:mediicinedeviceList){
                String res = sendSocketMessage(mediicinedevice.getEquNum()+"_T",type,message);
                logger.info("更新设备"+res);
                i++;
            }
            logger.info("更新"+i+"台设备");
        }
        return "更新"+i+"台设备";
    }
}

+ 22 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockUpService.java

@ -319,7 +319,9 @@ public class MedicineStockUpService extends BaseJpaService<Mediicinestockup, Med
                "t.remark AS remark,\n" +
                "t.replenish_cate AS replenishCate,\n" +
                "t.replenish_equ AS replenishEqu,\n" +
                "t.replenish_equ_name AS replenishEquName,\n" +
                "t.replenish_er AS replenishEr,\n" +
                "t.replenish_er_name AS replenishErName,\n" +
                "t.replenish_inventory AS replenishInventory,\n" +
                "t.state AS state,\n" +
                "t.track_num AS trackNum,\n" +
@ -519,4 +521,24 @@ public class MedicineStockUpService extends BaseJpaService<Mediicinestockup, Med
        return result;
    }
    /**
     * 根据用户和设备获取备货单详情
     * @param deviceId
     * @param userId
     * @return
     * @throws Exception
     */
    public JSONObject getUpDetailByUserIdAndDeviceId(String deviceId, String userId) throws Exception {
        JSONObject result = new JSONObject();
        //
        List<String> upIds = upDao.selectUpIdsByReplenishErAndReplenishEquAndState(userId, deviceId, "1");
        List<Mediicinestockupdetail> list = updetailDao.findMediicinestockupdetailsByIdstockupInOrderByIdstockupAscCreateTimeDesc(upIds);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        return result;
    }
}

+ 444 - 5
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -95,6 +95,10 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    @Autowired
    private MedicineShipmentLogDao medicineShipmentLogDao;
    @Autowired
    private MedicineWarrayRuleDao medicineWarrayRuleDao;
    /**
     * 设备出货服务,创建设备,创建库存内容
@ -164,6 +168,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                inventory.setCargoState("1");
                //设备初始化库存,默认货道是正常的
                inventory.setFaultState("0");
                //设备库存初始化,额定库存归0
                inventory.setRatedInventory(0);
                inventoryDao.save(inventory);
            }
        }
@ -528,7 +534,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceSaleStatus(String deviceId, String saleStatus){
    public String updateDeviceSaleStatus(String deviceId, String saleStatus) throws Exception {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(saleStatus)){
            result.put("msg","deviceId and saleStatus is null");
@ -543,6 +549,13 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        }
        mediicinedevice.setSaleStatus(saleStatus);
        this.save(mediicinedevice);
        //设备发送事件给前端
        if (saleStatus.equalsIgnoreCase("2")){
            medicineServive.sendSocketMessage(mediicinedevice.getEquNum()+"_T","equ_maintenance","设备维护");
        }else {
            medicineServive.sendSocketMessage(mediicinedevice.getEquNum()+"_T","equ_normal","设备正常");
        }
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
@ -688,6 +701,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    inventory.setNum("3");
                    inventory.setLongtime(null);
                    inventory.setOrgCode(null);
                    //额定 库存归0
                    inventory.setRatedInventory(0);
                    inventoryDao.save(inventory);
                }
            }
@ -2906,6 +2921,100 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    /**
     * 通过设备id获取设备的缺货信息
     * @param deviceId
     * @param page
     * @param size
     * @return
     * @throws Exception
     */
    public JSONObject getOutOfStockInfoByDeviceWithPage(String deviceId, int page, int size) throws Exception {
        JSONObject result = new JSONObject();
        String sql = "";
        {
            sql = "SELECT\n" +
                    "tmd.id AS id,\n" +
                    "tmd.approval_num AS approvalNum,\n" +
                    "tmd.barcode AS barcode,\n" +
                    "tmd.brand AS brand,\n" +
                    "tmd.dos_form AS dosForm,\n" +
                    "tmd.state AS state,\n" +
                    "tmd.drug_bar_code AS drugBarCode,\n" +
                    "tmd.drug_class AS drugClass,\n" +
                    "tmd.drug_class_code AS drugClassCode,\n" +
                    "tmd.drug_code AS drugCode,\n" +
                    "tmd.drug_name AS drugName,\n" +
                    "tmd.drug_name_alies AS drugNameAlies,\n" +
                    "tmd.drug_short_code AS drugShortCode,\n" +
                    "tmd.drug_type_code AS drugTypeCode,\n" +
                    "tmd.earlywarningcate AS earlywarningcate,\n" +
                    "tmd.inventory AS inventory,\n" +
                    "tmd.manufactor AS manufactor,\n" +
                    "tmd.med_cabinet AS medCabinet,\n" +
                    "tmd.pic AS pic,\n" +
                    "tmd.price AS price,\n" +
                    "tmd.sale_volume AS saleVolume,\n" +
                    "tmd.self_code AS selfCode,\n" +
                    "tmd.specif AS specif,\n" +
                    "tmd.unit AS unit,\n" +
                    "tmd.create_time AS createTime,\n" +
                    "tmd.create_user AS createUser,\n" +
                    "tmd.create_user_name AS createUserName,\n" +
                    "tmd.update_time AS updateTime,\n" +
                    "tmd.update_user AS updateUser,\n" +
                    "tmd.update_user_name AS updateUserName,\n" +
                    "tmd.drug_sku AS drugSku,\n" +
                    "tmd.drug_num AS drugNum,\n" +
                    "tmd.use_num AS useNum,\n" +
                    "tmd.use_way AS useWay,\n" +
                    "tmd.use_rate AS useRate,\n" +
                    "tmd.use_dose AS useDose,\n" +
                    "tmd.use_way_add AS useWayAdd,\n" +
                    "tmd.org_code AS orgCode,\n" +
                    "tmd.org_name AS orgName,\n" +
                    "tmd.quantity_unit AS quantityUnit,\n" +
                    "tmd.pack_unit AS packUnit,\n" +
                    "tmd.spell_code AS spellCode,\n" +
                    "\tsum(tmi.qty) AS qty,\n" +
                    "\t(\n" +
                    "\t\ttmi.rated_inventory - CAST(tmi.qty AS UNSIGNED)\n" +
                    "\t) AS daibukucun\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd ON tmi.drug_id = tmd.id\n" +
                    "WHERE" +
                    "\ttmi.id_device = '" + deviceId + "'\n" +
                    "AND CAST(tmi.qty as UNSIGNED) < tmi.rated_inventory\n" +
                    "AND tmi.drug_code IS NOT NULL\n" +
                    "AND tmi.org_code IS NOT NULL\n" +
                    "AND (tmi.state = 1 OR tmi.state = 21)\n" +
                    "ORDER BY\n" +
                    "\ttmi.drug_code,\n" +
                    "\ttmi.org_code";
        }
        List<Map<String, Object>> list = null;
        list = hibenateUtils.createSQLQuery(sql,page,size);
        String countSql = "SELECT\n" +
                "COUNT(DISTINCT(id))" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory\n" +
                "WHERE" +
                "\tid_device = '" + deviceId + "'\n" +
                "AND CAST(qty as UNSIGNED) < rated_inventory\n" +
                "AND drug_code IS NOT NULL\n" +
                "AND org_code IS NOT NULL\n" +
                "AND (state = 1 OR state = 21)\n" +
                "ORDER BY\n" +
                "\tdrug_code,\n" +
                "\torg_code";
        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
        result.put("count", count);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        return result;
    }
    /**
     * 获取设备库存
     * @param belongCommunity
@ -3489,7 +3598,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
//    @Transactional(rollbackFor = Exception.class)
    public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty,String userId) throws Exception {
        MediicinecabinetInventory inventory = inventoryDao.findOne(id);
        if (inventory==null){
@ -3540,9 +3649,15 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            cargoCapacityChanged = true;
            inventory.setCargoCapacity(qty);
        }
        //设置额定库存
        inventory.setRatedInventory(Integer.parseInt(qty));
        inventoryDao.save(inventory);
        //更改设备缺货状态
        updateDeviceState(inventory.getId());
        //重算设备容量
        if (cargoCapacityChanged) {
            //重算设备容量
            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
            String tempSql = "SELECT\n" +
                    "\tsum(t.cargo_capacity)\n" +
@ -3554,6 +3669,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            mediicinedevice.setCapacity(String.valueOf(jdbcTemplate.queryForObject(tempSql, Integer.class)));
            deviceDao.save(mediicinedevice);
        }
        return inventory;
    }
@ -3566,6 +3682,95 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        return  inventoryDao.findOne(id);
    }
    /**
     * 更新设备缺货状态,cargoId,货道id
     * @param cargoId
     */
    public void updateDeviceState(String cargoId) {
        //包含原来药品信息
        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
//        List<MediicinecabinetInventory> list = inventoryDao.findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(inventory.getIdDevice(), new String[]{"1", "21"});
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), new String[]{"1", "21"});
//        //药品变更
//        if (drugChanged) {
//            //变更的目标药品
//            Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId);
//            Iterator<Map<String, Object>> it = collect.iterator();
//            //剔除旧药品的数量
//            while (it.hasNext()) {
//                Map<String, Object> stringObjectMap = it.next();
//                if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) &&
//                        String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) {
//                    //说明只有一个货道是该种药品
//                    if (Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty()) == 0) {
//                        it.remove();
//                    } else {
//                        stringObjectMap.put("qty", String.valueOf(Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty())));
//                    }
//
//                }
//            }
//            //
//            Map<String, Object> tempMap = new HashMap<>();
//            tempMap.put("drugCode", mediicinedrugs.getDrugCode());
//            tempMap.put("orgCode", mediicinedrugs.getOrgCode());
//            tempMap.put("qty", qty);
//            tempMap.put("ratedInventory", Integer.parseInt(qty));
//            collect.add(tempMap);
//        } else {
//            //数量变更
//            if (qtyChanged) {
//                Iterator<Map<String, Object>> it = collect.iterator();
//                while (it.hasNext()) {
//                    Map<String, Object> stringObjectMap = it.next();
//                    if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) &&
//                            String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) {
//                        //下架
//                        if ("0".equals(qty)) {
//                            it.remove();
//                        }
//
//                        if (Integer.parseInt(qty) > Integer.parseInt(inventory.getQty())) {
//                            stringObjectMap.put("qty", qty);
//                            stringObjectMap.put("ratedInventory", Integer.parseInt(qty));
//                        } else if (Integer.parseInt(qty) < Integer.parseInt(inventory.getQty())) {
//                            it.remove();
//                        }
//
//                    }
//                }
//            }
//        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
        //该设备库存预警规则
        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(inventory.getEquNum(), 1);
        //不缺货
        mediicinedevice.setStatus("1");
        quit:for (MedicineWarrayRule rule : rules) {
            for (Map<String, Object> stringObjectMap : collect) {
                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + "");
                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) {
                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + "");
                    if ("%".equals(rule.getMatchUnit())) {
                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
                        if (tempQty <= matchValue) {
                            mediicinedevice.setStatus("0");
                            break quit;
                        }
                    }
                    if ("件".equals(rule.getMatchUnit())) {
                        if (tempQty <= rule.getMatchValue()) {
                            mediicinedevice.setStatus("0");
                            break quit;
                        }
                    }
                }
            }
        }
        deviceDao.save(mediicinedevice);
    }
    /**
     * 矫正库存\ 更新容量 \下架商品
@ -3604,18 +3809,24 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                inventory.setCargoCapacity(qty);
            }
            inventory.setQty(qty);
            //设置额定库存
            inventory.setRatedInventory(Integer.parseInt(qty));
        }
        //更改货道容量-start
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){
            if (Integer.parseInt(cargoCapacity) > 99) {
                throw new RuntimeException("货道容量最多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");
                //设置额定库存
                inventory.setRatedInventory(0);
            }
            inventory.setShelfStatus(status);
            MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
@ -3635,8 +3846,10 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        }
        inventory.setUpdateTime(new Date());
        inventoryDao.save(inventory);
        //更改设备缺货状态
        updateDeviceState(inventory.getId());
        //重算设备容量
        if (cargoCapacityChanged) {
            //重算设备容量
            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
            String tempSql = "SELECT\n" +
                    "\tsum(t.cargo_capacity)\n" +
@ -4024,5 +4237,231 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        return deviceDao.findMediicinedeviceByEquNum(equNum);
    }
    /**
     * 设置设备药品库存预警规则,rule1,规则1,rule2,规则2
     * @param isAll
     * @param equNums
     * @param jsonRules
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String setMedicineWarrayRule(Boolean isAll,String equNums, String jsonRules, String userId){
        JSONObject result = new JSONObject();
        JSONObject jsonObject = JSONObject.parseObject(jsonRules);
        JSONArray ruleArray = jsonObject.getJSONArray("rules");
        if (ruleArray.size() == 0) {
            result.put("msg","rule is empty");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        String belongCommunitys = "";
        String tempSql = "";
        //获取管理员所在社区code字符串
        {
            //市管理员
            if ("saasAdmin".equals(role.getCode())) {
                tempSql = "SELECT\n" +
                        "\t`code`\tas community\n" +
                        "FROM\n" +
                        "\tdm_hospital\n" +
                        "WHERE\n" +
                        "\tdel = 1";
            }
            //区域管理员
            if ("regionAdmin".equals(role.getCode())) {
                tempSql = "SELECT\n" +
                        "\tdh.`code` AS community\n" +
                        "FROM\n" +
                        "\twlyy_user_area t\n" +
                        "LEFT JOIN dm_hospital dh ON t.town = dh.town\n" +
                        "WHERE\n" +
                        "\tt.user_id = '" + userId + "'\n" +
                        "AND t.del = 1\n" +
                        "AND dh.del = 1";
            }
            //社区管理员
            if ("communityAdmin".equals(role.getCode())) {
                tempSql = "SELECT\n" +
                        "t.hospital AS community\n" +
                        "FROM\n" +
                        "wlyy_user_area AS t\n" +
                        "WHERE\n" +
                        "t.user_id = '" + userId + "'\n" +
                        "AND t.del = 1";
            }
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(tempSql);
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) {
                    if (belongCommunitys.indexOf(stringObjectMap.get("community") + "") == -1) {
                        if (StringUtils.isEmpty(belongCommunitys)) {
                            belongCommunitys += stringObjectMap.get("community").toString();
                        } else {
                            belongCommunitys += "," +  stringObjectMap.get("community").toString();
                        }
                    }
                }
            }
        }
        //所有设备
        if (isAll) {
            {
                tempSql = "SELECT\n" +
                        "\tt.id,\n" +
                        "\tt.equ_num,\n" +
                        "\tt.del,\n" +
                        "\tt.upper,\n" +
                        "\tt.lower,\n" +
                        "\tt.match_value,\n" +
                        "\tt.match_unit,\n" +
                        "\tt.create_time,\n" +
                        "\tt.create_user,\n" +
                        "\tt.create_user_name,\n" +
                        "\tt.update_time,\n" +
                        "\tt.update_user,\n" +
                        "\tt.update_user_name\n" +
                        "FROM\n" +
                        "\tt_medicine_warray_rule AS t\n" +
                        "LEFT JOIN t_mediicine_device tmd ON t.equ_num = tmd.equ_num\n" +
                        "WHERE\n" +
                        "\tt.del = 1\n" +
                        "AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',tmd.belong_community,',%')\n";
            }
            List<Map<String,Object>> list = hibenateUtils.createSQLQuery(tempSql);
            //失效原来规则
            for (Map<String, Object> stringObjectMap : list) {
                MedicineWarrayRule medicineWarrayRule = medicineWarrayRuleDao.findOne(stringObjectMap.get("id")+"");
                medicineWarrayRule.setDel(0);
                medicineWarrayRule.setUpdateTime(new Date());
                medicineWarrayRule.setUpdateUser(userId);
                medicineWarrayRuleDao.save(medicineWarrayRule);
            }
            List<Mediicinedevice> deviceList = deviceDao.findMediicinedevicesByBelongCommunityInAndDel(belongCommunitys.split(","), "1");
            for (Mediicinedevice mediicinedevice : deviceList) {
                for (Object obj : ruleArray) {
                    RuleDO ruleDO = null;
                    try {
                        ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
                    } catch (IOException e) {
                        result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
                        result.put("response", ConstantUtils.FAIL);
                        return result.toJSONString();
                    }
                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
                    medicineWarrayRule.setDel(1);
                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
                    medicineWarrayRule.setLower(ruleDO.getLower());
                    medicineWarrayRule.setUpper(ruleDO.getUpper());
                    medicineWarrayRule.setMatchValue(ruleDO.getMatchValue());
                    medicineWarrayRule.setMatchUnit(ruleDO.getMatchUnit());
                    medicineWarrayRule.setUpdateUser(userId);
                    medicineWarrayRule.setUpdateTime(new Date());
                    medicineWarrayRule.setCreateTime(new Date());
                    medicineWarrayRule.setCreateUser(userId);
                    medicineWarrayRuleDao.save(medicineWarrayRule);
                }
//                if (!StringUtils.isEmpty(rule1)) {
//                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
//                    medicineWarrayRule.setLower(Integer.parseInt(rule1.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule1.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule1.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule1.split(",")[3]);
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());
//                    medicineWarrayRule.setCreateUser(userId);
//                    medicineWarrayRuleDao.save(medicineWarrayRule);
//                }
//                if (!StringUtils.isEmpty(rule2)) {
//                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
//                    medicineWarrayRule.setLower(Integer.parseInt(rule2.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule2.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule2.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule2.split(",")[3]);
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());
//                    medicineWarrayRule.setCreateUser(userId);
//                    medicineWarrayRuleDao.save(medicineWarrayRule);
//                }
            }
            result.put("response", ConstantUtils.SUCCESS);
            result.put("msg", ConstantUtils.SUCCESS);
            return result.toJSONString();
        }
        for (String equNum : equNums.split(",")) {
            if (!StringUtils.isEmpty(equNum)) {
                List<MedicineWarrayRule> medicineWarrayRules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(equNum, 1);
                for (MedicineWarrayRule medicineWarrayRule : medicineWarrayRules) {
                    medicineWarrayRule.setDel(0);
                    medicineWarrayRule.setUpdateTime(new Date());
                    medicineWarrayRule.setUpdateUser(userId);
                    medicineWarrayRuleDao.save(medicineWarrayRule);
                }
                for (Object obj : ruleArray) {
                    RuleDO ruleDO = null;
                    try {
                        ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
                    } catch (IOException e) {
                        result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
                        result.put("response", ConstantUtils.FAIL);
                        return result.toJSONString();
                    }
                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
                    medicineWarrayRule.setDel(1);
                    medicineWarrayRule.setEquNum(equNum);
                    medicineWarrayRule.setLower(ruleDO.getLower());
                    medicineWarrayRule.setUpper(ruleDO.getUpper());
                    medicineWarrayRule.setMatchValue(ruleDO.getMatchValue());
                    medicineWarrayRule.setMatchUnit(ruleDO.getMatchUnit());
                    medicineWarrayRule.setUpdateUser(userId);
                    medicineWarrayRule.setUpdateTime(new Date());
                    medicineWarrayRule.setCreateTime(new Date());
                    medicineWarrayRule.setCreateUser(userId);
                    medicineWarrayRuleDao.save(medicineWarrayRule);
                }
//                if (!StringUtils.isEmpty(rule1)) {
//                    medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(equNum);
//                    medicineWarrayRule.setLower(Integer.parseInt(rule1.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule1.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule1.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule1.split(",")[3]);
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());
//                    medicineWarrayRule.setCreateUser(userId);
//                    medicineWarrayRuleDao.save(medicineWarrayRule);
//                }
//                if (!StringUtils.isEmpty(rule2)) {
//                    medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(equNum);
//                    medicineWarrayRule.setLower(Integer.parseInt(rule2.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule2.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule2.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule2.split(",")[3]);
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());
//                    medicineWarrayRule.setCreateUser(userId);
//                    medicineWarrayRuleDao.save(medicineWarrayRule);
//                }
            }
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg", ConstantUtils.SUCCESS);
        return result.toJSONString();
    }
}