Browse Source

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

chenjiasheng 3 years ago
parent
commit
c0effcfb64
15 changed files with 1867 additions and 71 deletions
  1. 44 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MediicineDeviceUser.java
  2. 14 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/Mediicinestockout.java
  3. 77 0
      common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/OutDO.java
  4. 36 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java
  5. 10 0
      svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicineDeviceUserDao.java
  6. 82 3
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java
  7. 48 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineOutEndpoint.java
  8. 45 4
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineUserEndpoint.java
  9. 3 3
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineDrugsService.java
  10. 96 9
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineOrderService.java
  11. 103 7
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockOutService.java
  12. 4 4
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockUpService.java
  13. 1026 0
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineUserService.java
  14. 21 21
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineWarrayService.java
  15. 258 20
      svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

+ 44 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MediicineDeviceUser.java

@ -0,0 +1,44 @@
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_mediicine_device_user")
public class MediicineDeviceUser extends UuidIdentityEntityWithOperator implements Serializable {
    private String deviceId;
    private String userId;
    private String del;
    public String getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getDel() {
        return del;
    }
    public void setDel(String del) {
        this.del = del;
    }
}

+ 14 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/Mediicinestockout.java

@ -79,6 +79,12 @@ public class Mediicinestockout extends UuidIdentityEntityWithOperator implements
     */
    private String receiveState;
    /**
     * 备货单号
     */
    private String upNum;
    public Mediicinestockout() {
    }
@ -185,4 +191,12 @@ public class Mediicinestockout extends UuidIdentityEntityWithOperator implements
    public void setReceiveState(String receiveState) {
        this.receiveState = receiveState;
    }
    public String getUpNum() {
        return upNum;
    }
    public void setUpNum(String upNum) {
        this.upNum = upNum;
    }
}

+ 77 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/OutDO.java

@ -0,0 +1,77 @@
package com.yihu.jw.entity.a1entity;
import java.io.Serializable;
import java.util.List;
public class OutDO implements Serializable {
    /**
     * 备货单id
     */
    private String upId;
    /**
     * 备注
     */
    private String remark;
    /**
     * 设备
     */
    private String deviceId;
    /**
     * 补货员
     */
    private String replenishEr;
    /**
     * 名称
     */
    private List<DrugDO> drugs;
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    public String getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }
    public String getReplenishEr() {
        return replenishEr;
    }
    public void setReplenishEr(String replenishEr) {
        this.replenishEr = replenishEr;
    }
    public List<DrugDO> getDrugs() {
        return drugs;
    }
    public void setDrugs(List<DrugDO> drugs) {
        this.drugs = drugs;
    }
    public String getUpId() {
        return upId;
    }
    public void setUpId(String upId) {
        this.upId = upId;
    }
}

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

