Browse Source

donate-console的配置更新,有关机构的接口

shicr 8 years ago
parent
commit
4ed6cb9a8f

+ 2 - 1
donate-console/src/main/java/com/uas/console/donate/Application.java

@@ -3,11 +3,12 @@ package com.uas.console.donate;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+import org.springframework.context.annotation.ImportResource;
 import org.springframework.web.bind.annotation.RestController;
 
 @SpringBootApplication
 @RestController
-
+@ImportResource("classpath:spring/*.xml")
 public class Application {
 
     public static void main(String[] args){

+ 48 - 16
donate-console/src/main/java/com/uas/console/donate/Impl/OrgServiceImpl.java

@@ -1,6 +1,7 @@
 package com.uas.console.donate.Impl;
 
 
+import com.alibaba.fastjson.JSON;
 import com.uas.console.donate.dao.OrgDao;
 import com.uas.console.donate.model.Org;
 import com.uas.console.donate.service.OrgService;
@@ -17,33 +18,54 @@ public class OrgServiceImpl implements OrgService {
     @Autowired
     private OrgDao orgDao;
 
+    //发起机构进行判断,有草稿取出草稿,没草稿新建机构表单
+    public Org show(){
+        if(orgDao.findDraft()==null){
+            return null;
+        }else{
+            return orgDao.findDraft();
+        }
+    }
+
+    //保存机构
     public Org save(Org org){
+        System.out.print(JSON.toJSONString(org));
+        //如果机构不是发布状态,就设置为草稿状态
+        if(org.getPublish()==null||org.getPublish()==1){
+            org.setPublish(1);
+        }
+       return orgDao.save(org);
+    }
+
+    //提交机构申请
+    public Org sumbit(Org org){
+        //设置未审核
+        org.setStatus(0);
+        //设置正式提交
+        org.setPublish(2);
         return orgDao.save(org);
     }
 
+    //查询某一机构具体信息
+    public Org findOne(Long id){
+        return orgDao.findOne(id);
+    }
+
     public Page<Org> findAll(Pageable pageable){
 
         return orgDao.findAll(pageable);
     }
 
-    public Page<Org> findUnnotify(Pageable pageable){
-        return orgDao.findUnnotify(pageable);
-    }
-
-    public Page<Org> findChecked(Pageable pageable){
-        return orgDao.findChecked(pageable);
-    }
 
-    public Page<Org> findRefused(Pageable pageable){
-        return orgDao.findRefused(pageable);
-    }
 
+    //批准某机构
     public Org approve(Long id){
         Org org=orgDao.findOne(id);
         org.setStatus(1);
         return orgDao.save(org);
     }
 
+    //驳回某机构
     public Org unapprove(Long id,String refuse){
         Org org=orgDao.findOne(id);
         org.setStatus(2);
@@ -51,16 +73,26 @@ public class OrgServiceImpl implements OrgService {
         return orgDao.save(org);
     }
 
-    public List<Org> findByTypeAndMajorArea(Integer type,Integer majorArea){
-        return orgDao.findByTypeAndMajorArea(type,majorArea);
+    //取出某状态下的所有机构
+    public List<Org> findByStatus(Integer status){
+        return orgDao.findByStatus(status);
     }
 
-    public List<Org> findByType(Integer type){
-        return orgDao.findByType(type);
+    //查询某审核状态下,属于某类别的机构
+    public List<Org> findByType(Integer type,Integer status){
+        return orgDao.findByType(type,status);
     }
 
-    public List<Org> findByMajorArea(Integer majorArea){
-        return orgDao.findByMajorArea(majorArea);
+    //查询某审核状态下,属于某领域的机构
+    public List<Org> findByMajorArea(Integer majorArea,Integer status){
+        return orgDao.findByMajorArea(majorArea,status);
     }
 
+    //查询某审核状态下,属于某类别和领域的机构
+    public List<Org> findByTypeAndMajorArea(Integer type,Integer majorArea,Integer status){
+        return orgDao.findByTypeAndMajorArea(type,majorArea,status);
+    }
+
+
+
 }

+ 123 - 31
donate-console/src/main/java/com/uas/console/donate/controller/OrgController.java

@@ -1,18 +1,19 @@
 package com.uas.console.donate.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.uas.console.donate.model.Org;
 import com.uas.console.donate.service.OrgService;
+import com.uas.dfs.service.FileClient;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
 
-import java.util.ArrayList;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 @Controller
@@ -21,46 +22,118 @@ public class OrgController {
     @Autowired
     private OrgService orgService;
 
+    @Autowired
+    private FileClient fileClient;
+
     /**
-     * 获取未通知的机构列表
+     * 发起机构,有草稿取出草稿,没有草稿就新增
      */
     @ResponseBody
-    @RequestMapping("/unnotify")
-    public Page<Org> findUnnotify(@RequestParam(value = "page",defaultValue = "0")Integer page,
-                                 @RequestParam(value = "size",defaultValue = "10")Integer size){
-        Pageable pageable=pageSort(page,size);
-
-        return orgService.findUnnotify(pageable);
+    @RequestMapping("/show")
+    public Org show(){
+        return orgService.show();
     }
-    private Pageable pageSort(Integer page,Integer size){
-        Sort.Order timeSort=new Sort.Order(Sort.Direction.DESC,"createTime");
-        List<Sort.Order> list=new ArrayList<Sort.Order>();
-        list.add(timeSort);
-        Sort sort = new Sort(list);
-        Pageable pageable=new PageRequest(page,size,sort);
-        return pageable;
+
+    /**
+     * 保存机构草稿
+     */
+    @ResponseBody
+    @RequestMapping("/save")
+    public Org save(@RequestParam(required = false) MultipartFile logo,
+                    @RequestParam(required = false) MultipartFile certificate,
+                    @RequestParam(required = false) MultipartFile personCertificate,
+                    @RequestParam(required = false) MultipartFile donateCertificate,
+                    @RequestParam(required = false) MultipartFile legalIdCard,
+                    @RequestParam(required = false) MultipartFile material,
+                    @RequestParam(required = false) MultipartFile certify,
+                    String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException{
+
+        Org org= JSONObject.parseObject(jsonStr,Org.class);
+
+        if (logo!=null) {
+            String file1=fileClient.upload(logo.getBytes(),logo.getSize(),"jpg",null);
+            org.setLogo(file1);
+        }
+        if(certificate!=null){
+            String file2=fileClient.upload(certificate.getBytes(),certificate.getSize(),"jpg",null);
+            org.setCertificate(file2);
+        }
+        if(personCertificate!=null){
+            String file3=fileClient.upload(personCertificate.getBytes(),personCertificate.getSize(),"jpg",null);
+            org.setPersonCertificate(file3);
+        }
+        if(donateCertificate!=null){
+            String file4=fileClient.upload(donateCertificate.getBytes(),donateCertificate.getSize(),"jpg",null);
+            org.setDonateCertificate(file4);
+        }
+        if(legalIdCard!=null){
+            String file5=fileClient.upload(legalIdCard.getBytes(),legalIdCard.getSize(),"jpg",null);
+            org.setLegalIdCard(file5);
+        }
+        if(material!=null){
+            String file6=fileClient.upload(material.getBytes(),material.getSize(),"jpg",null);
+            org.setMaterial(file6);
+        }
+        if(certify!=null){
+            String file7=fileClient.upload(certify.getBytes(),certify.getSize(),"jpg",null);
+            org.setCertify(file7);
+        }
+
+        return orgService.save(org);
     }
 
     /**
-     * 获取已审核的机构列表
+     *提交机构申请
      */
     @ResponseBody
-    @RequestMapping("/checked")
-    public Page<Org> findChecked(@RequestParam(value = "page",defaultValue = "0")Integer page,
-                                 @RequestParam(value = "size",defaultValue = "10")Integer size){
-        Pageable pageable=pageSort(page,size);
-        return orgService.findChecked(pageable);
+    @RequestMapping("/submit")
+    public Org submit(@RequestParam(required = false) MultipartFile logo,
+                      @RequestParam(required = false) MultipartFile certificate,
+                      @RequestParam(required = false) MultipartFile personCertificate,
+                      @RequestParam(required = false) MultipartFile donateCertificate,
+                      @RequestParam(required = false) MultipartFile legalIdCard,
+                      @RequestParam(required = false) MultipartFile material,
+                      @RequestParam(required = false) MultipartFile certify,
+                      String jsonStr, HttpServletRequest request, HttpServletResponse response) throws IOException{
+        Org org= JSONObject.parseObject(jsonStr,Org.class);
+        if (logo != null) {
+            String file1=fileClient.upload(logo.getBytes(),logo.getSize(),"jpg",null);
+            org.setLogo(file1);
+        }
+        if(certificate!=null){
+            String file2=fileClient.upload(certificate.getBytes(),certificate.getSize(),"jpg",null);
+            org.setCertificate(file2);
+        }
+        if(personCertificate!=null){
+            String file3=fileClient.upload(personCertificate.getBytes(),personCertificate.getSize(),"jpg",null);
+            org.setPersonCertificate(file3);
+        }
+        if(donateCertificate!=null){
+            String file4=fileClient.upload(donateCertificate.getBytes(),donateCertificate.getSize(),"jpg",null);
+            org.setDonateCertificate(file4);
+        }
+        if(legalIdCard!=null){
+            String file5=fileClient.upload(legalIdCard.getBytes(),legalIdCard.getSize(),"jpg",null);
+            org.setLegalIdCard(file5);
+        }
+        if(material!=null){
+            String file6=fileClient.upload(material.getBytes(),material.getSize(),"jpg",null);
+            org.setMaterial(file6);
+        }
+        if(certify!=null){
+            String file7=fileClient.upload(certify.getBytes(),certify.getSize(),"jpg",null);
+            org.setCertify(file7);
+        }
+        return orgService.sumbit(org);
     }
 
     /**
-     * 获取未通过的机构列表
+     * 查询某一机构详情信息
      */
     @ResponseBody
-    @RequestMapping("/refused")
-    public Page<Org> findRefused(@RequestParam(value = "page",defaultValue = "0")Integer page,
-                                @RequestParam(value = "size",defaultValue = "10")Integer size){
-        Pageable pageable=pageSort(page,size);
-        return orgService.findRefused(pageable);
+    @RequestMapping("/detail")
+    public Org detail(Long id){
+        return orgService.findOne(id);
     }
 
     /**
@@ -81,4 +154,23 @@ public class OrgController {
         return orgService.unapprove(id,refuse);
     }
 
+   /**
+    * 展示特定机构信息
+    * type=0,展示全部type,major=0展示所有major
+    * 默认展示已审核的机构信息
+    */
+     @ResponseBody
+     @RequestMapping("/showOrgs")
+     public List<Org> showOrgs(@RequestParam(defaultValue ="0") Integer type, @RequestParam(defaultValue="0") Integer majorArea, @RequestParam(defaultValue="1")Integer status) {
+         if (type == 0 && majorArea != 0) {
+             return orgService.findByMajorArea(majorArea,status);
+         } else if (type != 0 && majorArea == 0) {
+             return orgService.findByType(type,status);
+         } else if(type!=0 && majorArea!=0 ){
+             return orgService.findByTypeAndMajorArea(type, majorArea,status);
+         }else{
+             return orgService.findByStatus(status);
+         }
+     }
+
 }

+ 16 - 13
donate-console/src/main/java/com/uas/console/donate/dao/OrgDao.java

@@ -16,23 +16,26 @@ import java.util.List;
 @Repository
 public interface OrgDao extends JpaRepository<Org,Long>,JpaSpecificationExecutor<Org>,PagingAndSortingRepository<Org, Long> {
 
-    @Query("from Org where type=:type")
-    List<Org> findByType(@Param("type") Integer type);
+    //取出某状态下的所有已正式发布机构
+    @Query("from Org o where o.status=:status and publish=2")
+    List<Org> findByStatus(@Param("status")Integer status);
 
-    @Query("from Org where majorArea=:majorArea")
-    List<Org> findByMajorArea(@Param("majorArea") Integer majorArea);
+    //根据机构类型和状态查询已发布机构
+    @Query("from Org o where type=:type and status=:status and publish=2 order By createTime desc")
+    List<Org> findByType(@Param("type") Integer type,@Param("status")Integer status);
 
-    @Query("from Org where type=:type and majorArea=:majorArea")
-    List<Org> findByTypeAndMajorArea(@Param("type") Integer type,@Param("majorArea")Integer majorArea);
+    //根据机构主要领域和状态查询已发布机构
+    @Query("from Org o where majorArea=:majorArea and status=:status and publish=2 order By createTime desc")
+    List<Org> findByMajorArea(@Param("majorArea") Integer majorArea,@Param("status")Integer status);
 
-    Page<Org> findAll(Pageable pageable);
+    //根据机构类别,主要领域,状态查询已发布机构
+    @Query("from Org o where type=:type and majorArea=:majorArea and status=:status and publish=2 order By createTime desc" )
+    List<Org> findByTypeAndMajorArea(@Param("type") Integer type,@Param("majorArea")Integer majorArea,@Param("status")Integer status);
 
-    @Query("from Org o where o.status=0")
-    Page<Org> findUnnotify(Pageable pageable);
+    //取出草稿状态的机构
+    @Query("from Org  o where publish=1")
+    Org findDraft();
 
-    @Query("from Org o where o.status=1")
-    Page<Org> findChecked(Pageable pageable);
+    Page<Org> findAll(Pageable pageable);
 
-    @Query("from Org o where o.status=2")
-    Page<Org> findRefused(Pageable pageable);
 }

+ 14 - 0
donate-console/src/main/java/com/uas/console/donate/model/Org.java

@@ -269,6 +269,12 @@ public class Org implements Serializable{
     @Column(name = "org_bank_certify")
     private String certify;
 
+    /**
+     * 是否是草稿状态,1是草稿,2是发布
+     * @return
+     */
+    @Column(name = "org_publish")
+    private Integer publish;
 
 
     public Long getId() {
@@ -598,5 +604,13 @@ public class Org implements Serializable{
     public void setCertify(String certify) {
         this.certify = certify;
     }
+
+    public Integer getPublish() {
+        return publish;
+    }
+
+    public void setPublish(Integer publish) {
+        this.publish = publish;
+    }
 }
 

+ 18 - 6
donate-console/src/main/java/com/uas/console/donate/service/OrgService.java

@@ -11,11 +11,17 @@ public interface OrgService {
 
     Page<Org> findAll(Pageable pageable);
 
-    Page<Org> findUnnotify(Pageable pageable);
+    //发起机构,有草稿取出草稿,没有草稿,则新建机构
+    Org show();
 
-    Page<Org> findChecked(Pageable pageable);
+    //保存机构
+    Org save(Org org);
 
-    Page<Org> findRefused(Pageable pageable);
+    //提交机构申请
+    Org sumbit(Org org);
+
+    //获取某一机构详细信息
+    Org findOne(Long id);
 
     //批准机构申请
     Org approve(Long id);
@@ -23,12 +29,18 @@ public interface OrgService {
     //驳回机构申请
     Org unapprove(Long id,String refuse);
 
+    //取出某状态下的所有机构
+    List<Org> findByStatus(Integer status);
+
+    //根据机构类型和状态查询机构
+    List<Org> findByType(Integer type,Integer status);
 
-    List<Org> findByType(Integer type);
+    //根据机构主要领域和状态查询机构
+    List<Org> findByMajorArea(Integer majorArea,Integer status);
 
-    List<Org> findByMajorArea(Integer majorArea);
+    //根据机构类别,主要领域,状态查询机构
+    List<Org> findByTypeAndMajorArea(Integer type,Integer majorArea,Integer status);
 
-    List<Org> findByTypeAndMajorArea(Integer type,Integer majorArea);
 
 
 

+ 20 - 0
donate-console/src/main/java/com/uas/console/donate/util/ObjectUtils.java

@@ -1,9 +1,11 @@
 package com.uas.console.donate.util;
 
 import java.io.*;
+import java.lang.reflect.Field;
 import java.util.Collection;
 import java.util.Map;
 
+
 /**
  * 对象工具类
  * 
@@ -44,4 +46,22 @@ public class ObjectUtils {
 		ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
 		return (T) in.readObject();
 	}
+
+	/**
+	 * 判断对象里面的属相是否全为空,如果全是空则返回false
+	 */
+	public static boolean isNull(Object obj){
+		try {
+
+			for(Field f:obj.getClass().getDeclaredFields()){
+				f.setAccessible(true);
+				if(f.get(obj)!=null){
+					return true;
+				}
+			}
+		}catch (IllegalAccessException exception){
+
+		}
+		return false;
+	}
 }

+ 15 - 1
donate-console/src/main/resources/config/application-dev.properties

@@ -23,4 +23,18 @@ security.basic.path=/console
 security.user.name=admin
 security.user.password=select111***
 security.user.role=ADMIN
-security.ignored=false
+security.ignored=false
+
+spring.jpa.hibernate.show-sql= true  
+spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.dialect=org.hibernate.dialect.5Dialect  
+spring.jackson.serialization.indent_output=false  
+
+zk.url=zookeeper://10.10.100.11:2181
+dubbo.owner=test
+dubbo.group=test
+
+spring.http.encoding.force=true
+spring.http.multipart.enabled=true
+spring.http.multipart.max-file-size=128MB
+spring.http.multipart.max-request-size=128MB

+ 14 - 0
donate-console/src/main/resources/spring/dubbo.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
+
+    <dubbo:application name="b2b_consumer" />
+
+    <dubbo:registry address="${zk.url}" check="false" />
+
+    <!-- 分布式文件服务 -->
+    <dubbo:reference id="fileClient" interface="com.uas.dfs.service.FileClient" timeout="100000"/>
+
+</beans>