Explorar o código

系统字典及字典项接口

zdm %!s(int64=6) %!d(string=hai) anos
pai
achega
ac4ff5d9bb
Modificáronse 17 ficheiros con 1030 adicións e 155 borrados
  1. 31 2
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/health/house/HealthyHouseMapping.java
  2. 4 0
      svr/svr-healthy-house/pom.xml
  3. 4 5
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/HealthyHouseApplication.java
  4. 29 29
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/config/jpa/HibernateProperties.java
  5. 58 58
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/config/jpa/WlyyHouseJpa.java
  6. 153 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/dict/SystemDictController.java
  7. 156 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/dict/SystemDictEntryController.java
  8. 26 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/dict/SystemDictDao.java
  9. 57 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/dict/SystemDictEntryDao.java
  10. 0 59
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/IdEntity.java
  11. 54 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/DictEntryKey.java
  12. 51 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/SystemDict.java
  13. 143 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/SystemDictEntry.java
  14. 3 2
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/user/User.java
  15. 158 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/dict/SystemDictEntryService.java
  16. 70 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/dict/SystemDictService.java
  17. 33 0
      svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/util/PinyinUtil.java

+ 31 - 2
common/common-request-mapping/src/main/java/com/yihu/jw/rm/health/house/HealthyHouseMapping.java

@ -1,14 +1,43 @@
package com.yihu.jw.rm.health.house;
/**
 * Created by Trick on 2018/2/7.
 */