@ -42,6 +42,34 @@ public class BaseRequestMapping {
        public static final String resetDoctorPwd  = "/resetDoctorPwd";
    }
    public static class BaseUser extends Basic {
        public static final String PREFIX  = "/baseUser";
        public static final String DOCINFO  = "/docInfo";
        public static final String CREATE  = "/create";
        public static final String createUser  = "/createUser";
        public static final String getUserDetailListById  = "/getUserDetailListById";
        public static final String getUserDetailById  = "/getUserDetailById";
        public static final String getRecordDetailListById  = "/getRecordDetailListById";
        public static final String getOrgListByTown  = "/getOrgListByTown";
        public static final String enableOrDis  = "/enableOrDis";
        public static final String docFullInfo  = "/docFullInfo";
        public static final String allotDevice  = "/allotDevice";
        public static final String getRecordByPage  = "/getRecordByPage";
        public static final String docOrgDutyTreeInfo  = "/docOrgDutyTreeInfo";
        public static final String docOrgDeptTreeInfo  = "/docOrgDeptTreeInfo";
        public static final String getDoctorListByDept  = "/getDoctorListByDept";
        public static final String DOCTOR_INFO_IMPORT  = "/baseDoctorInfoImport";
        public static final String findIncentive  = "/findIncentive";
        public static final String findIncentiveById  = "/findIncentiveById";
        public static final String deleteIncentiveById  = "/deleteIncentiveById";
        public static final String saveIncentiveById  = "/saveIncentiveById";
        public static final String saveDoctorIncentive  = "/saveDoctorIncentive";
        public static final String findDoctorIncentive  = "/findDoctorIncentive";
        public static final String findDoctorOtherIncentive  = "/findDoctorOtherIncentive";
        public static final String removeIncentive  = "/removeIncentive";
        public static final String resetDoctorPwd  = "/resetDoctorPwd";
    }
    /**
     * 备货单  BaseSensitive
@ -82,8 +110,11 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/baseOut";
        public static final String DOCINFO  = "/docInfo";
        public static final String CREATE  = "/create";
        public static final String CREATEUP  = "/createUp";
        public static final String changeReceiveState  = "/changeReceiveState";
        public static final String changeMoreReceiveState  = "/changeMoreReceiveState";
        public static final String getOutDetailListById  = "/getOutDetailListById";
        public static final String getOutDetailById  = "/getOutDetailById";
        public static final String getOrgListByTown  = "/getOrgListByTown";
        public static final String enableOrDis  = "/enableOrDis";
        public static final String docFullInfo  = "/docFullInfo";
@ -137,10 +168,15 @@ 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 updateCommunity  = "/updateCommunity";
        public static final String updateAddressInfo  = "/updateAddressInfo";
        public static final String UPDATESTATUS  = "/updateStatus";
        public static final String UPDATESALESTATUS  = "/updateSaleStatus";
        public static final String getDeviceListByUserId  = "/getDeviceListByUserId";
        public static final String getUserListByDeviceId  = "/getUserListByDeviceId";
        public static final String getOutOfStockDeviceList  = "/getOutOfStockDeviceList";
        public static final String getDetialOutOfStock  = "/getDetialOutOfStock";
        public static final String getDevInventory  = "/getDevInventory";
        public static final String countall  = "/countall";
        public static final String countOnline  = "/countOnline";
        public static final String getDevicesByMoreContent  = "/getDevicesByMoreContent";

+ 10 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicineDeviceUserDao.java

@ -0,0 +1,10 @@
package com.yihu.jw.base.dao.a2dao;
import com.yihu.jw.entity.a1entity.MediicineDeviceUser;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface MediicineDeviceUserDao extends PagingAndSortingRepository<MediicineDeviceUser, String> {
}

+ 82 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -42,7 +42,7 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = BaseRequestMapping.BaseDevice.CREATE)
    @ApiOperation(value = "新增药品信息")
    @ApiOperation(value = "新增设备信息")
    public Envelop create(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam String jsonData) throws Exception {
@ -65,7 +65,7 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.UPDATE)
    @ApiOperation(value = "更新药品信息")
    @ApiOperation(value = "更新设备信息")
    public Envelop update(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam String jsonData) throws Exception {
@ -78,8 +78,73 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.updateAddressInfo)
    @ApiOperation(value = "设备分配投放地址")
    public Envelop updateAddressInfo(
            @ApiParam(name = "deviceId", value = "设备Id", required = true)
            @RequestParam(value = "deviceId", required = true) String deviceId,
            @ApiParam(name = "deliveryAddress", value = "投放地址", required = true)
            @RequestParam(value = "deliveryAddress", required = true) String deliveryAddress) throws Exception {
        String str = deviceService.updateDeviceAddress(deviceId, deliveryAddress);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.updateCommunity)
    @ApiOperation(value = "设备分配社区")
    public Envelop updateAddressInfo(
            @ApiParam(name = "deviceId", value = "设备Id", required = true)
            @RequestParam(value = "deviceId", required = true) String deviceId,
            @ApiParam(name = "belongCommunity", value = "所属社区id", required = true)
            @RequestParam(value = "belongCommunity", required = true) String belongCommunity,
            @ApiParam(name = "community", value = "社区中心名称", required = true)
            @RequestParam(value = "community", required = true) String community) throws Exception {
        String str = deviceService.updateDeviceCommunity(deviceId, belongCommunity, community);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.UPDATESTATUS)
    @ApiOperation(value = "更新设备状态")
    public Envelop updateStatus(
            @ApiParam(name = "deviceId", value = "设备Id", required = true)
            @RequestParam(value = "deviceId", required = true) String deviceId,
            @ApiParam(name = "status", value = "设备状态", required = true)
            @RequestParam(value = "status", required = true) String status) throws Exception {
        String str = deviceService.updateDeviceStatus(deviceId, status);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.UPDATESALESTATUS)
    @ApiOperation(value = "更新设备销售状态")
    public Envelop updateSaleStatus(
            @ApiParam(name = "deviceId", value = "设备Id", required = true)
            @RequestParam(value = "deviceId", required = true) String deviceId,
            @ApiParam(name = "saleStatus", value = "设备销售状态", required = true)
            @RequestParam(value = "saleStatus", required = true) String saleStatus) throws Exception {
        String str = deviceService.updateDeviceSaleStatus(deviceId, saleStatus);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.docFullInfo)
    @ApiOperation(value = "获取药品信息基础信息列表")
    @ApiOperation(value = "获取设备信息基础信息列表")
    public PageEnvelop getDeviceFullInfolist(
            @ApiParam(name = "content", value = "搜索内容")
            @RequestParam(value = "content", required = false) String content,
@ -225,4 +290,18 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
        return success(jsonObject.getJSONArray("msg"));
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDevInventory)
    @ApiOperation(value = "获取设备库存")
    public Envelop getDevInventory(
            @ApiParam(name = "belongCommunity", value = "社区")
            @RequestParam(value = "belongCommunity", required = false) String belongCommunity,
            @ApiParam(name = "deviceId", value = "所属设备")
            @RequestParam(value = "deviceId", required = false) String deviceId,
            @ApiParam(name = "netStatus", value = "网络状态")
            @RequestParam(value = "netStatus", required = false) String netStatus) throws Exception {
        JSONObject jsonObject = deviceService.getDevInventory(belongCommunity, deviceId, netStatus);
        return success(jsonObject.getJSONArray("msg"));
    }
}

+ 48 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineOutEndpoint.java

@ -29,6 +29,9 @@ public class MedicineOutEndpoint extends EnvelopRestEndpoint {
    @Autowired
    MedicineStockOutService stockoutService;
    @Autowired
    MedicineStockOutService outDetailService;
    @Autowired
    private MedicineOrderService orderservice;
    @Autowired
@ -38,6 +41,21 @@ public class MedicineOutEndpoint extends EnvelopRestEndpoint {
    @Value("${wechat.id}")
    private String wechatId;
    @PostMapping(value = BaseRequestMapping.BaseOut.CREATEUP)
    @ApiOperation(value = "生成出库单信息")
    public Envelop createUp(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam String jsonData) throws Exception {
        JSONObject jsonObject = null;
        String str = stockoutService.createDetailOut(jsonData);
        jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @PostMapping(value = BaseRequestMapping.BaseOut.CREATE)
    @ApiOperation(value = "新增出货单信息")
    public Envelop create(
@ -90,6 +108,22 @@ public class MedicineOutEndpoint extends EnvelopRestEndpoint {
        return success(jsonObject.getString("response"));
    }
    @PostMapping(value = BaseRequestMapping.BaseOut.changeMoreReceiveState)
    @ApiOperation(value = "修改领取状态")
    public Envelop changeMoreReceiveState(
            @ApiParam(name = "outIds", value = "出库单id")
            @RequestParam(value = "outIds", required = true) String outIds,
            @ApiParam(name = "state", value = "需要修改的状态")
            @RequestParam(value = "state", required = true) String state) throws Exception {
        String str = stockoutService.changeMoreReceiveState(outIds, state);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
    @GetMapping(value = BaseRequestMapping.BaseOut.docFullInfo)
    @ApiOperation(value = "获取出货单信息基础信息列表")
    public PageEnvelop getOutFullInfolist(
@ -118,6 +152,20 @@ public class MedicineOutEndpoint extends EnvelopRestEndpoint {
        return success(baseDoctors, Mediicinestockoutdetail.class);
    }
    @GetMapping(value = BaseRequestMapping.BaseOut.getOutDetailById)
    @ApiOperation(value = "出货单id获取出货详细信息" , notes="获取药品出货详细信息")
    public Envelop getUpDetailById(
            @ApiParam(name = "idOut", value = "出货单id", required = true)
            @RequestParam(value = "idOut") String idOut) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject jsonObject = outDetailService.getOutDetailById(idOut);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getJSONObject("msg"));
    }
    @ApiOperation(value = "读出货单列表", notes="参数未添加通过数据区域查询获取")
    @GetMapping("/list")
    public List<Mediicinestockout> list(){

+ 45 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineUserEndpoint.java

@ -1,25 +1,66 @@
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.MedicineOrderService;
import com.yihu.jw.base.service.a3service.MedicineStockOutService;
import com.yihu.jw.base.service.a3service.MedicineUserService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@Api(description = "用户管理")
@RestController
@RequestMapping("/MedicineUserEndpoint")
public class MedicineUserEndpoint {
@RequestMapping(value = BaseRequestMapping.BaseUser.PREFIX)
@Api(value = "用户管理", description = "用户(补货员)管理服务接口", tags = {"MedicineUser - 备货单管理服务接口"})
public class MedicineUserEndpoint extends EnvelopRestEndpoint {
    @Autowired
    MedicineStockOutService stockoutService;
    MedicineUserService userService;
    @Autowired
    private MedicineOrderService orderservice;
    @Autowired
    private ObjectMapper objectMapper;
    @Value("${wechat.id}")
    private String wechatId;
    @GetMapping(value = BaseRequestMapping.BaseUser.docFullInfo)
    @ApiOperation(value = "获取补货员信息基础信息列表")
    public PageEnvelop getDeviceFullInfolist(
            @ApiParam(name = "content", value = "搜索内容")
            @RequestParam(value = "content", required = false) String content,
            @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 = userService.queryUserListFullInfo(content, page, size, wechatId);
        return success(result.getJSONArray("msg"), result.getInteger("count"), page, size);
    }
    @GetMapping(value = BaseRequestMapping.BaseUser.allotDevice)
    @ApiOperation(value = "分配设备")
    public Envelop allotDevice(
            @ApiParam(name = "userIds", value = "补货员ids,多个用逗号隔开")
            @RequestParam(value = "userIds", required = true) String userIds,
            @ApiParam(name = "deviceIds", value = "设备ids,多个用英文逗号隔开", required = true)
            @RequestParam(value = "deviceIds") String deviceIds) throws Exception {
        JSONObject result = userService.allotDevice(userIds, deviceIds);
        return success(result.getString("response"));
    }
//---------众建平台,无法转移,
//    @GetMapping("getorderlist")

+ 3 - 3
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineDrugsService.java

@ -226,16 +226,16 @@ public class MedicineDrugsService extends BaseJpaService<Mediicinedrugs, Mediici
        String conditionSql = "";
        if (!StringUtils.isEmpty(state)){
            conditionSql += " and t.state = " + state;
            conditionSql += " and t.state = '" + state + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.drug_code, t.drug_bar_code, drug_name, t.drug_short_code) like '%"+content+"%'";
        }
        if (!StringUtils.isEmpty(drugClass)){
            conditionSql += " and t.drug_class_code = " + drugClass;
            conditionSql += " and t.drug_class_code = '" + drugClass + "'";
        }
        if (!StringUtils.isEmpty(drugType)){
            conditionSql += " and t.drug_type_code = " + drugType;
            conditionSql += " and t.drug_type_code = '" + drugType + "'";
        }
        if (!StringUtils.isEmpty(lowVolume)){
            conditionSql += " and t.sale_volume >= " + lowVolume;

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

@ -7,10 +7,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.a2dao.*;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.JavaBeanUtils;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import com.yihu.jw.entity.a1entity.Mediicineorder;
import com.yihu.jw.entity.a1entity.Mediicineorderdetail;
import com.yihu.jw.entity.a1entity.Mediicinestockoutdetail;
import com.yihu.jw.entity.a1entity.*;
import com.yihu.jw.entity.patient.Message;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
@ -40,6 +38,9 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
    @Autowired
    private MediicinestockoutdetailDao stockoutdetailDao;
    @Autowired
    private MediicineDeviceDao deviceDao;
    @Autowired
    private ObjectMapper objectMapper;
@ -190,10 +191,10 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        String conditionSql = "";
        if (!StringUtils.isEmpty(orderNum)){
            conditionSql += " and t.order_num = " + orderNum;
            conditionSql += " and t.order_num = '" + orderNum + "'";
        }
        if (!StringUtils.isEmpty(equNum)){
            conditionSql += " and t.equ_num = " + equNum;
            conditionSql += " and t.equ_num = '" + equNum + "'";
        }
        if (!StringUtils.isEmpty(contact)){
            conditionSql += " and t.contact like '%" + contact + "%'";
@ -205,13 +206,13 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
                    " AND t.prescribe_time <= '" + endTime + "'";
        }
        if (!StringUtils.isEmpty(sellState)){
            conditionSql += " and t.sell_state = " + sellState;
            conditionSql += " and t.sell_state = '" + sellState + "'";
        }
        if (!StringUtils.isEmpty(orderState)){
            conditionSql += " and t.order_state = " + orderState;
            conditionSql += " and t.order_state = '" + orderState + "'";
        }
        if (!StringUtils.isEmpty(dispensingWindow)){
            conditionSql += " and t.dispensing_window = " + dispensingWindow;
            conditionSql += " and t.dispensing_window = '" + dispensingWindow + "'";
        }
        sql = sql + conditionSql;
@ -311,4 +312,90 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        return stockoutdetailDao.getoutdetailbyorderid(idorder);
    }
    /**
     * 检查设备订单是否有药品
     * @param deviceId
     * @param orderId
     * @return
     */
    public JSONObject checkOrder(String deviceId, String orderId) {
        JSONObject result = new JSONObject();
        if (deviceId == null || orderId == null || StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(orderId)) {
            result.put("msg","parameter deviceId and orderId is null or empty");
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        String sql = "SELECT\n" +
                "    t.id AS id,\n" +
                "    t.batch_num AS batchNum,\n" +
                "    t.cargo_info AS cargoInfo,\n" +
                "    t.drug_code AS drugCode,\n" +
                "    t.id_order AS idOrder,\n" +
                "    t.med_info AS medInfo,\n" +
                "    t.order_no AS orderNo,\n" +
                "    t.price AS price,\n" +
                "    t.quantity AS quantity,\n" +
                "    t.address AS address,\n" +
                "    t.age AS age,\n" +
                "    t.amount AS amount,\n" +
                "    t.contact AS contact,\n" +
                "    t.dispensing_window AS dispensingWindow,\n" +
                "    t.equ_address AS equAddress,\n" +
                "    t.equ_num AS equNum,\n" +
                "    t.goods_name AS goodsName,\n" +
                "    t.goods_total_amount AS goodsTotalAmount,\n" +
                "    t.id_num AS idNum,\n" +
                "    t.info_access AS infoAccess,\n" +
                "    t.`name` AS `name`,\n" +
                "    t.net_sale_amount AS netSaleAmount,\n" +
                "    t.order_amount AS orderAmount,\n" +
                "    t.order_num AS orderNum,\n" +
                "    t.order_source AS orderSource,\n" +
                "    t.order_state AS orderState,\n" +
                "    t.order_type AS orderType,\n" +
                "    t.pay_time AS payTime,\n" +
                "    t.pick_up_num AS pickUpNum,\n" +
                "    t.prescribe_num AS prescribeNum,\n" +
                "    t.prescribe_time AS prescribeTime,\n" +
                "    t.sell_state AS sellState,\n" +
                "    t.sex AS sex,\n" +
                "    t.shipping_equ AS shippingEqu,\n" +
                "    t.shipping_time AS shippingTime,\n" +
                "    t.socialinsurpayment AS socialinsurpayment,\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.drug_sku AS drugSku,\n" +
                "    t.drug_num AS drugNum,\n" +
                "    t.specif AS specif,\n" +
                "    t.use_num AS useNum,\n" +
                "    t.use_way AS useWay,\n" +
                "    t.use_rate AS useRate,\n" +
                "    t.use_dose AS useDose,\n" +
                "    t.unit AS unit,\n" +
                "    t.use_way_add AS useWayAdd,\n" +
                "    t.manufactor AS manufactor\n" +
                "FROM\n" +
                "    t_mediicine_order_detail AS t\n" +
                "WHERE t.id_order = '" + orderId + "'";
        List<Map<String,Object>> list = null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            String secondSql = "SELECT * FROM t_mediicinecabinet_inventory where barcode = '" + stringObjectMap.get("drugId") + "' AND id_device  = '" + deviceId + "'";
        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        result.put("response", ConstantUtils.SUCCESS);
        return result;
    }
}

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

