Browse Source

补货日志

wangzhinan 3 years ago
parent
commit
ed1140b8db

+ 150 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MedicineDrugInventoryRecord.java

@ -0,0 +1,150 @@
package com.yihu.jw.entity.a1entity;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
@Entity
@Table(name="t_medicine_drug_inventory_record")
public class MedicineDrugInventoryRecord extends UuidIdentityEntityWithOperator implements Serializable {
    /**
     *  设备id
     */
    private String deviceId;
    /**
     *  设备编号
     */
    private String equNum;
    /**
     *  记录类型,1补货,2换货,3上架,4下架
     */
    private String type;
    /**
     *  层
     */
    private String layerNo;
    /**
     *  列
     */
    private String wayerNo;
    /**
     *  合并状态,1单列货道,2合并货道
     */
    private String mergeState;
    /**
     *  合并货道(列拼接)
     */
    private String mergeCargo;
    /**
     *  原药品id
     */
    private String oldDrugId;
    /**
     *  现药品id
     */
    private String drugId;
    /**
     *  原药品数量
     */
    private String oldQuantity;
    /**
     *  现药品数量
     */
    private String quantity;
    public MedicineDrugInventoryRecord() {
    }
    public String getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    public String getEquNum() {
        return equNum;
    }
    public void setEquNum(String equNum) {
        this.equNum = equNum;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getLayerNo() {
        return layerNo;
    }
    public void setLayerNo(String layerNo) {
        this.layerNo = layerNo;
    }
    public String getWayerNo() {
        return wayerNo;
    }
    public void setWayerNo(String wayerNo) {
        this.wayerNo = wayerNo;
    }
    public String getMergeState() {
        return mergeState;
    }
    public void setMergeState(String mergeState) {
        this.mergeState = mergeState;
    }
    public String getMergeCargo() {
        return mergeCargo;
    }
    public void setMergeCargo(String mergeCargo) {
        this.mergeCargo = mergeCargo;
    }
    public String getOldDrugId() {
        return oldDrugId;
    }
    public void setOldDrugId(String oldDrugId) {
        this.oldDrugId = oldDrugId;
    }
    public String getDrugId() {
        return drugId;
    }
    public void setDrugId(String drugId) {
        this.drugId = drugId;
    }
    public String getOldQuantity() {
        return oldQuantity;
    }
    public void setOldQuantity(String oldQuantity) {
        this.oldQuantity = oldQuantity;
    }
    public String getQuantity() {
        return quantity;
    }
    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }
}

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

@ -187,6 +187,7 @@ public class BaseRequestMapping {
        public static final String mergeAndSplitCargo  = "/mergeAndSplitCargo";
        public static final String getDeviceListByUserId  = "/getDeviceListByUserId";
        public static final String getDeviceListWithUserId  = "/getDeviceListWithUserId";
        public static final String getDeviceInventoryRecordListWithUserId  = "/getDeviceInventoryRecordListWithUserId";
        public static final String getInitDeviceByPage  = "/getInitDeviceByPage";
        public static final String getUserListByDeviceId  = "/getUserListByDeviceId";
        public static final String getOutOfStockDeviceList  = "/getOutOfStockDeviceList";

+ 14 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MedicineDrugInventoryRecordDao.java

@ -0,0 +1,14 @@
package com.yihu.jw.base.dao.a2dao;
import com.yihu.jw.entity.a1entity.MedicineDrugInventoryRecord;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface MedicineDrugInventoryRecordDao extends PagingAndSortingRepository<MedicineDrugInventoryRecord, String> {
    List<MedicineDrugInventoryRecord> findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(String deviceId, String euNum, String type);
}

+ 24 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -499,6 +499,22 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
        return success(result.getJSONArray("msg"), result.getInteger("count"), page, size);
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDeviceInventoryRecordListWithUserId)
    @ApiOperation(value = "获取设备列表and补货记录夹带userId", notes = "获取设备列表and补货记录")
    public PageEnvelop getDeviceInventoryRecordListWithUserId(
                                               @ApiParam(name = "userId", value = "用户id", required = true)
                                               @RequestParam(value = "userId") String userId,
                                               @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.getDeviceInventoryRecordListWithUserId(userId, page, size);
        return success(result.getJSONArray("msg"), result.getInteger("count"), page, size);
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getInitDeviceByPage)
    @ApiOperation(value = "获取初始化设备分页列表", notes = "获取初始化设备分页列表")
    public PageEnvelop getInitDeviceByPage(@ApiParam(name = "content", value = "搜索内容")
@ -584,8 +600,10 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "drugId", value = "药品id", required = true)
            @RequestParam(value = "drugId", required = true) String drugId,
            @ApiParam(name = "qty", value = "库存", required = true)
            @RequestParam(value = "qty", required = true) String qty) throws Exception {
        return success(deviceService.updateMediicinecabineInventoryById(id, drugId, qty));
            @RequestParam(value = "qty", required = true) String qty,
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId", required = true) String userId) throws Exception {
        return success(deviceService.updateMediicinecabineInventoryById(id, drugId, qty, userId));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.selectMediicinecabineInventoryById)
