Browse Source

SAAS名片

suxiaoyang 6 years ago
parent
commit
196ba73d30

+ 56 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/saas/SaasBusinessCardDO.java

@ -0,0 +1,56 @@
package com.yihu.jw.entity.base.saas;
import com.yihu.jw.entity.IntegerIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Entity - SAAS名片
 * Created by progr1mmer on 2018/9/7.
 */
@Entity
@Table(name = "base_saas_business_card")
public class SaasBusinessCardDO extends IntegerIdentityEntity {
    public enum Type {
        doctor,
        patient
    }
    //SAAS ID
    private String saasId;
    //字段
    private String field;
    //类型
    private Type type;
    @Column(name = "saas_id", nullable = false)
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "field", nullable = false)
    public String getField() {
        return field;
    }
    public void setField(String field) {
        this.field = field;
    }
    @Column(name = "type", nullable = false)
    public Type getType() {
        return type;
    }
    public void setType(Type type) {
        this.type = type;
    }
}

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

@ -35,6 +35,14 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/saas_default_module_function";
    }
    /**
     * SAAS名片
     */
    public static class SaasBusinessCard extends Basic {
        public static final String PREFIX  = "/saas_business_card";
        public static final String GENERATE = "/generate";
    }
    /**
     * 模块
     */

+ 50 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/saas/SaasBusinessCardVO.java

@ -0,0 +1,50 @@
package com.yihu.jw.restmodel.base.saas;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.restmodel.IntegerIdentityVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * VO - SAAS名片
 * Created by progr1mmer on 2018/9/7.
 */
@ApiModel(value = "SaasBusinessCardVO", description = "SAAS名片")
public class SaasBusinessCardVO extends IntegerIdentityVO {
    //SAAS ID
    @ApiModelProperty(value = "Saas ID", example = "402303ee65634dfs0234sf9ad2wa00d2")
    private String saasId;
    //字段
    @ApiModelProperty(value = "实体字段", example = "name")
    private String field;
    //类型
    @ApiModelProperty(value = "名片类型", example = "doctor")
    private SaasDO.Type type;
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getField() {
        return field;
    }
    public void setField(String field) {
        this.field = field;
    }
    public SaasDO.Type getType() {
        return type;
    }
    public void setType(SaasDO.Type type) {
        this.type = type;
    }
}

+ 39 - 11
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/web/endpoint/EnvelopRestEndpoint.java