@ -4,14 +4,10 @@ package com.yihu.jw.base.service.a3service;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.a2dao.MediicineorderDao;
import com.yihu.jw.base.dao.a2dao.MediicinestockoutDao;
import com.yihu.jw.base.dao.a2dao.MediicinestockoutdetailDao;
import com.yihu.jw.base.dao.a2dao.*;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.JavaBeanUtils;
import com.yihu.jw.entity.a1entity.Mediicineorder;
import com.yihu.jw.entity.a1entity.Mediicinestockout;
import com.yihu.jw.entity.a1entity.Mediicinestockoutdetail;
import com.yihu.jw.entity.a1entity.*;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
@ -36,12 +32,73 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
    private MediicinestockoutDao outDao;
    @Autowired
    private MediicinestockoutdetailDao outdetailDao;
    @Autowired
    private MediicineDeviceDao deviceDao;
    @Autowired
    private MediicinedrugsDao drugsDao;
    @Autowired
    private MediicinestockupDao upDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Transactional(rollbackFor = Exception.class)
    public String createDetailOut(String jsonData) {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(jsonData)){
            result.put("msg","jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        JSONObject out = JSONObject.parseObject(jsonData);
        OutDO obj = JSONObject.parseObject(out.getJSONObject("obj").toJSONString(), OutDO.class);
        if (obj == null ) {
            result.put("msg", "obj is null!");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        //需要补货的设备
        Mediicinedevice mediicinedevice = deviceDao.findOne(obj.getDeviceId());
        Mediicinestockout mediicinestockout = new Mediicinestockout();
        mediicinestockout.setReceiveState("1");
        mediicinestockout.setRemark(obj.getRemark());
        mediicinestockout.setReplenishEr(obj.getReplenishEr());
        mediicinestockout.setReplenishEqu(mediicinedevice.getId());
        mediicinestockout.setDocNum(String.valueOf(System.currentTimeMillis()));
        mediicinestockout.setDocTime(new Date());
        mediicinestockout.setCommunity(mediicinedevice.getBelongCommunity());
        mediicinestockout.setAddress(mediicinedevice.getDetailAddress());
        mediicinestockout.setReplenishCate("药品");
        mediicinestockout.setState("1");
        mediicinestockout.setReplenishInventory(obj.getDrugs().stream().reduce(0, (sum, p) -> sum += p.getQty() , Integer::sum).toString());
        //备货单号
        mediicinestockout.setUpNum(upDao.findOne(obj.getUpId()).getDocNum());
        outDao.save(mediicinestockout);
        for (DrugDO drug : obj.getDrugs()) {
            Mediicinedrugs mediicinedrugs = drugsDao.findOne(drug.getDrugId());
            Mediicinestockoutdetail mediicinestockoutdetail = new Mediicinestockoutdetail();
            mediicinestockoutdetail.setIdStockOut(mediicinestockout.getId());
            mediicinestockoutdetail.setDrugCode(mediicinedrugs.getDrugCode());
            mediicinestockoutdetail.setQuantity(drug.getQty().toString());
            mediicinestockoutdetail.setProductPic(mediicinedrugs.getPic());
            outdetailDao.save(mediicinestockoutdetail);
        }
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",ConstantUtils.SUCCESS);
        return result.toJSONString();
    }
    /**
     * 新增药品信息
     * @param jsonData
@ -156,6 +213,29 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
    }
    public String changeMoreReceiveState(String outIds,String state){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(outIds) || StringUtils.isEmpty(state)){
            result.put("msg","parameter outIds or state is null");
            result.put("response",ConstantUtils.FAIL);
            return result.toJSONString();
        }
        String[] ids = outIds.split(",");
        for (String id : ids) {
            if (!StringUtils.isEmpty(id)) {
                Mediicinestockout mediicinestockout = outDao.findOne(id);
                if( null == mediicinestockout ){
                    continue;
                }
                mediicinestockout.setReceiveState(state);
                this.save(mediicinestockout);
            }
        }
        result.put("response",ConstantUtils.SUCCESS);
        return result.toJSONString();
    }
    //orderNum, equNum, contact, startTime, endTime, sellState, orderState, dispensingWindow
    public JSONObject queryOutListFullInfo(
                                             String startTime, String endTime, String replenishEr,
@ -193,7 +273,7 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
                    " AND t.doc_time <= '" + endTime + "'";
        }
        if (!StringUtils.isEmpty(replenishEr)){
            conditionSql += " and t.replenish_er = " + replenishEr;
            conditionSql += " and t.replenish_er = '" + replenishEr + "'";
        }
        if (!StringUtils.isEmpty(docNum)){
            conditionSql += " and t.doc_num like '%" + docNum + "%'";
@ -228,4 +308,20 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
    public List<Mediicinestockoutdetail> getoutdetail(String idstockout) {
        return   outdetailDao.getoutdetail(idstockout);
    }
    public JSONObject getOutDetailById(String idstockout) {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(idstockout)){
            result.put("msg","idstockout is null");
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("info", outDao.findOne(idstockout));
        jsonObject.put("list", outdetailDao.getoutdetail(idstockout));
        result.put("msg", jsonObject);
        result.put("response", ConstantUtils.SUCCESS);
        return result;
    }
}

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

@ -225,7 +225,7 @@ public class MedicineStockUpService extends BaseJpaService<Mediicinestockup, Med
            conditionSql += " and t.doc_num like '%" + replenishErAndTrackNum + "%'";
        }
        if (!StringUtils.isEmpty(community)){
            conditionSql += " and t.community = " + community;
            conditionSql += " and t.community = '" + community + "'";
        }
        sql = sql + conditionSql;
@ -307,10 +307,10 @@ public class MedicineStockUpService extends BaseJpaService<Mediicinestockup, Med
        String conditionSql = "";
        //社区
        if (!StringUtils.isEmpty(community)){
            conditionSql += " and t.community = " + community;
            conditionSql += " and t.community = '" + community + "'";
        }
        if (!StringUtils.isEmpty(equId)){
            conditionSql += " and t.replenish_equ = " + equId;
            conditionSql += " and t.replenish_equ = '" + equId + "'";
        }
        if (!StringUtils.isEmpty(equName)){
            conditionSql += " and tmd.equ_name like '%" + equName + "%'";
@ -370,7 +370,7 @@ public class MedicineStockUpService extends BaseJpaService<Mediicinestockup, Med
                "    t.update_user AS updateUser,\n" +
                "    t.update_user_name AS updateUserName\n" +
                "FROM\n" +
                "    t_mediicine_stockrecord_detail AS t where idstockup = " + idstockup;
                "    t_mediicine_stockrecord_detail AS t where idstockup = '" + idstockup + "'";
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));

+ 1026 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineUserService.java

@ -0,0 +1,1026 @@
package com.yihu.jw.base.service.a3service;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.a2dao.MediicineDeviceDao;
import com.yihu.jw.base.dao.a2dao.MediicineDeviceUserDao;
import com.yihu.jw.base.dao.a2dao.MediicineUserDao;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.JavaBeanUtils;
import com.yihu.jw.entity.a1entity.MediicineDeviceUser;
import com.yihu.jw.entity.a1entity.Mediicinedevice;
import com.yihu.jw.entity.a1entity.Mediicineuser;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
 * Created by Bing on 2021/9/23.
 */
@Service
public class MedicineUserService extends BaseJpaService<Mediicineuser, MediicineUserDao> {
    @Autowired
    private MediicineUserDao userDao;
    @Autowired
    private MediicineDeviceUserDao deviceUserDao;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private HibenateUtils hibenateUtils;
//    /**
//     * 新增设备
//     * @param jsonData
//     * @return
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public String createDevice(String jsonData) {
//
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(jsonData)){
//            result.put("msg","jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        JSONObject device = JSONObject.parseObject(jsonData);
//        if(null == device){
//            result.put("msg","parameter device of jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        //判断设备id是否存在
////        if(StringUtils.isEmpty(device.getString("id"))){
////            result.put("msg","parameter id for device is null when update device");
////            result.put("response", ConstantUtils.FAIL);
////            return result.toJSONString();
////        }
//        Mediicinedevice mediicinedevice = null;
//        try {
//            mediicinedevice = objectMapper.readValue(device.toJSONString(), Mediicinedevice.class);
//        } catch (IOException e) {
//            result.put("msg", "convert device jsonObject to BaseDoctorDO failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        } catch (Exception e) {
//            result.put("msg", "convert device birth failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        this.save(mediicinedevice);
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",mediicinedevice);
//        return result.toJSONString();
//    }
//    /**
//     * 修改设备
//     * @param jsonData
//     * @return
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public String updateDevice(String jsonData){
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(jsonData)){
//            result.put("msg","jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        JSONObject device = JSONObject.parseObject(jsonData);
//        if(null == device){
//            result.put("msg","parameter device of jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        String orgCode="";
//        //判断设备id是否存在
//        if(StringUtils.isEmpty(device.getString("id"))){
//            result.put("msg","parameter id for device is null when update device");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        Mediicinedevice mediicinedevice = null;
//        try {
//            mediicinedevice = objectMapper.readValue(device.toJSONString(), Mediicinedevice.class);
//        } catch (IOException e) {
//            result.put("msg", "convert device jsonObject to BaseDoctorDO failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        } catch (Exception e) {
//            result.put("msg", "convert device birth failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        this.save(mediicinedevice);
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",mediicinedevice);
//        return result.toJSONString();
//    }
//    @Transactional(rollbackFor = Exception.class)
//    public String updateDeviceCommunity(String deviceId, String communityId, String community){
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(communityId)){
//            result.put("msg","deviceId and communityId is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
//        if (mediicinedevice == null) {
//            result.put("msg","device doesn't exist");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        mediicinedevice.setBelongCommunity(communityId);
//        mediicinedevice.setCommunity(community);
//        this.save(mediicinedevice);
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",mediicinedevice);
//        return result.toJSONString();
//    }
//    @Transactional(rollbackFor = Exception.class)
//    public String updateDeviceAddress(String deviceId, String address){
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(address)){
//            result.put("msg","deviceId and address is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
//        if (mediicinedevice == null) {
//            result.put("msg","device doesn't exist");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        mediicinedevice.setDeliveryAddress(address);
//        this.save(mediicinedevice);
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",mediicinedevice);
//        return result.toJSONString();
//    }
    /**
     * 分页查询补货员信息
     * @param content
     * @param page
     * @param size
     * @param wechatId
     * @return
     * @throws Exception
     */
    public JSONObject queryUserListFullInfo(String content,int page, int size,String wechatId) throws Exception {
        JSONObject result = new JSONObject();
        String sql = "SELECT\n" +
                "    t.id AS id,\n" +
                "    t.account AS account,\n" +
                "    t.belong_community AS belongCommunity,\n" +
                "    t.bir_date AS birDate,\n" +
                "    t.confirm_password AS confirmPassword,\n" +
                "    t.contact_info AS contactInfo,\n" +
                "    t.`name` AS `name`,\n" +
                "    t.`password` AS `password`,\n" +
                "    t.res_med_cabinet AS resMedCabinet,\n" +
                "    t.res_pon_area AS resPonArea,\n" +
                "    t.role AS role,\n" +
                "    t.sex AS sex,\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" +
                "FROM\n" +
                "    t_mediicine_user AS t\n" +
                "WHERE\n" +
                "    1=1\n";
        String conditionSql = "";
        if (!StringUtils.isEmpty(content)){
            conditionSql += " AND CONCAT(t.account, t.`name`) like '%"+ content +"%'";
        }
        sql = sql + conditionSql;
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql,page,size);
        for (Map<String, Object> stringObjectMap : list) {
        }
        String countSql = " select " +
                "     COUNT(DISTINCT (t.id)) as count " +
                "   from " +
                "     t_mediicine_user t " +
                "  where " +
                "  1=1   " +
                conditionSql;
        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 userIds
     * @param deviceIds
     * @return
     * @throws Exception
     */
    public JSONObject allotDevice(String userIds, String deviceIds) throws Exception {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(userIds) && StringUtils.isEmpty(deviceIds)) {
            result.put("response", ConstantUtils.FAIL);
            return result;
        }
        //绑定设备
        for (String userId : userIds.split(",")) {
            if (!StringUtils.isEmpty(userId)) {
                //移除不绑定设备
                String sql = "SELECT\n" +
                        "\tt.id AS id,\n" +
                        "\tt.device_id AS deviceId,\n" +
                        "\tt.user_id AS userId,\n" +
                        "\tt.del AS del,\n" +
                        "\tt.create_time AS createTime,\n" +
                        "\tt.create_user AS createUser,\n" +
                        "\tt.create_user_name AS createUserName,\n" +
                        "\tt.update_time AS updateTime,\n" +
                        "\tt.update_user AS updateUser,\n" +
                        "\tt.update_user_name AS updateUserName\n" +
                        "FROM\n" +
                        "\tt_mediicine_device_user AS t\n" +
                        "WHERE\n" +
                        "    t.user_id = '" + userId + "'\n" +
                        "AND '," + deviceIds + ",' NOT LIKE CONCAT('%,',t.device_id,',%')";
                List<Map<String,Object>> list=null;
                list = hibenateUtils.createSQLQuery(sql);
                if (list != null && list.size() > 0) {
                    for (Map<String, Object> stringObjectMap : list) {
                        MediicineDeviceUser mediicineDeviceUser = deviceUserDao.findOne(stringObjectMap.get("id").toString());
                        mediicineDeviceUser.setDel("0");
                        deviceUserDao.save(mediicineDeviceUser);
                    }
                }
//                if (list != null && list.size() > 0) {
//                    for (MediicineDeviceUser deviceUser : list) {
//                        deviceUser.setDel("0");
//                        deviceUserDao.save(deviceUser);
//                    }
//                }
                for (String deviceId : deviceIds.split(",")) {
                    if (!StringUtils.isEmpty(deviceId)) {
                        String countSql = " select " +
                                "     COUNT(DISTINCT (t.id)) as count " +
                                "   from " +
                                "     t_mediicine_device_user t " +
                                "  where " +
                                "  1=1 AND t.del = 1 AND t.device_id = '" + deviceId + "' AND t.user_id = '" + userId + "'";
                        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
                        if (count > 0) {
                            continue;
                        }
                        MediicineDeviceUser deviceUser = new MediicineDeviceUser();
                        deviceUser.setDel("1");
                        deviceUser.setDeviceId(deviceId);
                        deviceUser.setUserId(userId);
                        deviceUserDao.save(deviceUser);
                    }
                }
            }
        }
        result.put("response", ConstantUtils.SUCCESS);
        return result;
    }
    public JSONObject getDevicesByMoreContent(String content, String equClass, String belongCommunity,
                                              String networkStatus, String saleStatus, String machineCode, String deviceType, String equArea, String del, String status,String deliveryAddress, String wechatId) throws Exception {
        JSONObject result = new JSONObject();
        String 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" +
                "FROM\n" +
                "    t_mediicine_device AS t where 1=1\n";
        String conditionSql = "";
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = '"+equClass + "'";
        }
        if (!StringUtils.isEmpty(belongCommunity)){
            conditionSql += " and t.belong_community = '" + belongCommunity + "'";
        }
        if (!StringUtils.isEmpty(networkStatus)){
            conditionSql += " and t.network_status = '" + networkStatus + "'";
        }
        if (!StringUtils.isEmpty(saleStatus)){
            conditionSql += " and t.sale_status = '" + saleStatus + "'";
        }
        if (!StringUtils.isEmpty(machineCode)){
            conditionSql += " and t.machine_code like  '%" + machineCode + "%'";
        }
        if (!StringUtils.isEmpty(deviceType)){
            conditionSql += " and t.equ_type = '"+deviceType + "'";
        }
        if (!StringUtils.isEmpty(equArea)){
            conditionSql += " and t.equ_area = '"+equArea + "'";
        }
        if (!StringUtils.isEmpty(del)){
            conditionSql += " and t.del = '"+del + "'";
        }
        if (!StringUtils.isEmpty(status)){
            conditionSql += " and t.`status` = '"+status + "'";
        }
        if (!StringUtils.isEmpty(deliveryAddress)){
            conditionSql += " and t.delivery_address = '"+deliveryAddress + "'";
        }
        sql = sql + conditionSql;
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            if(!StringUtils.isEmpty(stringObjectMap.get("status"))){
                if ("1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "在线");
                }
                if ("0".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "离线");
                }
                if ("-1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "异常");
                }
            }
        }
        String countSql = " select " +
                "     COUNT(DISTINCT (t.id)) as count " +
                "   from " +
                "     t_mediicine_device t " +
                "  where " +
                "  1=1   " +
                conditionSql;
        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
        for (Map<String,Object> map:list){
        }
        result.put("count", count);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        return result;
    }
    /**
     * 根据人员id,查询与之绑定的设备
     * @param userId
     * @return
     * @throws Exception
     */
    public JSONObject getDevices(String userId) throws Exception {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(userId)){
            result.put("msg","parameter userId is null ");
            result.put("response",ConstantUtils.FAIL);
            return result;
        }
        String 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" +
                "FROM\n" +
                "    t_mediicine_device AS t where\n";
//        String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and ',"+userId+",' LIKE CONCAT('%,',du.user_id,',%'))";
        String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and du.user_id = '" + userId + "'";
        sql = sql + conditionSql;
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            if(!StringUtils.isEmpty(stringObjectMap.get("status"))){
                if ("1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "在线");
                }
                if ("0".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "离线");
                }
                if ("-1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "异常");
                }
            }
        }
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        return result;
    }
    /**
     * 根据设备id,查询与之绑定的补货员
     * @param deviceId
     * @return
     * @throws Exception
     */
    public JSONObject getUsers(String deviceId) throws Exception {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId)){
            result.put("msg","parameter deviceId is null ");
            result.put("response",ConstantUtils.FAIL);
            return result;
        }
        String sql = "SELECT\n" +
                "    t.id AS id,\n" +
                "    t.account AS account,\n" +
                "    t.belong_community AS belongCommunity,\n" +
                "    t.bir_date AS birDate,\n" +
                "    t.confirm_password AS confirmPassword,\n" +
                "    t.contact_info AS contactInfo,\n" +
                "    t.`name` AS `name`,\n" +
                "    t.`password` AS `password`,\n" +
                "    t.res_med_cabinet AS resMedCabinet,\n" +
                "    t.res_pon_area AS resPonArea,\n" +
                "    t.role AS role,\n" +
                "    t.sex AS sex,\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" +
                "FROM\n" +
                "    t_mediicine_user AS t where\n";
