You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tianze-pro/web/src/main/java/com/ibeetl/jlw/service/StudentAccountAssetAllocati...

252 lines
10 KiB
Java

package com.ibeetl.jlw.service;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.jwt.JWTUtil;
import cn.jlw.util.ToolUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ibeetl.admin.core.service.CoreBaseService;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.admin.core.web.JsonReturnCode;
import com.ibeetl.jlw.dao.StudentAccountAssetAllocationDao;
import com.ibeetl.jlw.entity.LoginTodo;
import com.ibeetl.jlw.entity.ResourcesApplication;
import com.ibeetl.jlw.entity.StudentAccountAssetAllocation;
import com.ibeetl.jlw.web.query.StudentAccountAssetAllocationQuery;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.SqlId;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
/**
* Service
* ID使insert(*,true)
*/
@Service
@Transactional
@Validated
public class StudentAccountAssetAllocationService extends CoreBaseService<StudentAccountAssetAllocation>{
@Autowired private StudentAccountAssetAllocationDao studentAccountAssetAllocationDao;
@Autowired private LoginTodoService loginTodoService;
@Autowired private ResourcesApplicationService resourcesApplicationService;
public PageQuery<StudentAccountAssetAllocation>queryByCondition(PageQuery query){
PageQuery ret = studentAccountAssetAllocationDao.queryByCondition(query);
queryListAfter(ret.getList());
return ret;
}
public PageQuery<StudentAccountAssetAllocation>queryByConditionQuery(PageQuery query){
PageQuery ret = studentAccountAssetAllocationDao.queryByConditionQuery(query);
queryListAfter(ret.getList());
return ret;
}
public void deleteByList(List list){
String ids = "";
ToolUtils.deleteNullList(list);
for(int i=0;null != list && i<list.size();i++){
ids += list.get(i).toString()+(i==list.size()-1?"":",");
}
if(StringUtils.isNotBlank(ids)){
studentAccountAssetAllocationDao.deleteStudentAccountAssetAllocationByIds(ids);
}
}
public void deleteStudentAccountAssetAllocation(String ids){
try {
studentAccountAssetAllocationDao.deleteStudentAccountAssetAllocationByIds(ids);
} catch (Exception e) {
throw new PlatformException("批量删除资产账户管理失败", e);
}
}
public String addAll(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
String msg = "";
List<StudentAccountAssetAllocation> studentAccountAssetAllocationList = new ArrayList<>();
try {
studentAccountAssetAllocationList = JSON.parseArray(studentAccountAssetAllocationQuery.getStudentAccountAssetAllocationJsonStr(), StudentAccountAssetAllocation.class);
} catch (Exception e) {
try {
studentAccountAssetAllocationList.add(JSONObject.parseObject(studentAccountAssetAllocationQuery.getStudentAccountAssetAllocationJsonStr(), StudentAccountAssetAllocation.class));
} catch (Exception e1) {}
}
ToolUtils.deleteNullList(studentAccountAssetAllocationList);
if(null != studentAccountAssetAllocationList && studentAccountAssetAllocationList.size()>0){
for(int i=0;i<studentAccountAssetAllocationList.size();i++){
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationList.get(i);
studentAccountAssetAllocation.setUserId(studentAccountAssetAllocationQuery.getUserId());
studentAccountAssetAllocation.setOrgId(studentAccountAssetAllocationQuery.getOrgId());
}
insertBatch(studentAccountAssetAllocationList);
}
return msg;
}
public JsonResult add(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
String msg = "";
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationQuery.pojo();
studentAccountAssetAllocationDao.insert(studentAccountAssetAllocation);
studentAccountAssetAllocationQuery.setId(studentAccountAssetAllocation.getId());
JsonResult jsonResult = new JsonResult();
jsonResult.setData(studentAccountAssetAllocation.getId());//自增的ID丢进去
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
jsonResult.setMsg(msg);
return jsonResult;
}
public String edit(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
String msg = "";
StudentAccountAssetAllocation studentAccountAssetAllocation = studentAccountAssetAllocationQuery.pojo();
studentAccountAssetAllocationDao.updateTemplateById(studentAccountAssetAllocation);
return msg;
}
public String updateGivenByIds(StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
String msg = "";
if(StringUtils.isNotBlank(studentAccountAssetAllocationQuery.get_given())){
boolean flag = studentAccountAssetAllocationDao.updateGivenByIds(studentAccountAssetAllocationQuery) > 0;
if(!flag){
msg = "更新指定参数失败";
}
}else{
msg = "指定参数为空";
}
return msg;
}
public List<StudentAccountAssetAllocation> getValues (Object paras){
return sqlManager.select(SqlId.of("jlw.studentAccountAssetAllocation.getStudentAccountAssetAllocationValues"), StudentAccountAssetAllocation.class, paras);
}
public List<StudentAccountAssetAllocation> getValuesByQuery (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
return studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
}
public List<StudentAccountAssetAllocation> getValuesByQueryNotWithPermission (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
return studentAccountAssetAllocationDao.getValuesByQueryNotWithPermission(studentAccountAssetAllocationQuery);
}
public StudentAccountAssetAllocation getInfo (Long id){
StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery = new StudentAccountAssetAllocationQuery();
studentAccountAssetAllocationQuery.setId(id);
List<StudentAccountAssetAllocation> list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
if(null != list && list.size()>0){
return list.get(0);
}else{
return null;
}
}
public StudentAccountAssetAllocation getInfo (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){
List<StudentAccountAssetAllocation> list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery);
if(null != list && list.size()>0){
return list.get(0);
}else{
return null;
}
}
/**
* : <br>
* tokenupdateVersion
*
* @param applicationToken
* @param param
* @Author: 87966
* @Date: 2023/3/6 16:31
*/
public void updateByApplicationToken(@NotBlank(message = "applicationToken 传递的token不能为空") String applicationToken, StudentAccountAssetAllocationQuery param) {
// 获取资金账户信息
List<StudentAccountAssetAllocation> accountAssetAllocationList = getByApplicationToken(applicationToken, param);
Assert.isTrue(accountAssetAllocationList.size() == 1, "无法对多个账户进行修改操作!");
Assert.notNull(param.getUpdateVersion(), "更新操作updateVersion 为必传项!");
// 主键拿过来
param.setId(accountAssetAllocationList.get(0).getId());
updateTemplate(param.pojo());
}
/**
* : <br>
* token
*
* @param applicationToken token
* @param param
* @return {@link List< StudentAccountAssetAllocation>}
* @Author: 87966
* @Date: 2023/3/6 16:32
*/
public List<StudentAccountAssetAllocation> getByApplicationToken(@NotBlank(message = "applicationToken 传递的token不能为空") String applicationToken, StudentAccountAssetAllocationQuery param) {
LoginTodo loginTodo = validateAndGetLoginTodo(applicationToken);
// 学生ID
final String studentId = loginTodo.getStudentid();
Assert.notEmpty(studentId, "该接口只允许学生访问!");
// 应用ID
final String applicationId = loginTodo.getApplicationId();
// 院校ID
final String universitiesCollegesId = loginTodo.getSchoolid();
Assert.isTrue(StrUtil.isAllNotEmpty(studentId, applicationId, universitiesCollegesId), "学生ID、应用ID、院校ID都不能为空");
// 从token中获取必要条件
param.setStudentId(Long.valueOf(studentId));
param.setApplicationId(Long.valueOf(applicationId));
param.setUniversitiesCollegesId(Long.valueOf(universitiesCollegesId));
List<StudentAccountAssetAllocation> accountAssetAllocation = getValuesByQueryNotWithPermission(param);
Assert.notNull(accountAssetAllocation, "账户不存在!");
return accountAssetAllocation;
}
/**
*
*
* @param applicationToken token
* @return
*/
private LoginTodo validateAndGetLoginTodo(String applicationToken) {
LoginTodo payload = loginTodoService.getPayloadByString(applicationToken);
Assert.notNull(payload, "回传的token不是有效的加密串");
ResourcesApplication resourcesApplication = resourcesApplicationService.queryById(payload.getApplicationId());
Assert.notNull(resourcesApplication, "未查询到应用的相关信息!");
boolean verify = JWTUtil.verify(applicationToken, resourcesApplication.getLinkSecretKey().getBytes(StandardCharsets.UTF_8));
Assert.isTrue(verify, "token被修改过更新失败");
return payload;
}
/**
*
*/
public void createFundAccountWithUserCreated() {
}
}