Browse Source

Merge branch 'dev' of yeshijie/jw2.0 into dev

yeshijie 7 years ago
parent
commit
d23c6b85dd

+ 11 - 0
common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceOrderDO.java

@ -64,6 +64,9 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
    @Column(name = "instruction")
    private String instruction;//订单说明
    @Column(name = "ymd")
    private String ymd;//年月日
    @Column(name = "del")
    private Integer del;//删除标志
@ -202,4 +205,12 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
    public void setDel(Integer del) {
        this.del = del;
    }
    public String getYmd() {
        return ymd;
    }
    public void setYmd(String ymd) {
        this.ymd = ymd;
    }
}

+ 132 - 0
common/common-util/src/main/java/com/yihu/jw/util/spring/SpringContext.java

@ -0,0 +1,132 @@
package com.yihu.jw.util.spring;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
/**
 * Spring上下文管理器。
 *
 * @author Sand
 * @version 1.0
 * @created 12-05-2015 17:47:55
 */
@Component
public class SpringContext implements ApplicationContextAware {
    private static ApplicationContext springContext = null;
    /**
     * 获取Spring应用上下文环境。
     *
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return springContext;
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        springContext = applicationContext;
    }
    /**
     * 获取服务。
     *
     * @param serviceName
     * @param <T>
     * @return
     */
    public static <T> T getService(String serviceName) {
        return (T) springContext.getBean(serviceName);
    }
    public static <T> T getService(Class<T> beanCls) {
        return (T) springContext.getBean(beanCls);
    }
    /**
     * 获取服务,并用参数初始化对象。
     *
     * @param serviceName
     * @param args
     * @param <T>
     * @return
     */
    public static <T> T getService(String serviceName, Object... args) {
        T ref = (T)springContext.getBean(serviceName, args);
        if (ref == null) return null;
        return ref;
    }
    public static <T> T getService(Class<T> beanCls, Object... args){
        T ref = (T)springContext.getBean(beanCls, args);
        if (ref == null) return null;
        return ref;
    }
    /**
     * 获取平台支持的所有服务名称。
     *
     * @return
     */
    public static String[] getAvailableServiceNames() {
        String[] serviceNames = springContext.getBeanDefinitionNames();
        return serviceNames;
    }
    /**
     * 判断是否支持特定服务。
     *
     * @param serviceName
     * @return
     */
    public static boolean isServiceSupported(String serviceName) {
        return springContext.containsBeanDefinition(serviceName);
    }
    /**
     * 获取服务的实现类。
     *
     * @param serviceName
     * @return
     */
    public static Class getServiceType(String serviceName) {
        return springContext.getType(serviceName);
    }
    /**
     * 判断服务是否为单例模式。
     *
     * @param serviceName
     * @return
     */
    public static boolean isSingleton(String serviceName) {
        return springContext.isSingleton(serviceName);
    }
    /**
     * 手动装配Bean
     * @param bean
     */
    public static void autowiredBean(Object bean) {
        autowiredBean(bean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
    }
    /**
     * 指定模式,手动装配Bean
     * @param bean
     * @param autowireMode
     */
    public static void autowiredBean(Object bean, int autowireMode) {
        String beanName = ClassUtils.getUserClass(bean).getName();
        AutowireCapableBeanFactory factory = springContext.getAutowireCapableBeanFactory();
        factory.autowireBeanProperties(bean, autowireMode, false);
        factory.initializeBean(bean, beanName);
    }
}

+ 2 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java

@ -66,7 +66,7 @@ public class FileUploadController extends EnvelopRestController{
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.DeviceSupplier.message_success_create, uploadVO);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
@ -91,7 +91,7 @@ public class FileUploadController extends EnvelopRestController{
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.DeviceSupplier.message_success_create, uploadVO);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);

+ 6 - 1
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceOrderDao.java

@ -5,11 +5,16 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author yeshijie on 2017/12/1.
 */
public interface IotDeviceOrderDao extends PagingAndSortingRepository<IotDeviceOrderDO,String>,JpaSpecificationExecutor<IotDeviceOrderDO> {
    @Query("from IotDeviceOrderDO w where w.id =?1")
    @Query("from IotDeviceOrderDO w where w.id =?1 and w.del=1")
    IotDeviceOrderDO findById(String id);
    @Query("from IotDeviceOrderDO w where w.ymd =?1")
    List<IotDeviceOrderDO> findByYmd(String ymd);
}

+ 11 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceOrderService.java

@ -7,6 +7,9 @@ import com.yihu.jw.util.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
 * @author yeshijie on 2017/12/8.
 */
@ -23,13 +26,20 @@ public class IotDeviceOrderService extends BaseJpaService<IotDeviceOrderDO,IotDe
     */
    public IotDeviceOrderDO create(IotDeviceOrderDO iotDeviceOrder) {
        String time = DateUtil.yyyy_MM_dd_HH_mm_ss;
        String time = DateUtil.dateToStr(new Date(),DateUtil.YYYYMMDD);
        List<IotDeviceOrderDO> doList = iotDeviceOrderDao.findByYmd(time);
        iotDeviceOrder.setOrderNo(String.format("",doList.size()));
        iotDeviceOrder.setSaasId(getCode());
        iotDeviceOrder.setDel(1);
        iotDeviceOrder.setYmd(time);
        return iotDeviceOrderDao.save(iotDeviceOrder);
    }
    public IotDeviceOrderDO findById(String id) {
        return iotDeviceOrderDao.findById(id);
    }
    public static void main(String[] args) {
        System.out.println(String.format("%05d", 5));
    }
}