项目中,我们经常会遇到上报数据的功能,今天小编就和大家从数据库到后端,再从后端到前端页面,一起实现这一功能。
逻辑:首先我需要查询表中的数据,查询到后再进行修改,修改的同时,状态也会修改。
一、我们首先设计数据库,命名规范,命名字段这些我就不多说了,只截取这一部分字段。
二、dao层写修改状态的接口。
/**
* @Description 更新上报状态
* @param
* @return
* @Author ying.wang1
* @Date 2022年03月14日 上午11:07:16
*/
int updateReportStatusByBusIds(@Param("reportStatus")int reportStatus, @Param("list") List<String> list);
三、mapper层写sql。
1、添加字段。
<resultMap>
<result column="reportStatus" property="reportStatus" jdbcType="VARCHAR" />
</resultMap>
2、sql上添加字段,我没写全部的字段,只写了部分。
<sql id="Base_Column_List" >
modifyTime,claimTypeId
orgCode, isDelete, createrId, createrName, createTime, modifierId, modifierName,
modifyTime,claimTypeId, reportStatus
</sql>
3、查询条件添加字段。
<!-- 查询纠纷列表-->
<select id="queryDsDetailList" resultType="com.pcitc.slms.ds.system.dto.DsDetailDto" parameterType="java.util.Map" >
select
dsd.dsDetailId,
dsd.endCaseReduce,
dsd.createTime,
dsd.reportStatus,
group_concat(DISTINCT dsl.lawyerName) as lawyerNames,
group_concat(DISTINCT CASE WHEN dsp.legalStatus = 1 THEN dsp.partyName END) as sourceMan,
LEFT JOIN ds_party dsp on dsd.dsDetailId = dsp.dsDetailId and dsp.isDelete = 0
where dsd.isDelete = 0
<if test="disputesBeginTime != null and disputesBeginTime != ''">
and dsd.disputesBeginTime >= #{disputesBeginTime,jdbcType=TIMESTAMP}
</if>
<if test="disputesEndTime != null and disputesEndTime != ''">
and dsd.disputesBeginTime <= #{disputesEndTime,jdbcType=TIMESTAMP}
</if>
<if test="reportStatus != null and reportStatus != ''">
and dsd.reportStatus = #{reportStatus,jdbcType=VARCHAR}
</if>
GROUP BY dsd.dsDetailId
order by createTime desc
4、更新上报信息(对应刚才dao的接口)。
<!-- 更新上报状态信息-->
<update id="updateReportStatusByBusIds" parameterType="com.pcitc.slms.ds.system.entity.DsDetail" >
update ds_detail
<set >
<if test="reportStatus != null" >
reportStatus = #{reportStatus,jdbcType=VARCHAR},
</if>
</set>
where dsDetailId in
<foreach collection="list" index="index" item="id" separator="," close=")" open="(">
#{id}
</foreach>
</update>
四、service接口。
/**
* @Description 上报纠纷信息
* @param
* @return
* @Author ying.wang1
* @Date 2022年03月14日 上午09:18:47
*/
boolean disputeUp(List<String> ids);
五、Impl实现。
@Override
@Transactional(rollbackFor = Exception.class)
public boolean disputeUp(List<String> ids) {
DsDetailDto disputeList = new DsDetailDto();
//调用成功后将状态改为上报成功
int num = dsDetailDao.updateReportStatusByBusIds(1,ids);
if(num > 0){
return true;
}else{
return false;
}
}
六、controller接口。
/**上报纠纷信息
* @param [ids]
* @author t-aiai.gao
* @date 2022/9/9 14:20
* @return com.pcitc.slms.common.dto.ResultInfoDTO<java.lang.Boolean>
**/
@RequestMapping(value = "/disputeUp", method = RequestMethod.POST)
public ResultInfoDTO<Boolean> disputeUp(@RequestBody List<String> ids){
ResultInfoDTO<Boolean> infoDTO = new ResultInfoDTO<Boolean>();
if(CollectionUtils.isNotEmpty(ids)){
log.info("上报纠纷信息开始===================>");
boolean result = dsDetailService.disputeUp(ids);
infoDTO.setReturnValue(true);
infoDTO.setData(result);
infoDTO.setMsg("上报纠纷信息成功!");
log.info("上报纠纷信息结束====================>");
}
return infoDTO;
}
七、前端页面之html。
<div class="ivu-form-item-content-x-lg">
<!--<div class="input-radio-box">-->
<!--业务暂未开放,确认后开放
<input class="ipt-type mr3" type="radio" name="choseUp"
value="1" checked/>已选中
<input class="ipt-type mr3" style="margin-left: 10px;" type="radio"
name="choseUp" value="0" />未选中-->
<button class="ipt-btn btnprimary mr5" type="button"
onclick="upData()">上报
</button>
<!--</div>-->
</div>
八、前端页面之js。
1、点击上报。
//点击上报
function upData() {
var checkVal = $("input[name='choseUp']:checked").val();
var choseYesIds = $("#ds-up-list").jqGrid('getGridParam', 'selarrrow');
console.log(choseYesIds)
var allIds = $("#ds-up-list").getDataIDs();
//已选中;未选中
if(checkVal == 1){
if(choseYesIds.length <= 0) {
layer.confirm("请至少选中一条数据!", {
icon: 2,
title: '提示'
},
function (e) {
layer.close(e);
});
}else{
disputeUp(choseYesIds)
}
}else if(checkVal == 0){
var choseNoIds = allIds.filter(function (val) { return !(choseYesIds.indexOf(val) > -1) })
.concat(choseYesIds.filter(function (val) { return !(allIds.indexOf(val) > -1) }))
disputeUp(choseNoIds)
}
}
2、调用接口。
//调用上报后台接口
function disputeUp(ids) {
if(ids.length > 0){
layer.confirm("确定上报?", {
icon: 3,
title: '提示'
},
function () {
$.ajax({
type: "POST",
contentType: "application/json",
url: "/请求名称/请求路径/请求方法",
dataType: "json",
data: JSON.stringify(ids),
success: function (data) {
if (data && data.returnValue) {
layer.msg("上报成功", {time: 1500, icon: 1}, function () {
刷新本表
});
} else {
layer.msg(data.msg, {time: 2000, icon: 2}, function () {
刷新另一个表
});
}
},
error: function () {
layer.msg("上报异常", {time: 2000, icon: 2}, function () {
刷新本表
});
},
});
});
}else{
layer.confirm("请至少选中一条数据!", {
icon: 2,
title: '提示'
},
function (e) {
layer.close(e);
});
}
}
如此,便能实现上报功能了。