public class HealthyHouseMapping {
    public static final String api_healthyHouse_common = "svr-healthy-house";
    public static final String api_success ="succes";
    public static final String api_success = "succes";
    public static class HealthyHouse {
    public static class HealthyHouse{
        //系统字典
        public static class SystemDict {
            public static final String CREATE = "/create/systemDict";
            public static final String DELETE = "/delete/systemDict";
            public static final String UPDATE = "/update/systemDict";
            public static final String PAGE = "/page/systemDicts";
            public static final String LIST = "/list/systemDicts";
            public static final String GETDICTBYID = "/getDictionaryById";
            public static final String GETDICTBYPHONETICCODE = "/getDictionaryByPhoneticCode";
            public static final String ISDICTNAMEEXISTS = "/isDictNameExists";
            public static final String ISDICTCODEEXISTS = "/isDictCodeExists";
        }
        //系统字典项
        public static class SystemDictEntry {
            public static final String CREATE = "/create/systemDictEntry";
            public static final String DELETE = "/delete/systemDictEntry";
            public static final String UPDATE = "/update/systemDictEntry";
            public static final String PAGE = "/page/systemDictEntrys";
            public static final String LIST = "/list/systemDictEntrys";
            public static final String GETDICTENTRYBYDICTIDANDCODE = "/getDictEntryByDictIdAndCode";
            public static final String GETDICTENTRYBYDICTIDANDNAME = "/getDictEntryByDictIdAndName";
            public static final String DELETEBYDICTIDANDCODE = "/deleteByDictIdAndCode";
            public static final String ISEXISTSDICTENTRYBYDICTIDANDCODE = "/isExistsDictEntryByDictIdAndCode";
        }
    }
}

+ 4 - 0
svr/svr-healthy-house/pom.xml

@ -90,6 +90,10 @@
			<groupId>com.yihu.jw</groupId>
			<artifactId>common-entity</artifactId>
		</dependency>
		<dependency>
			<groupId>com.yihu.jw</groupId>
			<artifactId>common-rest-model</artifactId>
		</dependency>
	</dependencies>

+ 4 - 5
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/HealthyHouseApplication.java

@ -1,14 +1,13 @@
package com.yihu.jw.healthyhouse;
package com.yihu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication(exclude = OAuth2AutoConfiguration.class)
@ComponentScan(basePackages = {"com"})
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@EnableJpaAuditing
public class HealthyHouseApplication {
	public static void main(String[] args) {

+ 29 - 29
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/config/jpa/HibernateProperties.java

@ -1,29 +1,29 @@
package com.yihu.jw.healthyhouse.config.jpa;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import java.util.Properties;
/**
 * Created by chenweida on 2017/4/6.
 */
@Component
@RefreshScope
public class HibernateProperties {
    @Value("${hibernate.dialect}")
    private String dialect;
    @Value("${hibernate.show_sql}")
    private String show_sql;
    @Value("${hibernate.ejb.naming_strategy}")
    private String naming_strategy;
    public  Properties hibProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect",dialect);
        properties.put("hibernate.show_sql", show_sql);
        properties.put("hibernate.ejb.naming_strategy", naming_strategy);
        return properties;
    }
}
//package com.yihu.jw.healthyhouse.config.jpa;
//
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
//import org.springframework.stereotype.Component;
//
//import java.util.Properties;
//
///**
// * Created by chenweida on 2017/4/6.
// */
//@Component
//@RefreshScope
//public class HibernateProperties {
//    @Value("${hibernate.dialect}")
//    private String dialect;
//    @Value("${hibernate.show_sql}")
//    private String show_sql;
//    @Value("${hibernate.ejb.naming_strategy}")
//    private String naming_strategy;
//
//    public  Properties hibProperties() {
//        Properties properties = new Properties();
//        properties.put("hibernate.dialect",dialect);
//        properties.put("hibernate.show_sql", show_sql);
//        properties.put("hibernate.ejb.naming_strategy", naming_strategy);
//        return properties;
//    }
//}

+ 58 - 58
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/config/jpa/WlyyHouseJpa.java

@ -1,58 +1,58 @@
package com.yihu.jw.healthyhouse.config.jpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;
/**
 * Created by chenweida on 2017/4/6.
 */
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "wlyyHouseEntityManagerFactory",
        transactionManagerRef = "wlyyHouseTransactionManager",
        basePackages = {"com.yihu.jw.healthyhouse.dao"})   //设置Repository所在位置
public class WlyyHouseJpa {
    @Autowired
    private HibernateProperties hibernateProperties;
    @Bean(name = "wlyyHouseEntityManagerFactory")
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(DataSource dataSource) {
        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
        emfb.setDataSource(dataSource);
        emfb.setPackagesToScan("com.yihu.jw.healthyhouse.entity");
        emfb.setPersistenceUnitName("archives");
        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        emfb.setJpaVendorAdapter(vendorAdapter);
        Properties properties = hibernateProperties.hibProperties();
        properties.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.ImprovedNamingStrategy");
        emfb.setJpaProperties(hibernateProperties.hibProperties());
        return emfb;
    }
    @Bean(name = "wlyyHouseTransactionManager")
    @Primary
    JpaTransactionManager transactionManagerSecondary(
            @Qualifier("wlyyHouseEntityManagerFactory") EntityManagerFactory builder) {
        return new JpaTransactionManager(builder);
    }
}
//package com.yihu.jw.healthyhouse.config.jpa;
//
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.JpaVendorAdapter;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.persistence.EntityManagerFactory;
//import javax.sql.DataSource;
//import java.util.Properties;
//
///**
// * Created by chenweida on 2017/4/6.
// */
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//        entityManagerFactoryRef = "wlyyHouseEntityManagerFactory",
//        transactionManagerRef = "wlyyHouseTransactionManager",
//        basePackages = {"com.yihu.jw.healthyhouse.dao"})   //设置Repository所在位置
//public class WlyyHouseJpa {
//
//    @Autowired
//    private HibernateProperties hibernateProperties;
//
//    @Bean(name = "wlyyHouseEntityManagerFactory")
//    @Primary
//    public LocalContainerEntityManagerFactoryBean entityManagerFactoryPrimary(DataSource dataSource) {
//
//        LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
//        emfb.setDataSource(dataSource);
//        emfb.setPackagesToScan("com.yihu.jw.healthyhouse.model");
//        emfb.setPersistenceUnitName("archives");
//        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
//        emfb.setJpaVendorAdapter(vendorAdapter);
//        Properties properties = hibernateProperties.hibProperties();
//        properties.put("hibernate.ejb.naming_strategy","org.hibernate.cfg.ImprovedNamingStrategy");
//        emfb.setJpaProperties(hibernateProperties.hibProperties());
//
//        return emfb;
//    }
//
//
//    @Bean(name = "wlyyHouseTransactionManager")
//    @Primary
//    JpaTransactionManager transactionManagerSecondary(
//            @Qualifier("wlyyHouseEntityManagerFactory") EntityManagerFactory builder) {
//        return new JpaTransactionManager(builder);
//    }
//}

+ 153 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/dict/SystemDictController.java

@ -0,0 +1,153 @@
package com.yihu.jw.healthyhouse.controller.dict;
import com.yihu.jw.healthyhouse.model.dict.SystemDict;
import com.yihu.jw.healthyhouse.service.dict.SystemDictService;
import com.yihu.jw.healthyhouse.util.PinyinUtil;
import com.yihu.jw.restmodel.web.Envelop;
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.health.house.HealthyHouseMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
/**
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@RestController
@RequestMapping(HealthyHouseMapping.api_healthyHouse_common)
@Api(value = "Dictionary", description = "系统全局字典管理", tags = {"系统字典-系统全局字典管理"})
public class SystemDictController extends EnvelopRestEndpoint {
    @Autowired
    private SystemDictService dictService;
    @ApiOperation(value = "获取字典列表", responseContainer = "List")
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.PAGE)
    public PageEnvelop<SystemDict> getDictionaries(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page) throws Exception {
        List<SystemDict> systemDictList = dictService.search(fields, filters, sorts, page, size);
        Long count = (long) (null == systemDictList ? 0 : systemDictList.size());
        return success(systemDictList, count.intValue(), page, size);
    }
    @ApiOperation(value = "创建字典")
    @PostMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.CREATE)
    public ObjEnvelop<SystemDict> createDictionary(
            @ApiParam(name = "dictionary", value = "字典JSON结构")
            @RequestBody SystemDict dict) throws IOException {
        if (StringUtils.isEmpty(dict.getName())) {
            return failed("字典名称不能为空!", ObjEnvelop.class);
        }
        if (StringUtils.isEmpty(dict.getPhoneticCode())) {
            dict.setPhoneticCode(PinyinUtil.getPinYinHeadChar(dict.getName(), true));
        }
        if (StringUtils.isEmpty(dict.getCode())) {
            dict.setCode(dict.getPhoneticCode());
        }
        SystemDict systemDict = dictService.save(dict);
        return success(systemDict);
    }
    @ApiOperation(value = "获取字典")
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.GETDICTBYID)
    public ObjEnvelop<SystemDict> getDictionary(
            @ApiParam(name = "id", value = "字典ID", defaultValue = "")
            @RequestParam(value = "id") String id) throws Exception {
        SystemDict dict = dictService.findById(id);
        if (dict == null) {
            return failed("字典不存在!", ObjEnvelop.class);
        }
        return success(dict);
    }
    @ApiOperation(value = "获取字典")
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.GETDICTBYPHONETICCODE)
    public ObjEnvelop<SystemDict> getDictionaryByPhoneticCode(
            @ApiParam(name = "phoneticCode", value = "拼音编码", required = true)
            @RequestParam(value = "phoneticCode") String phoneticCode) throws Exception {
        SystemDict dict = dictService.findByPhoneticCode(phoneticCode);
        if (dict == null) {
            return failed("字典不存在!", ObjEnvelop.class);
        }
        return success(dict);
    }
    @ApiOperation(value = "更新字典")
    @PutMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.UPDATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ObjEnvelop<SystemDict> updateDictionary(
            @ApiParam(name = "dictionary", value = "字典JSON结构")
            @RequestBody SystemDict dict) throws Exception {
        SystemDict oldDict = dictService.findById(dict.getId());
        if (null == oldDict) {
            return failed("字典不存在", ObjEnvelop.class);
        }
        if (StringUtils.isEmpty(dict.getName())) {
            return failed("字典名称不能为空", ObjEnvelop.class);
        }
        if (!oldDict.getName().equals(dict.getName()) && dictService.findByField("name", dict.getName()).size() > 0) {
            return failed("字典名称在系统中已存在", ObjEnvelop.class);
        }
        if (StringUtils.isEmpty(dict.getPhoneticCode())) {
            dict.setPhoneticCode(PinyinUtil.getPinYinHeadChar(dict.getName(), true));
        }
        if (StringUtils.isEmpty(dict.getCode())) {
            dict.setCode(dict.getPhoneticCode());
        }
        oldDict.setName(dict.getName());
        oldDict.setPhoneticCode(dict.getPhoneticCode());
        oldDict.setCode(dict.getCode());
        dictService.updateDict(oldDict);
        return success(oldDict);
    }
    @ApiOperation(value = "删除字典")
    @DeleteMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.DELETE)
    public Envelop deleteDictionary(
            @ApiParam(name = "dictId", value = "字典ID")
            @RequestParam(value = "dictId") String dictId) throws Exception {
        dictService.deleteDict(dictId);
        return success("success");
    }
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.ISDICTNAMEEXISTS)
    @ApiOperation(value = "判断提交的字典名称是否已经存在")
    public boolean isDictNameExists(
            @ApiParam(name = "dict_name", value = "字典名称")
            @RequestParam(value = "dict_name") String dictName) throws Exception {
        return dictService.isDictNameExists(dictName);
    }
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDict.ISDICTCODEEXISTS)
    @ApiOperation(value = "判断提交的字典编码是否已经存在")
    public boolean checkCode(
            @ApiParam(name = "code", value = "编码")
            @RequestParam(value = "code") String code) throws Exception {
        if (dictService.findByField("code", code).size() > 0) {
            return true;
        }
        return false;
    }
}

+ 156 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/dict/SystemDictEntryController.java

@ -0,0 +1,156 @@
package com.yihu.jw.healthyhouse.controller.dict;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.healthyhouse.model.dict.DictEntryKey;
import com.yihu.jw.healthyhouse.model.dict.SystemDict;
import com.yihu.jw.healthyhouse.model.dict.SystemDictEntry;
import com.yihu.jw.healthyhouse.service.dict.SystemDictEntryService;
import com.yihu.jw.healthyhouse.service.dict.SystemDictService;
import com.yihu.jw.restmodel.web.*;
import com.yihu.jw.rm.health.house.HealthyHouseMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@RestController
@RequestMapping(HealthyHouseMapping.api_healthyHouse_common)
@Api(value = "DictionaryEntry", description = "系统全局字典项管理", tags = {"系统字典-系统全局字典项管理"})
public class SystemDictEntryController extends EnvelopRestEndpoint {
    @Autowired
    private SystemDictService dictService;
    @Autowired
    private SystemDictEntryService systemDictEntryService;
    @ApiOperation(value = "获取字典项列表")
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDictEntry.PAGE)
    public PageEnvelop getSystemDictEntrys(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page) throws Exception {
        List<SystemDictEntry> systemDictEntryList = systemDictEntryService.search(fields,filters,sorts,page,size);
        return success(systemDictEntryList,systemDictEntryList.size(),page, size);
    }
    @ApiOperation(value = "创建字典项")
    @PostMapping(value = HealthyHouseMapping.HealthyHouse.SystemDictEntry.CREATE)
    public ObjEnvelop<SystemDictEntry> createDictEntry (
            @ApiParam(name = "entryJson", value = "字典JSON结构")
            @RequestParam(value = "entryJson") String entryJson) throws IOException{
        SystemDictEntry entry = toEntity(entryJson, SystemDictEntry.class);
        SystemDict systemDict = dictService.retrieve(entry.getDictId());
        if (systemDict == null) {
            return  failed("所属字典不存在!",ObjEnvelop.class);
        }
        int nextSort = systemDictEntryService.getNextSN(entry.getDictId());
        entry.setSort(nextSort);
        systemDictEntryService.createDictEntry(entry);
        return success(entry);
    }
    @ApiOperation(value = "获取字典项")
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.SystemDictEntry.GETDICTENTRYBYDICTIDANDCODE)
    public ObjEnvelop getDictEntry(
            @ApiParam(name = "dictId", value = "字典ID", required = true)
            @RequestParam(value = "dictId") String dictId,
            @ApiParam(name = "code", value = "字典项代码", required = true)
            @RequestParam(value = "code") String code) throws Exception{
        SystemDictEntry systemDictEntry = systemDictEntryService.getDictEntry(dictId, code);
        return success(systemDictEntry);
    }
    @ApiOperation(value = "删除字典项")
    @DeleteMapping(HealthyHouseMapping.HealthyHouse.SystemDictEntry.DELETEBYDICTIDANDCODE)
    public Envelop deleteDictEntry(
            @ApiParam(name = "dictId", value = "字典ID")
            @RequestParam(value = "dictId") String dictId,
            @ApiParam(name = "code", value = "字典项编码")
            @RequestParam(value = "code") String code) throws Exception{
        systemDictEntryService.deleteDictEntry(dictId, code);
        return success("success");
    }
    @ApiOperation(value = "删除字典")
    @DeleteMapping(value = HealthyHouseMapping.HealthyHouse.SystemDictEntry.DELETE)
    public Envelop deleteSystemDictEntry(
            @ApiParam(name = "entryId", value = "字典项ID")
            @RequestParam(value = "entryId") String entryId) throws Exception {
        systemDictEntryService.delete(entryId);
        return success("success");
    }
    @ApiOperation(value = "修改字典项")
    @PutMapping(value =HealthyHouseMapping.HealthyHouse.SystemDictEntry.UPDATE)
    public ObjEnvelop<SystemDictEntry> updateDictEntry(
            @ApiParam(name = "entryJson", value = "字典JSON结构")
            @RequestParam(value = "entryJson") String entryJson) throws IOException {
        SystemDictEntry entry = toEntity(entryJson, SystemDictEntry.class);
        SystemDictEntry temp = systemDictEntryService.retrieve(new DictEntryKey(entry.getCode(), entry.getDictId()));
        if (null == temp) {
            failed("字典项不存在!",ObjEnvelop.class);
        }
        systemDictEntryService.saveDictEntry(entry);
        return success(entry);
    }
    @GetMapping(value =HealthyHouseMapping.HealthyHouse.SystemDictEntry.ISEXISTSDICTENTRYBYDICTIDANDCODE)
    @ApiOperation(value = "根据dictId和code判断提交的字典项是否已经存在")
    public boolean isDictEntryCodeExists(
            @ApiParam(name = "dictId", value = "字典", defaultValue = "")
            @RequestParam(value = "dictId",required = true) String dictId,
            @ApiParam(name = "code", value = "字典项编码", defaultValue = "")
            @RequestParam(value = "code") String code){
        return systemDictEntryService.isDictContainEntry(dictId, code);
    }
    @GetMapping(value =HealthyHouseMapping.HealthyHouse.SystemDictEntry.GETDICTENTRYBYDICTIDANDNAME)
    @ApiOperation(value = "根据dictId和code判断提交的字典项是否已经存在")
    public boolean isDictEntryNameExists(
            @ApiParam(name = "dictId", value = "字典", defaultValue = "")
            @RequestParam(value = "dictId",required = true) String dictId,
            @ApiParam(name = "name", value = "字典项名称")
            @RequestParam(value = "name") String name){
        Page<SystemDictEntry> systemDictEntryPage= systemDictEntryService.findByDictIdAndValueLike(dictId, name,0,100);
        if(null!=systemDictEntryPage&&systemDictEntryPage.getSize()>0){
            return  true;
        }
        return false;
    }
    @GetMapping(HealthyHouseMapping.HealthyHouse.SystemDictEntry.LIST)
    @ApiOperation(value = "根据dictId获取所有字典项")
    public ListEnvelop GetSystemDictEntryListByDictId(
            @ApiParam(name = "dictId", value = "字典id")
            @RequestParam(value = "dictId") String dictId) throws Exception{
        List<SystemDictEntry> cardList = systemDictEntryService.getDictEntryCodeAndValueByDictId(dictId);
        return success(cardList);
    }
}

+ 26 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/dict/SystemDictDao.java

@ -0,0 +1,26 @@
package com.yihu.jw.healthyhouse.dao.dict;
import com.yihu.jw.healthyhouse.model.dict.SystemDict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
/**
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
public interface SystemDictDao extends JpaRepository<SystemDict, Long> {
    SystemDict findByName(String name);
    Page<SystemDict> findByNameOrPhoneticCodeOrderByNameAsc(String name, String phoneticCode, Pageable pageable);
    @Query("select max(dict.id) from SystemDict dict where 1=1")
    long getNextId();
    SystemDict findByPhoneticCode(String phoneticCode);
    SystemDict findById(String id);
}

+ 57 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/dict/SystemDictEntryDao.java

@ -0,0 +1,57 @@
package com.yihu.jw.healthyhouse.dao.dict;
import com.yihu.jw.healthyhouse.model.dict.DictEntryKey;
import com.yihu.jw.healthyhouse.model.dict.SystemDictEntry;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * 字典项DAO。
 *
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
public interface SystemDictEntryDao extends JpaRepository<SystemDictEntry, DictEntryKey> {
    List<SystemDictEntry> findByDictId(String dictId);
    Page<SystemDictEntry> findByDictId(String dictId, Pageable pageable);
    Page<SystemDictEntry> findByDictIdAndValueLike(String dictId, String value, Pageable pageable);
    @Modifying
    void deleteByDictId(String dictId);
    /**
     * 获取字典项下一排序号.
     *
     * @param dictId
     * @return
     */
    @Query("select max(entry.sort) from SystemDictEntry entry where entry.dictId = :dictId")
    Integer getNextEntrySN(@Param("dictId") String dictId);
    /**
     * 批量获取字典项列表.
     *
     * @param dictId
     * @param codes
     * @return
     */
    @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.code in (:codes) order by entry.sort asc")
    List<SystemDictEntry> findByDictIdAndCodes(@Param("dictId") String dictId, @Param("codes") String[] codes);
    @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.value = :value")
    List<SystemDictEntry> findByDictIdAndValue(@Param("dictId") String dictId, @Param("value") String value);
    List<SystemDictEntry> findByDictIdAndCode(@Param("dictId") String dictId, @Param("code") String code);
}

