Browse Source

Merge branch 'dev' of wangzhinan/wlyy2.0 into dev

huangwenjie 6 years ago
parent
commit
c88861edf4

+ 81 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/HospitalServiceItemDO.java

@ -0,0 +1,81 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-16 14:49
 * @desc 机构服务
 **/
@Entity
@Table(name = "wlyy_hospital_service_item")
public class HospitalServiceItemDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;//saasId
    @Column(name = "hospital")
    private String hospital; //医院code
    @Column(name = "hospital_name")
    private String hospitalName;//医院名称
    @Column(name = "service_item_id")
    private String serviceItemId;//服务项目id
    @Column(name = "status")
    private Integer status;//状态
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "hospital")
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    @Column(name = "hospital_name")
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    @Column(name = "service_item_id")
    public String getServiceItemId() {
        return serviceItemId;
    }
    public void setServiceItemId(String serviceItemId) {
        this.serviceItemId = serviceItemId;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 115 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/SpecialistEvaluateDO.java

@ -0,0 +1,115 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/20.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-20 9:47
 * @desc 评论表
 **/
@Entity
@Table(name = "wlyy_specialist_evaluate")
public class SpecialistEvaluateDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId; //saasId
    @Column(name = "doctor")
    private String doctor;//被评论的医生
    @Column(name = "patient")
    private String patient;//评论人
    @Column(name = "evaluate_type")
    private Integer evaluateType;//评论种类
    @Column(name = "relation_type")
    private Integer relationType;//评价类型
    @Column(name = "relation_code")
    private Integer relationCode;//所属服务code
    @Column(name = "score")
    private Integer score;//得分
    @Column(name = "type")
    private Integer type;//评论方式
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "doctor")
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "evaluate_type")
    public Integer getEvaluateType() {
        return evaluateType;
    }
    public void setEvaluateType(Integer evaluateType) {
        this.evaluateType = evaluateType;
    }
    @Column(name = "relation_type")
    public Integer getRelationType() {
        return relationType;
    }
    public void setRelationType(Integer relationType) {
        this.relationType = relationType;
    }
    @Column(name = "relation_code")
    public Integer getRelationCode() {
        return relationCode;
    }
    public void setRelationCode(Integer relationCode) {
        this.relationCode = relationCode;
    }
    @Column(name = "score")
    public Integer getScore() {
        return score;
    }
    public void setScore(Integer score) {
        this.score = score;
    }
    @Column(name = "type")
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
}

+ 93 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/SpecialistEvaluateLabelDO.java

@ -0,0 +1,93 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/20.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-20 10:01
 * @desc 评论标签
 **/
@Entity
@Table(name = "wlyy_specialist_evaluate_label")
public class SpecialistEvaluateLabelDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "doctor")
    private String doctor;//被评论的医生
    @Column(name = "evaluate_typr")
    private String evaluateType;//评论种类
    @Column(name = "relation_code")
    private String relationCode;//评论类型
    @Column(name = "content")
    private String content;//标签内容
    @Column(name = "patient")
    private String patient;//患者code
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "doctor")
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    @Column(name = "evaluate_type")
    public String getEvaluateType() {
        return evaluateType;
    }
    public void setEvaluateType(String evaluateType) {
        this.evaluateType = evaluateType;
    }
    @Column(name = "relation_code")
    public String getRelationCode() {
        return relationCode;
    }
    public void setRelationCode(String relationCode) {
        this.relationCode = relationCode;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
}

+ 81 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/SpecialistEvaluateScoreDO.java

@ -0,0 +1,81 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/20.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-20 10:28
 * @desc 被评论人积分
 **/
@Entity
@Table(name = "wlyy_specialist_evaluate_score")
public class SpecialistEvaluateScoreDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "doctor")
    private String doctor;//医生
    @Column(name = "evaluate_type")
    private String evaluateType;//评论种类
    @Column(name = "relation_code")
    private String relationCode;//关联code
    @Column(name = "score")
    private String score;//评论得分
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "doctor")
    public String getDoctor() {
        return doctor;
    }
    public void setDoctor(String doctor) {
        this.doctor = doctor;
    }
    @Column(name = "evaluate_type")
    public String getEvaluateType() {
        return evaluateType;
    }
    public void setEvaluateType(String evaluateType) {
        this.evaluateType = evaluateType;
    }
    @Column(name = "relation_code")
    public String getRelationCode() {
        return relationCode;
    }
    public void setRelationCode(String relationCode) {
        this.relationCode = relationCode;
    }
    @Column(name = "score")
    public String getScore() {
        return score;
    }
    public void setScore(String score) {
        this.score = score;
    }
}

