package com.nq.service.impl;
|
|
import com.nq.common.ServerResponse;
|
import com.nq.dao.SitePayOptionMapper;
|
import com.nq.pojo.SitePayOption;
|
import com.nq.service.ISitePayOptionService;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Service
|
public class SitePayOptionServiceImpl implements ISitePayOptionService {
|
|
@Resource
|
private SitePayOptionMapper sitePayOptionMapper;
|
|
@Override
|
public ServerResponse listForAdmin() {
|
List<SitePayOption> list = sitePayOptionMapper.listAllOrderBySort();
|
return ServerResponse.createBySuccess(list);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public ServerResponse updateSort(List<Integer> orderedIds) {
|
if (CollectionUtils.isEmpty(orderedIds)) {
|
return ServerResponse.createByErrorMsg("排序数据不能为空");
|
}
|
for (int i = 0; i < orderedIds.size(); i++) {
|
Integer id = orderedIds.get(i);
|
int param = i;
|
int sortOrder = i;
|
sitePayOptionMapper.updateParamAndSortOrder(id, param, sortOrder);
|
}
|
return ServerResponse.createBySuccessMsg("排序已更新");
|
}
|
|
@Override
|
public ServerResponse setEnabled(Integer id, Integer enabled) {
|
if (id == null) {
|
return ServerResponse.createByErrorMsg("id不能为空");
|
}
|
if (enabled == null || (enabled != 0 && enabled != 1)) {
|
return ServerResponse.createByErrorMsg("enabled 只能为 0 或 1");
|
}
|
int n = sitePayOptionMapper.updateEnabled(id, enabled);
|
if (n > 0) {
|
return ServerResponse.createBySuccessMsg(enabled == 1 ? "已开启" : "已关闭");
|
}
|
return ServerResponse.createByErrorMsg("操作失败");
|
}
|
|
@Override
|
public ServerResponse listForH5() {
|
List<SitePayOption> list = sitePayOptionMapper.listEnabledOrderBySort();
|
return ServerResponse.createBySuccess(list);
|
}
|
}
|