+ 0 - 59
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/IdEntity.java

@ -1,59 +0,0 @@
package com.yihu.jw.healthyhouse.model;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
 *  jpa基类
 *
 * @author HZY
 * @created 2018/9/18 17:11
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class IdEntity implements java.io.Serializable{
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    protected String id;  // 非业务主键
    @CreatedDate
    @Column(name = "create_date", nullable = false, length = 0,updatable = false)
    protected Date createDate;
    @LastModifiedDate
    @Column(name = "modify_date", nullable = false, length = 0)
    protected Date modifyDate;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public Date getCreateDate() {
        return createDate;
    }
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
    public Date getModifyDate() {
        return modifyDate;
    }
    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
}

+ 54 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/DictEntryKey.java

@ -0,0 +1,54 @@
package com.yihu.jw.healthyhouse.model.dict;
import java.io.Serializable;
import java.util.Objects;
/**
 * 字典项主键(联合主键)。
 */
public class DictEntryKey implements Serializable{
    String code;
    String dictId;
    public DictEntryKey(){
    }
    public DictEntryKey(String code, String dictId){
        this.code = code == null ? "" : code;
        this.dictId = dictId == null ? null : dictId;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getDictId() {
        return dictId;
    }
    public void setDictId(String dictId) {
        this.dictId = dictId;
    }
    @Override
    public boolean equals(Object obj) {
        if(obj instanceof DictEntryKey){
            DictEntryKey pk = (DictEntryKey)obj;
            if(this.code==pk.getCode() && this.dictId==(pk.getDictId())){
                return true;
            }
        }
        return false;
    }
    @Override
    public int hashCode() {
        return Objects.hash(code, dictId);
    }
}

+ 51 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/SystemDict.java

@ -0,0 +1,51 @@
package com.yihu.jw.healthyhouse.model.dict;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import com.yihu.jw.healthyhouse.util.PinyinUtil;
import javax.persistence.*;
/**
 * 系统字典
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@Entity
@Table(name = "system_dicts")
@Access(value = AccessType.PROPERTY)
public class SystemDict extends UuidIdentityEntityWithOperator {
    /** 名称*/
    private String name;
    /** 英文首字母*/
    private String phoneticCode;
    /** 编码*/
    private String code;
    @Column(name = "name", nullable = false)
    public String getName() {
        return this.name;
    }
    public void setName(String name){
        this.name = name;
        this.phoneticCode = PinyinUtil.getPinYinHeadChar(name, true);
    }
    @Column(name = "phonetic_code", nullable = false)
    public String getPhoneticCode() {
        return phoneticCode;
    }
    public void setPhoneticCode(String phoneticCode) {
        this.phoneticCode = phoneticCode;
    }
    @Column(name = "code", nullable = false)
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
}