//        String conditionSql = " t.id in (select du.user_id from t_mediicine_device_user du where del = 1 and ',"+deviceId+",' LIKE CONCAT('%,',du.device_id,',%'))";
        String conditionSql = " t.id in (select du.user_id from t_mediicine_device_user du where del = 1 and du.device_id = '" + deviceId + "'";
        sql = sql + conditionSql;
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
        }
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        return result;
    }
//    public JSONObject getOneDeviceInfo(String deviceId) throws Exception{
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(deviceId)){
//            result.put("msg","parameter deviceId is null ");
//            result.put("response",ConstantUtils.FAIL);
//            return result;
//        }
//        Mediicinedevice device = userDao.findOne(deviceId);
//        if(null == device){
//            result.put("msg","设备不存在:" + deviceId);
//            result.put("response",ConstantUtils.FAIL);
//            return result;
//        }
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("device",device);
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",jsonObject);
//        return result;
//    }
//    /**
//     * 获取设备总数
//     * @return
//     * @throws Exception
//     */
//    public JSONObject countAll() throws Exception{
//        JSONObject result = new JSONObject();
//
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("count",deviceDao.countAll());
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",jsonObject);
//        return result;
//    }
    /**
     * 获取设备总数
     * @return
     * @throws Exception
     */
    public  JSONObject countAll() throws Exception {
        JSONObject result = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        String sql = "select count(1) from t_mediicine_device a";
        int count = jdbcTemplate.queryForObject(sql,Integer.class);
        jsonObject.put("count", count);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg", jsonObject);
        return result;
    }
    //获取当前设备数量
//    public  long countAll() {
//        return deviceDao.countAll();
//    }
    /**
     * 获取当前设备数量
     * @return
     * @throws Exception
     */
    public JSONObject countOnline() throws Exception{
        JSONObject result = new JSONObject();
        String sql = "select count(1) from t_mediicine_device a where a.status = 1";
        int count = jdbcTemplate.queryForObject(sql,Integer.class);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count",count);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",jsonObject);
        return result;
    }
    //获取当前设备数量