+ 236 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/SpecialistServiceItemDO.java

@ -0,0 +1,236 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-16 10:16
 * @desc 服务项目
 **/
@Entity
@Table(name = "wlyy_service_item")
public class SpecialistServiceItemDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId; // saasId
    @Column(name = "title")
    private String title; //项目名称
    @Column(name = "content")
    private String content;//项目内涵
    @Column(name = "exclude_content")
    private String excludeContent; // 除去内容
    @Column(name = "description")
    private String description;//说明
    @Column(name = "disease_item")
    private String diseaseItem; //疾病项目
    @Column(name = "reserve")
    private Integer reserve; //是否预约
    @Column(name = "type")
    private Integer type;//完成方式
    @Column(name = "evaluation")
    private Integer evaluation;//项目评价
    @Column(name = "item_type")
    private Integer itemType; //项目类型
    @Column(name = "hospital_grade")
    private Integer hospitalGrade; //医院等级
    @Column(name = "three_hospitals")
    private Integer threeHospitals; //三级医院收费标准
    @Column(name = "two_hospitals")
    private Integer twoHospitals; //二级医院收费标准
    @Column(name = "one_hospitals")
    private Integer oneHospitals;//一级医院以及一级以下的社区医院
    @Column(name = "unit")
    private Integer unit; //计价单位
    @Column(name = "add_item")
    private String addItem;//加收项目
    @Column(name = "imediate")
    private Integer imediate;//立即生效
    @Column(name = "status")
    private Integer status; //删除状态
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "title")
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "exclude_content")
    public String getExcludeContent() {
        return excludeContent;
    }
    public void setExcludeContent(String excludeContent) {
        this.excludeContent = excludeContent;
    }
    @Column(name = "description")
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "disease_item")
    public String getDiseaseItem() {
        return diseaseItem;
    }
    public void setDiseaseItem(String diseaseItem) {
        this.diseaseItem = diseaseItem;
    }
    @Column(name = "reserve")
    public Integer getReserve() {
        return reserve;
    }
    public void setReserve(Integer reserve) {
        this.reserve = reserve;
    }
    @Column(name = "type")
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @Column(name = "evaluation")
    public Integer getEvaluation() {
        return evaluation;
    }
    public void setEvaluation(Integer evaluation) {
        this.evaluation = evaluation;
    }
    @Column(name = "item_type")
    public Integer getItemType() {
        return itemType;
    }
    public void setItemType(Integer itemType) {
        this.itemType = itemType;
    }
    @Column(name = "hospital_grade")
    public Integer getHospitalGrade() {
        return hospitalGrade;
    }
    public void setHospitalGrade(Integer hospitalGrade) {
        this.hospitalGrade = hospitalGrade;
    }
    @Column(name = "three_hospitals")
    public Integer getThreeHospitals() {
        return threeHospitals;
    }
    public void setThreeHospitals(Integer threeHospitals) {
        this.threeHospitals = threeHospitals;
    }
    @Column(name = "two_hospitals")
    public Integer getTwoHospitals() {
        return twoHospitals;
    }
    public void setTwoHospitals(Integer twoHospitals) {
        this.twoHospitals = twoHospitals;
    }
    @Column(name = "one_hospitals")
    public Integer getOneHospitals() {
        return oneHospitals;
    }
    public void setOneHospitals(Integer oneHospitals) {
        this.oneHospitals = oneHospitals;
    }
    @Column(name = "unit")
    public Integer getUnit() {
        return unit;
    }
    public void setUnit(Integer unit) {
        this.unit = unit;
    }
    @Column(name = "add_item")
    public String getAddItem() {
        return addItem;
    }
    public void setAddItem(String addItem) {
        this.addItem = addItem;
    }
    @Column(name = "imediate")
    public Integer getImediate() {
        return imediate;
    }
    public void setImediate(Integer imediate) {
        this.imediate = imediate;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 70 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/specialist/SpecialistServiceItemOperateLogDO.java

@ -0,0 +1,70 @@
package com.yihu.jw.entity.specialist;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author wangzhinan
 * @create 2018-08-16 10:36
 * @desc 服务项目修改记录
 **/
@Entity
@Table(name = "wlyy_service_item_operate_log")
public class SpecialistServiceItemOperateLogDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "service_item_id")
    private String serviceItemId; //服务项目id
    @Column(name = "operate_log")
    private String operateLog; //操作日志
    @Column(name = "status")
    private Integer status;//删除状态
    @Column(name = "saas_id")
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    @Column(name = "service_item_id")
    public String getServiceItemId() {
        return serviceItemId;
    }
    public void setServiceItemId(String serviceItemId) {
        this.serviceItemId = serviceItemId;
    }
    @Column(name = "operate_log")
    public String getOperateLog() {
        return operateLog;
    }
    public void setOperateLog(String operateLog) {
        this.operateLog = operateLog;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
}