+ 143 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/dict/SystemDictEntry.java

@ -0,0 +1,143 @@
package com.yihu.jw.healthyhouse.model.dict;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.healthyhouse.util.PinyinUtil;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
 *系统字典项。
 *
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@Entity
@Table(name = "system_dict_entries")
@Access(value = AccessType.PROPERTY)
@Embeddable
@IdClass(DictEntryKey.class)
public class SystemDictEntry  implements Serializable {
    private static final long serialVersionUID = 1L;
    String dictId;
    String code;
    String value;
    Integer sort;
    String phoneticCode;
    String catalog;
    String pcode;//上级id
    /** 创建日期 */
    private Date createDate;
    /** 创建者 */
    private String creator;
    /** 修改日期 */
    private Date modifyDate;
    /** 修改者 */
    private String modifier;
    public SystemDictEntry(){
    }
    @Id
    @Column(name = "code", unique = true, nullable = false ,insertable = false, updatable = false)
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Id
    @Column(name = "dictId", unique = true, nullable = false ,insertable = false, updatable = false)
    public String getDictId() {
        return dictId;
    }
    public void setDictId(String dictId) {
        this.dictId = dictId;
    }
    @Column(name = "value", nullable = true)
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
        this.phoneticCode = PinyinUtil.getPinYinHeadChar(value, true);
    }
    @Column(name = "phoneticCode", nullable = true)
    public String getPhoneticCode() {
        return phoneticCode;
    }
    public void setPhoneticCode(String phoneticCode) {
        this.phoneticCode = phoneticCode;
    }
    @Column(name = "sort", nullable = true)
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    @Column(name = "catalog", nullable = true)
    public String getCatalog() {
        return catalog;
    }
    public void setCatalog(String catalog) {
        this.catalog = catalog;
    }
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "create_date", nullable = false, updatable = false)
    public Date getCreateDate() {
        return createDate;
    }
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
    @Column(name = "creator")
    public String getCreator() {
        return creator;
    }
    public void setCreator(String creator) {
        this.creator = creator;
    }
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(name = "modify_date", nullable = false)
    public Date getModifyDate() {
        return modifyDate;
    }
    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }
    @Column(name = "modifier")
    public String getModifier() {
        return modifier;
    }
    public void setModifier(String modifier) {
        this.modifier = modifier;
    }
    @Column(name = "pcode")
    public String getPcode() {
        return pcode;
    }
    public void setPcode(String pcode) {
        this.pcode = pcode;
    }
}

