Преглед изворни кода

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

wangzhinan пре 5 година
родитељ
комит
05cfe3b259

+ 41 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/mapping/service/PatientMappingService.java

@ -2,6 +2,7 @@ package com.yihu.jw.hospital.mapping.service;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.patient.dao.BasePatientDao;
import net.sf.json.JSONArray;
import com.yihu.jw.entity.hospital.mapping.PatientMappingDO;
@ -29,7 +30,8 @@ public class PatientMappingService {
    private PatientMappingDao patientMappingDao;
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private YkyyEntranceService ykyyEntranceService;
    @Autowired
    private EntranceService entranceService;
@ -65,6 +67,44 @@ public class PatientMappingService {
        }
    }
    /**
     * 眼科医院
     * @param patient
     * @return
     * @throws Exception
     */
    public String findYkyyPatNoByPatient(String patient)throws Exception{
        logger.info("findYkyyPatNoByPatient:"+patient);
        BasePatientDO patientDO = basePatientDao.findById(patient);
        logger.info("patientDO:"+patientDO.toString());
        PatientMappingDO patientMappingDO = patientMappingDao.findByIdcardAndSource(patientDO.getIdcard(),"1");
        if(patientMappingDO!=null){
            return patientMappingDO.getMappingCode();
        }
        com.alibaba.fastjson.JSONArray rs = ykyyEntranceService.findHisPatient(patientDO.getIdcard());
        if(rs!=null&&rs.size()>0){
            //获取居民信息
            com.alibaba.fastjson.JSONObject json = rs.getJSONObject(0);
            String mappingCode = json.getString("brid").trim();
            //存储对应映射关系
            PatientMappingDO mappingDO = new PatientMappingDO();
            mappingDO.setSource("1");
            mappingDO.setPatientName(patientDO.getName());
            mappingDO.setPatient(patientDO.getId());
            mappingDO.setMappingCode(mappingCode);
            mappingDO.setCreateTime(new Date());
            mappingDO.setIdcard(patientDO.getIdcard());
            patientMappingDao.save(mappingDO);
            return mappingCode;
        }else{
            return null;
        }
    }
    public String findHisPatNoByPatient(String patient)throws Exception{
        logger.info("findHisPatNoByPatient:"+patient);
        BasePatientDO patientDO = basePatientDao.findById(patient);

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/YkyyPrescriptionService.java

@ -99,7 +99,7 @@ public class YkyyPrescriptionService extends BaseJpaService<WlyyPrescriptionDO,
     */
    public  List<WlyyOutpatientVO> findOutpatientList(String patient, String startTime, String endTime, boolean demoFlag)throws Exception{
        logger.info("findOutpatientList patient:"+patient);
        String patNo =patientMappingService.findHisPatNoByPatient(patient);
        String patNo =patientMappingService.findYkyyPatNoByPatient(patient);
        if(StringUtils.isBlank(patNo)){
            return null;
        }

+ 16 - 0
business/base-service/src/main/java/com/yihu/jw/utils/hibernate/HibenateUtils.java

@ -1,5 +1,6 @@
package com.yihu.jw.utils.hibernate;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
@ -165,4 +166,19 @@ public class HibenateUtils {
        transaction.commit();
    }
    /**
     * 更新
     * @param entity
     */
    public void update(Object entity){
        entityManager.merge(entity);
        entityManager.flush();
    }
    public void update(String id,String phone){
        BasePatientDO basePatientDO = entityManager.find(BasePatientDO.class,id);
        basePatientDO.setPhone(phone);
        update(basePatientDO);
    }
}

+ 85 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/platform/IotShareInterfaceDO.java

@ -0,0 +1,85 @@
package com.yihu.jw.entity.iot.platform;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
@Entity
@Table(name = "iot_share_interface")
public class IotShareInterfaceDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "method_name")
    private String methodName;//方法名
    @Column(name = "interface_name")
    private String interfaceName;//接口名称
    @Column(name = "type_name")
    private String typeName;//业务类型名称
    @Column(name = "explanation")
    private String explanation;//说明
    @Column(name = "del")
    private String del;//是否删除 1:删除  0:不删除
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getMethodName() {
        return methodName;
    }
    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }
    public String getInterfaceName() {
        return interfaceName;
    }
    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }
    public String getTypeName() {
        return typeName;
    }
    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }
    public String getExplanation() {
        return explanation;
    }
    public void setExplanation(String explanation) {
        this.explanation = explanation;
    }
    public String getDel() {
        return del;
    }
    public void setDel(String del) {
        this.del = del;
    }
}