//    public  long countOnline() {
//        return deviceDao.countOnline();
//    }
    public JSONObject saveDmMedicineDevice(String json) throws IOException {
        JSONObject result = new JSONObject();
//        MedicineDevice device = objectMapper.readValue(json,MedicineDevice.class);
//        Integer deviceType = device.getMedicineDeviceType();
//        String categoryCode = device.getCategoryCode();
//        String name = device.getName();
//        String model = device.getCategoryCode();
//        String brands = device.getBrands();
//        String photo =device.getPhoto();
//        String isMultiUser = device.getIsMultiUser();
//        if (null==deviceType||StringUtils.isBlank(categoryCode)||StringUtils.isBlank(name)||StringUtils.isBlank(model)||
//                StringUtils.isBlank(brands)||StringUtils.isBlank(photo)||StringUtils.isBlank(isMultiUser)){
//            result.put(ResponseContant.resultFlag,ResponseContant.fail);
//            result.put(ResponseContant.resultMsg,"数据数据错误,必填字段为空");
//            return result;
//        }
//        //判断型号是否重复
//        MedicineDevice deviceTmp = deviceDao.findByModel(device.getModel());
//        if (null!=deviceTmp){
//            if (null==device.getId()){
//                result.put(ResponseContant.resultFlag,ResponseContant.fail);
//                result.put(ResponseContant.resultMsg,"设备型号已存在");
//                return result;
//            }else if (deviceTmp.getId().longValue()!=device.getId().longValue()){//
//                result.put(ResponseContant.resultFlag,ResponseContant.fail);
//                result.put(ResponseContant.resultMsg,"设备型号已存在");
//                return result;
//            }
//        }
//        if (null==device.getId()){
//            device.setDel("1");
//        }
//        deviceDao.save(device);
//        result.put(ResponseContant.resultFlag,ResponseContant.success);
//        result.put(ResponseContant.resultMsg,"success");
        return result;
    }
    /**
     * 获取缺货设备列表
     * @param replenishEr
     * @param address
     * @return
     * @throws Exception
     */
    public JSONObject getOutOfStockDeviceList(String replenishEr, String address) throws Exception {
        JSONObject result = new JSONObject();
        String sql = "SELECT\n" +
                "\tifnull(sum(tmi.qty), 0) AS totalQty,\n" +
                "\tifnull(\n" +
                "\t\tt.aisles - count(tmi.id),\n" +
                "\t\tt.aisles\n" +
                "\t) AS unusedAisles,\n" +
                "\tifnull(\n" +
                "\t\tt.capacity - sum(tmi.qty),\n" +
                "\t\tt.capacity\n" +
                "\t) AS unuserdCapacity,\n" +
                "\tifnull((t.capacity - sum(tmi.qty)) / t.capacity, 0) AS idleRate,\n" +
                "\tt.id as id,\n" +
                "\tt.belong_community as belongCommunity,\n" +
                "\tt.community as community,\n" +
                "\tt.del as del,\n" +
                "\tt.delivery_address as deliveryAddress,\n" +
                "\tt.detail_address as detailAddress,\n" +
                "\tt.equ_area as equArea,\n" +
                "\tt.equ_class as equClass,\n" +
                "\tt.equ_info as equInfo,\n" +
                "\tt.equ_name as equName,\n" +
                "\tt.equ_num as equNum,\n" +
                "\tt.equ_type as equType,\n" +
                "\tt.fbelong_community as fbelongCommunity,\n" +
                "\tt.machine_code as machineCode,\n" +
                "\tt.network_status as networkStatus,\n" +
                "\tt.poweron_test as poweronTest,\n" +
                "\tt.reg_date as regDate,\n" +
                "\tt.sale_status as saleStatus,\n" +
                "\tt.signalintensity as signalintensity,\n" +
                "\tt.upgr_adesit as upgrAdesit,\n" +
                "\tt.`status` as `status`,\n" +
                "\tt.card_status as cardStatus,\n" +
                "\tt.operator as operator,\n" +
                "\tt.pack_age as packAge,\n" +
                "\tt.usage_flow as usageFlow,\n" +
                "\tt.flow as flow,\n" +
                "\tt.create_time as createTime,\n" +
                "\tt.create_user as createUser,\n" +
                "\tt.create_user_name as createUserName,\n" +
                "\tt.update_time as updateTime,\n" +
                "\tt.update_user as updateUser,\n" +
                "\tt.update_user_name as updateUserName,\n" +
                "\tt.aisles as aisles,\n" +
                "\tt.capacity as capacity,\n" +
                "\tt.ratio as ratio,\n" +
                "\tt.cargo_capacity as cargoCapacity\n" +
                "FROM\n" +
                "\tt_mediicine_device t\n" +
                "LEFT JOIN t_mediicinecabinet_inventory tmi ON t.id = tmi.id_device\n" +
                "WHERE 1=1\n" ;
        if (!StringUtils.isEmpty(replenishEr)) {
            sql +=" AND t.id in (select device_id from t_mediicine_device_user tmdu left join t_mediicine_user tmu on tmdu.user_id = tmu.id where tmdu.del = 1 and CONCAT(tmu.name,tmu.account) like '%" + replenishEr + "%')\n";
        }
        if (!StringUtils.isEmpty(address)) {
            sql += " AND CONCAT(t.detail_address,t.delivery_address) like '%" + address + "%'\n";
        }
       sql += "GROUP BY\n" +
            "\tt.id\n" +
            "HAVING\n" +
            "\tsum(tmi.qty) < t.capacity * t.ratio\n" +
            "OR sum(tmi.qty) IS NULL";
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            if(!StringUtils.isEmpty(stringObjectMap.get("status"))){
                if ("1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "在线");
                }
                if ("0".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "离线");
                }
                if ("-1".equals(stringObjectMap.get("status").toString())) {
                    stringObjectMap.put("statusName", "异常");
                }
            }
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",list);
        return result;
    }
    /**
     * 获取所属id的缺货信息
     * @param ids
     * @return
     * @throws Exception
     */
    public JSONObject getDetialOutOfStock(String ids) throws Exception {
        JSONObject result = new JSONObject();
        String 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" +
                "FROM\n" +
                "    t_mediicine_device AS t WHERE ',"+ ids +",' LIKE CONCAT('%,',t.id,',%')";
        String sencordSql = "SELECT\n" +
                "\ttmi.layer_no AS layerNo,\n" +
                "\ttmi.wayer_no AS wayerNo,\n" +
                "\ttmi.qty AS qty,\n" +
                "\ttmd.id AS id,\n" +
                "\ttmd.approval_num AS approvalNum,\n" +
                "\ttmd.barcode AS barcode,\n" +
                "\ttmd.brand AS brand,\n" +
                "\ttmd.dos_form AS dosForm,\n" +
                "\ttmd.state AS state,\n" +
                "\ttmd.drug_bar_code AS drugBarCode,\n" +
                "\ttmd.drug_class AS drugClass,\n" +
                "\ttmd.drug_class_code AS drugClassCode,\n" +
                "\ttmd.drug_code AS drugCode,\n" +
                "\ttmd.drug_name AS drugName,\n" +
                "\ttmd.drug_name_alies AS drugNameAlies,\n" +
                "\ttmd.drug_short_code AS drugShortCode,\n" +
                "\ttmd.drug_type_code AS drugTypeCode,\n" +
                "\ttmd.earlywarningcate AS earlywarningcate,\n" +
                "\ttmd.inventory AS inventory,\n" +
                "\ttmd.manufactor AS manufactor,\n" +
                "\ttmd.med_cabinet AS medCabinet,\n" +
                "\ttmd.pic AS pic,\n" +
                "\ttmd.price AS price,\n" +
                "\ttmd.sale_volume AS saleVolume,\n" +
                "\ttmd.self_code AS selfCode,\n" +
                "\ttmd.specif AS specif,\n" +
                "\ttmd.unit AS unit,\n" +
                "\ttmd.create_time AS createTime,\n" +
                "\ttmd.create_user AS createUser,\n" +
                "\ttmd.create_user_name AS createUserName,\n" +
                "\ttmd.update_time AS updateTime,\n" +
                "\ttmd.update_user AS updateUser,\n" +
                "\ttmd.update_user_name AS updateUserName,\n" +
                "\ttmd.drug_sku AS drugSku,\n" +
                "\ttmd.drug_num AS drugNum,\n" +
                "\ttmd.use_num AS useNum,\n" +
                "\ttmd.use_way AS useWay,\n" +
                "\ttmd.use_rate AS useRate,\n" +
                "\ttmd.use_dose AS useDose,\n" +
                "\ttmd.use_way_add AS useWayAdd,\n" +
                "\ttmd.org_code AS orgCode,\n" +
                "\ttmd.org_name AS orgName\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory tmi\n" +
                "LEFT JOIN t_mediicine_drugs tmd ON tmi.barcode = tmd.id";
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            String tempStr = "";
//            tempStr = sencordSql + " where ',"+stringObjectMap.get("id")+",' LIKE CONCAT('%,',tmi.id_device,',%')";
            tempStr = sencordSql + " WHERE tmi.id_device = '" + stringObjectMap.get("id").toString() + "'";
            List<Map<String, Object>> childList = null;
            childList = hibenateUtils.createSQLQuery(tempStr);
            if (childList != null) {
                for (Map<String, Object> objectMap : childList) {
                    objectMap.put("upInventory", Integer.parseInt(stringObjectMap.get("cargoCapacity").toString()) - Integer.parseInt(objectMap.get("qty").toString()));
                }
                stringObjectMap.put("children", childList);
            }
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",list);
        return result;
    }
    /**
     * 获取设备库存
     * @param belongCommunity
     * @param deviceId
     * @param netStatus
     * @return
     * @throws Exception
     */
    public JSONObject getDevInventory(String belongCommunity, String deviceId, String netStatus) throws Exception {
        JSONObject result = new JSONObject();
        String 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" +
                "FROM\n" +
                "    t_mediicine_device AS t WHERE 1=1";
        if (!StringUtils.isEmpty(deviceId)) {
            sql += " AND t.id = '" + deviceId + "'";
        }
        if (!StringUtils.isEmpty(belongCommunity)) {
            sql += " AND t.belong_community = '" + belongCommunity + "'";
        }
        if (!StringUtils.isEmpty(netStatus)) {
            sql += " AND t.network_status = '" + netStatus + "'";
        }
        String sencordSql = "SELECT\n" +
                "\ttmi.layer_no AS layerNo,\n" +
                "\ttmi.wayer_no AS wayerNo,\n" +
                "\ttmi.qty AS qty,\n" +
                "\ttmd.id AS id,\n" +
                "\ttmd.approval_num AS approvalNum,\n" +
                "\ttmd.barcode AS barcode,\n" +
                "\ttmd.brand AS brand,\n" +
                "\ttmd.dos_form AS dosForm,\n" +
                "\ttmd.state AS state,\n" +
                "\ttmd.drug_bar_code AS drugBarCode,\n" +
                "\ttmd.drug_class AS drugClass,\n" +
                "\ttmd.drug_class_code AS drugClassCode,\n" +
                "\ttmd.drug_code AS drugCode,\n" +
                "\ttmd.drug_name AS drugName,\n" +
                "\ttmd.drug_name_alies AS drugNameAlies,\n" +
                "\ttmd.drug_short_code AS drugShortCode,\n" +
                "\ttmd.drug_type_code AS drugTypeCode,\n" +
                "\ttmd.earlywarningcate AS earlywarningcate,\n" +
                "\ttmd.inventory AS inventory,\n" +
                "\ttmd.manufactor AS manufactor,\n" +
                "\ttmd.med_cabinet AS medCabinet,\n" +
                "\ttmd.pic AS pic,\n" +
                "\ttmd.price AS price,\n" +
                "\ttmd.sale_volume AS saleVolume,\n" +
                "\ttmd.self_code AS selfCode,\n" +
                "\ttmd.specif AS specif,\n" +
                "\ttmd.unit AS unit,\n" +
                "\ttmd.create_time AS createTime,\n" +
                "\ttmd.create_user AS createUser,\n" +
                "\ttmd.create_user_name AS createUserName,\n" +
                "\ttmd.update_time AS updateTime,\n" +
                "\ttmd.update_user AS updateUser,\n" +
                "\ttmd.update_user_name AS updateUserName,\n" +
                "\ttmd.drug_sku AS drugSku,\n" +
                "\ttmd.drug_num AS drugNum,\n" +
                "\ttmd.use_num AS useNum,\n" +
                "\ttmd.use_way AS useWay,\n" +
                "\ttmd.use_rate AS useRate,\n" +
                "\ttmd.use_dose AS useDose,\n" +
                "\ttmd.use_way_add AS useWayAdd,\n" +
                "\ttmd.org_code AS orgCode,\n" +
                "\ttmd.org_name AS orgName\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory tmi\n" +
                "LEFT JOIN t_mediicine_drugs tmd ON tmi.barcode = tmd.id";
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
//            String tempStr = sencordSql + " where ',"+stringObjectMap.get("id").toString()+",' LIKE CONCAT('%,',tmi.id_device,',%')";
            String tempStr = sencordSql + " WHERE tmi.id_device = '" + stringObjectMap.get("id").toString() + "'";
            List<Map<String, Object>> childList = null;
            childList = hibenateUtils.createSQLQuery(tempStr);
            if (childList != null) {
                for (Map<String, Object> objectMap : childList) {
                    objectMap.put("upInventory", Integer.parseInt(stringObjectMap.get("cargoCapacity").toString()) - Integer.parseInt(objectMap.get("qty").toString()));
                }
                stringObjectMap.put("children", childList);
                stringObjectMap.put("totalQty", childList.stream().reduce(0, (sum,  p) -> sum += Integer.parseInt(p.get("qty").toString()), Integer::sum));
            }
            //历史订单数
            String secondSql = "SELECT COUNT(DISTINCT(t.id)) FROM t_mediicine_order t WHERE t.shipping_equ = '" + stringObjectMap.get("id").toString() + "'";
            stringObjectMap.put("orderQty", jdbcTemplate.queryForObject(secondSql, Integer.class));
            //总销售额
            secondSql = "SELECT SUM(t.amount) FROM t_mediicine_order t WHERE t.shipping_equ = '" + stringObjectMap.get("id").toString() + "'";
            stringObjectMap.put("orderTotalAmount", jdbcTemplate.queryForObject(secondSql, Integer.class));
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",list);
        return result;
    }
}