+ 3 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/user/User.java

@ -1,6 +1,7 @@
package com.yihu.jw.healthyhouse.model.user;
import com.yihu.jw.healthyhouse.model.IdEntity;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -14,7 +15,7 @@ import java.util.Date;
 */
@Entity
@Table(name = "user")
public class User extends IdEntity implements Serializable{
public class User extends UuidIdentityEntityWithOperator {
    @Column(name = "login_code", nullable = false)
    private String loginCode;

+ 158 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/dict/SystemDictEntryService.java

@ -0,0 +1,158 @@
package com.yihu.jw.healthyhouse.service.dict;
import com.yihu.jw.healthyhouse.dao.dict.SystemDictEntryDao;
import com.yihu.jw.healthyhouse.model.dict.DictEntryKey;
import com.yihu.jw.healthyhouse.model.dict.SystemDictEntry;
import com.yihu.mysql.query.BaseJpaService;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 * 字典项服务。
 *
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@Service
@Transactional
public class SystemDictEntryService extends BaseJpaService<SystemDictEntry, SystemDictEntryDao> {
    @Autowired
    private SystemDictEntryDao systemDictEntryDao;
    /**
     * 下一字典项排序号。
     *
     * @param dictId
     * @return
     */
    public int getNextSN(String dictId) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        Integer nextSort = repo.getNextEntrySN(dictId);
        return null == nextSort ? 1 : nextSort + 1;
    }
    /**
     * 获取所有字典项。对于大字典,若不分页效率可能会很低。
     *
     * @param dictId 字典ID
     * @param page   分页,-1 表示查找全部
     * @param size   页大小, page 为 -1 时忽略此参数
     * @return
     */
    public Page<SystemDictEntry> getDictEntries(String dictId, int page, int size) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        return repo.findByDictId(dictId, page == -1 ? null : new PageRequest(page, size));
    }
    /**
     * 获取简易字典项列表.
     *
     * @param dictId
     * @param codes  字典项代码列表,为空返回所有字典项. 但对于大字典效率会很低.
     * @return
     */
    public List<SystemDictEntry> getDictEntries(String dictId, String[] codes) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        if (codes == null) {
            return repo.findByDictId(dictId);
        } else {
            return repo.findByDictIdAndCodes(dictId, codes);
        }
    }
    /**
     * 获取字典项。
     *
     * @param dictId
     * @param code
     * @return
     */
    public SystemDictEntry getDictEntry(String dictId, String code) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        return repo.findOne(new DictEntryKey(code, dictId));
    }
    public SystemDictEntry getDictEntryByValueAndDictId(String value, String dictId) {
        List<SystemDictEntry> systemDictEntryList = systemDictEntryDao.findByDictIdAndValue(dictId, value);
        if (null != systemDictEntryList && systemDictEntryList.size() > 0) {
            return systemDictEntryList.get(0);
        }
        return null;
    }
    /**
     * 按字典ID与字典项值查找字典项.
     *
     * @param dictId
     * @param value
     * @param page
     * @param size
     * @return
     */
    public Page<SystemDictEntry> findByDictIdAndValueLike(String dictId, String value, int page, int size) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        return repo.findByDictIdAndValueLike(dictId, value, new PageRequest(page, size));
    }
    /**
     * 按字典ID查找字典项.
     *
     * @param dictId
     * @param page
     * @param size
     * @return
     */
    public Page<SystemDictEntry> findByDictId(String dictId, int page, int size) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        return repo.findByDictId(dictId, new PageRequest(page, size));
    }
    public boolean isDictContainEntry(String dictId, String code) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        SystemDictEntry systemDictEntry = repo.findOne(new DictEntryKey(code, dictId));
        return systemDictEntry != null;
    }
    public SystemDictEntry saveDictEntry(SystemDictEntry systemDictEntry) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        return repo.save(systemDictEntry);
    }
    public void createDictEntry(SystemDictEntry systemDictEntry) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        repo.save(systemDictEntry);
    }
    public void deleteDictEntry(String dictId, String code) {
        SystemDictEntryDao repo = (SystemDictEntryDao) getJpaRepository();
        repo.delete(new DictEntryKey(code, dictId));
    }
    /**
     * 根据字典id获取字典项编码和值
     */
    public List getDictEntryCodeAndValueByDictId(String dict_id) {
        String sql = "SELECT code,value FROM system_dict_entries where dict_id=:dict_id";
        SQLQuery sqlQuery = currentSession().createSQLQuery(sql);
        sqlQuery.setParameter("dict_id", dict_id);
        return sqlQuery.list();
    }
}