@ -616,8 +634,10 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "cargoCapacity", value = "容量", required = false)
            @RequestParam(value = "cargoCapacity", required = false) String cargoCapacity,
            @ApiParam(name = "status", value = "下架状态0", required = false)
            @RequestParam(value = "status", required = false) String status) throws Exception {
        return success(deviceService.updateMediicinecabineInventoryInfoById(id, qty, cargoCapacity, status));
            @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId) throws Exception {
        return success(deviceService.updateMediicinecabineInventoryInfoById(id, qty, cargoCapacity, status, userId));
    }

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

@ -179,7 +179,7 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        String conditionSql = "";
        String belongCommunitys = "";
        String sql = "";
        //获取社区id,串
        //获取社区code,串
        {
            //市管理员
            if ("saasAdmin".equals(role.getCode())) {

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockOutService.java

@ -110,6 +110,7 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
            Mediicinestockoutdetail mediicinestockoutdetail = new Mediicinestockoutdetail();
            mediicinestockoutdetail.setIdStockOut(mediicinestockout.getId());
            mediicinestockoutdetail.setDrugCode(mediicinedrugs.getDrugCode());
            mediicinestockoutdetail.setDrugName(mediicinedrugs.getDrugName());
            mediicinestockoutdetail.setDrugId(mediicinedrugs.getId());
            mediicinestockoutdetail.setOrgCode(mediicinedrugs.getOrgCode());
            mediicinestockoutdetail.setQuantity(drug.getQty().toString());

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

@ -52,6 +52,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    @Autowired
    private MediicinecabinetInventoryDao inventoryDao;
    @Autowired
    private MedicineDrugInventoryRecordDao inventoryRecordDao;
    @Autowired
    MedicineServive medicineServive;
@ -1153,6 +1156,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("device",device);
        //1补货,2换货,3上架,4下架
        jsonObject.put("inventoryList",inventoryRecordDao.findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(device.getId(), device.getEquNum(),"1"));
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",jsonObject);
        return result;
@ -1976,6 +1981,202 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    public JSONObject getDeviceInventoryRecordListWithUserId(String userId, int page, int size) throws Exception {
        JSONObject result = new JSONObject();
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        List<Map<String, Object>> deviceList = null;
        //查询控制语句
        String conditionSql = "";
        if ("replenisher".equals(role.getCode())) {
            //补货员所分配的设备
            String deviceIds = "";
            {
                String sql = "SELECT\n" +
                        "\tdevice_id\n" +
                        "FROM\n" +
                        "\tt_mediicine_device_user\n" +
                        "WHERE\n" +
                        "\tuser_id = '" + userId +"'\n" +
                        "AND del = 1";
                //设备列表
                List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
                for (Map<String, Object> stringObjectMap : list) {
                    if (stringObjectMap.get("device_id") != null && !StringUtils.isEmpty(stringObjectMap.get("device_id").toString())) {
                        if (StringUtils.isEmpty(deviceIds)) {
                            deviceIds += stringObjectMap.get("device_id").toString();
                        } else {
                            deviceIds += "," +  stringObjectMap.get("device_id").toString();
                        }
                    }
                }
            }
            //模拟补货员未绑定设备
//            deviceIds = "";
            conditionSql  = "AND ',"+ deviceIds +",' LIKE CONCAT('%,',t.id,',%')\n";
        } else {
            String belongCommunitys = "";
            String tempSql = "";
            //获取管理员所在社区id字符串
            {
                //市管理员
                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 (StringUtils.isEmpty(belongCommunitys)) {
                            belongCommunitys += stringObjectMap.get("community").toString();
                        } else {
                            belongCommunitys += "," +  stringObjectMap.get("community").toString();
                        }
                    }
                }
            }
            if (!StringUtils.isEmpty(belongCommunitys)) {
                conditionSql += "AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
            }
        }
        String sql = "";
        {
            sql += "SELECT\n" +
                    "    t.id AS id,\n" +
                    "    t.belong_community AS belongCommunity,\n" +
                    "    t.community AS community,\n" +
                    "    t.del AS del,\n" +
                    "    t.delivery_address AS deliveryAddress,\n" +
                    "    t.detail_address AS detailAddress,\n" +
                    "    t.equ_area AS equArea,\n" +
                    "    t.equ_class AS equClass,\n" +
                    "    t.equ_info AS equInfo,\n" +
                    "    t.equ_name AS equName,\n" +
                    "    t.equ_num AS equNum,\n" +
                    "    t.equ_type AS equType,\n" +
                    "    t.fbelong_community AS fbelongCommunity,\n" +
                    "    t.machine_code AS machineCode,\n" +
                    "    t.network_status AS networkStatus,\n" +
                    "    t.poweron_test AS poweronTest,\n" +
                    "    t.reg_date AS regDate,\n" +
                    "    t.sale_status AS saleStatus,\n" +
                    "    t.signalintensity AS signalintensity,\n" +
                    "    t.upgr_adesit AS upgrAdesit,\n" +
                    "    t.`status` AS `status`,\n" +
                    "    t.card_status AS cardStatus,\n" +
                    "    t.operator AS operator,\n" +
                    "    t.pack_age AS packAge,\n" +
                    "    t.usage_flow AS usageFlow,\n" +
                    "    t.flow AS flow,\n" +
                    "    t.create_time AS createTime,\n" +
                    "    t.create_user AS createUser,\n" +
                    "    t.create_user_name AS createUserName,\n" +
                    "    t.update_time AS updateTime,\n" +
                    "    t.update_user AS updateUser,\n" +
                    "    t.update_user_name AS updateUserName,\n" +
                    "    t.aisles AS aisles,\n" +
                    "    t.capacity AS capacity,\n" +
                    "    t.ratio AS ratio,\n" +
                    "    t.cargo_capacity AS cargoCapacity,\n" +
                    "    t.layer AS layer,\n" +
                    "    t.wayer AS wayer\n" +
                    "FROM\n" +
                    "    t_mediicine_device AS t\n" +
                    "WHERE 1=1 AND t.del = 1\n";
        }
        conditionSql += "AND t.belong_community IS NOT NULL\n";
        sql = sql + conditionSql;
        deviceList = hibenateUtils.createSQLQuery(sql, page, size);
        Map<String, String> equTypeMap = new HashMap<>();
        equTypeMap.put("1", "测试类型1");
        equTypeMap.put("2", "测试类型2");
        equTypeMap.put("3", "测试类型3");
        for (Map<String, Object> stringObjectMap : deviceList) {
            if(!StringUtils.isEmpty(stringObjectMap.get("equType"))){
                stringObjectMap.put("equTypeName", equTypeMap.get(stringObjectMap.get("equType")));
            }
            if(!StringUtils.isEmpty(stringObjectMap.get("networkStatus"))){
                if ("1".equals(stringObjectMap.get("networkStatus").toString())) {
                    stringObjectMap.put("networkStatusName", "在线");
                }
                if ("0".equals(stringObjectMap.get("networkStatus").toString())) {
                    stringObjectMap.put("networkStatusName", "离线");
                }
            }
            if(!StringUtils.isEmpty(stringObjectMap.get("saleStatus"))){
                if ("1".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "在售");
                }
                if ("2".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "停售");
                }
                if ("3".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "故障");
                }
            }
            if(!StringUtils.isEmpty(stringObjectMap.get("cardStatus"))){
                if ("1".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "正常");
                }
                if ("2".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "到期");
                }
                if ("3".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "未知");
                }
            }
            stringObjectMap.put("children",
                    inventoryRecordDao.findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(
                            stringObjectMap.get("id").toString(),
                            stringObjectMap.get("equNum").toString(), "1"));
        }
        String countSql = " select " +
                "     COUNT(DISTINCT (t.id)) as count " +
                "   from " +
                "     t_mediicine_device t " +
                "  where " +
                "  1=1  and t.del = 1  " +
                conditionSql;
        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
        result.put("count", count);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(deviceList));
        return result;
    }
    /**
     * 获取初始化设备列表
     * @param content
@ -2773,14 +2974,44 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     * @return
     * @throws Exception
     */
    public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty) throws Exception {
    @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){
            throw new Exception("不存在改货道!");
        }
        //记录补货or换货or上架(上货)信息
        //上货
        MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
        inventoryRecord.setDeviceId(inventory.getIdDevice());
        inventoryRecord.setEquNum(inventory.getEquNum());
        inventoryRecord.setOldDrugId(inventory.getDrugId());
        inventoryRecord.setDrugId(drugId);
        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);
        //补货
        if (inventory.getDrugId() != null && !StringUtils.isEmpty(inventory.getDrugId()) && drugId.equals(inventory.getDrugId())) {
            inventoryRecord.setType("1");
        }
        //换货
        if (inventory.getDrugId() != null && !StringUtils.isEmpty(inventory.getDrugId()) && !drugId.equals(inventory.getDrugId())) {
            inventoryRecord.setType("2");
        }
        //上架(上货)
        if (inventory.getDrugId() == null && StringUtils.isEmpty(inventory.getDrugId())) {
            inventoryRecord.setType("3");
        }
        inventoryRecordDao.save(inventoryRecord);
        Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId);
        inventory.setUpdateTime(new Date());
        inventory.setDrugCode(mediicinedrugs.getDrugCode());
        inventory.setOrgCode(mediicinedrugs.getOrgCode());
        inventory.setDrugName(mediicinedrugs.getDrugName());
        inventory.setPrice(mediicinedrugs.getPrice()+"");
        inventory.setSku(mediicinedrugs.getDrugSku());
@ -2814,9 +3045,24 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     * @return
     * @throws Exception
     */
    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status) throws Exception {
    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception {
        MediicinecabinetInventory inventory =  inventoryDao.findOne(id);
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
            //有药品时的补货
            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())) {
                inventory.setCargoCapacity(qty);
@ -2832,6 +3078,20 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                inventory.setQty("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());
        return inventoryDao.save(inventory);