根据id查询数据

查询 list

Controller

@RestController
@RequestMapping("/riskevent")
@Api(value = "/riskevent", description = "风险事件管理")
public class SEventController extends MpBaseController {
    @Autowired
    private SEventService eventService;
/**
     * 根据id 查找 风险事件
     * @param
     * @return
     */
    @RequiresPermissions("scyf:riskevent:query")
    @GetMapping(value = { "/", "/{eventId}" })
    @ApiOperation(value = "eventId",notes = "根据id找信息")
    public AjaxResult getEventById(@PathVariable @ApiParam(value = "主键") Integer eventId){
        SEventDto eventDto =  eventService.getById(eventId);
        if(eventDto.getEventId == eventId){
            return AjaxResult.success("查询成功",eventDto);
        }
        return AjaxResult.error("查询失败");
    }
}

eventService.getById(eventId) 是MybatisPlus的方法 因为SEventService extends IService<SEvent>

但是 当 通过id 查找的不是本类的实体类 而是 Dto,就需要自己写方法

/**
     * 根据id获取SUnitDto
     */
    @RequiresPermissions("scyf:riskunit:query")
    @GetMapping(value = { "/", "/{unitId}" })
    public AjaxResult getInfo(@PathVariable(value = "unitId", required = false) Integer unitId)
    {
        SUnitDto sUnitDto = sUnitService.getRiskUnitById(unitId);
        if (sUnitDto.getUnitId() == unitId){
            return AjaxResult.success("查询成功",sUnitDto);
        }
        return AjaxResult.error("查询失败");
    }
public interface SUnitService extends IService<SUnit> {
    SUnitDto getRiskUnitById(Integer unitId);
}

ServiceImpl

@Service
public class SUnitServiceImpl extends ServiceImpl<SUnitMapper, SUnit> implements SUnitService {
    @Override
    public SUnitDto getRiskUnitById(Integer unitId) {
        return sUnitMapper.selectSUnitDtoById(unitId);
    }
}

Mapper

public interface SUnitMapper extends BaseMapper<SUnit> {
SUnitDto selectSUnitDtoById(Integer unitId);
}

Mapper.xml

<resultMap type="com.ruoyi.scyf.api.domain.dto.SUnitDto" id="SUnitResult">
        <id     property="unitId"       column="unit_id"      />
        <result property="riskUnitName"       column="risk_unit_name"      />
        <result property="riskUnitId"     column="risk_unit_id"    />
        <result property="qrCode"     column="qr_code"    />
        <result property="longitude"        column="longitude"        />
        <result property="latitude"  column="latitude"  />
        <result property="xCoordinate"          column="x_coordinate"          />
        <result property="yCoordinate"       column="y_coordinate"       />
        <result property="addr"     column="addr"     />
        <result property="position"       column="position"       />
        <result property="safetyWarningSigns"      column="safety_warning_signs"     />
        <result property="post"      column="post"     />
        <result property="sign"    column="sign"   />
        <result property="createBy"     column="create_by"    />
        <result property="createTime"   column="create_time"  />
        <result property="updateBy"     column="update_by"    />
        <result property="updateTime"   column="update_time"  />
        <result property="assTime"       column="ass_time"       />
        <result property="exaTime"       column="exa_time"       />
        <result property="unitDegree"       column="unit_degree"       />
        <result property="assId" column="ass_id"/>
        <result property="accId" column="acc_id"/>
        <result property="dxId" column="dx_id"/>
        <result property="classId" column="class_id"/>
        <result property="disTypeId" column="dis_type_id"/>
        <result property="disId" column="dis_id"/>
        <result property="exaId" column="exa_id"/>
        <result property="response" column="response"/>
        <result property="hazards" column="hazards"/>
        <result property="consequence" column="consequence"/>
        <result property="analysis" column="analysis"/>
        <result property="remarks" column="remarks"/>
        <result property="pic" column="pic"/>
<!--        <association property="sRiskManagementDto" javaType="com.ruoyi.scyf.api.domain.dto.SRiskManagementDto" resultMap="SRiskManagementDtoResult" />-->
        <association property="sRiskManagementDto" javaType="com.ruoyi.scyf.api.domain.dto.SRiskManagementDto" resultMap="com.ruoyi.mapper.SRiskManagementMapper.SRiskManaResult" />
        <association property="sClass" javaType="com.ruoyi.scyf.api.domain.SClass" resultMap="SClassResult" />
        <association property="sDiseases" javaType="com.ruoyi.scyf.api.domain.SDiseases" resultMap="SDiseasesResult"/>
        <association property="sDiseasesType" javaType="com.ruoyi.scyf.api.domain.SDiseasesType" resultMap="SDiseasesTypeResult"/>
        <association property="sAccidentType" javaType="com.ruoyi.scyf.api.domain.SAccidentType" resultMap="SAccidentTypeResult"/>
        <association property="bsUser" javaType="com.ruoyi.system.api.domain.SysUser" resultMap="SysUserResult"/>
        <association property="shUser" javaType="com.ruoyi.system.api.domain.SysUser" resultMap="SysUserResult"/>
        <collection property="sFactors" ofType="com.ruoyi.scyf.api.domain.SFactors" resultMap="SFactorsResult"/>
</resultMap> 
<sql id="all">
        select t1.*,t2.class_name,t3.*,t4.fac_id,t4.fac_name,t5.dis_type,t6.*,t7.acc_name,t8.user_name,t9.user_name
        from s_unit t1
                 left join s_class t2 on t1.class_id = t2.id
                 left join (select a.partition_id,a.current_state, a.risk_name, b.dept_name, c.user_name, d.danger_name, d.danger_code, d.danger_level, e.label, a.update_time
                            from s_risk_management a
                                     left join sys_dept b
                                               on a.dept_id = b.dept_id
                                     left join `ry-cloud`.sys_user c
                                               on a.user_id = c.user_id
                                     left join s_danger_info d
                                               on a.hazard_source_id = d.danger_id
                                     left join s_process_type e
                                               on a.process_type_id = e.process_type_id) t3 on t1.dx_id = t3.partition_id
                 left join s_factors t4 on t4.fac_id in (select a.fac_id
                                                         from s_risk_factors a
                                                                  left join s_unit b
                                                                            on a.unit_id = b.unit_id)
                 left join s_diseases_type t5 on t5.id = t1.dis_type_id
                 left join s_diseases t6 on t6.id = t1.dis_id
                 left join s_accident_type t7 on t7.id = t1.acc_id
                 left join sys_user t8 on t1.ass_id = t8.user_id
                 left join sys_user t9 on t1.exa_id = t9.user_id
</sql>
<select id="selectSUnitDtoById" resultMap="SUnitResult">
        <include refid="all"></include>
        where unit_id = #{unitId}
    </select>

IService

default T getById(Serializable id) {
        return this.getBaseMapper().selectById(id);
    }

Mapper

T selectById(Serializable id);

Mapper.xml

<resultMap id="map1" type="com.ruoyi.aqsc.domain.SysWarning">
        <id column="warning_id" property="warningId"></id>
        <result column="warning_name" property="warningName"></result>
        <result column="warning_category" property="warningCategory"></result>
        <result column="install_date" property="installDate"></result>
        <result column="dept_id" property="deptId"></result>
        <result column="location" property="location"></result>
        <result column="edit_time" property="editTime"></result>
</resultMap>
<select id="selectById" parameterType="Long" resultMap="map1">
        select *
        from sys_warning
        where warning_id = #{warningId}
</select>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值