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{ @Autowired private StudentAccountAssetAllocationDao studentAccountAssetAllocationDao; @Autowired private LoginTodoService loginTodoService; @Autowired private ResourcesApplicationService resourcesApplicationService; public PageQueryqueryByCondition(PageQuery query){ PageQuery ret = studentAccountAssetAllocationDao.queryByCondition(query); queryListAfter(ret.getList()); return ret; } public PageQueryqueryByConditionQuery(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 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 0; if(!flag){ msg = "更新指定参数失败"; } }else{ msg = "指定参数为空"; } return msg; } public List getValues (Object paras){ return sqlManager.select(SqlId.of("jlw.studentAccountAssetAllocation.getStudentAccountAssetAllocationValues"), StudentAccountAssetAllocation.class, paras); } public List getValuesByQuery (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){ return studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery); } public List getValuesByQueryNotWithPermission (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){ return studentAccountAssetAllocationDao.getValuesByQueryNotWithPermission(studentAccountAssetAllocationQuery); } public StudentAccountAssetAllocation getInfo (Long id){ StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery = new StudentAccountAssetAllocationQuery(); studentAccountAssetAllocationQuery.setId(id); List list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery); if(null != list && list.size()>0){ return list.get(0); }else{ return null; } } public StudentAccountAssetAllocation getInfo (StudentAccountAssetAllocationQuery studentAccountAssetAllocationQuery){ List list = studentAccountAssetAllocationDao.getValuesByQuery(studentAccountAssetAllocationQuery); if(null != list && list.size()>0){ return list.get(0); }else{ return null; } } /** * 功能描述:
* 通过token、updateVersion来更新属性 * * @param applicationToken * @param param * @Author: 87966 * @Date: 2023/3/6 16:31 */ public void updateByApplicationToken(@NotBlank(message = "applicationToken 传递的token不能为空!") String applicationToken, StudentAccountAssetAllocationQuery param) { // 获取资金账户信息 List accountAssetAllocationList = getByApplicationToken(applicationToken, param); Assert.isTrue(accountAssetAllocationList.size() == 1, "无法对多个账户进行修改操作!"); Assert.notNull(param.getUpdateVersion(), "更新操作,updateVersion 为必传项!"); // 主键拿过来 param.setId(accountAssetAllocationList.get(0).getId()); updateTemplate(param.pojo()); } /** * 功能描述:
* 通过token获取资金账户 * * @param applicationToken token * @param param 一些参数 * @return {@link List< StudentAccountAssetAllocation>} * @Author: 87966 * @Date: 2023/3/6 16:32 */ public List 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 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() { } }