Browse Source

物联网修改获取字典和创建字典接口

humingfen 5 years ago
parent
commit
9b30b51f51

+ 22 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/dict/IotSystemDictDO.java

@ -5,6 +5,7 @@ import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
/**
@ -29,6 +30,10 @@ public class IotSystemDictDO extends UuidIdentityEntityWithOperator implements S
    private Long sort;//排序
    @Column(name = "del")
    private Integer del;//删除标志
    @Column(name = "parent_code")
    private String parentCode;
    @Transient
    private String parentName;//父类字典名称
    public String getSaasId() {
        return saasId;
@ -85,4 +90,21 @@ public class IotSystemDictDO extends UuidIdentityEntityWithOperator implements S
    public void setDel(Integer del) {
        this.del = del;
    }
    public String getParentCode() {
        return parentCode;
    }
    public void setParentCode(String parentCode) {
        this.parentCode = parentCode;
    }
    @Transient
    public String getParentName() {
        return parentName;
    }
    public void setParentName(String parentName) {
        this.parentName = parentName;
    }
}

+ 9 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/dict/IotSystemDictVO.java

@ -14,6 +14,8 @@ import java.io.Serializable;
@ApiModel(description = "系统字典表")
public class IotSystemDictVO implements Serializable {
    @ApiModelProperty("字典id")
    private String id;
    @ApiModelProperty("字典项代码")
    private String code;//
    @ApiModelProperty("字典项值")
@ -35,4 +37,11 @@ public class IotSystemDictVO implements Serializable {
        this.value = value;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
}

+ 6 - 10
svr/svr-iot/src/main/java/com/yihu/iot/controller/common/IotSystemDictController.java

@ -1,11 +1,9 @@
package com.yihu.iot.controller.common;
import com.yihu.iot.dao.dict.IotSystemDictDao;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.iot.dict.IotSystemDictVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -13,7 +11,6 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
@ -26,18 +23,16 @@ public class IotSystemDictController extends EnvelopRestEndpoint {
    @Autowired
    private IotSystemDictService iotSystemDictService;
    @Autowired
    private IotSystemDictDao iotSystemDictDao;
    @GetMapping(value = IotRequestMapping.System.findDictByCode)
    @ApiOperation(value = "获取字典列表(不分页)")
    public MixEnvelop<IotSystemDictVO, IotSystemDictVO> getList(
    public MixEnvelop<IotSystemDictDO, IotSystemDictDO> getList(
            @ApiParam(name = "dictName", value = "字典名称", defaultValue = "COMPANY_TYPE")
            @RequestParam(value = "dictName", required = true) String dictName) throws Exception {
        try {
            List<IotSystemDictDO> doList = iotSystemDictDao.findByDictName(dictName);
            List<IotSystemDictVO> voList = convertToModels(doList,new ArrayList<IotSystemDictVO>(doList.size()),IotSystemDictVO.class);
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions,voList);
            List<IotSystemDictDO> doList = iotSystemDictService.getListByDictName(dictName);
//            List<IotSystemDictVO> voList = convertToModels(doList,new ArrayList<IotSystemDictVO>(doList.size()),IotSystemDictVO.class);
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions,doList);
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
@ -46,9 +41,10 @@ public class IotSystemDictController extends EnvelopRestEndpoint {
    @PostMapping(value = IotRequestMapping.System.createDict)
    @ApiOperation(value = "创建字典", notes = "创建字典")
    public MixEnvelop<IotSystemDictDO, IotSystemDictDO> create(@ApiParam(name = "jsonData", value = "字典json", defaultValue = "{\"value\":\"血糖\", \"dictName\":\"DEVICE_TYPE\"}")
    public MixEnvelop<IotSystemDictDO, IotSystemDictDO> create(@ApiParam(name = "jsonData", value = "字典json", defaultValue = "{\"value\":\"血糖仪\", \"dictName\":\"DEVICE_TYPE\"}")
                                                       @RequestParam String jsonData) {
        try {
//            List<IotSystemDictDO> dictDOList = new ObjectMapper().readValue(jsonData, new TypeReference<List<IotSystemDictDO>>(){});
            IotSystemDictDO dictDO = toEntity(jsonData, IotSystemDictDO.class);
            return MixEnvelop.getSuccess(IotRequestMapping.Company.message_success_create, iotSystemDictService.create(dictDO));
        } catch (Exception e) {

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/dao/dict/IotSystemDictDao.java

@ -13,7 +13,7 @@ import java.util.List;
public interface IotSystemDictDao extends PagingAndSortingRepository<IotSystemDictDO,String>,
        JpaSpecificationExecutor<IotSystemDictDO> {
    @Query("from IotSystemDictDO w where w.dictName =?1 and w.del = 1 ORDER BY sort")
    @Query("from IotSystemDictDO w where w.dictName =?1 and w.del = 1 ORDER BY w.parentCode,sort")
    List<IotSystemDictDO> findByDictName(String dictName);
    @Query("from IotSystemDictDO w where w.dictName =?1 and w.del = 1 ORDER BY w.code desc ")

+ 19 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/dict/IotSystemDictService.java

@ -43,10 +43,12 @@ public class IotSystemDictService extends BaseJpaService<IotSystemDictDO,IotSyst
    public IotSystemDictDO create(IotSystemDictDO dictDO) {
        String value = dictDO.getValue();
        String parentCode = dictDO.getParentCode();
        //判断新增或者编辑
        if(StringUtils.isNotBlank(dictDO.getCode())){
            dictDO = iotSystemDictDao.findByDictNameAndCodeAndDel(dictDO.getDictName(), dictDO.getCode(), 1);
            dictDO.setValue(value);
            dictDO.setParentCode(parentCode);
            dictDO.setUpdateTime(new Date());
        }else {
            //获取最近一条添加记录的code
@ -63,4 +65,21 @@ public class IotSystemDictService extends BaseJpaService<IotSystemDictDO,IotSyst
        iotSystemDictDao.save(dictDO);
        return dictDO;
    }
    /**
     * 根据字典类名获取相关字典数据
     * @param dictName
     * @return
     */
    public List<IotSystemDictDO> getListByDictName(String dictName){
        List<IotSystemDictDO> systemDictDOList = iotSystemDictDao.findByDictName(dictName);
        for(IotSystemDictDO dictDO : systemDictDOList){
            if(StringUtils.isNotBlank(dictDO.getParentCode())){
                //获取父类字典名称
                IotSystemDictDO parentDict = iotSystemDictDao.findOne(dictDO.getParentCode());
                dictDO.setParentName(parentDict.getValue());
            }
        }
        return systemDictDOList;
    }
}