+ 70 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/dict/SystemDictService.java

@ -0,0 +1,70 @@
package com.yihu.jw.healthyhouse.service.dict;
import com.yihu.jw.healthyhouse.dao.dict.SystemDictDao;
import com.yihu.jw.healthyhouse.dao.dict.SystemDictEntryDao;
import com.yihu.jw.healthyhouse.model.dict.SystemDict;
import com.yihu.mysql.query.BaseJpaService;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 系统字典管理器.
 *
 * @author zdm
 * @version 1.0
 * @created 2018.09.18
 */
@Service
@Transactional
public class SystemDictService extends BaseJpaService<SystemDict, SystemDictDao> {
    @Autowired
    private SystemDictDao dictRepo;
    @Autowired
    private SystemDictEntryDao entryRepo;
    public Page<SystemDict> getDictList(String sorts, int page, int size) {
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return dictRepo.findAll(pageable);
    }
    public void updateDict(SystemDict dict) {
        dictRepo.save(dict);
    }
    public void deleteDict(String dictId) {
        entryRepo.deleteByDictId(dictId);
        dictRepo.delete(Long.parseLong(dictId));
    }
    public boolean isDictNameExists(String name) {
        SystemDict systemDict = dictRepo.findByName(name);
        return systemDict != null;
    }
    public Page<SystemDict> searchDict(String name, String phoneticCode, int page, int size) {
        return dictRepo.findByNameOrPhoneticCodeOrderByNameAsc(name, phoneticCode, new PageRequest(page, size));
    }
    public long getNextId() {
        long id = dictRepo.getNextId()+1;
        return id;
    }
    public SystemDict findByPhoneticCode(String code) {
        return dictRepo.findByPhoneticCode(code);
    }
    public SystemDict findById(String id) {
        return  dictRepo.findById(id);
    }
}

+ 33 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/util/PinyinUtil.java

@ -0,0 +1,33 @@
package com.yihu.jw.healthyhouse.util;
import net.sourceforge.pinyin4j.PinyinHelper;
/**
 * 拼音工具包装。
 *
 * @author Sand
 * @version 1.0
 * @created 2015.07.30 15:33
 */
public class PinyinUtil {
    /**
     * 提取汉字的首字母
     * @param str
     * @return
     */
    public static String getPinYinHeadChar(String str, boolean upperCase) {
        String convert = "";
        for (int j = 0; j < str.length(); j++) {
            char word = str.charAt(j);
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
            if (pinyinArray != null) {
                convert += pinyinArray[0].charAt(0);
            } else {
                convert += word;
            }
        }
        return upperCase ? convert.toUpperCase() : convert;
    }
}