+ 7 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/specialist/SpecialistMapping.java

@ -65,4 +65,11 @@ public class SpecialistMapping {
        public static final String checkAfterQrCode = "checkAfterQrCode";
    }
    public static class serviceItem{
        public static final String createServiceItem = "/createServiceItem";
        public static final String getServiceItem = "/getServiceItem";
        public static final String batchDelete = "/batchDelete";
        public static final String updateServiceItem = "/updateServiceItem";
    }
}

+ 130 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/SpecialistServiceItemController.java

@ -0,0 +1,130 @@
package com.yihu.jw.controller;/**
 * Created by nature of king on 2018/8/17.
 */
import com.alibaba.fastjson.JSONArray;
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.specialist.SpecialistMapping;
import com.yihu.jw.service.SpecialistServiceItemService;
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.cloud.sleuth.Tracer;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @author wangzhinan
 * @create 2018-08-17 9:33
 * @desc 服务项目
 **/
@RestController
@RequestMapping(SpecialistMapping.api_specialist_common)
@Api(tags = "服务项目相关操作", description = "服务项目相关操作")
public class SpecialistServiceItemController extends EnvelopRestController {
    @Autowired
    private Tracer tracer;
    @Autowired
    private SpecialistServiceItemService specialistServiceItemService;
    /**
     * 服务项目列表查询
     *
     * @param serviceItem
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping(value = SpecialistMapping.serviceItem.getServiceItem)
    @ApiOperation(value = "服务项目列表查询")
    public Envelop<SpecialistServiceItemDO> select(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                                       @RequestParam(value = "serviceItem")String serviceItem,
                                                   @ApiParam(value = "当前页",name = "page")
                                                   @RequestParam(value = "page",defaultValue = "1") Integer page,
                                                   @ApiParam(value = "显示记录数",name = "pageSize",defaultValue = "10")
                                                       @RequestParam(value = "pageSize") Integer pageSize){
        try {
            SpecialistServiceItemDO serviceItemDO = toEntity(serviceItem,SpecialistServiceItemDO.class);
            return specialistServiceItemService.select(serviceItemDO,page,pageSize);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    /**
     * 服务项目添加
     *
     * @param serviceItem
     * @return
     */
    @GetMapping(value = SpecialistMapping.serviceItem.createServiceItem)
    @ApiOperation(value = "服务项目添加")
    public Envelop<Boolean> insert(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                                       @RequestParam(value = "serviceItem")String serviceItem){
        try {
            SpecialistServiceItemDO serviceItemDO = toEntity(serviceItem,SpecialistServiceItemDO.class);
            return specialistServiceItemService.insert(serviceItemDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    /**
     * 批量删除服务项目
     * @param ids
     * @return
     */
    @PostMapping(value = SpecialistMapping.serviceItem.batchDelete)
    @ApiOperation(value = "批量删除服务项目")
    public Envelop<Boolean> batchDelete(@ApiParam(name="ids",value = "id集合")
                                        @RequestParam(value = "ids",required = false)String ids){
        try{
            Envelop<Boolean> envelop = new Envelop<>();
            JSONArray array = JSONArray.parseArray(ids);
            List<String> itemIds = new ArrayList<>();
            for (int i = 0;i<array.size();i++){
                itemIds.add(array.getString(i));
            }
            specialistServiceItemService.batchDelete(itemIds);
            envelop.setObj(true);
            return envelop;
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
    /**
     * 更新服务项目
     *
     * @param serviceItem
     * @return
     */
    @GetMapping(value = SpecialistMapping.serviceItem.updateServiceItem)
    @ApiOperation(value = "服务项目更新")
    public Envelop<Boolean> udpate(@ApiParam(name = "serviceItem", value = "服务项目JSON")
                                   @RequestParam(value = "serviceItem")String serviceItem){
        try {
            SpecialistServiceItemDO serviceItemDO = toEntity(serviceItem,SpecialistServiceItemDO.class);
            return specialistServiceItemService.update(serviceItemDO);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 16 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/SpecialistServiceItemDao.java

@ -0,0 +1,16 @@
package com.yihu.jw.dao;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-16 10:58
 * @desc 服务项目Dao
 **/
public interface SpecialistServiceItemDao extends PagingAndSortingRepository<SpecialistServiceItemDO, String>,
        JpaSpecificationExecutor<SpecialistServiceItemDO> {
}

+ 17 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/SpecialistServiceItemOperateLogDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.dao;/**
 * Created by nature of king on 2018/8/16.
 */
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author wangzhinan
 * @create 2018-08-16 11:04
 * @desc 服务项目操作日志
 **/
public interface SpecialistServiceItemOperateLogDao  extends PagingAndSortingRepository<SpecialistServiceItemOperateLogDO, String>,
        JpaSpecificationExecutor<SpecialistServiceItemOperateLogDO> {
}

+ 35 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistServiceItemOperateLogService.java

@ -0,0 +1,35 @@
package com.yihu.jw.service;/**
 * Created by nature of king on 2018/8/17.
 */
import com.yihu.jw.dao.SpecialistServiceItemOperateLogDao;
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import com.yihu.jw.restmodel.common.Envelop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * @author wangzhinan
 * @create 2018-08-17 8:48
 * @desc 服务项目操作记录
 **/
@Service
@Transactional
public class SpecialistServiceItemOperateLogService {
    @Autowired
    private SpecialistServiceItemOperateLogDao specialistServiceItemOperateLogDao;
    /**
     *
     * @param specialistServiceItemOperateLogDO
     * @return
     */
    public Envelop<Boolean> insert(SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO){
        Envelop<Boolean> envelop = new Envelop<>();
        specialistServiceItemOperateLogDao.save(specialistServiceItemOperateLogDO);
        envelop.setObj(true);
        return envelop;
    }
}

+ 157 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistServiceItemService.java

@ -0,0 +1,157 @@
package com.yihu.jw.service;/**
 * Created by nature of king on 2018/8/17.
 */
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.dao.SpecialistServiceItemDao;
import com.yihu.jw.dao.SpecialistServiceItemOperateLogDao;
import com.yihu.jw.entity.specialist.SpecialistServiceItemDO;
import com.yihu.jw.entity.specialist.SpecialistServiceItemOperateLogDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.rm.health.bank.HealthBankMapping;
import com.yihu.jw.util.ISqlUtils;
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 javax.persistence.Column;
import javax.persistence.Table;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author wangzhinan
 * @create 2018-08-17 8:48
 * @desc 服务项目
 **/
@Service
@Transactional
public class SpecialistServiceItemService {
    @Autowired
    private SpecialistServiceItemDao specialistServiceItemDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SpecialistServiceItemOperateLogDao specialistServiceItemOperateLogDao;
    /**
     * 添加服务项目
     *
     * @param specialistServiceItemDO
     * @return
     */
    public Envelop<Boolean> insert(SpecialistServiceItemDO specialistServiceItemDO){
        Envelop<Boolean> envelop = new Envelop<>();
        specialistServiceItemDao.save(specialistServiceItemDO);
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 按条件查询
     *
     * @param specialistServiceItemDO
     * @param page
     * @param size
     * @return
     */
    public Envelop<SpecialistServiceItemDO> select(SpecialistServiceItemDO specialistServiceItemDO,Integer page,Integer size){
        Envelop<SpecialistServiceItemDO> envelop = new Envelop<>();
        String sql = ISqlUtils.getSql(specialistServiceItemDO,page,size,"*");
        List<SpecialistServiceItemDO> specialistServiceItemDOS = jdbcTemplate.query(sql,new BeanPropertyRowMapper(SpecialistServiceItemDO.class));
        String sqlcount = new ISqlUtils().getSql(specialistServiceItemDO,0,0,"count");
        List<Map<String,Object>> rstotal = jdbcTemplate.queryForList(sqlcount);
        Long count = 0L;
        if(rstotal!=null&&rstotal.size()>0){
            count = (Long) rstotal.get(0).get("total");
        }
        return Envelop.getSuccessListWithPage(HealthBankMapping.api_success,specialistServiceItemDOS,page,size,count);
    }
    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    public Envelop<Boolean> batchDelete(List<String> ids){
        Envelop<Boolean> envelop = new Envelop<>();
        for (int i =0;i<ids.size();i++){
            SpecialistServiceItemDO specialistServiceItemDO = specialistServiceItemDao.findOne(ids.get(i));
            specialistServiceItemDO.setStatus(0);
            specialistServiceItemDO.setCreateTime(new Date());
            specialistServiceItemDO.setUpdateTime(new Date());
            specialistServiceItemDao.save(specialistServiceItemDO);
        }
        envelop.setObj(true);
        return envelop;
    }
    /**
     * 修改服务项目
     *
     * @param specialistServiceItemDO
     * @return
     */
    public Envelop<Boolean> update(SpecialistServiceItemDO specialistServiceItemDO){
        Envelop<Boolean> envelop = new Envelop<>();
        SpecialistServiceItemDO specialistServiceItemDO1 = specialistServiceItemDao.findOne(specialistServiceItemDO.getId());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(specialistServiceItemDO1);
        String sql = ISqlUtils.getUpdateSql(specialistServiceItemDO);
        jdbcTemplate.update(sql);
        Class c = specialistServiceItemDO.getClass();
        Table table = (Table)c.getAnnotation(Table.class);
        String tableName = table.name();
        Field[] fArray = c.getDeclaredFields();
        JSONArray array = new JSONArray();
        for (Field f:fArray){
            String getMethoName = "";
            JSONObject object = new JSONObject();
            boolean isCExist = f.isAnnotationPresent(Column.class);
            if (isCExist){
                Column mc = f.getAnnotation(Column.class);
                String columeName = mc.name();
                String name = f.getName();
                Class a= f.getType();
                Object value= null;
                getMethoName = "get" + name.substring(0,1).toUpperCase()+name.substring(1);
                try {
                    Method m = c.getMethod(getMethoName);
                    value = (Object)m.invoke(specialistServiceItemDO);
                    if (value == null || "".equals(value)){
                        continue;
                    }
                    else if (value instanceof  String || value instanceof Integer){
                        value = "'"+value+"'";
                        object.put(name+"旧",jsonObject.getString(name));
                        object.put(name,value);
                        array.add(object);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        SpecialistServiceItemOperateLogDO specialistServiceItemOperateLogDO = new SpecialistServiceItemOperateLogDO();
        specialistServiceItemOperateLogDO.setSaasId("dev");
        specialistServiceItemOperateLogDO.setServiceItemId(specialistServiceItemDO.getId());
        specialistServiceItemOperateLogDO.setStatus(1);
        specialistServiceItemOperateLogDO.setOperateLog(array.toJSONString());
        specialistServiceItemOperateLogDO.setCreateTime(new Date());
        specialistServiceItemOperateLogDO.setUpdateTime(new Date());
        specialistServiceItemOperateLogDao.save(specialistServiceItemOperateLogDO);
        envelop.setObj(true);
        return envelop;
    }
}

+ 148 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/util/ISqlUtils.java

@ -0,0 +1,148 @@
package com.yihu.jw.util;/**
 * Created by nature of king on 2018/4/27.
 */
import com.alibaba.fastjson.JSONObject;
import javax.persistence.Column;
import javax.persistence.Table;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * @author wangzhinan
 * @create 2018-04-27 12:47
 * @desc sql自定义编辑
 **/
public class ISqlUtils {
    public static String getSql(Object object,Integer page,Integer size,String isFlag){
        StringBuffer sb = new StringBuffer();
        Class c =object.getClass();
        Table table = (Table)c.getAnnotation(Table.class);
        String tableName = table.name();
        if (isFlag.equalsIgnoreCase("count")){
            sb.append("select count(1) AS total from ").append(tableName).append(" where 1=1");
        }else if(isFlag.equalsIgnoreCase("*")){
            sb.append("select * from ").append(tableName).append(" where 1=1 ");
        }
        JSONObject object1  = (JSONObject) JSONObject.toJSON(object);
        if (object1.getString("id") !=null){
            sb.append(" and id = '" + object1.getString("id")+"' ");
        }
        Field[] fArray= c.getDeclaredFields();
        for(Field f:fArray){
                //拿到字段后与实体类中的属性匹配,并得到其get方法,用来获取他的属性值
                String getMethodName ="";
                boolean isCExist =f.isAnnotationPresent(Column.class);
                if(isCExist){
                    Column mc =f.getAnnotation(Column.class);
                    String columeName =mc.name();  //字段对应数据库名字
                    String name =f.getName();       //字段名字
                    Class a= f.getType();          //字段类型
                    Object value=null;              //字段值
                    getMethodName="get"+name.substring(0,1).toUpperCase()+name.substring(1);//拼接属性的get方法
                    try {
                        Method m =c.getMethod(getMethodName);
                        value =(Object)m.invoke(object);     //拿到属性的值
                        if(value == null || "".equals(value)){  //如果属性没值,不拼接sql
                            continue;
                        }
                        else if(value instanceof String){
                            value ="'%"+value+"%'";
                            sb.append(" and ").append(columeName +" like " ).append(value+"");
                        }else if (value instanceof Integer){
                            value = value;
                            sb.append(" and ").append(columeName +" = " ).append(value+"");
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
        }
        if(isFlag.equalsIgnoreCase("*")){
            sb.append(" ORDER BY create_time DESC ").append("LIMIT ").append((page-1)*size+",").append(size);
        }
        return sb.toString();
    }
    public static String getAllSql(Object object){
        StringBuffer sb = new StringBuffer();
        Class c =object.getClass();
        Table table = (Table)c.getAnnotation(Table.class);
        String tableName = table.name();
        sb.append("select * from ").append(tableName).append(" where 1=1 ");
        Field[] fArray= c.getDeclaredFields();
        for(Field f:fArray){
            //拿到字段后与实体类中的属性匹配,并得到其get方法,用来获取他的属性值
            String getMethodName ="";
            boolean isCExist =f.isAnnotationPresent(Column.class);
            if(isCExist){
                Column mc =f.getAnnotation(Column.class);
                String columeName =mc.name();  //字段对应数据库名字
                String name =f.getName();       //字段名字
                Object value=null;              //字段值
                getMethodName="get"+name.substring(0,1).toUpperCase()+name.substring(1);//拼接属性的get方法
                try {
                    Method m =c.getMethod(getMethodName);
                    value =(Object)m.invoke(object);     //拿到属性的值
                    if(value == null || "".equals(value) || value.equals(Integer.parseInt("0"))){  //如果属性没值,不拼接sql
                        continue;
                    }
                    else if(value instanceof String){
                        value ="'"+value+"'";
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                sb.append(" and ").append(columeName +"=" ).append(value+"");
            }
        }
        return sb.toString();
    }
    public static  String getUpdateSql(Object object){
        StringBuffer sb = new StringBuffer();
        Class c = object.getClass();
        Table table = (Table)c.getAnnotation(Table.class);
        String tableName = table.name();
        sb.append("update ").append(tableName).append(" set ");
        Field[] fArray = c.getDeclaredFields();
        for (Field f:fArray){
            String getMethoName = "";
            boolean isCExist = f.isAnnotationPresent(Column.class);
            if (isCExist){
                Column mc = f.getAnnotation(Column.class);
                String columeName = mc.name();
                String name = f.getName();
                Class a= f.getType();
                Object value= null;
                getMethoName = "get" + name.substring(0,1).toUpperCase()+name.substring(1);
                try {
                    Method m = c.getMethod(getMethoName);
                    if (Date.class.isAssignableFrom(a)){
                        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        value = sdf.format((Object)m.invoke(object));
                    }else {
                        value = (Object)m.invoke(object);
                    }
                    if (value == null || "".equals(value)){
                        continue;
                    }
                    else if (value instanceof  String){
                        value = "'"+value+"'";
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
                sb.append(columeName + "=").append(value+"").append(",");
            }
        }
        sb.deleteCharAt(sb.length()-1);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(object);
        sb.append(" where ").append("id = ").append("'"+jsonObject.get("id")+"'");
        return sb.toString();
    }
}