@ -29,6 +29,10 @@ public abstract class EnvelopRestEndpoint {
    @Autowired
    protected ObjectMapper objectMapper;
    protected Envelop success() {
        return success("success");
    }
    protected Envelop success(String message) {
        return success(message, 200);
    }
@ -45,8 +49,8 @@ public abstract class EnvelopRestEndpoint {
    }
    protected <J, _J> ObjEnvelop<_J> success(J obj, Class<_J> target){
        _J _target = convertToModel(obj, target);
        return success(_target);
        _J _obj = convertToModel(obj, target);
        return success("success", _obj);
    }
    protected <J> ObjEnvelop<J> success(String message, J obj){
@ -54,8 +58,8 @@ public abstract class EnvelopRestEndpoint {
    }
    protected <J, _J> ObjEnvelop<_J> success(String message, J obj, Class<_J> target){
        _J _target = convertToModel(obj, target);
        return success(message, _target);
        _J _obj = convertToModel(obj, target);
        return success(message, 200, _obj);
    }
    protected <J> ObjEnvelop<J> success(String message, int status, J obj){
@ -67,8 +71,8 @@ public abstract class EnvelopRestEndpoint {
    }
    protected <J, _J> ObjEnvelop<_J> success(String message, int status, J obj, Class<_J> target){
        _J _target = convertToModel(obj, target);
        return success(message, status, _target);
        _J _obj = convertToModel(obj, target);
        return success(message, status, _obj);
    }
    protected <T> ListEnvelop<T> success(List<T> contents){
@ -77,7 +81,7 @@ public abstract class EnvelopRestEndpoint {
    protected <T, _T> ListEnvelop<_T> success(List<T> contents, Class<_T> target){
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), target);
        return success(_contents);
        return success("success", _contents);
    }
    protected <T> ListEnvelop<T> success(String message, List<T> contents){
@ -86,7 +90,7 @@ public abstract class EnvelopRestEndpoint {
    protected <T, _T> ListEnvelop<_T> success(String message, List<T> contents, Class<_T> target){
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), target);
        return success(message, _contents);
        return success(message, 200, _contents);
    }
    protected <T> ListEnvelop<T> success(String message, int status, List<T> contents){
@ -108,7 +112,7 @@ public abstract class EnvelopRestEndpoint {
    protected <T, _T> PageEnvelop<_T> success(List<T> contents, int totalCount, int currPage, int pageSize, Class<_T> target){
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), target);
        return success(_contents, totalCount, currPage, pageSize);
        return success("success", _contents, totalCount, currPage, pageSize);
    }
    protected <T> PageEnvelop<T> success(String message, List<T> contents, int totalCount, int currPage, int pageSize) {
@ -117,7 +121,7 @@ public abstract class EnvelopRestEndpoint {
    protected <T, _T> PageEnvelop<_T> success(String message, List<T> contents, int totalCount, int currPage, int pageSize, Class<_T> target){
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), target);
        return success(message, _contents, totalCount, currPage, pageSize);
        return success(message, 200, _contents, totalCount, currPage, pageSize);
    }
    protected <T> PageEnvelop<T> success(String message, int status,  List<T> contents, int totalCount, int currPage, int pageSize) {
@ -140,16 +144,34 @@ public abstract class EnvelopRestEndpoint {
        return success("success", contents, obj);
    }
    protected <T, J, _T, _J> MixEnvelop<_T, _J> success(List<T> contents, J obj, Class<_T> targetContents, Class<_J> targetObj) {
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), targetContents);
        _J _obj = convertToModel(obj, targetObj);
        return success("success", _contents, _obj);
    }
    protected <T, J> MixEnvelop<T, J> success(String message, List<T> contents, J obj) {
        return success(message, 200, contents, obj);
    }
    protected <T, J, _T, _J> MixEnvelop<_T, _J>  success(String message, List<T> contents, J obj, Class<_T> targetContents, Class<_J> targetObj) {
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), targetContents);
        _J _obj = convertToModel(obj, targetObj);
        return success(message, 200, _contents, _obj);
    }
    protected <T, J> MixEnvelop<T, J> success(String message, int status, List<T> contents, J obj) {
        return success(message, status, contents, obj, contents.size(), 1, contents.size());
    }
    protected <T, J, _T, _J> MixEnvelop<_T, _J> success(String message, int status, List<T> contents, J obj, Class<_T> targetContents, Class<_J> targetObj) {
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), targetContents);
        _J _obj = convertToModel(obj, targetObj);
        return success(message, status, _contents, _obj, _contents.size(), 1, _contents.size());
    }
    protected <T, J> MixEnvelop<T, J> success(String message, int status, List<T> contents, J obj, int totalCount, int currPage, int pageSize) {
        MixEnvelop<T, J> mixEnvelop = new MixEnvelop();
        MixEnvelop<T, J> mixEnvelop = new MixEnvelop<>();
        mixEnvelop.setMessage(message);
        mixEnvelop.setStatus(status);
        mixEnvelop.setCurrPage(currPage);
@ -160,6 +182,12 @@ public abstract class EnvelopRestEndpoint {
        return mixEnvelop;
    }
    protected <T, J, _T, _J> MixEnvelop<_T, _J> success(String message, int status, List<T> contents, J obj, int totalCount, int currPage, int pageSize, Class<_T> targetContents, Class<_J> targetObj) {
        List<_T> _contents = convertToModels(contents, new ArrayList<>(contents.size()), targetContents);
        _J _obj = convertToModel(obj, targetObj);
        return success(message, status, _contents, _obj, totalCount, currPage, pageSize);
    }
    protected Envelop failed (String message) {
        return failed(message, -10000);
    }

+ 13 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/saas/SaasBusinessCardDao.java

@ -0,0 +1,13 @@
package com.yihu.jw.base.dao.saas;
import com.yihu.jw.entity.base.saas.SaasBusinessCardDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - SAAS名片
 * Created by progr1mmer on 2018/9/7.
 */
public interface SaasBusinessCardDao extends PagingAndSortingRepository<SaasBusinessCardDO, Integer>, JpaSpecificationExecutor<SaasBusinessCardDO> {
}

+ 111 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/saas/SaasBusinessCardEndpoint.java

@ -0,0 +1,111 @@
package com.yihu.jw.base.endpoint.saas;
import com.yihu.jw.base.service.saas.SaasBusinessCardService;
import com.yihu.jw.entity.base.saas.SaasBusinessCardDO;
import com.yihu.jw.restmodel.base.saas.SaasBusinessCardVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
 * Endpoint - SAAS名片
 * Created by progr1mmer on 2018/8/14.
 * @author progr1mmer
 */
@RestController
@RequestMapping(value = BaseRequestMapping.SaasBusinessCard.PREFIX)
@Api(value = "SAAS名片管理", description = "SAAS名片管理服务接口", tags = {"wlyy基础服务 - SAAS名片管理服务接口"})
public class SaasBusinessCardEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private SaasBusinessCardService saasBusinessCardService;
    @PostMapping(value = BaseRequestMapping.SaasBusinessCard.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建")
    public ObjEnvelop<SaasBusinessCardVO> create (
            @ApiParam(name = "json", value = "Json数据", required = true)
            @RequestBody String jsonData) throws Exception {
        SaasBusinessCardDO saasBusinessCardDO = toEntity(jsonData, SaasBusinessCardDO.class);
        saasBusinessCardDO = saasBusinessCardService.save(saasBusinessCardDO);
        return success(saasBusinessCardDO, SaasBusinessCardVO.class);
    }
    @PostMapping(value = BaseRequestMapping.SaasBusinessCard.DELETE)
    @ApiOperation(value = "删除")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id串,中间用,分隔", required = true)
            @RequestParam(value = "ids") String ids) {
        saasBusinessCardService.delete(ids.split(","));
        return success("删除成功");
    }
    @PostMapping(value = BaseRequestMapping.SaasBusinessCard.UPDATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新")
    public Envelop update (
            @ApiParam(name = "json", value = "Json数据", required = true)
            @RequestBody String jsonData) throws Exception {
        SaasBusinessCardDO saasBusinessCardDO = toEntity(jsonData, SaasBusinessCardDO.class);
        if (null == saasBusinessCardDO.getId()) {
            return failed("ID不能为空", Envelop.class);
        }
        saasBusinessCardDO = saasBusinessCardService.save(saasBusinessCardDO);
        return success(saasBusinessCardDO);
    }
    @GetMapping(value = BaseRequestMapping.SaasBusinessCard.PAGE)
    @ApiOperation(value = "获取分页")
    public PageEnvelop<SaasBusinessCardVO> page (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @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 {
        List<SaasBusinessCardDO> saasBusinessCardDOS = saasBusinessCardService.search(fields, filters, sorts, page, size);
        int count = (int)saasBusinessCardService.getCount(filters);
        return success(saasBusinessCardDOS, count, page, size, SaasBusinessCardVO.class);
    }
    @GetMapping(value = BaseRequestMapping.SaasBusinessCard.LIST)
    @ApiOperation(value = "获取列表")
    public ListEnvelop<SaasBusinessCardVO> list (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        List<SaasBusinessCardDO> saasBusinessCardDOS = saasBusinessCardService.search(fields, filters, sorts);
        return success(saasBusinessCardDOS, SaasBusinessCardVO.class);
    }
    @GetMapping(value = BaseRequestMapping.SaasBusinessCard.GENERATE)
    @ApiOperation(value = "生成名片")
    public ObjEnvelop<Map> generate (
            @ApiParam(name = "type", value = "名片类型", required = true)
            @RequestParam(value = "type") SaasBusinessCardDO.Type type,
            @ApiParam(name = "saasId", value = "SAAS ID", required = true)
            @RequestParam(value = "saasId") String saasId,
            @ApiParam(name = "sourceId", value = "实体对象ID,如医生、居民", required = true)
            @RequestParam(value = "sourceId") String sourceId) throws Exception {
        Map<String, Object> card = saasBusinessCardService.generateBusinessCard(type, saasId, sourceId);
        return success(card);
    }
}

+ 41 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/saas/SaasBusinessCardService.java

@ -0,0 +1,41 @@
package com.yihu.jw.base.service.saas;
import com.yihu.jw.base.dao.saas.SaasBusinessCardDao;
import com.yihu.jw.base.service.doctor.BaseDoctorService;
import com.yihu.jw.entity.base.saas.SaasBusinessCardDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Service - SAAS名片
 * Created by progr1mmer on 2018/9/7.
 */
@Service
public class SaasBusinessCardService extends BaseJpaService<SaasBusinessCardDO, SaasBusinessCardDao> {
    @Autowired
    private BaseDoctorService doctorService;
    public Map<String, Object> generateBusinessCard(SaasBusinessCardDO.Type type, String saasId, String id) throws Exception {
        List<SaasBusinessCardDO> saasBusinessCardDO = search("type=" + type  + ";saasId=" + saasId);
        Map<String, Object> card = new HashMap<>();
        if (type == SaasBusinessCardDO.Type.doctor) {
            //模拟加载医生数据
            Map<String, Object> source = new HashMap<>();
            saasBusinessCardDO.forEach(item -> card.put(item.getField(), source.get(item.getField())));
            return card;
        } else if (type == SaasBusinessCardDO.Type.patient) {
            //模拟加载居民数据
            Map<String, Object> source = new HashMap<>();
            saasBusinessCardDO.forEach(item -> card.put(item.getField(), source.get(item.getField())));
            return card;
        }
        return card;
    }
}