Java Code Examples for com.jfinal.plugin.activerecord.Db#update()
The following examples show how to use
com.jfinal.plugin.activerecord.Db#update() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductViewsCountUpdateTask.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void run() { if (countsMap.isEmpty()) { return; } Map<Long, AtomicLong> articleViews = new HashMap<>(countsMap); countsMap.clear(); for (Map.Entry<Long, AtomicLong> entry : articleViews.entrySet()) { Db.update("update product set real_view_count = real_view_count + " + entry.getValue().get() + " where id = ? ", entry.getKey()); Db.update("update product set view_count = view_count + " + entry.getValue().get() + " where id = ? ", entry.getKey()); Aop.get(ProductService.class).removeCacheById(entry.getKey()); } }
Example 2
Source File: ArticleCommentReplyCountUpdateTask.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void run() { if (countsMap.isEmpty()) { return; } Map<Long, AtomicLong> articleViews = new HashMap<>(countsMap); countsMap.clear(); for (Map.Entry<Long, AtomicLong> entry : articleViews.entrySet()) { Db.update("update article_comment set reply_count = reply_count + " + entry.getValue().get() + " where id = ? ", entry.getKey()); Aop.get(ArticleCommentService.class).deleteCacheById(entry.getKey()); } }
Example 3
Source File: ProductCommentsCountUpdateTask.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void run() { if (countsMap.isEmpty()) { return; } Map<Long, AtomicLong> articleViews = new HashMap<>(countsMap); countsMap.clear(); for (Map.Entry<Long, AtomicLong> entry : articleViews.entrySet()) { Db.update("update product set comment_count = comment_count + " + entry.getValue().get() + " where id = ? ", entry.getKey()); Aop.get(ProductService.class).removeCacheById(entry.getKey()); } }
Example 4
Source File: SysRoleController.java From my_curd with Apache License 2.0 | 6 votes |
/** * 角色配置权限 菜单更新 */ @Before(Tx.class) public void menuTreeUpdate() { String roleId = get("roleId"); String menuIds = get("menuIds"); if (StringUtils.isEmpty(roleId)) { renderFail("roleId 参数不可为空."); return; } // 删除 角色原有菜单 String deleteSql = "delete from sys_role_menu where sysRoleId = ?"; Db.update(deleteSql, roleId); // 添加 角色新菜单 if (StringUtils.notEmpty(menuIds)) { String[] menuIdAry = menuIds.split(","); for (String menuId : menuIdAry) { SysRoleMenu sysRoleMenu = new SysRoleMenu(); sysRoleMenu.setSysRoleId(roleId).setSysMenuId(menuId) .setCreater(WebUtils.getSessionUsername(this)) .setCreateTime(new Date()) .save(); } } renderSuccess("菜单权限操作成功"); }
Example 5
Source File: SysConfigServiceImpl.java From sdb-mall with Apache License 2.0 | 5 votes |
@Override @JFinalTx public void updateValueByKey(String key, String value) { SqlPara sqlPara = Db.getSqlPara("sysConfig.updateValueByKey", Kv.by("paramValue", value).set("paramKey", key)); Db.update(sqlPara); sysConfigRedis.delete(key); }
Example 6
Source File: SysDictController.java From my_curd with Apache License 2.0 | 5 votes |
/** * 删除 sysDict */ @Before(IdsRequired.class) public void deleteDictAction() { String ids = getPara("ids").replaceAll(",", "','"); String sql = "update sys_dict set delFlag = 'X' where id in ('" + ids + "')"; Db.update(sql); renderSuccess(DELETE_SUCCESS); }
Example 7
Source File: ExSingleTableController.java From my_curd with Apache License 2.0 | 5 votes |
/** * 删除 action */ @Before(IdsRequired.class) public void deleteAction() { String ids = getPara("ids").replaceAll(",", "','"); String deleteSql = "delete from ex_single_table where id in ( '" + ids + "' ) "; Db.update(deleteSql); renderSuccess(DELETE_SUCCESS); }
Example 8
Source File: BusinessFormInfoController.java From my_curd with Apache License 2.0 | 5 votes |
/** * 删除 action */ @Before(IdsRequired.class) public void deleteAction() { String ids = getPara("ids").replaceAll(",", "','"); String deleteSql = "delete from business_form_info where id in ( '" + ids + "' ) "; Db.update(deleteSql); renderSuccess(DELETE_SUCCESS); }
Example 9
Source File: SysUserController.java From my_curd with Apache License 2.0 | 5 votes |
/** * 重置密码 */ @Before(IdsRequired.class) public void resetPwd() { String ids = getPara("ids").replaceAll(",", "','"); String sha1Pwd = HashKit.sha1(DEFAULT_PWD); String sql = "update sys_user set password = ? where id in ('" + ids + "')"; Db.update(sql, sha1Pwd); renderSuccess("重置密码成功。新密码: " + DEFAULT_PWD); }
Example 10
Source File: SysSettingController.java From my_curd with Apache License 2.0 | 5 votes |
/** * 删除 action */ @Before(IdsRequired.class) public void deleteAction() { String ids = getPara("ids").replaceAll(",", "','"); String deleteSql = "delete from sys_setting where id in ( '" + ids + "' ) "; Db.update(deleteSql); refreshSetting(); renderSuccess(DELETE_SUCCESS); }
Example 11
Source File: UserOrderItemServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean doSubtractProductCountById(Object id, Long userId) { return Db.update("update user_order_item set product_count = product_count - 1 " + " where id = ? && product_count > 1 && buyer_id = ?", id, userId) > 0; }
Example 12
Source File: MemberPriceServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void saveOrUpdateByProduct(String productType, Long productId, String[] memberGroupIds, String[] memberGroupPrices) { if (memberGroupIds == null || memberGroupPrices == null || memberGroupIds.length == 0) { Db.update("delete from member_price where product_id = ?", productId); return; } //这种情况应该不可能出现 if (memberGroupIds.length != memberGroupPrices.length) { return; } for (int i = 0; i < memberGroupIds.length; i++) { String memberGroupId = memberGroupIds[i]; String memberGroupPrice = memberGroupPrices[i]; MemberPrice existModel = findByPorductAndGroup(productType, productId, memberGroupId); //删除之前的数据 if (existModel != null && StrUtil.isBlank(memberGroupPrice)) { delete(existModel); continue; } //更新之前的数据 else if (existModel != null && StrUtil.isNotBlank(memberGroupPrice)) { existModel.setPrice(new BigDecimal(memberGroupPrice)); update(existModel); continue; } //创建新的数据 else if (existModel == null && StrUtil.isNotBlank(memberGroupPrice)) { existModel = new MemberPrice(); existModel.setProductType(productType); existModel.setProductId(productId); existModel.setGroupId(Long.valueOf(memberGroupId)); existModel.setPrice(new BigDecimal(memberGroupPrice)); existModel.setCreated(new Date()); save(existModel); } // else if (existModel == null && StrUtil.isBlank(memberGroupPrice)) {} } }
Example 13
Source File: InstallController.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
/** * 初始化第一个用户 * * @param username * @param pwd */ private void initFirstUser(String username, String pwd) { if (StrUtil.isBlank(username) || StrUtil.isBlank(pwd)) { return; } UserService userService = Aop.get(UserService.class); User user = userService.findById(1L); if (user == null) { user = new User(); user.setNickname(username); user.setRealname(username); user.setCreateSource(User.SOURCE_WEB_REGISTER); user.setCreated(new Date()); user.setActivated(new Date()); } String salt = HashKit.generateSaltForSha256(); String hashedPass = HashKit.sha256(salt + pwd); user.setSalt(salt); user.setPassword(hashedPass); user.setUsername(username); if (StrUtil.isEmail(username)) { user.setEmail(username.toLowerCase()); } user.setStatus(User.STATUS_OK); userService.saveOrUpdate(user); RoleService roleService = Aop.get(RoleService.class); Role role = roleService.findById(1L); if (role == null) { role = new Role(); role.setCreated(new Date()); } role.setName("默认角色"); role.setDescription("这个是系统自动创建的默认角色"); role.setFlag(Role.ADMIN_FLAG); role.setModified(new Date()); roleService.saveOrUpdate(role); Db.update("DELETE FROM `user_role_mapping` WHERE `user_id` = 1"); Db.update("INSERT INTO `user_role_mapping` (`user_id`, `role_id`) VALUES (1, 1)"); }
Example 14
Source File: AccountAPIController.java From jfinal-api-scaffold with MIT License | 4 votes |
/** * 用户注册 */ @ClearInterceptor() public void register(){ //必填信息 String loginName = getPara("loginName");//登录帐号 int code = getParaToInt("code", 0);//手机验证码 int sex = getParaToInt("sex", 0);//性别 String password = getPara("password");//密码 String nickName = getPara("nickName");//昵称 //头像信息,为空则使用默认头像地址 String avatar = getPara("avatar", AppProperty.me().defaultUserAvatar()); //校验必填项参数 if(!notNull(Require.me() .put(loginName, "loginName can not be null") .put(code, "code can not be null")//根据业务需求决定是否使用此字段 .put(password, "password can not be null") .put(nickName, "nickName can not be null"))){ return; } //检查账户是否已被注册 if (Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null) { renderJson(new BaseResponse(Code.ACCOUNT_EXISTS, "mobile already registered")); return; } //检查验证码是否有效, 如果业务不需要,则无需保存此段代码 if (Db.findFirst("SELECT * FROM t_register_code WHERE mobile=? AND code = ?", loginName, code) == null) { renderJson(new BaseResponse(Code.CODE_ERROR,"code is invalid")); return; } //保存用户数据 String userId = RandomUtils.randomCustomUUID(); new User() .set("userId", userId) .set(User.LOGIN_NAME, loginName) .set(User.PASSWORD, StringUtils.encodePassword(password, "md5")) .set(User.NICK_NAME, nickName) .set(User.CREATION_DATE, DateUtils.getNowTimeStamp()) .set(User.SEX, sex) .set(User.AVATAR, avatar) .save(); //删除验证码记录 Db.update("DELETE FROM t_register_code WHERE mobile=? AND code = ?", loginName, code); //返回数据 renderJson(new BaseResponse("success")); }
Example 15
Source File: SinglePageServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean deleteByIds(Object... ids) { return Db.update("delete from single_page where id in " + SqlUtils.buildInSqlPara(ids)) > 0; }
Example 16
Source File: UserRoleServiceImpl.java From jboot-admin with Apache License 2.0 | 4 votes |
@Override public int deleteByUserId(Long userId) { return Db.update("delete from sys_user_role where user_id = ?", userId); }
Example 17
Source File: WechatReplyServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean deleteByIds(Object... ids) { return Db.update("delete from wechat_reply where id in " + SqlUtils.buildInSqlPara(ids)) > 0; }
Example 18
Source File: User.java From zrlog with Apache License 2.0 | 4 votes |
public boolean updatePassword(int userId, String password) { return Db.update("update " + TABLE_NAME + " set password=? where userId=?", password, userId) > 0; }
Example 19
Source File: SinglePageCommentServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void doIncCommentReplyCount(long commentId) { Db.update("update single_page_comment set reply_count = reply_count + 1" + " where id = ? ", commentId); }
Example 20
Source File: RoleResServiceImpl.java From jboot-admin with Apache License 2.0 | 4 votes |
@Override public int deleteByRoleId(Long roleId) { return Db.update("delete from sys_role_res where role_id = ?", roleId); }