+ 18 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java

@ -22,6 +22,7 @@ public class IotRequestMapping {
        public static final String patientDevice = api_iot_common + "/patientDevice";
        public static final String wlyy = api_iot_common + "/wlyy";
        public static final String figereLabel = api_iot_common + "/figereLabel";
        public static final String platform = api_iot_common + "/platform";
        public static final String hospital = api_iot_common + "/hospital";
@ -74,6 +75,7 @@ public class IotRequestMapping {
        public static final String auditCompanyNoPass = "auditCompanyNoPass";
        public static final String findAll = "findAll";
        public static final String enterType = "enterType";
        public static final String conditionQueryPage = "conditionQueryPage";
        public static final String findCompanyCertPage = "findCompanyCertPage";
        public static final String findCompanyCertById = "findCompanyCertById";
@ -285,6 +287,22 @@ public class IotRequestMapping {
    }
    /**
     * 居民标签信息模块常量
     */
    public static class  Platform{
        public static final String addInterface ="addInterface";
        public static final String editInterface ="editInterface";
        public static final String findInterfaceById ="findInterfaceById";
        public static final String findAll ="findAll";
        public static final String conditionQueryPage ="conditionQueryPage";
        public static final String message_success_add = "add success";
        public static final String message_success_edit = "edit success";
        public static final String message_success_find = "find success";
    }
    /**
     * 单位模块常量
     */

+ 9 - 7
common/common-util/src/main/java/com/yihu/jw/util/common/FileUtil.java

@ -5,6 +5,7 @@ import com.yihu.fastdfs.FastDFSUtil;
import it.sauronsoftware.jave.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
@ -15,10 +16,11 @@ import java.io.InputStream;
 * 文件处理工具类
 * @author huangwenjie
 */
@Component
public class FileUtil {
	
	@Autowired
	private FastDFSUtil fastDFSHelper;
	public FastDFSUtil fastDFSHelper;
	
	public void changeToMp3(String sourcePath, String targetPath) {
		File source = new File(sourcePath);
@ -49,18 +51,19 @@ public class FileUtil {
	 */
	
	
	public String copyTempVoice(String voices_Path,String fastdfs_file_url) throws Exception {
	public  String copyTempVoice(String voices_Path,String fastdfs_file_url) throws Exception {
		// 文件保存的临时路径
		FastDFSUtil fastDFSUtil = new FastDFSUtil();
		String fileUrls = "";
		File f = new File(voices_Path);
		if (f.exists()) {
			String fileName = f.getName();
			InputStream in = new FileInputStream(f);
			ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
			//得到文件类型
			String fileType = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
			ObjectNode result = fastDFSHelper.upload(in, fileType, "");
			in.close();
			if (result != null) {
				fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + fastdfs_file_url
				fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
						+ result.get("groupName").toString().replaceAll("\"", "") + "/"
						+ result.get("remoteFileName").toString().replaceAll("\"", "");
				f.delete();
@ -79,7 +82,6 @@ public class FileUtil {
	public String copyTempImage(String files,String tempPath) throws Exception {
		// 文件保存的临时路径
		String[] fileArray = files.split(",");
		FastDFSUtil fastDFSUtil = new FastDFSUtil();
		String fileUrls = "";
		for (String file : fileArray) {
			File f = new File(tempPath + file);
@ -87,7 +89,7 @@ public class FileUtil {
			if (f.exists()) {
				String fileName = f.getName();
				InputStream in = new FileInputStream(f);
				ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
				ObjectNode result = fastDFSHelper.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
				in.close();
				if (result != null) {
					//1.3.7去掉前缀

+ 3 - 5
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/consult/PatientConsultEndpoint.java

@ -16,17 +16,14 @@ import com.yihu.jw.im.service.ImService;
import com.yihu.jw.order.BusinessOrderService;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.service.BasePatientService;
import com.yihu.jw.restmodel.im.ConsultVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.FileUtil;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.WechatDao;
import com.yihu.jw.wechat.enterprise.EnterpriseService;
import com.yihu.jw.wechat.service.WechatInfoService;
@ -92,8 +89,6 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
	@Autowired
	private BusinessOrderService businessOrderService;
	
	public FileUtil fileUtil;
	
	@Value("${fastDFS.fastdfs_file_url}")
	private String fastdfs_file_url;
	
@ -109,6 +104,9 @@ public class PatientConsultEndpoint extends EnvelopRestEndpoint {
	@Value("${wechat.id}")
	private String wxId;
	
	@Autowired
	private FileUtil fileUtil;
	
	@GetMapping(value = BaseHospitalRequestMapping.PatientIM.records)
	@ApiOperation(value = "患者咨询记录查询")
	public Envelop records(

+ 34 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/company/IotCompanyController.java

@ -69,6 +69,39 @@ public class IotCompanyController extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = IotRequestMapping.Company.conditionQueryPage)
    @ApiOperation(value = "条件查找企业", notes = "条件查找企业")
    public MixEnvelop<IotCompanyVO, IotCompanyVO> conditionQueryPage(@ApiParam(name = "name", value = "厂商名称或联系人名称", defaultValue = "")
                                                                  @RequestParam(value = "name", required = false) String name,
                                                                  @ApiParam(name = "status", value = "审核状态", defaultValue = "")
                                                                  @RequestParam(value = "status", required = false) String status,
                                                                  @ApiParam(name = "type", value = "产商类型", defaultValue = "")
                                                                  @RequestParam(value = "type", required = false) String type,
                                                                  @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                                  @RequestParam(value = "page", required = false) Integer page,
                                                                  @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                                  @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            if(StringUtils.isBlank(status)){
                return iotCompanyService.conditionQueryPage(page,size,null,name,type);
            }else {
                return iotCompanyService.conditionQueryPage(page,size,status,name,type);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Company.addCompany)
    @ApiOperation(value = "创建企业", notes = "创建企业")
    public MixEnvelop<IotCompanyVO, IotCompanyVO> addCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
@ -103,6 +136,7 @@ public class IotCompanyController extends EnvelopRestEndpoint {
                                                                    @ApiParam(name = "msg",value = "拒绝说明") @RequestParam(value = "msg",required = true,defaultValue = "")String msg){
        try {
            return  iotCompanyService.auditCompany(id, msg);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());

+ 126 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/platform/IotInterfaceController.java

@ -0,0 +1,126 @@
package com.yihu.iot.controller.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.service.platform.IotShareInterfaceService;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
@RestController
@RequestMapping(IotRequestMapping.Common.platform)
@Api(tags = "平台接口管理相关操作", description = "平台接口管理相关操作")
public class IotInterfaceController extends EnvelopRestEndpoint {
    @Autowired
    private IotShareInterfaceService iotShareInterfaceService;
    @PostMapping(value = IotRequestMapping.Platform.addInterface)
    @ApiOperation(value = "新增共享接口",notes = "新增共享接口")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> addInterface(@ApiParam(name = "JSON",value = "接口JSON串") @RequestParam(value = "JSON",required = true)String json){
        try {
            iotShareInterfaceService.addInterface(json);
            return MixEnvelop.getSuccess(IotRequestMapping.Platform.message_success_add);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Platform.editInterface)
    @ApiOperation(value = "编辑共享接口",notes = "编辑共享接口")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> editInterface(@ApiParam(name = "JSON",value = "接口JSON串") @RequestParam(value = "JSON",required = true)String json){
        try {
            iotShareInterfaceService.editInterface(json);
            return MixEnvelop.getSuccess(IotRequestMapping.Platform.message_success_edit);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Platform.findInterfaceById)
    @ApiOperation(value = "查找共享接口",notes = "查找共享接口")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> findInterfaceById(@ApiParam(name = "id",value = "id") @RequestParam(value = "id",required = true)String id){
        try {
           IotShareInterfaceDO iotShareInterfaceDO = iotShareInterfaceService.findInterfaceById(id);
            return MixEnvelop.getSuccess(IotRequestMapping.Platform.message_success_find,iotShareInterfaceDO);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Platform.findAll)
    @ApiOperation(value = "分页查询所有",notes = "分页查询所有")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> findAll(@ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                                           @RequestParam(value = "page", required = false) Integer page,
                                                                       @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                                           @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return iotShareInterfaceService.findAll(page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Platform.conditionQueryPage)
    @ApiOperation(value = "条件查询分页",notes = "条件查询分页")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> conditionQueryPage(@ApiParam(name = "type", value = "业务类型", defaultValue = "")
                                                                       @RequestParam(value = "type", required = false) String type,
                                                                            @ApiParam(name = "name", value = "接口名称", defaultValue = "")
                                                                       @RequestParam(value = "name", required = false) String name,
                                                                            @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                                       @RequestParam(value = "page", required = false) Integer page,
                                                                            @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                                       @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return iotShareInterfaceService.conditionQueryPage(page,size,type,name);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 14 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/platform/IotShareInterfaceDao.java

@ -0,0 +1,14 @@
package com.yihu.iot.dao.platform;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
public interface IotShareInterfaceDao extends PagingAndSortingRepository<IotShareInterfaceDO,String>, JpaSpecificationExecutor<IotShareInterfaceDO> {
}

+ 32 - 12
svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyService.java

@ -217,7 +217,18 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotCompanyVOList, page, size,count);
    }
/*    public MixEnvelop<IotCompanyVO, IotCompanyVO> queryPage(Integer page, Integer size, String status, String name, String type){
    /**
     * 条件分页查找
     * @param page
     * @param size
     * @param status
     * @param name
     * @param type
     * @return
     */
    public MixEnvelop<IotCompanyVO, IotCompanyVO> conditionQueryPage(Integer page, Integer size, String status, String name, String type){
        StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_company c ,iot_company_type t WHERE c.del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_company c ,iot_company_type t WHERE c.del=1 ");
        List<Object> args = new ArrayList<>();
@ -227,22 +238,28 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
            args.add(status);
        }
        if(StringUtils.isNotBlank(name)){
            sql.append(" and (c.name like ? or c.contacts_name like ?)");
            sqlCount.append(" and (c.name like '").append(name).append("' or c.contacts_name like '").append(name).append("')");
            args.add(name);
            args.add(name);
            sql.append(" and (c.name like '%").append(name).append("%' or c.contacts_name like '%").append(name).append("%')");
            sqlCount.append(" and (c.name like '%").append(name).append("%' or c.contacts_name like '%").append(name).append("%')");
        }
        if(StringUtils.isNotBlank(type)){
            sql.append(" and c.id = t.company_id and t.type=? ");
            sqlCount.append(" and c.id = t.company_id and t.type='").append(type).append("' ");
            sql.append(" and c.id = t.company_id and t.type_name=? ");
            sqlCount.append(" and c.id = t.company_id and t.type_name='").append(type).append("' ");
            args.add(type);
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotCompanyDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotCompanyDO.class));
        list.forEach(one->{
            findType(one);
        });
        if(StringUtils.isBlank(type)){
            //得到list数据
            list.forEach(one->{
                findAppType(one);
            });
        }else {
            list.forEach(one->{
                findType(one);
            });
        }
        List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
@ -250,7 +267,9 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
        List<IotCompanyVO> iotCompanyVOList = convertToModelVOs(list,new ArrayList<>(list.size()));
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotCompanyVOList, page, size,count);
    }*/
    }
    /**
     * 新增
@ -297,6 +316,7 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
            });
            iotCompanyTypeDao.save(companyTypes);
        }
        //应用的营业执照号 可以相同
        if("0".equalsIgnoreCase(iotCompany.getAccountType())){
            List<IotCompanyDO> iotCompanyDOS = iotCompanyDao.findByAccountType(iotCompany.getAccountType());
@ -573,7 +593,7 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
    public MixEnvelop auditCompany(String id) {
        IotCompanyDO companyDO = findById(id);
        if (companyDO==null){
            return MixEnvelop.getError("无该企业");
        }
        String uname = userAgent.getUNAME();
        if (uname==null){

+ 128 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/platform/IotShareInterfaceService.java

@ -0,0 +1,128 @@
package com.yihu.iot.service.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.platform.IotShareInterfaceDao;
import com.yihu.jw.entity.iot.company.IotCompanyDO;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class IotShareInterfaceService extends BaseJpaService<IotShareInterfaceDO, IotShareInterfaceDao> {
    @Autowired
    private IotShareInterfaceDao iotShareInterfaceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 增加接口
     * @param jsonData
     * @return
     */
    public void addInterface(String jsonData){
        IotShareInterfaceDO iotShareInterfaceDO = JSONObject.parseObject(jsonData, IotShareInterfaceDO.class);
        iotShareInterfaceDO.setDel("0");
        iotShareInterfaceDao.save(iotShareInterfaceDO);
    }
    /**
     * 编辑接口
     * @param json
     * @return
     */
    public void editInterface(String json) {
        IotShareInterfaceDO newInterface = JSONObject.parseObject(json, IotShareInterfaceDO.class);
        IotShareInterfaceDO oldInterface = iotShareInterfaceDao.findOne(newInterface.getId());
        oldInterface.setTypeName(newInterface.getTypeName());
        oldInterface.setExplanation(newInterface.getExplanation());
        oldInterface.setMethodName(newInterface.getMethodName());
        oldInterface.setInterfaceName(newInterface.getInterfaceName());
        oldInterface.setId(newInterface.getId());
        oldInterface.setDel("0");
        iotShareInterfaceDao.save(oldInterface);
    }
    /**
     * 根据ID查询接口
     * @param id
     * @return
     */
    public IotShareInterfaceDO findInterfaceById(String id) throws ParseException {
        IotShareInterfaceDO iotShareInterfaceDO = iotShareInterfaceDao.findOne(id);
        return iotShareInterfaceDO;
    }
    /**
     * 分页查询所有
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> findAll(Integer page, Integer size) throws ParseException {
        String filters = "del=0;";
        String sorts = "-updateTime";//按更新时间降序
        List<IotShareInterfaceDO> list = search(null, filters, sorts, page, size);
        //获取总数
        long count = getCount(filters);
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,list,page, size,count);
    }
    /**
     * 分页查询所有
     * @param page
     * @param size
     * @param type
     * @param name
     * @return
     */
    public MixEnvelop<IotShareInterfaceDO, IotShareInterfaceDO> conditionQueryPage(Integer page, Integer size, String type, String name){
        StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_share_interface c  WHERE c.del=0 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_share_interface c  WHERE c.del=0 ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(type)){
            sql.append(" and c.type_name=? ");
            sqlCount.append(" and c.type_name='").append(type).append("' ");
            args.add(type);
        }
        if(StringUtils.isNotBlank(name)){
            sql.append(" and c.method_name like '%").append(name).append("%'");
            sqlCount.append(" and c.method_name like '%").append(name).append("%'");
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotCompanyDO> list = jdbcTemplate.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotShareInterfaceDO.class));
        List<Map<String,Object>> countList = jdbcTemplate.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,list, page, size,count);
    }
}

+ 1 - 1
svr/svr-iot/src/main/resources/bootstrap.yml

@ -1,3 +1,3 @@
spring:
  application:
    name: svr-iot  #注册到发现服务的id 如果id一样 eurika会自动做负载
    name: svr-iot-shw #注册到发现服务的id 如果id一样 eurika会自动做负载