controller
@ApiOperation(value = "添加文章")@PostMapping("/addwengzhang")public String addwengzhang(@RequestBody WengDto wengDto) {if (wengDto.getContent() == null || wengDto.getTitle() == null) {return "参数不可为空";}User user = userMapper.selctbyOpenID(wengDto.getOpenid());Wenzhang wenzhang = new Wenzhang();wenzhang.setTitle(wengDto.getTitle());wenzhang.setContent(wengDto.getContent());wenzhang.setImage(wengDto.getImage());wenzhang.setMpopenid(wengDto.getOpenid());wenzhang.setTags(null);wenzhang.setUserid(user.getUsername());wenzhang.setId(String.valueOf(new Random().nextInt(1000000000)));TimeZone chinaTimeZone = TimeZone.getTimeZone("Asia/Shanghai");Date chinaCurrentTime = new Date();chinaCurrentTime.setTime(chinaCurrentTime.getTime() + chinaTimeZone.getRawOffset());wenzhang.setCreatetime(chinaCurrentTime);wenzhang.setUpdatetime(chinaCurrentTime);wenzhang.setFavournum(0);wenzhang.setThumbnum(0);wenzhangService.addwenzhang(wenzhang);Document document = new Document();document.setOpenid(wengDto.getOpenid());Random random = new Random();document.setId(random.nextInt(100000000) + 1);LocalDateTime china = LocalDateTime.now(); // Get current time in China timezoneDateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");document.setTime(china.format(formatter));document.setWenzhangname(wengDto.getTitle());document.setCoin(2);documentMapper.insertDocument(document);User use = userMapper.selectByMpOpenId(wengDto.getOpenid());if (use != null) {user.setCoin(user.getCoin() + 2);userMapper.updateUserCoins(user);}
发布文章积分自动增加
maper
@Update("UPDATE user SET coin = #{coin} WHERE mpOpenId = #{mpopenid}")void updateUserCoins(User user);