+ 21 - 21
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineWarrayService.java

@ -86,13 +86,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        conditionSql += " and t.type='temperature'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(lowT)) {
            conditionSql += " and t.temperature >= " + lowT;
@ -179,13 +179,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        conditionSql += " and t.type='humidity'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(lowT)) {
            conditionSql += " and t.humidity >= " + lowT;
@ -273,13 +273,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        conditionSql += " and t.type='offline'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
@ -361,13 +361,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        conditionSql += " and t.type='fault'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
@ -447,13 +447,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        String conditionSql = "";
        conditionSql += " and t.type='flow'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
@ -534,13 +534,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        conditionSql += " and t.type='network'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
@ -621,13 +621,13 @@ public class MedicineWarrayService extends BaseJpaService<Mediicinewarray, Medii
        String conditionSql = "";
        conditionSql += " and t.type='exceed'";
        if (!StringUtils.isEmpty(idDevice)){
            conditionSql += " and t.id_device = " + idDevice;
            conditionSql += " and t.id_device = '" + idDevice + "'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = " + equClass;
            conditionSql += " and t.equ_class = '" + equClass + "'";
        }
        if (!StringUtils.isEmpty(netStatus)){
            conditionSql += " and t.network_status = " + netStatus;
            conditionSql += " and t.network_status = '" + netStatus + "'";
        }
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";

+ 258 - 20
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -129,6 +129,106 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        return result.toJSONString();
    }
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceCommunity(String deviceId, String communityId, String community){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(communityId)){
            result.put("msg","deviceId and communityId is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        if (mediicinedevice == null) {
            result.put("msg","device doesn't exist");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        mediicinedevice.setBelongCommunity(communityId);
        mediicinedevice.setCommunity(community);
        this.save(mediicinedevice);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
    }
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceAddress(String deviceId, String address){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(address)){
            result.put("msg","deviceId and address is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        if (mediicinedevice == null) {
            result.put("msg","device doesn't exist");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        mediicinedevice.setDeliveryAddress(address);
        this.save(mediicinedevice);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
    }
    /**
     * 更新设备状态
     * @param deviceId
     * @param status
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceStatus(String deviceId, String status){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(status)){
            result.put("msg","deviceId and status is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        if (mediicinedevice == null) {
            result.put("msg","device doesn't exist");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        mediicinedevice.setStatus(status);
        this.save(mediicinedevice);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
    }
    /**
     * 更新设备销售状态
     * @param deviceId
     * @param status
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String updateDeviceSaleStatus(String deviceId, String saleStatus){
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId) && StringUtils.isEmpty(saleStatus)){
            result.put("msg","deviceId and saleStatus is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        if (mediicinedevice == null) {
            result.put("msg","device doesn't exist");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        mediicinedevice.setSaleStatus(saleStatus);
        this.save(mediicinedevice);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
    }
    /**
     * 分页查询设备信息
     * @param content
@ -183,23 +283,23 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "    t.ratio as ratio,\n" +
                "    t.cargo_capacity as cargoCapacity\n" +
                "FROM\n" +
                "    t_mediicine_device AS t where 1=1\n";
                "    t_mediicine_device AS t where 1=1 AND t.del = 1\n";
        String conditionSql = "";
        if (!StringUtils.isEmpty(content)){
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
            conditionSql += " AND CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = "+equClass;
            conditionSql += " AND t.equ_class = '"+equClass + "'";
        }
        if (!StringUtils.isEmpty(belongCommunity)){
            conditionSql += " and t.belong_community = " + belongCommunity;
            conditionSql += " AND t.belong_community = '" + belongCommunity+ "'";
        }
        if (!StringUtils.isEmpty(networkStatus)){
            conditionSql += " and t.network_status = " + networkStatus;
            conditionSql += " AND t.network_status = '" + networkStatus + "'";
        }
        if (!StringUtils.isEmpty(saleStatus)){
            conditionSql += " and t.sale_status = " + saleStatus;
            conditionSql += " AND t.sale_status = '" + saleStatus + "'";
        }
        sql = sql + conditionSql;
@ -285,35 +385,35 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            conditionSql += " and CONCAT(t.equ_name, t.equ_num) like '%" + content + "%'";
        }
        if (!StringUtils.isEmpty(equClass)){
            conditionSql += " and t.equ_class = "+equClass;
            conditionSql += " and t.equ_class = '"+equClass + "'";
        }
        if (!StringUtils.isEmpty(belongCommunity)){
            conditionSql += " and t.belong_community = " + belongCommunity;
            conditionSql += " and t.belong_community = '" + belongCommunity + "'";
        }
        if (!StringUtils.isEmpty(networkStatus)){
            conditionSql += " and t.network_status = " + networkStatus;
            conditionSql += " and t.network_status = '" + networkStatus + "'";
        }
        if (!StringUtils.isEmpty(saleStatus)){
            conditionSql += " and t.sale_status = " + saleStatus;
            conditionSql += " and t.sale_status = '" + saleStatus + "'";
        }
        if (!StringUtils.isEmpty(machineCode)){
            conditionSql += " and t.machine_code like  '%" + machineCode + "%'";
        }
        if (!StringUtils.isEmpty(deviceType)){
            conditionSql += " and t.equ_type = "+deviceType;
            conditionSql += " and t.equ_type = '"+deviceType + "'";
        }
        if (!StringUtils.isEmpty(equArea)){
            conditionSql += " and t.equ_area = "+equArea;
            conditionSql += " and t.equ_area = '"+equArea + "'";
        }
        if (!StringUtils.isEmpty(del)){
            conditionSql += " and t.del = "+del;
            conditionSql += " and t.del = '"+del + "'";
        }
        if (!StringUtils.isEmpty(status)){
            conditionSql += " and t.`status` = "+status;
            conditionSql += " and t.`status` = '"+status + "'";
        }
        if (!StringUtils.isEmpty(deliveryAddress)){
            conditionSql += " and t.delivery_address = "+deliveryAddress;
            conditionSql += " and t.delivery_address = '"+deliveryAddress + "'";
        }
        sql = sql + conditionSql;
@ -404,7 +504,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "FROM\n" +
                "    t_mediicine_device AS t where\n";
        String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and du.user_id = " + userId + ")";
//        String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and ',"+userId+",' LIKE CONCAT('%,',du.user_id,',%'))";
        String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and du.user_id = '" + userId + "'";
        sql = sql + conditionSql;
@ -466,7 +567,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "FROM\n" +
                "    t_mediicine_user AS t where\n";
        String conditionSql = " t.id in (select du.user_id from t_mediicine_device_user du where del = 1 and du.device_id = " + deviceId + ")";
//        String conditionSql = " t.id in (select du.user_id from t_mediicine_device_user du where del = 1 and ',"+deviceId+",' LIKE CONCAT('%,',du.device_id,',%'))";
        String conditionSql = " t.id in (select du.user_id from t_mediicine_device_user du where del = 1 and du.device_id = '" + deviceId + "'";
        sql = sql + conditionSql;
@ -744,7 +846,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "    t.ratio AS ratio,\n" +
                "    t.cargo_capacity AS cargoCapacity\n" +
                "FROM\n" +
                "    t_mediicine_device AS t WHERE  t.id in (" + ids + ")";
                "    t_mediicine_device AS t WHERE ',"+ ids +",' LIKE CONCAT('%,',t.id,',%')";
        String sencordSql = "SELECT\n" +
                "\ttmi.layer_no AS layerNo,\n" +
                "\ttmi.wayer_no AS wayerNo,\n" +
@ -795,9 +897,11 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
            sencordSql += " where tmi.id_device = " + stringObjectMap.get("id");
            String tempStr = "";
//            tempStr = sencordSql + " where ',"+stringObjectMap.get("id")+",' LIKE CONCAT('%,',tmi.id_device,',%')";
            tempStr = sencordSql + " WHERE tmi.id_device = '" + stringObjectMap.get("id").toString() + "'";
            List<Map<String, Object>> childList = null;
            childList = hibenateUtils.createSQLQuery(sencordSql);
            childList = hibenateUtils.createSQLQuery(tempStr);
            if (childList != null) {
                for (Map<String, Object> objectMap : childList) {
                    objectMap.put("upInventory", Integer.parseInt(stringObjectMap.get("cargoCapacity").toString()) - Integer.parseInt(objectMap.get("qty").toString()));
@ -812,5 +916,139 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    /**
     * 获取设备库存
     * @param belongCommunity
     * @param deviceId
     * @param netStatus
     * @return
     * @throws Exception
     */
    public JSONObject getDevInventory(String belongCommunity, String deviceId, String netStatus) throws Exception {
        JSONObject result = new JSONObject();
        String 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" +
                "FROM\n" +
                "    t_mediicine_device AS t WHERE 1=1";
        if (!StringUtils.isEmpty(deviceId)) {
            sql += " AND t.id = '" + deviceId + "'";
        }
        if (!StringUtils.isEmpty(belongCommunity)) {
            sql += " AND t.belong_community = '" + belongCommunity + "'";
        }
        if (!StringUtils.isEmpty(netStatus)) {
            sql += " AND t.network_status = '" + netStatus + "'";
        }
        String sencordSql = "SELECT\n" +
                "\ttmi.layer_no AS layerNo,\n" +
                "\ttmi.wayer_no AS wayerNo,\n" +
                "\ttmi.qty AS qty,\n" +
                "\ttmd.id AS id,\n" +
                "\ttmd.approval_num AS approvalNum,\n" +
                "\ttmd.barcode AS barcode,\n" +
                "\ttmd.brand AS brand,\n" +
                "\ttmd.dos_form AS dosForm,\n" +
                "\ttmd.state AS state,\n" +
                "\ttmd.drug_bar_code AS drugBarCode,\n" +
                "\ttmd.drug_class AS drugClass,\n" +
                "\ttmd.drug_class_code AS drugClassCode,\n" +
                "\ttmd.drug_code AS drugCode,\n" +
                "\ttmd.drug_name AS drugName,\n" +
                "\ttmd.drug_name_alies AS drugNameAlies,\n" +
                "\ttmd.drug_short_code AS drugShortCode,\n" +
                "\ttmd.drug_type_code AS drugTypeCode,\n" +
                "\ttmd.earlywarningcate AS earlywarningcate,\n" +
                "\ttmd.inventory AS inventory,\n" +
                "\ttmd.manufactor AS manufactor,\n" +
                "\ttmd.med_cabinet AS medCabinet,\n" +
                "\ttmd.pic AS pic,\n" +
                "\ttmd.price AS price,\n" +
                "\ttmd.sale_volume AS saleVolume,\n" +
                "\ttmd.self_code AS selfCode,\n" +
                "\ttmd.specif AS specif,\n" +
                "\ttmd.unit AS unit,\n" +
                "\ttmd.create_time AS createTime,\n" +
                "\ttmd.create_user AS createUser,\n" +
                "\ttmd.create_user_name AS createUserName,\n" +
                "\ttmd.update_time AS updateTime,\n" +
                "\ttmd.update_user AS updateUser,\n" +
                "\ttmd.update_user_name AS updateUserName,\n" +
                "\ttmd.drug_sku AS drugSku,\n" +
                "\ttmd.drug_num AS drugNum,\n" +
                "\ttmd.use_num AS useNum,\n" +
                "\ttmd.use_way AS useWay,\n" +
                "\ttmd.use_rate AS useRate,\n" +
                "\ttmd.use_dose AS useDose,\n" +
                "\ttmd.use_way_add AS useWayAdd,\n" +
                "\ttmd.org_code AS orgCode,\n" +
                "\ttmd.org_name AS orgName\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory tmi\n" +
                "LEFT JOIN t_mediicine_drugs tmd ON tmi.barcode = tmd.id";
        List<Map<String,Object>> list=null;
        list = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : list) {
//            String tempStr = sencordSql + " where ',"+stringObjectMap.get("id").toString()+",' LIKE CONCAT('%,',tmi.id_device,',%')";
            String tempStr = sencordSql + " WHERE tmi.id_device = '" + stringObjectMap.get("id").toString() + "'";
            List<Map<String, Object>> childList = null;
            childList = hibenateUtils.createSQLQuery(tempStr);
            if (childList != null) {
                for (Map<String, Object> objectMap : childList) {
                    objectMap.put("upInventory", Integer.parseInt(stringObjectMap.get("cargoCapacity").toString()) - Integer.parseInt(objectMap.get("qty").toString()));
                }
                stringObjectMap.put("children", childList);
                stringObjectMap.put("totalQty", childList.stream().reduce(0, (sum,  p) -> sum += Integer.parseInt(p.get("qty").toString()), Integer::sum));
            }
            //历史订单数
            String secondSql = "SELECT COUNT(DISTINCT(t.id)) FROM t_mediicine_order t WHERE t.shipping_equ = '" + stringObjectMap.get("id").toString() + "'";
            stringObjectMap.put("orderQty", jdbcTemplate.queryForObject(secondSql, Integer.class));
            //总销售额
            secondSql = "SELECT SUM(t.amount) FROM t_mediicine_order t WHERE t.shipping_equ = '" + stringObjectMap.get("id").toString() + "'";
            stringObjectMap.put("orderTotalAmount", jdbcTemplate.queryForObject(secondSql, Integer.class));
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",list);
        return result;
    }
}